We’re rewarding the question askers & reputations are being recalculated! Read more.
2 added 394 characters in body
source | link

I think the author made a tiny error:

while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP)

should be

while( GetTickCount() < next_game_tick && loops < MAX_FRAMESKIP)

That is: as long as it is not yet time to draw our next frame and while we have not skipped as much frames as MAX_FRAMESKIP we should wait.

I also don't understand why he updates next_game_tick in the loop and I assume it is another error. Since at the start of a frame you can determine when the next frame should be (when using a fixed frame rate). The next game tick does not depend on how much time we have left over after updating and rendering.

The author also makes another common error

with whatever is left render the game as many times as possible.

Instead of trying to render as many times as possible in the time between the update logic andThis means rendering the time till nextsame frame you should only draw once and then just waitmultiple times. Its useless to letThe author is even aware of that:

The game will be updated at a steady 50 times per second, and rendering is done as fast as possible. Remark that when rendering is done more than 50 times per second, some subsequent frames will be the same, so actual visual frames will be displayed at a maximum of 50 frames per second.

This only causes the GPU to do extraunnecessary work and even risk having drawing take to long so thatif rendering takes longer than expected it could cause you have to catch upstart working on your next frame since when nothing is updated, everything stays the samelater than intended so you are drawing exactly the same thing multiple times. Unfortunately this errorit is a very common one (even the creators of the XNA framework did this wrong inbetter to yield to the first iteration)OS and wait.

I think the author made a tiny error:

while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP)

should be

while( GetTickCount() < next_game_tick && loops < MAX_FRAMESKIP)

That is: as long as it is not yet time to draw our next frame and while we have not skipped as much frames as MAX_FRAMESKIP we should wait.

The author also makes another common error

with whatever is left render the game as many times as possible.

Instead of trying to render as many times as possible in the time between the update logic and the time till next frame you should only draw once and then just wait. Its useless to let the GPU do extra work and even risk having drawing take to long so that you have to catch up next frame since when nothing is updated, everything stays the same so you are drawing exactly the same thing multiple times. Unfortunately this error is a very common one (even the creators of the XNA framework did this wrong in the first iteration).

I think the author made a tiny error:

while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP)

should be

while( GetTickCount() < next_game_tick && loops < MAX_FRAMESKIP)

That is: as long as it is not yet time to draw our next frame and while we have not skipped as much frames as MAX_FRAMESKIP we should wait.

I also don't understand why he updates next_game_tick in the loop and I assume it is another error. Since at the start of a frame you can determine when the next frame should be (when using a fixed frame rate). The next game tick does not depend on how much time we have left over after updating and rendering.

The author also makes another common error

with whatever is left render the game as many times as possible.

This means rendering the same frame multiple times. The author is even aware of that:

The game will be updated at a steady 50 times per second, and rendering is done as fast as possible. Remark that when rendering is done more than 50 times per second, some subsequent frames will be the same, so actual visual frames will be displayed at a maximum of 50 frames per second.

This only causes the GPU to do unnecessary work and if rendering takes longer than expected it could cause you to start working on your next frame later than intended so it is better to yield to the OS and wait.

1
source | link

I think the author made a tiny error:

while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP)

should be

while( GetTickCount() < next_game_tick && loops < MAX_FRAMESKIP)

That is: as long as it is not yet time to draw our next frame and while we have not skipped as much frames as MAX_FRAMESKIP we should wait.

The author also makes another common error

with whatever is left render the game as many times as possible.

Instead of trying to render as many times as possible in the time between the update logic and the time till next frame you should only draw once and then just wait. Its useless to let the GPU do extra work and even risk having drawing take to long so that you have to catch up next frame since when nothing is updated, everything stays the same so you are drawing exactly the same thing multiple times. Unfortunately this error is a very common one (even the creators of the XNA framework did this wrong in the first iteration).