From 5d209c8dc8a0c992dbe4eb87b78ae3dced01145b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 8 May 2020 18:41:27 -0400 Subject: [PATCH] General: Mark a handful of deduced const variables as const explicitly Same behavior, but makes it explicit to the reader that these are const. Prevents cases where the reader might assume that just because the variable isn't const qualified that it must be mutable, when it actually isn't. --- Runtime/CGameOptions.cpp | 4 ++-- Runtime/CResLoader.cpp | 4 ++-- Runtime/GuiSys/CGuiFrame.cpp | 9 ++++++--- Runtime/GuiSys/CGuiSliderGroup.cpp | 9 ++++++--- Runtime/GuiSys/CGuiTextSupport.cpp | 2 +- Runtime/GuiSys/CHudVisorBeamMenu.cpp | 16 ++++++++-------- Runtime/Weapon/CAuxWeapon.cpp | 12 ++++++++---- Runtime/Weapon/CPlayerGun.cpp | 11 ++++++----- Runtime/World/CFishCloud.cpp | 2 +- Runtime/World/CPlayer.cpp | 2 +- Runtime/World/CScriptGunTurret.cpp | 4 ++-- Runtime/World/CWallWalker.cpp | 7 ++++--- 12 files changed, 47 insertions(+), 35 deletions(-) diff --git a/Runtime/CGameOptions.cpp b/Runtime/CGameOptions.cpp index 1f662ef9d..5b8e4ff3a 100644 --- a/Runtime/CGameOptions.cpp +++ b/Runtime/CGameOptions.cpp @@ -117,7 +117,7 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) { xd0_29_allItemsCollected = stream.ReadEncoded(1) != 0; xbc_autoMapperKeyState = stream.ReadEncoded(2); - auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); + const auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); size_t cinematicCount = 0; for (const auto& world : memWorlds) { TLockedToken saveWorld = @@ -162,7 +162,7 @@ void CPersistentOptions::PutTo(CBitStreamWriter& w) const { w.WriteEncoded(xd0_29_allItemsCollected, 1); w.WriteEncoded(xbc_autoMapperKeyState, 2); - auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); + const auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); for (const auto& world : memWorlds) { const TLockedToken saveWorld = g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), world.second.GetSaveWorldAssetId()}); diff --git a/Runtime/CResLoader.cpp b/Runtime/CResLoader.cpp index 24318ad84..43cade117 100644 --- a/Runtime/CResLoader.cpp +++ b/Runtime/CResLoader.cpp @@ -132,10 +132,10 @@ void CResLoader::GetTagListForFile(const char* pakName, std::vector& bool CResLoader::_GetTagListForFile(std::vector& out, const std::string& path, const std::unique_ptr& file) const { if (CStringExtras::CompareCaseInsensitive(file->GetPath(), path)) { - auto& depList = file->GetDepList(); + const auto& depList = file->GetDepList(); out.reserve(depList.size()); for (const auto& dep : depList) { - auto resInfo = file->GetResInfo(dep); + const auto* const resInfo = file->GetResInfo(dep); out.emplace_back(resInfo->GetType(), dep); } return true; diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index 151a7cfa1..221870588 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -187,11 +187,14 @@ void CGuiFrame::LoadWidgetsInGame(CInputStream& in, CSimplePool* sp) { } void CGuiFrame::ProcessUserInput(const CFinalInput& input) const { - if (input.ControllerIdx() != 0) + if (input.ControllerIdx() != 0) { return; - for (auto& widget : x2c_widgets) { - if (widget->GetIsActive()) + } + + for (const auto& widget : x2c_widgets) { + if (widget->GetIsActive()) { widget->ProcessUserInput(input); + } } } diff --git a/Runtime/GuiSys/CGuiSliderGroup.cpp b/Runtime/GuiSys/CGuiSliderGroup.cpp index bdb3e49d7..bc9438412 100644 --- a/Runtime/GuiSys/CGuiSliderGroup.cpp +++ b/Runtime/GuiSys/CGuiSliderGroup.cpp @@ -33,12 +33,15 @@ void CGuiSliderGroup::StartIncreasing() { } bool CGuiSliderGroup::TestCursorHit(const zeus::CMatrix4f& vp, const zeus::CVector2f& point) const { - if (xcc_sliderRangeWidgets[0]->GetWidgetTypeID() != FOURCC('MODL')) + if (xcc_sliderRangeWidgets[0]->GetWidgetTypeID() != FOURCC('MODL')) { return false; + } + CGuiModel* bar = static_cast(xcc_sliderRangeWidgets[0]); - auto& modelTok = bar->GetModel(); - if (!modelTok || !modelTok.IsLoaded()) + const auto& modelTok = bar->GetModel(); + if (!modelTok || !modelTok.IsLoaded()) { return false; + } const zeus::CVector3f& s0 = xcc_sliderRangeWidgets[0]->GetIdlePosition(); const zeus::CVector3f& s1 = xcc_sliderRangeWidgets[1]->GetIdlePosition(); diff --git a/Runtime/GuiSys/CGuiTextSupport.cpp b/Runtime/GuiSys/CGuiTextSupport.cpp index 9a62ed6c0..7a93a8e9b 100644 --- a/Runtime/GuiSys/CGuiTextSupport.cpp +++ b/Runtime/GuiSys/CGuiTextSupport.cpp @@ -68,7 +68,7 @@ float CGuiTextSupport::GetCurrentAnimationOverAge() const { if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { if (x50_typeEnable) { if (x40_primStartTimes.size()) { - auto& lastTime = x40_primStartTimes.back(); + const auto& lastTime = x40_primStartTimes.back(); ret = std::max(ret, (buf->GetPrimitiveCount() - lastTime.second) / x58_chRate + lastTime.first); } else { ret = std::max(ret, buf->GetPrimitiveCount() / x58_chRate); diff --git a/Runtime/GuiSys/CHudVisorBeamMenu.cpp b/Runtime/GuiSys/CHudVisorBeamMenu.cpp index 8d6623665..2cc4a9388 100644 --- a/Runtime/GuiSys/CHudVisorBeamMenu.cpp +++ b/Runtime/GuiSys/CHudVisorBeamMenu.cpp @@ -13,23 +13,23 @@ namespace urde { constexpr std::array BaseMenuNames{ - "BaseWidget_VisorMenu", - "BaseWidget_BeamMenu", + "BaseWidget_VisorMenu"sv, + "BaseWidget_BeamMenu"sv, }; constexpr std::array TextNames{ - "TextPane_VisorMenu", - "TextPane_BeamMenu", + "TextPane_VisorMenu"sv, + "TextPane_BeamMenu"sv, }; constexpr std::array BaseTitleNames{ - "basewidget_visormenutitle", - "basewidget_beammenutitle", + "basewidget_visormenutitle"sv, + "basewidget_beammenutitle"sv, }; constexpr std::array ModelNames{ - "model_visor", - "model_beam", + "model_visor"sv, + "model_beam"sv, }; constexpr std::array, 2> MenuItemOrders{{ diff --git a/Runtime/Weapon/CAuxWeapon.cpp b/Runtime/Weapon/CAuxWeapon.cpp index f87c5ddf6..2955c8da8 100644 --- a/Runtime/Weapon/CAuxWeapon.cpp +++ b/Runtime/Weapon/CAuxWeapon.cpp @@ -326,16 +326,20 @@ void CAuxWeapon::RenderMuzzleFx() const { } TUniqueId CAuxWeapon::HasTarget(const CStateManager& mgr) const { - if (x74_firingBeamId == CPlayerState::EBeamId::Wave) - if (auto* wb = static_cast(mgr.GetObjectById(x70_waveBusterId))) + if (x74_firingBeamId == CPlayerState::EBeamId::Wave) { + if (const auto* wb = static_cast(mgr.GetObjectById(x70_waveBusterId))) { return wb->GetHomingTargetId(); + } + } return kInvalidUniqueId; } void CAuxWeapon::SetNewTarget(TUniqueId targetId, CStateManager& mgr) { - if (x74_firingBeamId == CPlayerState::EBeamId::Wave) - if (auto* wb = static_cast(mgr.ObjectById(x70_waveBusterId))) + if (x74_firingBeamId == CPlayerState::EBeamId::Wave) { + if (auto* wb = static_cast(mgr.ObjectById(x70_waveBusterId))) { wb->SetNewTarget(targetId); + } + } } } // namespace urde diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index d533f78f8..dae5cd08c 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -1515,11 +1515,12 @@ void CPlayerGun::UpdateWeaponFire(float dt, const CPlayerState& playerState, CSt if (!x835_31_actorAttached) { x835_28_bombReady = true; if (x53a_powerBomb != kInvalidUniqueId && !mgr.CanCreateProjectile(x538_playerId, EWeaponType::PowerBomb, 1)) { - auto* pb = static_cast(mgr.GetObjectById(x53a_powerBomb)); - if (pb && pb->GetCurTime() <= 4.25f) + const auto* pb = static_cast(mgr.GetObjectById(x53a_powerBomb)); + if (pb && pb->GetCurTime() <= 4.25f) { x835_28_bombReady = false; - else + } else { x53a_powerBomb = kInvalidUniqueId; + } } if (((pressedStates & 0x1) != 0 || x32c_chargePhase != EChargePhase::NotCharging) && mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::MorphBallBombs)) { @@ -2088,9 +2089,9 @@ void CPlayerGun::PreRender(const CStateManager& mgr, const zeus::CFrustum& frust } void CPlayerGun::RenderEnergyDrainEffects(const CStateManager& mgr) const { - if (TCastToConstPtr player = mgr.GetObjectById(x538_playerId)) { + if (const TCastToConstPtr player = mgr.GetObjectById(x538_playerId)) { for (const auto& source : player->GetEnergyDrain().GetEnergyDrainSources()) { - if (auto* metroid = CPatterned::CastTo(mgr.GetObjectById(source.GetEnergyDrainSourceId()))) { + if (const auto* metroid = CPatterned::CastTo(mgr.GetObjectById(source.GetEnergyDrainSourceId()))) { metroid->RenderHitGunEffect(); return; } diff --git a/Runtime/World/CFishCloud.cpp b/Runtime/World/CFishCloud.cpp index d8633693d..125a2f7ad 100644 --- a/Runtime/World/CFishCloud.cpp +++ b/Runtime/World/CFishCloud.cpp @@ -643,7 +643,7 @@ std::optional CFishCloud::GetTouchBounds() const { void CFishCloud::CreateBoidDeathParticle(CBoid& b) const { auto it = x21c_deathParticleCounts.begin(); - for (auto& p : x1f8_particleGens) { + for (const auto& p : x1f8_particleGens) { p->SetParticleEmission(true); p->SetTranslation(b.x0_pos); p->ForceParticleCreation(*it); diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 33b8e64dd..3e39f57e1 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -1267,7 +1267,7 @@ static CAssetId UpdatePersistentScanPercent(u32 prevLogScans, u32 logScans, u32 if (scanPercentProgStep > prevScanPercentProgStep) { const char* const messageResBase = UnlockMessageResBases[zeus::clamp(0, scanPercentProgStep - 1, 1)]; const auto message = std::string(messageResBase).append(1, firstTime ? '1' : '2'); - const auto id = g_ResFactory->GetResourceIdByName(message); + const auto* const id = g_ResFactory->GetResourceIdByName(message); if (id != nullptr) { return id->id; } diff --git a/Runtime/World/CScriptGunTurret.cpp b/Runtime/World/CScriptGunTurret.cpp index 9f26a7a41..c1a5b726a 100644 --- a/Runtime/World/CScriptGunTurret.cpp +++ b/Runtime/World/CScriptGunTurret.cpp @@ -381,8 +381,8 @@ void CScriptGunTurret::SetupCollisionManager(CStateManager& mgr) { x49c_collisionManager->SetActive(mgr, GetActive()); for (int i = 0; i < x49c_collisionManager->GetNumCollisionActors(); ++i) { - auto& desc = x49c_collisionManager->GetCollisionDescFromIndex(i); - if (TCastToPtr cAct = mgr.ObjectById(desc.GetCollisionActorId())) { + const auto& desc = x49c_collisionManager->GetCollisionDescFromIndex(i); + if (const TCastToPtr cAct = mgr.ObjectById(desc.GetCollisionActorId())) { cAct->AddMaterial(EMaterialTypes::ProjectilePassthrough, mgr); cAct->SetMaterialFilter(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Player}, {EMaterialTypes::Character, EMaterialTypes::NoStaticCollision, EMaterialTypes::NoPlatformCollision})); diff --git a/Runtime/World/CWallWalker.cpp b/Runtime/World/CWallWalker.cpp index 80cc249a8..673150ef6 100644 --- a/Runtime/World/CWallWalker.cpp +++ b/Runtime/World/CWallWalker.cpp @@ -53,11 +53,12 @@ void CWallWalker::AlignToFloor(CStateManager& mgr, float radius, const zeus::CVe zeus::CAABox aabb(newPos - margin, newPos + margin); CAreaCollisionCache ccache(aabb); CGameCollision::BuildAreaCollisionCache(mgr, ccache); - if (x5d6_25_hasAlignSurface) + if (x5d6_25_hasAlignSurface) { x5d6_25_hasAlignSurface = PointOnSurface(x568_alignNormal, newPos); + } if (!x5d6_25_hasAlignSurface || !(x5d4_thinkCounter & 0x3)) { - for (auto& leaf : ccache) { - for (auto& node : leaf) { + for (const auto& leaf : ccache) { + for (const auto& node : leaf) { CAreaOctTree::TriListReference triArr = node.GetTriangleArray(); for (u16 i = 0; i < triArr.GetSize(); ++i) { u16 triIdx = triArr.GetAt(i);