Added VFR::getDeltaFrame (#122)

* Added getDeltaFrame and changed getDeltaTime

* Replaced getDeltaTime usages with getDeltaFrame

* Moved getDeltaTime above getDeltaFrame
This commit is contained in:
Briggs Baltzell 2023-07-01 15:29:40 -05:00 committed by GitHub
parent bdd6e57d63
commit fd527f9216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 25 additions and 22 deletions

View File

@ -111,7 +111,7 @@ void PlacementMgr::x() {
f32 last_time = mTime; f32 last_time = mTime;
auto* vfr = VFR::instance(); auto* vfr = VFR::instance();
mTime += vfr->getDeltaTime(); mTime += vfr->getDeltaFrame();
mTimeUpdated = s32(last_time) != s32(mTime); mTimeUpdated = s32(last_time) != s32(mTime);
} }

View File

@ -26,7 +26,7 @@ void SystemTimers::prepareStageUnload() {}
void SystemTimers::incrementCountersAndUpdate() { void SystemTimers::incrementCountersAndUpdate() {
mFrameCounter++; mFrameCounter++;
mFrameCounter2++; mFrameCounter2++;
f32 deltaTime = VFR::instance()->getDeltaTime(); f32 deltaTime = VFR::instance()->getDeltaFrame();
mVfrTimer += deltaTime; mVfrTimer += deltaTime;
while (mVfrTimer >= 1) { while (mVfrTimer >= 1) {

View File

@ -4,7 +4,7 @@
namespace ksys { namespace ksys {
void Timer::update(f32* t, f32 rate) { void Timer::update(f32* t, f32 rate) {
*t += VFR::instance()->getDeltaTime() * rate; *t += VFR::instance()->getDeltaFrame() * rate;
} }
void Timer::update() { void Timer::update() {

View File

@ -189,7 +189,7 @@ void VFR::ScopedDeltaSetter::set(u32 include_mask, u32 exclude_mask) {
f32 raw_delta; f32 raw_delta;
const auto delta = vfr->getDeltaAndSetMin(&raw_delta, include_mask, exclude_mask); const auto delta = vfr->getDeltaAndSetMin(&raw_delta, include_mask, exclude_mask);
const auto time = vfr->getDeltaTime(); const auto time = vfr->getDeltaFrame();
if (delta != time) { if (delta != time) {
mPreviousDelta = raw_delta; mPreviousDelta = raw_delta;
if (delta > 0.0) if (delta > 0.0)

View File

@ -69,7 +69,10 @@ public:
// TODO: requires ksys::Sound // TODO: requires ksys::Sound
void resetTimeMultiplier(u32 idx); 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 getDeltaTime() const { return getDeltaTime(sead::CoreInfo::getCurrentCoreId()); }
f32 getIntervalRatio(u32 core) const { return *mIntervalRatios[core]; } f32 getIntervalRatio(u32 core) const { return *mIntervalRatios[core]; }
@ -77,16 +80,16 @@ public:
template <typename T> template <typename T>
static inline void add(T* value, const T& v) { static inline void add(T* value, const T& v) {
*value += v * instance()->getDeltaTime(); *value += v * instance()->getDeltaFrame();
} }
template <typename T> template <typename T>
static inline void multiply(T* value, f32 scalar) { 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) { 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> template <typename T>
@ -97,7 +100,7 @@ public:
template <typename T> template <typename T>
static inline void lerp(T* value, const T& b, f32 t, f32 max_delta) { static inline void lerp(T* value, const T& b, f32 t, f32 max_delta) {
const auto f = getLerpFactor(t); 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 diff = b - *value;
const auto d = f * sead::Mathf::abs(diff); const auto d = f * sead::Mathf::abs(diff);
if (d > max_d) if (d > max_d)
@ -109,8 +112,8 @@ public:
template <typename T> template <typename T>
static inline bool lerp(T* value, const T& b, f32 t, f32 max_delta, f32 min_delta) { static inline bool lerp(T* value, const T& b, f32 t, f32 max_delta, f32 min_delta) {
const auto f = getLerpFactor(t); const auto f = getLerpFactor(t);
const auto max_d = instance()->getDeltaTime() * max_delta; const auto max_d = instance()->getDeltaFrame() * max_delta;
const auto min_d = instance()->getDeltaTime() * min_delta; const auto min_d = instance()->getDeltaFrame() * min_delta;
const auto diff = b - *value; const auto diff = b - *value;
const auto d = f * sead::Mathf::abs(diff); const auto d = f * sead::Mathf::abs(diff);
@ -132,7 +135,7 @@ public:
template <typename VectorT> template <typename VectorT>
static inline bool chaseVec(VectorT* value, const VectorT& target, f32 t) { 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 diff = target - *value;
const auto norm = diff.length(); const auto norm = diff.length();

View File

@ -13,7 +13,7 @@ util::InitTimeInfoEx sInitInfo;
template <typename T> template <typename T>
void updateStatsImpl(const T& value, T* prev_value, T* mean) { 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; *prev_value = value;
*mean = new_mean; *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) { 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); return sead::Mathf::chase(&value, target, delta);
} }

View File

@ -345,14 +345,14 @@ void EnvMgr::updateForcedBloodMoon() {
case 1: case 1:
// Update the forced blood moon timer // Update the forced blood moon timer
if (evt::Manager::instance()->hasActiveEvent() || mBloodMoonProhibited) { if (evt::Manager::instance()->hasActiveEvent() || mBloodMoonProhibited) {
mForcedBloodMoonTimer -= VFR::instance()->getDeltaTime(); mForcedBloodMoonTimer -= VFR::instance()->getDeltaFrame();
if (mForcedBloodMoonTimer <= 0.0f) { if (mForcedBloodMoonTimer <= 0.0f) {
mForcedBloodMoonTimer = 0.0f; mForcedBloodMoonTimer = 0.0f;
mForcedBloodMoonStatus = 0; mForcedBloodMoonStatus = 0;
mForcedBloodMoonReady = false; mForcedBloodMoonReady = false;
} }
} else { } else {
mForcedBloodMoonTimer += VFR::instance()->getDeltaTime(); mForcedBloodMoonTimer += VFR::instance()->getDeltaFrame();
if (mForcedBloodMoonTimer >= BloodMoonTimerDuration) { if (mForcedBloodMoonTimer >= BloodMoonTimerDuration) {
mForcedBloodMoonTimer = BloodMoonTimerDuration; mForcedBloodMoonTimer = BloodMoonTimerDuration;
mForcedBloodMoonReady = true; mForcedBloodMoonReady = true;
@ -376,7 +376,7 @@ void EnvMgr::updateForcedBloodMoon() {
case 3: case 3:
// Slowly fade out the blood moon state // Slowly fade out the blood moon state
mForcedBloodMoonTimer -= VFR::instance()->getDeltaTime(); mForcedBloodMoonTimer -= VFR::instance()->getDeltaFrame();
if (mForcedBloodMoonTimer <= 0.0f) { if (mForcedBloodMoonTimer <= 0.0f) {
mForcedBloodMoonTimer = 0.0f; mForcedBloodMoonTimer = 0.0f;
mForcedBloodMoonStatus = 0; mForcedBloodMoonStatus = 0;
@ -389,14 +389,14 @@ void EnvMgr::updateForcedBloodMoon() {
case 4: case 4:
// [Alternative state 2] Wait for blood moons to be allowed again // [Alternative state 2] Wait for blood moons to be allowed again
if (mBloodMoonProhibited && !mDeactivateForcedBloodMoon) { if (mBloodMoonProhibited && !mDeactivateForcedBloodMoon) {
mForcedBloodMoonTimer -= VFR::instance()->getDeltaTime(); mForcedBloodMoonTimer -= VFR::instance()->getDeltaFrame();
if (mForcedBloodMoonTimer <= 0.0f) { if (mForcedBloodMoonTimer <= 0.0f) {
mForcedBloodMoonTimer = 0.0f; mForcedBloodMoonTimer = 0.0f;
mForcedBloodMoonStatus = 0; mForcedBloodMoonStatus = 0;
return; return;
} }
} else { } else {
mForcedBloodMoonTimer += VFR::instance()->getDeltaTime(); mForcedBloodMoonTimer += VFR::instance()->getDeltaFrame();
if (mForcedBloodMoonTimer >= BloodMoonTimerDuration) { if (mForcedBloodMoonTimer >= BloodMoonTimerDuration) {
mForcedBloodMoonTimer = BloodMoonTimerDuration; mForcedBloodMoonTimer = BloodMoonTimerDuration;
mForcedBloodMoonReady = true; mForcedBloodMoonReady = true;

View File

@ -317,7 +317,7 @@ void TimeMgr::calc_() {
if (!mPlayedDemo103Or997 || evt::Manager::instance()->hasActiveEvent()) if (!mPlayedDemo103Or997 || evt::Manager::instance()->hasActiveEvent())
break; break;
const auto delta = mTimeStep * VFR::instance()->getDeltaTime(); const auto delta = mTimeStep * VFR::instance()->getDeltaFrame();
mIsTimeFlowingNormally = true; mIsTimeFlowingNormally = true;
mTime += delta; mTime += delta;
if (mTime >= 24_h) { if (mTime >= 24_h) {
@ -431,7 +431,7 @@ void TimeMgr::calc_() {
break; break;
case TimeUpdateMode::OnlyUpdateTimeOfDay: case TimeUpdateMode::OnlyUpdateTimeOfDay:
mTime += mTimeStep * VFR::instance()->getDeltaTime(); mTime += mTimeStep * VFR::instance()->getDeltaFrame();
if (mTime >= 24_h) if (mTime >= 24_h)
mTime -= 24_h; mTime -= 24_h;
break; break;

View File

@ -7,7 +7,7 @@ SEAD_SINGLETON_DISPOSER_IMPL(DebugInput)
void DebugInput::update() { void DebugInput::update() {
if (mFlags.isOnBit(0)) { if (mFlags.isOnBit(0)) {
mLastDelta += VFR::instance()->getDeltaTime(); mLastDelta += VFR::instance()->getDeltaFrame();
while (mLastDelta > 30.0) { while (mLastDelta > 30.0) {
mLastDelta -= 30.0; mLastDelta -= 30.0;
} }