static int s_iTargetUPS = 100;
static float s_fAccUpdateWait = 0;
+static int s_iTargetFPS = 100;
+static float s_fAccDrawWait = 0;
+
static int s_iUPS, s_iFPS;
static int s_iUpdateCount, s_iDrawCount;
static MICRO s_micLastSecond;
if(s_iMinWaitMicro < s_fAccUpdateWait)
{
- int iWaits = s_fAccUpdateWait / s_iMinWaitMicro;
+ int iWaits = (int)(s_fAccUpdateWait / s_iMinWaitMicro);
s_fAccUpdateWait -= iWaits * s_iMinWaitMicro;
SDL_Delay(iWaits * s_iMinWaitMilli);
}
while(s_bIsRunning)
{
- draw();
+ MICRO time = tickCountMicro();
+ draw();
+ time = tickCountMicro() - time;
+
+ float wait = (1000000.0 / s_iTargetFPS - time);
+ s_fAccDrawWait += 0 < wait ? wait : 0;
+
+ if(s_iMinWaitMicro < s_fAccDrawWait)
+ {
+ int iWaits = (int)(s_fAccDrawWait / s_iMinWaitMicro);
+ s_fAccDrawWait -= iWaits * s_iMinWaitMicro;
+ SDL_Delay(iWaits * s_iMinWaitMilli);
+ }
}
drawClean();