int gameOn = 1
int simulationTime = 0;
while (1){
int realTime = Gettime();
while (simulationTime < realTime){
simulationTime += 16; //Timeslice is ALWAYS 16ms.
UpdateWorld(16);
}
RenderWorld();
}
This system is very well known in the game industry and is actually the keystone of games such as Starcraft II or id Software engines !
I measured the time inside the second while, and it always alternates between 0 and 1 ms (using SDL_GetTicks). While the frame rate outside the loop remains variable. (Different FPS values on each iteration.)
I also don't understand why the argument 16 is necessary in his “UpdateWorld” function.
Furthermore, the second loop runs exactly once every frame on my machine. I don't see how this is supposed to work at all. Do you?
Source:
- https://www.fabiensanglard.net/timer_and_framerate/index.php