CLight: Mark caching member variables as mutable

Member variables acting as caches is one of the areas where marking
variables as mutable makes sense.

We can do this to allow for the elimination of const_cast in some member
functions.
This commit is contained in:
Lioncash 2020-03-17 20:45:49 -04:00
parent 9483b64c91
commit e821f736de
2 changed files with 10 additions and 10 deletions

View File

@ -27,20 +27,20 @@ float CLight::CalculateLightRadius() const {
float CLight::GetIntensity() const {
if (x4c_24_intensityDirty) {
const_cast<CLight*>(this)->x4c_24_intensityDirty = false;
x4c_24_intensityDirty = false;
float coef = 1.f;
if (x1c_type == ELightType::Custom)
if (x1c_type == ELightType::Custom) {
coef = x30_angleC;
const_cast<CLight*>(this)->x48_cachedIntensity =
coef * std::max(x18_color.r(), std::max(x18_color.g(), x18_color.b()));
}
x48_cachedIntensity = coef * std::max(x18_color.r(), std::max(x18_color.g(), x18_color.b()));
}
return x48_cachedIntensity;
}
float CLight::GetRadius() const {
if (x4c_25_radiusDirty) {
const_cast<CLight*>(this)->x44_cachedRadius = CalculateLightRadius();
const_cast<CLight*>(this)->x4c_25_radiusDirty = false;
x44_cachedRadius = CalculateLightRadius();
x4c_25_radiusDirty = false;
}
return x44_cachedRadius;
}

View File

@ -35,10 +35,10 @@ class CLight {
float x38_angleQ = 0.f;
u32 x3c_priority = 0;
u32 x40_lightId = 0; // Serves as unique key
float x44_cachedRadius = 0.f;
float x48_cachedIntensity = 0.f;
bool x4c_24_intensityDirty : 1;
bool x4c_25_radiusDirty : 1;
mutable float x44_cachedRadius = 0.f;
mutable float x48_cachedIntensity = 0.f;
mutable bool x4c_24_intensityDirty : 1;
mutable bool x4c_25_radiusDirty : 1;
float CalculateLightRadius() const;