diff options
| author | Briggs Baltzell <b3apollo13@gmail.com> | 2023-07-01 15:29:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-01 21:29:40 +0100 |
| commit | fd527f92164b8efdb746cffcf23c4f033fbffa76 (patch) | |
| tree | 492976adfdf031252c85de91a185bfd625738a0c /src/KingSystem/System | |
| parent | bdd6e57d63bde1714fb42197ac4080833ac6b572 (diff) | |
Added VFR::getDeltaFrame (#122)
* Added getDeltaFrame and changed getDeltaTime
* Replaced getDeltaTime usages with getDeltaFrame
* Moved getDeltaTime above getDeltaFrame
Diffstat (limited to 'src/KingSystem/System')
| -rw-r--r-- | src/KingSystem/System/SystemTimers.cpp | 2 | ||||
| -rw-r--r-- | src/KingSystem/System/Timer.cpp | 2 | ||||
| -rw-r--r-- | src/KingSystem/System/VFR.cpp | 2 | ||||
| -rw-r--r-- | src/KingSystem/System/VFR.h | 19 | ||||
| -rw-r--r-- | src/KingSystem/System/VFRValue.cpp | 4 |
5 files changed, 16 insertions, 13 deletions
diff --git a/src/KingSystem/System/SystemTimers.cpp b/src/KingSystem/System/SystemTimers.cpp index 4142cfd9..31c87562 100644 --- a/src/KingSystem/System/SystemTimers.cpp +++ b/src/KingSystem/System/SystemTimers.cpp @@ -26,7 +26,7 @@ void SystemTimers::prepareStageUnload() {} void SystemTimers::incrementCountersAndUpdate() { mFrameCounter++; mFrameCounter2++; - f32 deltaTime = VFR::instance()->getDeltaTime(); + f32 deltaTime = VFR::instance()->getDeltaFrame(); mVfrTimer += deltaTime; while (mVfrTimer >= 1) { diff --git a/src/KingSystem/System/Timer.cpp b/src/KingSystem/System/Timer.cpp index 00749b9f..64aef391 100644 --- a/src/KingSystem/System/Timer.cpp +++ b/src/KingSystem/System/Timer.cpp @@ -4,7 +4,7 @@ namespace ksys { void Timer::update(f32* t, f32 rate) { - *t += VFR::instance()->getDeltaTime() * rate; + *t += VFR::instance()->getDeltaFrame() * rate; } void Timer::update() { diff --git a/src/KingSystem/System/VFR.cpp b/src/KingSystem/System/VFR.cpp index e0f6d8b2..f2ae8d1f 100644 --- a/src/KingSystem/System/VFR.cpp +++ b/src/KingSystem/System/VFR.cpp @@ -189,7 +189,7 @@ void VFR::ScopedDeltaSetter::set(u32 include_mask, u32 exclude_mask) { f32 raw_delta; const auto delta = vfr->getDeltaAndSetMin(&raw_delta, include_mask, exclude_mask); - const auto time = vfr->getDeltaTime(); + const auto time = vfr->getDeltaFrame(); if (delta != time) { mPreviousDelta = raw_delta; if (delta > 0.0) diff --git a/src/KingSystem/System/VFR.h b/src/KingSystem/System/VFR.h index a664c2c1..1f69fbdc 100644 --- a/src/KingSystem/System/VFR.h +++ b/src/KingSystem/System/VFR.h @@ -69,7 +69,10 @@ public: // TODO: requires ksys::Sound void resetTimeMultiplier(u32 idx); - f32 getDeltaTime(u32 core) const { return *mDeltaFrames[core]; } + f32 getDeltaFrame(u32 core) const { return *mDeltaFrames[core]; } + f32 getDeltaFrame() const { return getDeltaFrame(sead::CoreInfo::getCurrentCoreId()); } + + f32 getDeltaTime(u32 core) const { return *mDeltaTimes[core]; } f32 getDeltaTime() const { return getDeltaTime(sead::CoreInfo::getCurrentCoreId()); } f32 getIntervalRatio(u32 core) const { return *mIntervalRatios[core]; } @@ -77,16 +80,16 @@ public: template <typename T> static inline void add(T* value, const T& v) { - *value += v * instance()->getDeltaTime(); + *value += v * instance()->getDeltaFrame(); } template <typename T> static inline void multiply(T* value, f32 scalar) { - *value *= std::pow(scalar, instance()->getDeltaTime()); + *value *= std::pow(scalar, instance()->getDeltaFrame()); } static inline f32 getLerpFactor(f32 t) { - return 1.0f - std::pow(1.0f - t, instance()->getDeltaTime()); + return 1.0f - std::pow(1.0f - t, instance()->getDeltaFrame()); } template <typename T> @@ -97,7 +100,7 @@ public: template <typename T> static inline void lerp(T* value, const T& b, f32 t, f32 max_delta) { const auto f = getLerpFactor(t); - const auto max_d = instance()->getDeltaTime() * max_delta; + const auto max_d = instance()->getDeltaFrame() * max_delta; const auto diff = b - *value; const auto d = f * sead::Mathf::abs(diff); if (d > max_d) @@ -109,8 +112,8 @@ public: template <typename T> static inline bool lerp(T* value, const T& b, f32 t, f32 max_delta, f32 min_delta) { const auto f = getLerpFactor(t); - const auto max_d = instance()->getDeltaTime() * max_delta; - const auto min_d = instance()->getDeltaTime() * min_delta; + const auto max_d = instance()->getDeltaFrame() * max_delta; + const auto min_d = instance()->getDeltaFrame() * min_delta; const auto diff = b - *value; const auto d = f * sead::Mathf::abs(diff); @@ -132,7 +135,7 @@ public: template <typename VectorT> static inline bool chaseVec(VectorT* value, const VectorT& target, f32 t) { - const auto delta = instance()->getDeltaTime() * t; + const auto delta = instance()->getDeltaFrame() * t; const auto diff = target - *value; const auto norm = diff.length(); diff --git a/src/KingSystem/System/VFRValue.cpp b/src/KingSystem/System/VFRValue.cpp index aa9328b2..de18914e 100644 --- a/src/KingSystem/System/VFRValue.cpp +++ b/src/KingSystem/System/VFRValue.cpp @@ -13,7 +13,7 @@ util::InitTimeInfoEx sInitInfo; template <typename T> void updateStatsImpl(const T& value, T* prev_value, T* mean) { - const T new_mean = ((*prev_value + value) / 2) * VFR::instance()->getDeltaTime(); + const T new_mean = ((*prev_value + value) / 2) * VFR::instance()->getDeltaFrame(); *prev_value = value; *mean = new_mean; } @@ -49,7 +49,7 @@ bool VFRValue::lerp(const f32& b, f32 t, f32 max_delta, f32 min_delta) { } bool VFRValue::chase(const f32& target, f32 step) { - const auto delta = step * VFR::instance()->getDeltaTime(); + const auto delta = step * VFR::instance()->getDeltaFrame(); return sead::Mathf::chase(&value, target, delta); } |
