Sign in to follow this  

Different type of game loop question

Recommended Posts

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 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!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this