From a2517a504ea1285fd13b4c44925fa8a5c5159099 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 22 Mar 2020 06:05:56 -0400 Subject: [PATCH] CIntElement: Remove const_cast CIESampleAndHold caches values internally for use later in a non-visible manner to the user of the class. This is a good place for mutable to be used. This improves the readability of the GetValue() implementation. --- Runtime/Particle/CIntElement.cpp | 8 ++++---- Runtime/Particle/CIntElement.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Runtime/Particle/CIntElement.cpp b/Runtime/Particle/CIntElement.cpp index 654f874e2..591bf4d93 100644 --- a/Runtime/Particle/CIntElement.cpp +++ b/Runtime/Particle/CIntElement.cpp @@ -189,12 +189,12 @@ bool CIESampleAndHold::GetValue(int frame, int& valOut) const { int b, c; xc_waitFramesMin->GetValue(frame, b); x10_waitFramesMax->GetValue(frame, c); - /* const-correctness, who needs it? */ - const_cast(this)->x8_nextSampleFrame = CRandom16::GetRandomNumber()->Range(b, c) + frame; + x8_nextSampleFrame = CRandom16::GetRandomNumber()->Range(b, c) + frame; x4_sampleSource->GetValue(frame, valOut); - const_cast(this)->x14_holdVal = valOut; - } else + x14_holdVal = valOut; + } else { valOut = x14_holdVal; + } return false; } diff --git a/Runtime/Particle/CIntElement.hpp b/Runtime/Particle/CIntElement.hpp index 78602b998..671c506ef 100644 --- a/Runtime/Particle/CIntElement.hpp +++ b/Runtime/Particle/CIntElement.hpp @@ -134,10 +134,10 @@ public: class CIESampleAndHold : public CIntElement { std::unique_ptr x4_sampleSource; - int x8_nextSampleFrame = 0; + mutable int x8_nextSampleFrame = 0; std::unique_ptr xc_waitFramesMin; std::unique_ptr x10_waitFramesMax; - int x14_holdVal; + mutable int x14_holdVal; public: CIESampleAndHold(std::unique_ptr&& a, std::unique_ptr&& b, std::unique_ptr&& c)