feat(util): add CGameTime::GameTimeUpdate
Some checks are pending
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:cl compiler_name:MSVC cxx:cl os:windows-latest system_name:Windows test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:clang compiler_name:Clang cxx:clang++ os:macos-latest system_name:macOS test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:gcc compiler_name:GCC cxx:g++ os:ubuntu-latest system_name:Linux test_path:WhoaTest]) (push) Waiting to run

This commit is contained in:
fallenoak 2026-01-28 22:01:23 -06:00
parent 886ababae9
commit 721ee527eb
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
3 changed files with 43 additions and 0 deletions

View File

@ -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<uint32_t>(this->m_gameMinutesThisTick);
// Clamp to differential
if (this->m_timeDifferential < minutesToConsume) {
minutesToConsume = this->m_timeDifferential;
}
this->m_timeDifferential -= minutesToConsume;
this->m_gameMinutesThisTick -= static_cast<float>(minutesToConsume);
}
while (this->m_gameMinutesThisTick >= 1.0f) {
this->m_gameMinutesThisTick -= 1.0f;
this->TickMinute();
}
}
void CGameTime::PerformCallbacks(int32_t minutes) { void CGameTime::PerformCallbacks(int32_t minutes) {
// TODO // TODO
} }

View File

@ -7,6 +7,7 @@ class CGameTime : public WowTime {
public: public:
// Public member functions // Public member functions
void GameTimeSetTime(const WowTime& time, bool shouldTick); void GameTimeSetTime(const WowTime& time, bool shouldTick);
void GameTimeUpdate(float elapsedSec);
private: private:
// Private member variables // Private member variables

View File

@ -37,3 +37,23 @@ TEST_CASE("CGameTime::GameTimeSetTime", "[util]") {
CHECK(gameTime.m_year == 26); 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);
}
}