Advertisement
Guest User

Dewitters Game Loop

a guest
Jan 18th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1.   const int TICKS_PER_SECOND = 25;
  2.     const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
  3.     const int MAX_FRAMESKIP = 5;
  4.  
  5.     DWORD next_game_tick = GetTickCount();
  6.     int loops;
  7.     float interpolation;
  8.  
  9.     bool game_is_running = true;
  10.     while( game_is_running ) {
  11.  
  12.         loops = 0;
  13.         while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
  14.             update_game();
  15.  
  16.             next_game_tick += SKIP_TICKS;
  17.             loops++;
  18.         }
  19.  
  20.         interpolation = float( GetTickCount() + SKIP_TICKS - next_game_tick )
  21.                         / float( SKIP_TICKS );
  22.         display_game( interpolation );
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement