Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. double Timestamp() // seconds
  2. {
  3.     const double scale = 1.0 / 1000.0;
  4.     return SDL_GetTicks() * scale;
  5. }
  6.  
  7.     int frames = 0;
  8.  
  9.     const double dt = 0.01;
  10.  
  11.     double lastFPS = Timestamp();
  12.     double currentTime = Timestamp();
  13.     double timeAccum = 0.0;
  14.  
  15.     double t = 0.0;
  16.  
  17.     while (1)
  18.     {
  19.         double newTime = Timestamp();
  20.         double frameTime = newTime - currentTime;
  21.         if (frameTime > MAX_UPDATE_TIME)
  22.             frameTime = MAX_UPDATE_TIME; // avoid runaway simulation
  23.         currentTime = newTime;
  24.  
  25.         timeAccum += frameTime;
  26.  
  27.         while (timeAccum >= dt)
  28.         {
  29.             // simulate physics
  30.  
  31.             timeAccum -= dt;
  32.             t += dt;
  33.         }
  34.  
  35.  
  36.  
  37.     blah blah blah
  38.  
  39.         glFlush();
  40.         SDL_GL_SwapBuffers();
  41.  
  42.         frames++;
  43.  
  44.         if (currentTime - lastFPS > 1.0) {
  45.             std::cout << "FPS: "
  46.                 << frames / (currentTime - lastFPS)
  47.                 << std::endl;
  48.             lastFPS = currentTime;
  49.             frames = 0;
  50.         }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement