diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 85d065a54..118a58f7c 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -72,6 +72,7 @@ MainLoop::MainLoop(unsigned parent_pid) m_curr_time = 0; m_prev_time = 0; m_throttle_fps = true; + m_allow_large_dt = false; m_frame_before_loading_world = false; #ifdef WIN32 if (parent_pid != 0) @@ -159,8 +160,8 @@ float MainLoop::getLimitedDt() // when the computer can't keep it up, slow down the shown time instead // But this can not be done in networking, otherwise the game time on // client and server will not be in synch anymore - if (!NetworkConfig::get()->isNetworking() || - !World::getWorld()) + if ((!NetworkConfig::get()->isNetworking() || !World::getWorld()) && + !m_allow_large_dt) { /* time 3 internal substeps take */ const float MAX_ELAPSED_TIME = 3.0f*1.0f / 60.0f*1000.0f; @@ -327,6 +328,7 @@ void MainLoop::run() m_request_abort = true; } #endif + PROFILER_PUSH_CPU_MARKER("Main loop", 0xFF, 0x00, 0xF7); left_over_time += getLimitedDt(); diff --git a/src/main_loop.hpp b/src/main_loop.hpp index ce60eda8a..0311e014c 100644 --- a/src/main_loop.hpp +++ b/src/main_loop.hpp @@ -36,6 +36,9 @@ private: /** True if the frame rate should be throttled. */ bool m_throttle_fps; + + /** True if dt is not decreased for low fps */ + bool m_allow_large_dt; bool m_frame_before_loading_world; @@ -54,6 +57,7 @@ public: void abort() { m_abort = true; } void requestAbort() { m_request_abort = true; } void setThrottleFPS(bool throttle) { m_throttle_fps = throttle; } + void setAllowLargeDt(bool enable) { m_allow_large_dt = enable; } // ------------------------------------------------------------------------ /** Returns true if STK is to be stoppe. */ bool isAborted() const { return m_abort; } diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index 1bc9c0f09..b2506700a 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -17,6 +17,7 @@ #include "modes/cutscene_world.hpp" +#include "main_loop.hpp" #include "animations/animation_base.hpp" #include "animations/three_d_animation.hpp" #include "audio/sfx_manager.hpp" @@ -71,6 +72,9 @@ CutsceneWorld::CutsceneWorld() : World() */ void CutsceneWorld::init() { + // Use real dt even if fps is low. It allows to keep everything synchronized + main_loop->setAllowLargeDt(true); + m_second_reset = false; World::init(); @@ -170,6 +174,7 @@ void CutsceneWorld::init() */ CutsceneWorld::~CutsceneWorld() { + main_loop->setAllowLargeDt(false); } // ~CutsceneWorld //----------------------------------------------------------------------------- void CutsceneWorld::reset(bool restart)