Improve CRippleManager::AddRipple

Former-commit-id: 5b4dfc0258
This commit is contained in:
Henrique Gemignani Passos Lima 2022-10-20 04:10:34 +03:00
parent d1c7ac8887
commit 4f1099b640
2 changed files with 21 additions and 11 deletions

View File

@ -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<CRipple>& Ripples() { return x4_ripples; }
const rstl::vector<CRipple>& GetRipples() const { return x4_ripples; }
void SetAlpha(float a) { x14_alpha = a; }
float GetAlpha() const { return x14_alpha; }
};
#endif // _CRIPPLEMANAGER

View File

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