From db695f11f6d74c9ea9be6b325f857cbbf98c72cd Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 18 Dec 2020 18:26:22 +0100 Subject: [PATCH] Spectre/Game/GameTime: Store max accumulated time in a member variable and calculate it once in setTimeStep() --- include/Spectre/Game/GameTime.h | 1 + source/Game/GameTime.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/Spectre/Game/GameTime.h b/include/Spectre/Game/GameTime.h index 37aa167..861c2d3 100644 --- a/include/Spectre/Game/GameTime.h +++ b/include/Spectre/Game/GameTime.h @@ -39,6 +39,7 @@ protected : Stopwatch m_watch; Time m_acc; + Time m_max_acc; // Timeslice. Time m_slice; diff --git a/source/Game/GameTime.cpp b/source/Game/GameTime.cpp index f8e2b64..f20b3e4 100644 --- a/source/Game/GameTime.cpp +++ b/source/Game/GameTime.cpp @@ -18,6 +18,7 @@ double GameTime::getTimeStep() const void GameTime::setTimeStep(unsigned long updates_per_sec) { m_slice = Time::seconds(1.0f / ((double) updates_per_sec)); + m_max_acc = Time::seconds(1.0f / m_slice.seconds()); reset(); } @@ -58,8 +59,8 @@ void GameTime::reset() void GameTime::accumulateTime() { m_acc += m_watch.restart(); - if (m_acc.seconds() > (1.0f / m_slice.seconds())) { - m_acc = Time::seconds(1.0f / m_slice.seconds()); + if (m_acc > m_max_acc) { + m_acc = m_max_acc; } }