From 6a413d912b0d6c012771d3099a598bf3a0f6e59f Mon Sep 17 00:00:00 2001 From: Ryan Flegel Date: Sun, 10 Apr 2005 19:01:01 +0000 Subject: [PATCH] Applied new FPS reg. patch from Enrico SVN-Revision: 2363 --- src/gameloop.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 19b0f9f2d..e7f1c92b3 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -664,7 +664,7 @@ GameSession::run() current_ = this; int fps_cnt = 0; - unsigned int fps_nextframe_ticks; // fps regulating code + double fps_nextframe_ticks; // fps regulating code // Eat unneeded events SDL_Event event; @@ -690,7 +690,7 @@ GameSession::run() } // fps regualting code - const int wantedFps= 60; // set to 60 by now + const double wantedFps= 60.0; // set to 60 by now while (fps_nextframe_ticks > SDL_GetTicks()){ /* just wait */ // If we really have to wait long, then do an imprecise SDL_Delay() @@ -699,7 +699,11 @@ GameSession::run() } } - fps_nextframe_ticks = SDL_GetTicks() + (1000 / wantedFps); // sets the ticks that must have elapsed + float diff = SDL_GetTicks() - fps_nextframe_ticks; + if (diff > 5.0) + fps_nextframe_ticks = SDL_GetTicks() + (1000.0 / wantedFps); // sets the ticks that must have elapsed + else + fps_nextframe_ticks += 1000.0 / wantedFps; // sets the ticks that must have elapsed // in order for the next frame to start. -- 2.11.0