尽管以下代码可以节省一些电量,但 FPS 的上限并不正确。当它应该将帧速率锁定在 60 FPS 时,我得到 82。30 帧也是如此,我得到 49 FPS。
计算 FPS:
previousTime = currentTime;
currentTime = SDL_GetTicks();
fps_++;
if (currentTime - lastOutput >= 1000)
{
lastOutput = currentTime;
fps = fps_; // the variable 'fps' is displayed
fps_ = 0;
}
限制FPS:
if (currentTime - previousTime < 1000 / maxFPS)
{
SDL_Delay(1000 / maxFPS - currentTime + previousTime);
}
我搞砸了什么?