Created
August 8, 2014 12:36
-
-
Save REPOmAN2v2/33e936151b5a5d08e4c0 to your computer and use it in GitHub Desktop.
Fixed timestep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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