X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgameloop.cpp;h=19b0f9f2d479ed82156b6bc04e43668ab25fa81c;hb=c51d5419b2d4806ac513a465559d55ccb2387720;hp=ca9a0bcea8c9996982c66cfa461d57b596751bea;hpb=e8a1d89d3d0f4824d3d906ca67149afec0a75e4b;p=supertux.git diff --git a/src/gameloop.cpp b/src/gameloop.cpp index ca9a0bcea..19b0f9f2d 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -656,6 +656,7 @@ GameSession::process_menu() } } + GameSession::ExitStatus GameSession::run() { @@ -663,6 +664,7 @@ GameSession::run() current_ = this; int fps_cnt = 0; + unsigned int fps_nextframe_ticks; // fps regulating code // Eat unneeded events SDL_Event event; @@ -673,6 +675,7 @@ GameSession::run() Uint32 lastticks = SDL_GetTicks(); fps_ticks = SDL_GetTicks(); + fps_nextframe_ticks = SDL_GetTicks(); // fps regulating code while (exit_status == ES_NONE) { Uint32 ticks = SDL_GetTicks(); @@ -682,8 +685,23 @@ GameSession::run() lastticks = ticks; // 40fps is minimum - if(elapsed_time > .025) - elapsed_time = .025; + if(elapsed_time > 0.025){ + elapsed_time = 0.025; + } + + // fps regualting code + const int wantedFps= 60; // 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() + if (fps_nextframe_ticks - SDL_GetTicks() > 15){ + SDL_Delay(5); + } + + } + fps_nextframe_ticks = SDL_GetTicks() + (1000 / wantedFps); // sets the ticks that must have elapsed + // in order for the next frame to start. + /* Handle events: */ currentsector->player->input.old_fire = currentsector->player->input.fire;