Different type of game loop question

Started by
0 comments, last by DrunkCanada 17 years, 1 month ago
So i've been doing game programming for a little while (in java) and I recently switched to c++ just to become more familiar with the language, either way this is not a question about languages. I've been doing some research on game loops and I came across this site which seems to explain 4 different type of game loops. Heres the link if you are interested http://dewitters.koonsolo.com/gameloop.html I chose to implement this loop which basically limits the game to update at 25 fps, but it can render as fast as possible. Although this is my concern, I am a bit sceptical that if I were to write a game using this loop (since it updates the game state not based on time but based on frames), that it would not run the same on a slow pc compared to a fast pc. The reason I am using this type of loop instead of a time based loop is because I like the idea of not limiting the rendering based on the game logic and vise versa. Anyways I am just curious as to if you guys see any flaws in the following loop. //gonna put this in a code block (first post not sure how to do it) const int TICKS_PER_SECOND = 25; const int SKIP_TICKS = 1000 / TICKS_PER_SECOND; const int MAX_FRAMESKIP = 5; DWORD next_game_tick = GetTickCount(); int loops; float interpolation; bool game_is_running = true; while( game_is_running ) { loops = 0; while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) { update_game(); next_game_tick += SKIP_TICKS; loops++; } interpolation = float( GetTickCount() + SKIP_TICKS - next_game_tick ) / float( SKIP_TICKS ); display_game( interpolation ); } Thanks!
Advertisement
Looks pretty good to me I use a simmilar loop in my engine

This topic is closed to new replies.

Advertisement