Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double Timestamp() // seconds
- {
- const double scale = 1.0 / 1000.0;
- return SDL_GetTicks() * scale;
- }
- int frames = 0;
- const double dt = 0.01;
- double lastFPS = Timestamp();
- double currentTime = Timestamp();
- double timeAccum = 0.0;
- double t = 0.0;
- while (1)
- {
- double newTime = Timestamp();
- double frameTime = newTime - currentTime;
- if (frameTime > MAX_UPDATE_TIME)
- frameTime = MAX_UPDATE_TIME; // avoid runaway simulation
- currentTime = newTime;
- timeAccum += frameTime;
- while (timeAccum >= dt)
- {
- // simulate physics
- timeAccum -= dt;
- t += dt;
- }
- blah blah blah
- glFlush();
- SDL_GL_SwapBuffers();
- frames++;
- if (currentTime - lastFPS > 1.0) {
- std::cout << "FPS: "
- << frames / (currentTime - lastFPS)
- << std::endl;
- lastFPS = currentTime;
- frames = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement