feat(util): add CGameTime::GameTimeSetTime
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 21:31:24 -06:00
parent 1d91a49462
commit 886ababae9
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
3 changed files with 64 additions and 9 deletions

View File

@ -1,6 +1,47 @@
#include "util/time/CGameTime.hpp"
#include "common/Time.hpp"
void CGameTime::GameTimeSetTime(const WowTime& time, bool shouldTick) {
WowTime biasTime = time;
if (this->m_timeBias) {
auto minutes = biasTime.GetHourAndMinutes() + this->m_timeBias;
if (minutes < 0) {
minutes += 1440;
} else {
minutes %= 1440;
}
biasTime.SetHourAndMinutes(minutes);
}
if (this->m_dateBias) {
biasTime.AddDays(this->m_dateBias, false);
}
static_cast<WowTime&>(*this) = biasTime;
if (shouldTick) {
// Rewind time by exactly one minute
if (this->m_minute != 0) {
this->m_minute--;
} else {
this->m_minute = 59;
if (this->m_hour != 0) {
this->m_hour--;
} else {
this->m_hour = 23;
this->AddDays(-1, false);
}
}
// Tick ahead exactly one minute (ensures callbacks fire and various counters update)
this->TickMinute();
}
}
void CGameTime::PerformCallbacks(int32_t minutes) {
// TODO
}

View File

@ -6,8 +6,7 @@
class CGameTime : public WowTime {
public:
// Public member functions
void PerformCallbacks(int32_t minutes);
void TickMinute();
void GameTimeSetTime(const WowTime& time, bool shouldTick);
private:
// Private member variables
@ -24,6 +23,10 @@ class CGameTime : public WowTime {
float float48 = 0.0f;
float float4C = 0.0f;
// TODO m_callbackLists
// Private member functions
void PerformCallbacks(int32_t minutes);
void TickMinute();
};
#endif

View File

@ -16,13 +16,24 @@ TEST_CASE("CGameTime::CGameTime", "[util]") {
}
}
TEST_CASE("CGameTime::TickMinute", "[util]") {
SECTION("ticks minute correctly") {
CGameTime time;
time.SetHourAndMinutes(0, 0);
time.TickMinute();
TEST_CASE("CGameTime::GameTimeSetTime", "[util]") {
SECTION("sets 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;
CHECK(time.m_hour == 0);
CHECK(time.m_minute == 1);
CGameTime gameTime;
gameTime.GameTimeSetTime(time, true);
CHECK(gameTime.m_minute == 18);
CHECK(gameTime.m_hour == 11);
CHECK(gameTime.m_weekday == 3);
CHECK(gameTime.m_monthday == 27);
CHECK(gameTime.m_month == 0);
CHECK(gameTime.m_year == 26);
}
}