0
#define FPS_INTERVAL 1.0 //seconds.
Uint32 fps_lasttime = SDL_GetTicks(); //the last recorded time.
Uint32 fps_current; //the current FPS.
Uint32 fps_frames = 0; //frames passed since the last recorded fps.
// you would initalise these in a main method, really.
void loop()
{
//YOUR PAINTING STUFF HERE...
//********//
fps_frames++;
if (fps_lasttime < SDL_GetTicks() - FPS_INTERVAL*1000)
{
fps_lasttime = SDL_GetTicks();
fps_current = fps_frames;
fps_frames = 0;
}
}
我把上面的代碼來自: http://sdl.beuc.net/sdl.wiki/SDL_Average_FPS_Measurement計算FPS使用SDL 2.0
我理解的代碼,但FPS_INTERVAL混淆了我,因爲我實在無法理解爲什麼需要它的if語句。有人可以解釋這個嗎?
而且我也必須使用Uint32或將任何int做這項工作,爲什麼?
我在YouTube教程中看到,程序員只使用'int'而不使用'uint32' –
如果「程序員」決定混合具有可能不同大小的帶符號值和無符號值,他將負責解決所有衝突。爲什麼你想要那個? –
我不打算使用任何其他類型。我只是想知道爲什麼在該教程中程序員使用int,但無論如何感謝您的幫助! –