From 0ae2364b24a0032c0b745b236e7b907a090767ed Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Mar 2020 20:01:57 -0400 Subject: [PATCH 1/3] CStateManager: Remove unnecessary casts --- Runtime/CStateManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 7b7b7df61..98ef15933 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -319,12 +319,12 @@ bool CStateManager::RenderLast(TUniqueId uid) { void CStateManager::AddDrawableActorPlane(const CActor& actor, const zeus::CPlane& plane, const zeus::CAABox& aabb) const { const_cast(actor).SetAddedToken(x8dc_objectDrawToken + 1); - g_Renderer->AddPlaneObject(static_cast(&actor), aabb, plane, 0); + g_Renderer->AddPlaneObject(&actor, aabb, plane, 0); } void CStateManager::AddDrawableActor(const CActor& actor, const zeus::CVector3f& vec, const zeus::CAABox& aabb) const { const_cast(actor).SetAddedToken(x8dc_objectDrawToken + 1); - g_Renderer->AddDrawable(static_cast(&actor), vec, aabb, 0, IRenderer::EDrawableSorting::SortedCallback); + g_Renderer->AddDrawable(&actor, vec, aabb, 0, IRenderer::EDrawableSorting::SortedCallback); } bool CStateManager::SpecialSkipCinematic() { From 58b112dbe6ca2e379db8759fac6ed334d61d629a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Mar 2020 20:05:21 -0400 Subject: [PATCH 2/3] CStateManager: Convert reinterpret_cast instances over to static_cast Conversions from void* can be done with static_cast. --- Runtime/CStateManager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 98ef15933..e19ca34a3 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -286,10 +286,10 @@ void CStateManager::UpdateThermalVisor() { } void CStateManager::RendererDrawCallback(const void* drawable, const void* ctx, int type) { - const CStateManager& mgr = *reinterpret_cast(ctx); + const CStateManager& mgr = *static_cast(ctx); switch (type) { case 0: { - const CActor& actor = *reinterpret_cast(drawable); + const CActor& actor = *static_cast(drawable); if (actor.xc8_drawnToken == mgr.x8dc_objectDrawToken) break; if (actor.xc6_nextDrawNode != kInvalidUniqueId) @@ -299,10 +299,10 @@ void CStateManager::RendererDrawCallback(const void* drawable, const void* ctx, break; } case 1: - reinterpret_cast(drawable)->Render(mgr.x8f0_shadowTex); + static_cast(drawable)->Render(mgr.x8f0_shadowTex); break; case 2: - reinterpret_cast(drawable)->Render(); + static_cast(drawable)->Render(); break; default: break; @@ -479,7 +479,7 @@ void CStateManager::DrawReflection(const zeus::CVector3f& reflectPoint) { } void CStateManager::ReflectionDrawer(void* ctx, const zeus::CVector3f& vec) { - reinterpret_cast(ctx)->DrawReflection(vec); + static_cast(ctx)->DrawReflection(vec); } void CStateManager::CacheReflection() { g_Renderer->CacheReflection(ReflectionDrawer, this, true); } From 179f0b5f08d7c3833e16605eb3d710ba5aa24b6b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Mar 2020 20:07:53 -0400 Subject: [PATCH 3/3] CStateManager: Remove instances of const_cast where applicable Eliminates trivial casts that don't require much modifications to other existing interfaces. --- Runtime/CStateManager.cpp | 33 +++++++++++++++++---------------- Runtime/CStateManager.hpp | 6 +++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index e19ca34a3..51fab9e31 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -524,8 +524,8 @@ void CStateManager::RenderCamerasAndAreaLights() const { filter.Draw(); } -void CStateManager::DrawE3DeathEffect() const { - CPlayer& player = *x84c_player; +void CStateManager::DrawE3DeathEffect() { + const CPlayer& player = *x84c_player; if (player.x9f4_deathTime > 0.f) { if (player.x2f8_morphBallState != CPlayer::EPlayerMorphBallState::Unmorphed) { 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(); } } - 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; color.a() = whiteAmt; - const_cast(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()) { zeus::CColor color = zeus::skWhite; color.a() = 1.f - xf0c_escapeTimer; - const_cast(m_escapeWhiteout).draw(color); + m_escapeWhiteout.draw(color); } } @@ -629,7 +630,7 @@ void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport, cam->GetFarClipDistance()); } -void CStateManager::DrawWorld() const { +void CStateManager::DrawWorld() { SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue); CTimeProvider timeProvider(xf14_curTimeMod900); SViewport backupViewport = g_Viewport; @@ -682,11 +683,11 @@ void CStateManager::DrawWorld() const { CPlayerState::EPlayerVisor visor = x8b8_playerState->GetActiveVisor(*this); bool thermal = visor == CPlayerState::EPlayerVisor::Thermal; if (thermal) { - const_cast(*this).xf34_thermalFlag = EThermalDrawFlag::Cold; + xf34_thermalFlag = EThermalDrawFlag::Cold; mask = 0x34; targetMask = 0; } else { - const_cast(*this).xf34_thermalFlag = EThermalDrawFlag::Bypass; + xf34_thermalFlag = EThermalDrawFlag::Bypass; mask = 1 << (visor == CPlayerState::EPlayerVisor::XRay ? 3 : 1); targetMask = 0; } @@ -758,7 +759,7 @@ void CStateManager::DrawWorld() const { x884_actorModelParticles->AddStragglersToRenderer(*this); } - ++const_cast(*this).x8dc_objectDrawToken; + ++x8dc_objectDrawToken; x84c_player->GetMorphBall()->DrawBallShadow(*this); @@ -786,7 +787,7 @@ void CStateManager::DrawWorld() const { CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR); } g_Renderer->DoThermalBlendCold(); - const_cast(*this).xf34_thermalFlag = EThermalDrawFlag::Hot; + xf34_thermalFlag = EThermalDrawFlag::Hot; for (TUniqueId id : x86c_stateManagerContainer->xf370_) if (const CActor* actor = static_cast(GetObjectById(id))) @@ -802,7 +803,7 @@ void CStateManager::DrawWorld() const { g_Renderer->DrawAreaGeometry(area.x4_selfIdx, mask, 0x10); } - ++const_cast(*this).x8dc_objectDrawToken; + ++x8dc_objectDrawToken; for (int i = 0; i < areaCount; ++i) { const CGameArea& area = *areaArr[i]; @@ -823,7 +824,7 @@ void CStateManager::DrawWorld() const { x84c_player->AddToRenderer(frustum, *this); } - ++const_cast(*this).x8dc_objectDrawToken; + ++x8dc_objectDrawToken; g_Renderer->EnablePVS(pvs, area.x4_selfIdx); g_Renderer->DrawSortedGeometry(area.x4_selfIdx, mask, 0x10); @@ -856,7 +857,7 @@ void CStateManager::DrawWorld() const { if (thermal) { g_Renderer->DoThermalBlendHot(); g_Renderer->SetThermal(false, 0.f, zeus::skBlack); - const_cast(*this).xf34_thermalFlag = EThermalDrawFlag::Bypass; + xf34_thermalFlag = EThermalDrawFlag::Bypass; } DrawDebugStuff(); @@ -1458,7 +1459,7 @@ void CStateManager::ApplyDamageToWorld(TUniqueId damager, const CActor& actor, c zeus::CAABox aabb(pos - info.GetRadius(), pos + info.GetRadius()); bool bomb = false; - TCastToPtr weapon = const_cast(actor); + TCastToConstPtr weapon = actor; if (weapon) 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) { - if (TCastToPtr wpn = const_cast(damager)) { + if (TCastToConstPtr wpn = damager) { if (True(wpn->GetAttribField() & (EProjectileAttrib::Bombs | EProjectileAttrib::PowerBombs))) { bool powerBomb = (wpn->GetAttribField() & EProjectileAttrib::PowerBombs) == EProjectileAttrib::PowerBombs; if (TCastToPtr water = damagee) { diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 001a952cc..7d8fd19e2 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -252,13 +252,13 @@ public: void BuildDynamicLightListForWorld(); void DrawDebugStuff() const; void RenderCamerasAndAreaLights() const; - void DrawE3DeathEffect() const; - void DrawAdditionalFilters() const; + void DrawE3DeathEffect(); + void DrawAdditionalFilters(); zeus::CFrustum SetupDrawFrustum(const SViewport& vp) const; zeus::CFrustum SetupViewForDraw(const SViewport& vp) const; zeus::CFrustum SetupViewForCubeFaceDraw(const zeus::CVector3f& pos, int face) const; void ResetViewAfterDraw(const SViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const; - void DrawWorld() const; + void DrawWorld(); void DrawActorCubeFaces(CActor& actor, int& cubeInst) const; void DrawWorldCubeFaces() const; void SetupFogForArea3XRange(TAreaId area) const;