From 51755635aa148f951f7c5ddb5047d0768c98d3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 25 Jan 2021 15:53:03 +0100 Subject: [PATCH] ksys: Implement Timer --- data/uking_functions.csv | 6 +++--- src/KingSystem/System/Timer.cpp | 21 +++++++++++++++++++++ src/KingSystem/System/Timer.h | 12 ++++++------ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index f7f8cf51..50906f8f 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -91872,9 +91872,9 @@ 0x00000071011c0b1c,j__ZdlPv_1213,4, 0x00000071011c0b20,BaseProcMgr::Struct2::getForBaseProcDualHeap,8, 0x00000071011c0b28,BaseProcMgr::Struct2::setHeap,8, -0x00000071011c0b30,TimerSimple::update,128, -0x00000071011c0bb0,Timer::update,136, -0x00000071011c0c38,Timer::ended,48, +0x00000071011c0b30,TimerSimple::update,128,_ZN4ksys5Timer6updateEPff +0x00000071011c0bb0,Timer::update,136,_ZN4ksys5Timer6updateEv +0x00000071011c0c38,Timer::ended,48,_ZNK4ksys5Timer8hasEndedEf 0x00000071011c0c68,sub_71011C0C68,100,_ZN4ksys3VFR18SingletonDisposer_D2Ev 0x00000071011c0ccc,sub_71011C0CCC,108,_ZN4ksys3VFR18SingletonDisposer_D0Ev 0x00000071011c0d38,VFR::createInstance,332,_ZN4ksys3VFR14createInstanceEPN4sead4HeapE diff --git a/src/KingSystem/System/Timer.cpp b/src/KingSystem/System/Timer.cpp index ad1d92e8..00749b9f 100644 --- a/src/KingSystem/System/Timer.cpp +++ b/src/KingSystem/System/Timer.cpp @@ -1 +1,22 @@ #include "KingSystem/System/Timer.h" +#include "KingSystem/System/VFR.h" + +namespace ksys { + +void Timer::update(f32* t, f32 rate) { + *t += VFR::instance()->getDeltaTime() * rate; +} + +void Timer::update() { + previous_value = value; + update(&value, rate); +} + +bool Timer::hasEnded(f32 end_time) const { + if (value == end_time) + return true; + + return (previous_value - end_time) * (value - end_time) < 0.0; +} + +} // namespace ksys diff --git a/src/KingSystem/System/Timer.h b/src/KingSystem/System/Timer.h index fbd46ac6..95962ba5 100644 --- a/src/KingSystem/System/Timer.h +++ b/src/KingSystem/System/Timer.h @@ -6,21 +6,21 @@ namespace ksys { struct Timer { Timer() = default; - Timer(f32 value, f32 previous_value, f32 speed = -1.0) - : value(value), previous_value(previous_value), speed(speed) {} + Timer(f32 value, f32 previous_value, f32 rate = -1.0) + : value(value), previous_value(previous_value), rate(rate) {} - void reset(f32 value_, f32 speed_ = -1.0) { + void reset(f32 value_, f32 rate_ = -1.0) { value = previous_value = value_; - speed = speed_; + rate = rate_; } void update(); - static void update(f32& t); + static void update(f32* t, f32 rate); bool hasEnded(f32 end_time) const; f32 value{}; f32 previous_value{}; - f32 speed{}; + f32 rate{}; }; } // namespace ksys