mirror of
https://github.com/whoahq/whoa.git
synced 2026-03-18 13:41:06 +03:00
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
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:
parent
1d91a49462
commit
886ababae9
@ -1,6 +1,47 @@
|
|||||||
#include "util/time/CGameTime.hpp"
|
#include "util/time/CGameTime.hpp"
|
||||||
#include "common/Time.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) {
|
void CGameTime::PerformCallbacks(int32_t minutes) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,7 @@
|
|||||||
class CGameTime : public WowTime {
|
class CGameTime : public WowTime {
|
||||||
public:
|
public:
|
||||||
// Public member functions
|
// Public member functions
|
||||||
void PerformCallbacks(int32_t minutes);
|
void GameTimeSetTime(const WowTime& time, bool shouldTick);
|
||||||
void TickMinute();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Private member variables
|
// Private member variables
|
||||||
@ -24,6 +23,10 @@ class CGameTime : public WowTime {
|
|||||||
float float48 = 0.0f;
|
float float48 = 0.0f;
|
||||||
float float4C = 0.0f;
|
float float4C = 0.0f;
|
||||||
// TODO m_callbackLists
|
// TODO m_callbackLists
|
||||||
|
|
||||||
|
// Private member functions
|
||||||
|
void PerformCallbacks(int32_t minutes);
|
||||||
|
void TickMinute();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -16,13 +16,24 @@ TEST_CASE("CGameTime::CGameTime", "[util]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("CGameTime::TickMinute", "[util]") {
|
TEST_CASE("CGameTime::GameTimeSetTime", "[util]") {
|
||||||
SECTION("ticks minute correctly") {
|
SECTION("sets game time correctly") {
|
||||||
CGameTime time;
|
WowTime time;
|
||||||
time.SetHourAndMinutes(0, 0);
|
time.m_minute = 18;
|
||||||
time.TickMinute();
|
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);
|
CGameTime gameTime;
|
||||||
CHECK(time.m_minute == 1);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user