For those familiar with Dewitter's game loop, I could use your help understanding some parts of it

Here: http://www.koonsolo.com/news/dewitters-gameloop/ Is the link to the original article. and Here : http://pastebin.com/zAxrzKtv is the link to the code I need help with understanding. Now I understand generally what the entire loop does but the thing I have an issue with understanding is the condition in the while loop that updates the game state that checks to see if loops is less than Max_Frame_Skips.Now I know its supposed do something with creating a minimum frame-rate the game can have but I just don't get how it does it. what is really going on there? and another problem I am having is understanding the whole interpolation thing and I have no idea what is means, how its calculated, and how it would be implemented.
Last edited on
Basically, you are updating the game every x milliseconds. while( GetTickCount() > next_game_tick. If the computer gets behind in this code, it continues updating until it's caught up (hence the while loop). The && loops < MAX_FRAMESKIP) { is included to prevent the while loop from going on too long if the code is really far behind.

Essentially, if the computer lags for 500ms and the game is supposed to update every 100ms, the game will update 5 times before the frame is drawn to keep on track. However, if the computer lags for 5 minutes, it will only update MAX_FRAMESKIP number of times, so that the game doesn't crash from doing an insane amount of work to catch up.

Now, the interpolation is the neat part. You are only updating every x milliseconds, so if you move your character by a little bit every time, the max speed the person will see is (1000 / x) frames per second, no matter how many times the screen could have been drawn. The interpolation will make it so that if you can draw the screen ten times before the game needs to be updated, the render function can automatically make the animations to change position slowly or animate something more smoothly than if it gets updated only once every x milliseconds.

To implement this, all you need to do is figure out how much time has gone by (the float interpolation; variable), and then move the character or do whatever a certain amount on the screen, depending on how much time has gone by. This would mean in your update function, you would have to set a speed for the character movement and a target location for it to move to, rather than setting solid x and y variables. Let the render function deal with the actual position for drawing.

If you need more of an explanation or need me to clarify something, let me know.
Topic archived. No new replies allowed.