CStateManager: Remove instances of const_cast where applicable

Eliminates trivial casts that don't require much modifications to other
existing interfaces.
This commit is contained in:
Lioncash 2020-03-16 20:07:53 -04:00
parent 58b112dbe6
commit 179f0b5f08
2 changed files with 20 additions and 19 deletions

View File

@ -524,8 +524,8 @@ void CStateManager::RenderCamerasAndAreaLights() const {
filter.Draw(); filter.Draw();
} }
void CStateManager::DrawE3DeathEffect() const { void CStateManager::DrawE3DeathEffect() {
CPlayer& player = *x84c_player; const CPlayer& player = *x84c_player;
if (player.x9f4_deathTime > 0.f) { if (player.x9f4_deathTime > 0.f) {
if (player.x2f8_morphBallState != CPlayer::EPlayerMorphBallState::Unmorphed) { if (player.x2f8_morphBallState != CPlayer::EPlayerMorphBallState::Unmorphed) {
float blurAmt = zeus::clamp(0.f, (player.x9f4_deathTime - 1.f) / (6.f - 1.f), 1.f); float blurAmt = zeus::clamp(0.f, (player.x9f4_deathTime - 1.f) / (6.f - 1.f), 1.f);
@ -535,18 +535,19 @@ void CStateManager::DrawE3DeathEffect() const {
blur.Draw(); blur.Draw();
} }
} }
float whiteAmt = zeus::clamp(0.f, 1.f - player.x9f4_deathTime / (0.05f * 6.f), 1.f);
const float whiteAmt = zeus::clamp(0.f, 1.f - player.x9f4_deathTime / (0.05f * 6.f), 1.f);
zeus::CColor color = zeus::skWhite; zeus::CColor color = zeus::skWhite;
color.a() = whiteAmt; color.a() = whiteAmt;
const_cast<CColoredQuadFilter&>(m_deathWhiteout).draw(color); m_deathWhiteout.draw(color);
} }
} }
void CStateManager::DrawAdditionalFilters() const { void CStateManager::DrawAdditionalFilters() {
if (xf0c_escapeTimer < 1.f && xf0c_escapeTimer > 0.f && !x870_cameraManager->IsInCinematicCamera()) { if (xf0c_escapeTimer < 1.f && xf0c_escapeTimer > 0.f && !x870_cameraManager->IsInCinematicCamera()) {
zeus::CColor color = zeus::skWhite; zeus::CColor color = zeus::skWhite;
color.a() = 1.f - xf0c_escapeTimer; color.a() = 1.f - xf0c_escapeTimer;
const_cast<CColoredQuadFilter&>(m_escapeWhiteout).draw(color); m_escapeWhiteout.draw(color);
} }
} }
@ -629,7 +630,7 @@ void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport,
cam->GetFarClipDistance()); cam->GetFarClipDistance());
} }
void CStateManager::DrawWorld() const { void CStateManager::DrawWorld() {
SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue); SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue);
CTimeProvider timeProvider(xf14_curTimeMod900); CTimeProvider timeProvider(xf14_curTimeMod900);
SViewport backupViewport = g_Viewport; SViewport backupViewport = g_Viewport;
@ -682,11 +683,11 @@ void CStateManager::DrawWorld() const {
CPlayerState::EPlayerVisor visor = x8b8_playerState->GetActiveVisor(*this); CPlayerState::EPlayerVisor visor = x8b8_playerState->GetActiveVisor(*this);
bool thermal = visor == CPlayerState::EPlayerVisor::Thermal; bool thermal = visor == CPlayerState::EPlayerVisor::Thermal;
if (thermal) { if (thermal) {
const_cast<CStateManager&>(*this).xf34_thermalFlag = EThermalDrawFlag::Cold; xf34_thermalFlag = EThermalDrawFlag::Cold;
mask = 0x34; mask = 0x34;
targetMask = 0; targetMask = 0;
} else { } else {
const_cast<CStateManager&>(*this).xf34_thermalFlag = EThermalDrawFlag::Bypass; xf34_thermalFlag = EThermalDrawFlag::Bypass;
mask = 1 << (visor == CPlayerState::EPlayerVisor::XRay ? 3 : 1); mask = 1 << (visor == CPlayerState::EPlayerVisor::XRay ? 3 : 1);
targetMask = 0; targetMask = 0;
} }
@ -758,7 +759,7 @@ void CStateManager::DrawWorld() const {
x884_actorModelParticles->AddStragglersToRenderer(*this); x884_actorModelParticles->AddStragglersToRenderer(*this);
} }
++const_cast<CStateManager&>(*this).x8dc_objectDrawToken; ++x8dc_objectDrawToken;
x84c_player->GetMorphBall()->DrawBallShadow(*this); x84c_player->GetMorphBall()->DrawBallShadow(*this);
@ -786,7 +787,7 @@ void CStateManager::DrawWorld() const {
CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR); CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR);
} }
g_Renderer->DoThermalBlendCold(); g_Renderer->DoThermalBlendCold();
const_cast<CStateManager&>(*this).xf34_thermalFlag = EThermalDrawFlag::Hot; xf34_thermalFlag = EThermalDrawFlag::Hot;
for (TUniqueId id : x86c_stateManagerContainer->xf370_) for (TUniqueId id : x86c_stateManagerContainer->xf370_)
if (const CActor* actor = static_cast<const CActor*>(GetObjectById(id))) if (const CActor* actor = static_cast<const CActor*>(GetObjectById(id)))
@ -802,7 +803,7 @@ void CStateManager::DrawWorld() const {
g_Renderer->DrawAreaGeometry(area.x4_selfIdx, mask, 0x10); g_Renderer->DrawAreaGeometry(area.x4_selfIdx, mask, 0x10);
} }
++const_cast<CStateManager&>(*this).x8dc_objectDrawToken; ++x8dc_objectDrawToken;
for (int i = 0; i < areaCount; ++i) { for (int i = 0; i < areaCount; ++i) {
const CGameArea& area = *areaArr[i]; const CGameArea& area = *areaArr[i];
@ -823,7 +824,7 @@ void CStateManager::DrawWorld() const {
x84c_player->AddToRenderer(frustum, *this); x84c_player->AddToRenderer(frustum, *this);
} }
++const_cast<CStateManager&>(*this).x8dc_objectDrawToken; ++x8dc_objectDrawToken;
g_Renderer->EnablePVS(pvs, area.x4_selfIdx); g_Renderer->EnablePVS(pvs, area.x4_selfIdx);
g_Renderer->DrawSortedGeometry(area.x4_selfIdx, mask, 0x10); g_Renderer->DrawSortedGeometry(area.x4_selfIdx, mask, 0x10);
@ -856,7 +857,7 @@ void CStateManager::DrawWorld() const {
if (thermal) { if (thermal) {
g_Renderer->DoThermalBlendHot(); g_Renderer->DoThermalBlendHot();
g_Renderer->SetThermal(false, 0.f, zeus::skBlack); g_Renderer->SetThermal(false, 0.f, zeus::skBlack);
const_cast<CStateManager&>(*this).xf34_thermalFlag = EThermalDrawFlag::Bypass; xf34_thermalFlag = EThermalDrawFlag::Bypass;
} }
DrawDebugStuff(); DrawDebugStuff();
@ -1458,7 +1459,7 @@ void CStateManager::ApplyDamageToWorld(TUniqueId damager, const CActor& actor, c
zeus::CAABox aabb(pos - info.GetRadius(), pos + info.GetRadius()); zeus::CAABox aabb(pos - info.GetRadius(), pos + info.GetRadius());
bool bomb = false; bool bomb = false;
TCastToPtr<CWeapon> weapon = const_cast<CActor&>(actor); TCastToConstPtr<CWeapon> weapon = actor;
if (weapon) if (weapon)
bomb = True(weapon->GetAttribField() & (EProjectileAttrib::Bombs | EProjectileAttrib::PowerBombs)); bomb = True(weapon->GetAttribField() & (EProjectileAttrib::Bombs | EProjectileAttrib::PowerBombs));
@ -1644,7 +1645,7 @@ bool CStateManager::MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterial
} }
void CStateManager::TestBombHittingWater(const CActor& damager, const zeus::CVector3f& pos, CActor& damagee) { void CStateManager::TestBombHittingWater(const CActor& damager, const zeus::CVector3f& pos, CActor& damagee) {
if (TCastToPtr<CWeapon> wpn = const_cast<CActor&>(damager)) { if (TCastToConstPtr<CWeapon> wpn = damager) {
if (True(wpn->GetAttribField() & (EProjectileAttrib::Bombs | EProjectileAttrib::PowerBombs))) { if (True(wpn->GetAttribField() & (EProjectileAttrib::Bombs | EProjectileAttrib::PowerBombs))) {
bool powerBomb = (wpn->GetAttribField() & EProjectileAttrib::PowerBombs) == EProjectileAttrib::PowerBombs; bool powerBomb = (wpn->GetAttribField() & EProjectileAttrib::PowerBombs) == EProjectileAttrib::PowerBombs;
if (TCastToPtr<CScriptWater> water = damagee) { if (TCastToPtr<CScriptWater> water = damagee) {

View File

@ -252,13 +252,13 @@ public:
void BuildDynamicLightListForWorld(); void BuildDynamicLightListForWorld();
void DrawDebugStuff() const; void DrawDebugStuff() const;
void RenderCamerasAndAreaLights() const; void RenderCamerasAndAreaLights() const;
void DrawE3DeathEffect() const; void DrawE3DeathEffect();
void DrawAdditionalFilters() const; void DrawAdditionalFilters();
zeus::CFrustum SetupDrawFrustum(const SViewport& vp) const; zeus::CFrustum SetupDrawFrustum(const SViewport& vp) const;
zeus::CFrustum SetupViewForDraw(const SViewport& vp) const; zeus::CFrustum SetupViewForDraw(const SViewport& vp) const;
zeus::CFrustum SetupViewForCubeFaceDraw(const zeus::CVector3f& pos, int face) const; zeus::CFrustum SetupViewForCubeFaceDraw(const zeus::CVector3f& pos, int face) const;
void ResetViewAfterDraw(const SViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const; void ResetViewAfterDraw(const SViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const;
void DrawWorld() const; void DrawWorld();
void DrawActorCubeFaces(CActor& actor, int& cubeInst) const; void DrawActorCubeFaces(CActor& actor, int& cubeInst) const;
void DrawWorldCubeFaces() const; void DrawWorldCubeFaces() const;
void SetupFogForArea3XRange(TAreaId area) const; void SetupFogForArea3XRange(TAreaId area) const;