Skip to content

Instantly share code, notes, and snippets.

@REPOmAN2v2
Created August 8, 2014 12:36
Show Gist options
  • Save REPOmAN2v2/33e936151b5a5d08e4c0 to your computer and use it in GitHub Desktop.
Save REPOmAN2v2/33e936151b5a5d08e4c0 to your computer and use it in GitHub Desktop.
Fixed timestep
int main(void)
{
int frames = 0;
double fpstimer;
double ticktimer = 0.0;
double last;
last = dtime();
while (1) {
double now = getTime();
double dt = now - last;
last = now;
// they need to advance with the same frame delta
ticktimer += dt;
fpstimer += dt;
// 128fps
if (ticktimer >= 1.0/128.0) {
++frames;
ticktimer -= 1.0/128.0;
// should not reset to 0, you might have uneven residue left
// so you should decrease by exactly one timestep
}
if (fpstimer >= 1.0) {
printf("fps: %d\n", frames);
frames = 0;
fpstimer -= 1.0;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment