mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-02 00:32:45 +03:00
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
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
886ababae9
commit
721ee527eb
@ -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) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user