ksys: Fix some VFR functions not being inline

This commit is contained in:
Léo Lam 2021-05-13 15:24:31 +02:00
parent 561e83b869
commit 3af5a55a65
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 65 additions and 68 deletions

View File

@ -628,7 +628,7 @@
0x000000710001b4d0,sub_710001B4D0,100,
0x000000710001b534,sub_710001B534,104,
0x000000710001b59c,sub_710001B59C,796,
0x000000710001b8b8,vfr::updateTimer,412,_ZN4ksys8VFRValue9lerpValueEPfRKffff
0x000000710001b8b8,vfr::updateTimer,412,_ZN4ksys3VFR4lerpIfEEbPT_RKS2_fff
0x000000710001ba54,sub_710001BA54,60,
0x000000710001ba90,sub_710001BA90,60,
0x000000710001bacc,sub_710001BACC,288,

Can't render this file because it is too large.

View File

@ -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() {

View File

@ -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) {

View File

@ -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);