summaryrefslogtreecommitdiff
path: root/src/KingSystem
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2022-10-13 01:57:37 +0200
committerLéo Lam <leo@leolam.fr>2022-10-13 01:58:10 +0200
commit18510196d9cc74230f679a3ca849347702f3715a (patch)
treee5c9bee6ece806ffb25e1a4f01d6060fff49795c /src/KingSystem
parent0bdc0c761165a51a72753f21eefff94e8f692f10 (diff)
ksys: Refactor VFRVec3f::chase into reusable/inlinable function
Might be useful for https://decomp.me/scratch/n58lh
Diffstat (limited to 'src/KingSystem')
-rw-r--r--src/KingSystem/System/VFR.h15
-rw-r--r--src/KingSystem/System/VFRValue.cpp12
2 files changed, 16 insertions, 11 deletions
diff --git a/src/KingSystem/System/VFR.h b/src/KingSystem/System/VFR.h
index 945072ce..a664c2c1 100644
--- a/src/KingSystem/System/VFR.h
+++ b/src/KingSystem/System/VFR.h
@@ -130,6 +130,21 @@ public:
return false;
}
+ template <typename VectorT>
+ static inline bool chaseVec(VectorT* value, const VectorT& target, f32 t) {
+ const auto delta = instance()->getDeltaTime() * t;
+ const auto diff = target - *value;
+ const auto norm = diff.length();
+
+ if (norm <= delta) {
+ value->e = target.e;
+ return true;
+ }
+
+ value->setScaleAdd(delta, (1.0f / norm) * diff, *value);
+ return false;
+ }
+
private:
struct TimeSpeedMultipliers : sead::Buffer<TimeSpeedMultiplier> {
TimeSpeedMultipliers() {
diff --git a/src/KingSystem/System/VFRValue.cpp b/src/KingSystem/System/VFRValue.cpp
index f8452a72..aa9328b2 100644
--- a/src/KingSystem/System/VFRValue.cpp
+++ b/src/KingSystem/System/VFRValue.cpp
@@ -71,17 +71,7 @@ void VFRVec3f::lerp(const sead::Vector3f& b, f32 t) {
}
bool VFRVec3f::chase(const sead::Vector3f& target, f32 t) {
- const auto delta = VFR::instance()->getDeltaTime() * t;
- const auto diff = target - value;
- const auto norm = diff.length();
-
- if (norm <= delta) {
- sead::MemUtil::copy(&value, &target, sizeof(value));
- return true;
- }
-
- value += diff * (1.0f / norm) * delta;
- return false;
+ return VFR::chaseVec(&value, target, t);
}
void VFRValue::setToMax(const f32& max) {