diff --git a/code/snowballs2/client/src/game_time.cpp b/code/snowballs2/client/src/game_time.cpp index 62bfc2b2b..c6b1ff62c 100644 --- a/code/snowballs2/client/src/game_time.cpp +++ b/code/snowballs2/client/src/game_time.cpp @@ -42,6 +42,14 @@ static bool _SkipAnimationOnce; static NLMISC::TTime _TimeMs; static CValueSmootherTemplate _FpsSmoother; +namespace +{ + +NLMISC::TLocalTime a_LocalTimeDelta; +NL3D::TGlobalAnimationTime a_AnimationTimeDelta; + +} /* anonymous namespace */ + static void cbFpsSmoothing(CConfigFile::CVar &var) { _FpsSmoother.init((uint)var.asInt()); @@ -53,8 +61,10 @@ void CGameTime::init() _TimeMs = NLMISC::CTime::getLocalTime(); LocalTime = ((TLocalTime)_TimeMs) / 1000.0; LocalTimeDelta = 0.0; + a_LocalTimeDelta = 0.0; AnimationTime = 0.0; AnimationTimeDelta = 0.f; + a_AnimationTimeDelta = 0.0; FramesPerSecond = 0.f; FramesPerSecondSmooth = 0.f; CConfiguration::setAndCallback("FpsSmoothing", cbFpsSmoothing); @@ -78,26 +88,24 @@ void CGameTime::updateTime() // average of previous fps and this fps should be ok FramesPerSecond *= 3; - LocalTimeDelta = 0.f; - AnimationTimeDelta = 0.f; + a_LocalTimeDelta = 0.f; + a_AnimationTimeDelta = 0.f; } else { FramesPerSecond = 1000.0f / (float)deltams; TLocalTime localTime = ((TLocalTime)timems) / 1000.0; - LocalTimeDelta = localTime - LocalTime; - LocalTime = localTime; + a_LocalTimeDelta = localTime - LocalTime; if (_SkipAnimationOnce) { - AnimationTimeDelta = 0.f; + a_AnimationTimeDelta = 0.f; _SkipAnimationOnce = false; } else { - AnimationTimeDelta = (TAnimationTime)LocalTimeDelta; - AnimationTime += (TGlobalAnimationTime)LocalTimeDelta; + a_AnimationTimeDelta = (TGlobalAnimationTime)a_LocalTimeDelta; } } @@ -105,6 +113,15 @@ void CGameTime::updateTime() FramesPerSecondSmooth = _FpsSmoother.getSmoothValue(); } +void CGameTime::advanceTime(double f) +{ + LocalTimeDelta = a_LocalTimeDelta * f; + LocalTime += LocalTimeDelta; + TGlobalAnimationTime atd = a_AnimationTimeDelta * f; + AnimationTimeDelta = (NL3D::TAnimationTime)atd; + AnimationTime += atd; +} + void CGameTime::skipAnimationOnce() { _SkipAnimationOnce = true; diff --git a/code/snowballs2/client/src/game_time.h b/code/snowballs2/client/src/game_time.h index 72a671d43..7cf4ec827 100644 --- a/code/snowballs2/client/src/game_time.h +++ b/code/snowballs2/client/src/game_time.h @@ -40,6 +40,9 @@ public: static void updateTime(); + /// Advance time to target time by factor f. + static void advanceTime(double f); + /// Used when loading, this will skip changing animation time on the next update /// (updates aren't called during loading) static void skipAnimationOnce(); diff --git a/code/snowballs2/client/src/snowballs_client.cpp b/code/snowballs2/client/src/snowballs_client.cpp index 76338cfa5..1d7fefd60 100644 --- a/code/snowballs2/client/src/snowballs_client.cpp +++ b/code/snowballs2/client/src/snowballs_client.cpp @@ -679,6 +679,7 @@ void loopIngame() // 02. Update Time (deltas) CGameTime::updateTime(); + CGameTime::advanceTime(1.0); // 03. Update Input (keyboard controls, etc) Driver->EventServer.pump(); // Pump user input messages