summaryrefslogtreecommitdiff
path: root/src/KingSystem
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-05-13 15:24:31 +0200
committerLéo Lam <leo@leolam.fr>2021-05-13 15:41:30 +0200
commit3af5a55a653a477c70e90dc3773ad50bfa2b4fb2 (patch)
tree2f82931d2b9476479ae778a866bd1b7f433e5b1c /src/KingSystem
parent561e83b869157c8f91305baf4ff1095161ac9960 (diff)
ksys: Fix some VFR functions not being inline
Diffstat (limited to 'src/KingSystem')
-rw-r--r--src/KingSystem/System/VFR.h57
-rw-r--r--src/KingSystem/System/VFRValue.cpp73
-rw-r--r--src/KingSystem/System/VFRValue.h1
3 files changed, 64 insertions, 67 deletions
diff --git a/src/KingSystem/System/VFR.h b/src/KingSystem/System/VFR.h
index 97562e87..10a8bcaa 100644
--- a/src/KingSystem/System/VFR.h
+++ b/src/KingSystem/System/VFR.h
@@ -1,9 +1,11 @@
#pragma once
#include <basis/seadTypes.h>
+#include <cmath>
#include <container/seadBuffer.h>
#include <container/seadSafeArray.h>
#include <heap/seadDisposer.h>
+#include <math/seadMathCalcCommon.h>
#include <mc/seadCoreInfo.h>
#include <prim/seadBitFlag.h>
#include "KingSystem/Utils/Types.h"
@@ -69,6 +71,61 @@ public:
f32 getDeltaTime(u32 core) const { return *mDeltaFrames[core]; }
f32 getDeltaTime() const { return getDeltaTime(sead::CoreInfo::getCurrentCoreId()); }
+ template <typename T>
+ static inline void add(T* value, const T& v) {
+ *value += v * instance()->getDeltaTime();
+ }
+
+ template <typename T>
+ static inline void multiply(T* value, f32 scalar) {
+ *value *= std::pow(scalar, instance()->getDeltaTime());
+ }
+
+ static inline f32 getLerpFactor(f32 t) {
+ return 1.0f - std::pow(1.0f - t, instance()->getDeltaTime());
+ }
+
+ template <typename T>
+ static inline void lerp(T* value, const T& b, f32 t) {
+ *value += getLerpFactor(t) * (b - *value);
+ }
+
+ 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 diff = b - *value;
+ const auto d = f * sead::absf(diff);
+ if (d > max_d)
+ *value += diff < 0.0 ? -max_d : max_d;
+ else
+ *value += f * diff;
+ }
+
+ 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 diff = b - *value;
+ const auto d = f * sead::absf(diff);
+
+ if (sead::absf(diff) <= min_d) {
+ *value = b;
+ return true;
+ }
+
+ if (d > max_d) {
+ *value += diff < 0.0 ? -max_d : max_d;
+ } else if (d < min_d) {
+ *value += diff < 0.0 ? -min_d : min_d;
+ } else {
+ *value = *value + f * diff;
+ }
+ return false;
+ }
+
private:
struct TimeSpeedMultipliers : sead::Buffer<TimeSpeedMultiplier> {
TimeSpeedMultipliers() {
diff --git a/src/KingSystem/System/VFRValue.cpp b/src/KingSystem/System/VFRValue.cpp
index a49d4161..471f18a2 100644
--- a/src/KingSystem/System/VFRValue.cpp
+++ b/src/KingSystem/System/VFRValue.cpp
@@ -11,10 +11,6 @@ namespace {
util::InitTimeInfoEx sInitInfo;
-f32 getLerpFactor(f32 t) {
- return 1.0f - std::pow(1.0f - t, VFR::instance()->getDeltaTime());
-}
-
template <typename T>
void updateStatsImpl(const T& value, T* prev_value, T* mean) {
const T new_mean = ((*prev_value + value) / 2) * VFR::instance()->getDeltaTime();
@@ -22,57 +18,6 @@ void updateStatsImpl(const T& value, T* prev_value, T* mean) {
*mean = new_mean;
}
-template <typename T>
-void addImpl(T* value, const T& v) {
- *value += v * VFR::instance()->getDeltaTime();
-}
-
-template <typename T>
-void multiplyImpl(T* value, f32 scalar) {
- *value *= std::pow(scalar, VFR::instance()->getDeltaTime());
-}
-
-template <typename T>
-void lerpImpl(T* value, const T& b, f32 t) {
- *value += getLerpFactor(t) * (b - *value);
-}
-
-template <typename T>
-void lerpImpl(T* value, const T& b, f32 t, f32 max_delta) {
- const auto f = getLerpFactor(t);
- const auto max_d = VFR::instance()->getDeltaTime() * max_delta;
- const auto diff = b - *value;
- const auto d = f * sead::absf(diff);
- if (d > max_d)
- *value += diff < 0.0 ? -max_d : max_d;
- else
- *value += f * diff;
-}
-
-template <typename T>
-bool lerpImpl(T* value, const T& b, f32 t, f32 max_delta, f32 min_delta) {
- const auto f = getLerpFactor(t);
- const auto max_d = VFR::instance()->getDeltaTime() * max_delta;
- const auto min_d = VFR::instance()->getDeltaTime() * min_delta;
-
- const auto diff = b - *value;
- const auto d = f * sead::absf(diff);
-
- if (sead::absf(diff) <= min_d) {
- *value = b;
- return true;
- }
-
- if (d > max_d) {
- *value += diff < 0.0 ? -max_d : max_d;
- } else if (d < min_d) {
- *value += diff < 0.0 ? -min_d : min_d;
- } else {
- *value += f * diff;
- }
- return false;
-}
-
} // namespace
VFRValue::VFRValue() = default;
@@ -84,27 +29,23 @@ void VFRValue::updateStats() {
}
void VFRValue::operator+=(const f32& rhs) {
- addImpl(&value, rhs);
+ VFR::add(&value, rhs);
}
void VFRValue::operator*=(f32 scalar) {
- multiplyImpl(&value, scalar);
+ VFR::multiply(&value, scalar);
}
void VFRValue::lerp(const f32& b, f32 t) {
- lerpImpl(&value, b, t);
+ VFR::lerp(&value, b, t);
}
void VFRValue::lerp(const f32& b, f32 t, f32 max_delta) {
- lerpImpl(&value, b, t, max_delta);
+ VFR::lerp(&value, b, t, max_delta);
}
bool VFRValue::lerp(const f32& b, f32 t, f32 max_delta, f32 min_delta) {
- return lerpValue(&value, b, t, max_delta, min_delta);
-}
-
-bool VFRValue::lerpValue(f32* value, const f32& b, f32 t, f32 max_delta, f32 min_delta) {
- return lerpImpl(value, b, t, max_delta, min_delta);
+ return VFR::lerp(&value, b, t, max_delta, min_delta);
}
bool VFRValue::chase(const f32& target, f32 step) {
@@ -122,11 +63,11 @@ void VFRVec3f::updateStats() {
}
void VFRVec3f::operator*=(f32 scalar) {
- multiplyImpl(&value, scalar);
+ VFR::multiply(&value, scalar);
}
void VFRVec3f::lerp(const sead::Vector3f& b, f32 t) {
- lerpImpl(&value, b, t);
+ VFR::lerp(&value, b, t);
}
bool VFRVec3f::chase(const sead::Vector3f& target, f32 t) {
diff --git a/src/KingSystem/System/VFRValue.h b/src/KingSystem/System/VFRValue.h
index 34acbdcc..ff7a5a41 100644
--- a/src/KingSystem/System/VFRValue.h
+++ b/src/KingSystem/System/VFRValue.h
@@ -16,7 +16,6 @@ struct VFRValue {
void lerp(const f32& b, f32 t);
void lerp(const f32& b, f32 t, f32 max_delta);
bool lerp(const f32& b, f32 t, f32 max_delta, f32 min_delta);
- static bool lerpValue(f32* value, const f32& b, f32 t, f32 max_delta, f32 min_delta);
bool chase(const f32& target, f32 step);
void setToMax(const f32& max);
void setToMin(const f32& min);