From 4f1099b640f965eb57a0f3ee518d2510c61138ba Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Thu, 20 Oct 2022 04:10:34 +0300 Subject: [PATCH] Improve CRippleManager::AddRipple Former-commit-id: 5b4dfc02584f2b6f6eae9d621f031f529e35ebc6 --- include/MetroidPrime/CRippleManager.hpp | 9 +++++++++ src/MetroidPrime/CRippleManager.cpp | 23 ++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/MetroidPrime/CRippleManager.hpp b/include/MetroidPrime/CRippleManager.hpp index abfcbf32..001072fe 100644 --- a/include/MetroidPrime/CRippleManager.hpp +++ b/include/MetroidPrime/CRippleManager.hpp @@ -20,6 +20,15 @@ public: void Update(float dt); float GetLastRippleDeltaTime(TUniqueId rippler) const; void AddRipple(const CRipple& ripple); + + void SetMaxTimeFalloff(float time) { x0_maxTimeFalloff = time; } + float GetMaxTimeFalloff() const { return x0_maxTimeFalloff; } + + rstl::vector& Ripples() { return x4_ripples; } + const rstl::vector& GetRipples() const { return x4_ripples; } + + void SetAlpha(float a) { x14_alpha = a; } + float GetAlpha() const { return x14_alpha; } }; #endif // _CRIPPLEMANAGER diff --git a/src/MetroidPrime/CRippleManager.cpp b/src/MetroidPrime/CRippleManager.cpp index 6f8e5e10..e73d09fb 100644 --- a/src/MetroidPrime/CRippleManager.cpp +++ b/src/MetroidPrime/CRippleManager.cpp @@ -42,22 +42,23 @@ float CRippleManager::GetLastRippleDeltaTime(TUniqueId rippler) const { void CRippleManager::AddRipple(const CRipple& ripple) { float maxTime = 0.f; - float itTime; - rstl::vector< CRipple >::iterator t; rstl::vector< CRipple >::iterator oldestRipple = x4_ripples.end(); - rstl::vector< CRipple >::iterator it = x4_ripples.begin(); - for (; (t = oldestRipple, - it != x4_ripples.end() && (itTime = it->GetTime(), t = it, itTime != 9999.0f)); - ++it) { - if (itTime > maxTime) { + for (rstl::vector< CRipple >::iterator it = x4_ripples.begin(); it != x4_ripples.end(); ++it) { + if (it->GetTime() == 9999.0f) { oldestRipple = it; - maxTime = itTime; + break; + } + + if (it->GetTime() > maxTime) { + oldestRipple = it; + maxTime = it->GetTime(); } } - if (t != x4_ripples.end()) { - *t = ripple; - x0_maxTimeFalloff = rstl::max_val(x0_maxTimeFalloff, ripple.GetTimeFalloff()); + if (oldestRipple != x4_ripples.end()) { + *oldestRipple = ripple; + oldestRipple->SetTime(0.f); + SetMaxTimeFalloff(rstl::max_val(GetMaxTimeFalloff(), ripple.GetTimeFalloff())); } }