From 74df3c7e38b4c411fdc3cbe7a8376d4afdc5ad52 Mon Sep 17 00:00:00 2001 From: husho Date: Sat, 26 May 2018 19:15:56 +0300 Subject: [PATCH] Fixed: accumulated time during pauses, caused terrible framerate --- rwgame/RWGame.cpp | 59 +++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index 1cea32ae..0ca4afc3 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -423,39 +423,42 @@ int RWGame::run() { chrono::duration(currentFrame - lastFrame).count(); lastFrame = currentFrame; - // Clamp frameTime, so we won't freeze completely - if (frameTime > 0.1f) { - frameTime = 0.1f; - } + if (!world->isPaused()) { + accumulatedTime += frameTime; - accumulatedTime += frameTime; - - auto deltaTimeWithTimeScale = deltaTime * world->state->basic.timeScale; - - RW_PROFILE_BEGIN("Update"); - while (accumulatedTime >= deltaTime && !world->isPaused()) { - if (!StateManager::currentState()) { - break; + // Clamp frameTime, so we won't freeze completely + if (frameTime > 0.1f) { + frameTime = 0.1f; } - RW_PROFILE_BEGIN("physics"); - world->dynamicsWorld->stepSimulation( - deltaTimeWithTimeScale, kMaxPhysicsSubSteps, deltaTime); + auto deltaTimeWithTimeScale = + deltaTime * world->state->basic.timeScale; + + RW_PROFILE_BEGIN("Update"); + while (accumulatedTime >= deltaTime && !world->isPaused()) { + if (!StateManager::currentState()) { + break; + } + + RW_PROFILE_BEGIN("physics"); + world->dynamicsWorld->stepSimulation( + deltaTimeWithTimeScale, kMaxPhysicsSubSteps, deltaTime); + RW_PROFILE_END(); + + RW_PROFILE_BEGIN("state"); + StateManager::get().tick(deltaTimeWithTimeScale); + RW_PROFILE_END(); + + RW_PROFILE_BEGIN("engine"); + tick(deltaTimeWithTimeScale); + RW_PROFILE_END(); + + getState()->swapInputState(); + + accumulatedTime -= deltaTime; + } RW_PROFILE_END(); - - RW_PROFILE_BEGIN("state"); - StateManager::get().tick(deltaTimeWithTimeScale); - RW_PROFILE_END(); - - RW_PROFILE_BEGIN("engine"); - tick(deltaTimeWithTimeScale); - RW_PROFILE_END(); - - getState()->swapInputState(); - - accumulatedTime -= deltaTime; } - RW_PROFILE_END(); RW_PROFILE_BEGIN("Render"); RW_PROFILE_BEGIN("engine");