From 69820471349ae5cc02543770a2f500c162a22f18 Mon Sep 17 00:00:00 2001 From: MonsterDruide1 <5958456@gmail.com> Date: Thu, 5 Aug 2021 01:33:20 +0200 Subject: [PATCH] ksys: Add SystemTimers --- data/uking_functions.csv | 22 ++++++------ src/KingSystem/System/CMakeLists.txt | 2 ++ src/KingSystem/System/SystemTimers.cpp | 49 ++++++++++++++++++++++++++ src/KingSystem/System/SystemTimers.h | 31 ++++++++++++++++ 4 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 src/KingSystem/System/SystemTimers.cpp create mode 100644 src/KingSystem/System/SystemTimers.h diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 6fdd3779..d2f5c3bc 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -80052,17 +80052,17 @@ Address,Quality,Size,Name 0x0000007100eda27c,O,000288,_ZNK5uking6action19SystemSetWindAction27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE 0x0000007100eda39c,O,000092,_ZNK5uking6action19SystemSetWindAction18getRuntimeTypeInfoEv 0x0000007100eda3f8,O,000052,_ZN5uking6action19SystemSetWindActionD0Ev -0x0000007100eda42c,U,000100,PlacementGlobal::Disposer::dtor -0x0000007100eda490,U,000108,PlacementGlobal::Disposer::dtorDelete -0x0000007100eda4fc,U,000152,PlacementGlobal::createInstance -0x0000007100eda594,U,000088,PlacementGlobal::deleteInstance -0x0000007100eda5ec,U,000004,nullsub_4054 -0x0000007100eda5f0,U,000004,j__ZdlPv_960 -0x0000007100eda5f4,U,000012,PlacementGlobal::init -0x0000007100eda600,U,000012,PlacementGlobal::__auto0 -0x0000007100eda60c,U,000004,nullsub_4055 -0x0000007100eda610,U,000236,PlacementGlobal::incrementCountersAndUpdate -0x0000007100eda6fc,U,000028,PlacementGlobal::incrementCounters +0x0000007100eda42c,O,000100,_ZN4ksys12SystemTimers18SingletonDisposer_D1Ev +0x0000007100eda490,O,000108,_ZN4ksys12SystemTimers18SingletonDisposer_D0Ev +0x0000007100eda4fc,O,000152,_ZN4ksys12SystemTimers14createInstanceEPN4sead4HeapE +0x0000007100eda594,O,000088,_ZN4ksys12SystemTimers14deleteInstanceEv +0x0000007100eda5ec,O,000004,_ZN4ksys12SystemTimersD1Ev +0x0000007100eda5f0,O,000004,_ZN4ksys12SystemTimersD0Ev +0x0000007100eda5f4,O,000012,_ZN4ksys12SystemTimers4initEv +0x0000007100eda600,O,000012,_ZN4ksys12SystemTimers5init2Ev +0x0000007100eda60c,O,000004,_ZN4ksys12SystemTimers18prepareStageUnloadEv +0x0000007100eda610,O,000236,_ZN4ksys12SystemTimers26incrementCountersAndUpdateEv +0x0000007100eda6fc,O,000028,_ZN4ksys12SystemTimers17incrementCountersEv 0x0000007100eda718,U,000104,System::construct 0x0000007100eda780,U,000004,j_Actor::m0_4 0x0000007100eda784,U,000008, diff --git a/src/KingSystem/System/CMakeLists.txt b/src/KingSystem/System/CMakeLists.txt index f3fe4e5b..b9dae8a7 100644 --- a/src/KingSystem/System/CMakeLists.txt +++ b/src/KingSystem/System/CMakeLists.txt @@ -35,6 +35,8 @@ target_sources(uking PRIVATE StringBoard.h SystemPauseMgr.cpp SystemPauseMgr.h + SystemTimers.cpp + SystemTimers.h Timer.cpp Timer.h UIGlue.cpp diff --git a/src/KingSystem/System/SystemTimers.cpp b/src/KingSystem/System/SystemTimers.cpp new file mode 100644 index 00000000..4142cfd9 --- /dev/null +++ b/src/KingSystem/System/SystemTimers.cpp @@ -0,0 +1,49 @@ +#include "KingSystem/System/SystemTimers.h" + +#include "KingSystem/System/VFR.h" + +namespace ksys { + +SEAD_SINGLETON_DISPOSER_IMPL(SystemTimers) + +SystemTimers::~SystemTimers() = default; + +void SystemTimers::init() { + mVfrTimer = 0; + mFrameCounterB = 0; + mVfrTimer2 = 0; + mFrameCounterB2 = 0; + mFrameCounter = 0; + mFrameCounter2 = 0; +} + +void SystemTimers::init2() { + init(); +} + +void SystemTimers::prepareStageUnload() {} + +void SystemTimers::incrementCountersAndUpdate() { + mFrameCounter++; + mFrameCounter2++; + f32 deltaTime = VFR::instance()->getDeltaTime(); + mVfrTimer += deltaTime; + + while (mVfrTimer >= 1) { + mFrameCounterB++; + mVfrTimer--; + } + + mVfrTimer2 += deltaTime; + while (mVfrTimer2 >= 1) { + mFrameCounterB2++; + mVfrTimer2--; + } +} + +void SystemTimers::incrementCounters() { + mFrameCounter++; + mFrameCounterB++; +} + +} // namespace ksys diff --git a/src/KingSystem/System/SystemTimers.h b/src/KingSystem/System/SystemTimers.h new file mode 100644 index 00000000..81203aff --- /dev/null +++ b/src/KingSystem/System/SystemTimers.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include "KingSystem/Utils/Types.h" + +namespace ksys { + +class SystemTimers { + SEAD_SINGLETON_DISPOSER(SystemTimers); + + SystemTimers() = default; + virtual ~SystemTimers(); + +public: + void init(); + void init2(); + void prepareStageUnload(); + void incrementCountersAndUpdate(); + void incrementCounters(); + + unsigned int mFrameCounter = 0; + int mFrameCounter2 = 0; + float mVfrTimer = 0; + int mFrameCounterB = 0; + float mVfrTimer2 = 0; + int mFrameCounterB2 = 0; +}; +KSYS_CHECK_SIZE_NX150(SystemTimers, 0x40); + +} // namespace ksys