From 4e9ee3a3a36f94738036b2628a44a41328a17646 Mon Sep 17 00:00:00 2001 From: cracker64 Date: Tue, 21 May 2013 23:05:27 -0400 Subject: [PATCH] Fix incorrect FPS counter, need to count blit too. 2x scale gets a massive *real* fps boost, the fps lied before. --- src/PowderToySDL.cpp | 45 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 94559b232..44971793a 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -495,30 +495,7 @@ void EngineProcess() frameStart = SDL_GetTicks(); engine->Tick(); engine->Draw(); - frameTime = SDL_GetTicks() - frameStart; - frameTimeAvg = (frameTimeAvg*(1.0f-0.2f)) + (0.2f*frameTime); - if(ui::Engine::Ref().FpsLimit > 2.0f) - { - float targetFrameTime = 1000.0f/((float)ui::Engine::Ref().FpsLimit); - if(targetFrameTime - frameTimeAvg > 0) - { - SDL_Delay((targetFrameTime - frameTimeAvg) + 0.5f); - frameTime = SDL_GetTicks() - frameStart;//+= (int)(targetFrameTime - frameTimeAvg); - } - } - - correctedFrameTimeAvg = (correctedFrameTimeAvg*(1.0f-0.05f)) + (0.05f*frameTime); - fps = 1000.0f/correctedFrameTimeAvg; - engine->SetFps(fps); - - if(frameStart-lastTick>250) - { - //Run client tick every second - lastTick = frameStart; - Client::Ref().Tick(); - } - if(scale != engine->Scale || fullscreen != engine->Fullscreen) { sdl_scrn = SDLSetScreen(engine->Scale, engine->Fullscreen); @@ -533,6 +510,28 @@ void EngineProcess() else blit(engine->g->vid); #endif + + frameTime = SDL_GetTicks() - frameStart; + frameTimeAvg = (frameTimeAvg*(1.0f-0.2f)) + (0.2f*frameTime); + if(ui::Engine::Ref().FpsLimit > 2.0f) + { + float targetFrameTime = 1000.0f/((float)ui::Engine::Ref().FpsLimit); + if(targetFrameTime - frameTimeAvg > 0) + { + SDL_Delay((targetFrameTime - frameTimeAvg) + 0.5f); + frameTime = SDL_GetTicks() - frameStart;//+= (int)(targetFrameTime - frameTimeAvg); + } + } + correctedFrameTimeAvg = (correctedFrameTimeAvg*(1.0f-0.05f)) + (0.05f*frameTime); + fps = 1000.0f/correctedFrameTimeAvg; + engine->SetFps(fps); + + if(frameStart-lastTick>250) + { + //Run client tick every second + lastTick = frameStart; + Client::Ref().Tick(); + } } #ifdef DEBUG std::cout << "Breaking out of EngineProcess" << std::endl;