gpt4 book ai didi

c++ - 我是否正确计算了我的 FPS?

转载 作者:太空狗 更新时间:2023-10-29 20:30:51 31 4
gpt4 key购买 nike

所以我想知道我是否正确计算了我的 FPS:

Uint32 delayFrom(float startTime, float endTime){
return(endTime - startTime );
}


int main(){
int numFrames = 0;
Uint32 startTime = SDL_GetTicks();
while(!done){
frameTime = 0;
float fps = ( numFrames/(float)(SDL_GetTicks() - startTime) )*1000;
cout << fps << endl;
SDL_Delay(delayFrom(frameTime, 1/60));
++numFrames;
}
}

最佳答案

int main() {
int numFrames = 0;
Uint32 startTime = SDL_GetTicks();
while (!done) {
++numFrames;
Uint32 elapsedMS = SDL_GetTicks() - startTime; // Time since start of loop
if (elapsedMS) { // Skip this the first frame
double elapsedSeconds = elapsedMS / 1000.0; // Convert to seconds
double fps = numFrames / elapsedSeconds; // FPS is Frames / Seconds
cout << fps << endl;
}
SDL_Delay(1.0/60.0); // Use floating point division, not integer
}
}

关于c++ - 我是否正确计算了我的 FPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5614018/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com