[英]Calculating FPS With SDL 2.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_INTERVAL使我感到困惑,因為我真的無法理解為什么if語句中需要它。 有人可以解釋嗎?
而且我是否必須使用Uint32或任何int可以完成工作,為什么?
SDL_GetTicks()
返回毫秒數; FPS_INTERVAL
指定計數幀的秒數(此處為-1); 將其乘以1000得到毫秒數。
回復: SDL_GetTicks()
返回的內容。 您還會使用其他什么類型,為什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.