From 721ee527eb3291867784228827880bea86093d2f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 28 Jan 2026 22:01:23 -0600 Subject: [PATCH] feat(util): add CGameTime::GameTimeUpdate --- src/util/time/CGameTime.cpp | 22 ++++++++++++++++++++++ src/util/time/CGameTime.hpp | 1 + test/util/time/CGameTime.cpp | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/util/time/CGameTime.cpp b/src/util/time/CGameTime.cpp index 6cf165c..f0ecf39 100644 --- a/src/util/time/CGameTime.cpp +++ b/src/util/time/CGameTime.cpp @@ -42,6 +42,28 @@ void CGameTime::GameTimeSetTime(const WowTime& time, bool shouldTick) { } } +void CGameTime::GameTimeUpdate(float elapsedSec) { + this->m_gameMinutesThisTick += this->m_gameMinutesPerRealSecond * elapsedSec; + + // Skip minute ticks for time differential + if (this->m_timeDifferential != 0 && this->m_gameMinutesThisTick >= 1.0f) { + auto minutesToConsume = static_cast(this->m_gameMinutesThisTick); + + // Clamp to differential + if (this->m_timeDifferential < minutesToConsume) { + minutesToConsume = this->m_timeDifferential; + } + + this->m_timeDifferential -= minutesToConsume; + this->m_gameMinutesThisTick -= static_cast(minutesToConsume); + } + + while (this->m_gameMinutesThisTick >= 1.0f) { + this->m_gameMinutesThisTick -= 1.0f; + this->TickMinute(); + } +} + void CGameTime::PerformCallbacks(int32_t minutes) { // TODO } diff --git a/src/util/time/CGameTime.hpp b/src/util/time/CGameTime.hpp index 445dbf9..ed02236 100644 --- a/src/util/time/CGameTime.hpp +++ b/src/util/time/CGameTime.hpp @@ -7,6 +7,7 @@ class CGameTime : public WowTime { public: // Public member functions void GameTimeSetTime(const WowTime& time, bool shouldTick); + void GameTimeUpdate(float elapsedSec); private: // Private member variables diff --git a/test/util/time/CGameTime.cpp b/test/util/time/CGameTime.cpp index 88dfd6d..4f1d20c 100644 --- a/test/util/time/CGameTime.cpp +++ b/test/util/time/CGameTime.cpp @@ -37,3 +37,23 @@ TEST_CASE("CGameTime::GameTimeSetTime", "[util]") { CHECK(gameTime.m_year == 26); } } + +TEST_CASE("CGameTime::GameTimeUpdate", "[util]") { + SECTION("updates game time correctly") { + WowTime time; + time.m_minute = 18; + time.m_hour = 11; + time.m_weekday = 3; + time.m_monthday = 27; + time.m_month = 0; + time.m_year = 26; + + CGameTime gameTime; + gameTime.GameTimeSetTime(time, true); + + gameTime.GameTimeUpdate(60.0f); + + CHECK(gameTime.m_hour == 11); + CHECK(gameTime.m_minute == 19); + } +}