Ember

loop

Feb 20th, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. void Game::Run()
  2. {
  3.     LARGE_INTEGER li;
  4.     Double frequency;
  5.     Double time;
  6.     bool done, result;
  7.  
  8.     // Get the high-resolution timer frequency
  9.     result = QueryPerformanceFrequency(&li);
  10.     if(!result) { return; }
  11.  
  12.     // Set the timer frequency to milliseconds
  13.     frequency = (double)li.QuadPart / 1000.0;
  14.  
  15.     // Loop until the engine wants to quit
  16.     done = false;
  17.     while(!done)
  18.     {
  19.         // Reset the timer
  20.         QueryPerformanceCounter(&li);
  21.         time = li.QuadPart;
  22.  
  23.         // Do frame processing
  24.         result = Frame();
  25.         if(!result) { done = true; }
  26.  
  27.         // Get the elasped time
  28.         QueryPerformanceCounter(&li);
  29.         time = li.QuadPart - time;
  30.         time /= frequency;
  31.  
  32.         // Sleep
  33.         Long sleeptime = mFrameTime - time;
  34.         Sleep(max(sleeptime, 0));
  35.     }
  36.  
  37.     return;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment