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.
This commit is contained in:
Lioncash 2020-05-08 18:41:27 -04:00
parent 6658be66c2
commit 5d209c8dc8
12 changed files with 47 additions and 35 deletions

View File

@ -117,7 +117,7 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) {
xd0_29_allItemsCollected = stream.ReadEncoded(1) != 0; xd0_29_allItemsCollected = stream.ReadEncoded(1) != 0;
xbc_autoMapperKeyState = stream.ReadEncoded(2); xbc_autoMapperKeyState = stream.ReadEncoded(2);
auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); const auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds();
size_t cinematicCount = 0; size_t cinematicCount = 0;
for (const auto& world : memWorlds) { for (const auto& world : memWorlds) {
TLockedToken<CSaveWorld> saveWorld = TLockedToken<CSaveWorld> saveWorld =
@ -162,7 +162,7 @@ void CPersistentOptions::PutTo(CBitStreamWriter& w) const {
w.WriteEncoded(xd0_29_allItemsCollected, 1); w.WriteEncoded(xd0_29_allItemsCollected, 1);
w.WriteEncoded(xbc_autoMapperKeyState, 2); w.WriteEncoded(xbc_autoMapperKeyState, 2);
auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds(); const auto& memWorlds = g_MemoryCardSys->GetMemoryWorlds();
for (const auto& world : memWorlds) { for (const auto& world : memWorlds) {
const TLockedToken<CSaveWorld> saveWorld = const TLockedToken<CSaveWorld> saveWorld =
g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), world.second.GetSaveWorldAssetId()}); g_SimplePool->GetObj(SObjectTag{FOURCC('SAVW'), world.second.GetSaveWorldAssetId()});

View File

@ -132,10 +132,10 @@ void CResLoader::GetTagListForFile(const char* pakName, std::vector<SObjectTag>&
bool CResLoader::_GetTagListForFile(std::vector<SObjectTag>& out, const std::string& path, bool CResLoader::_GetTagListForFile(std::vector<SObjectTag>& out, const std::string& path,
const std::unique_ptr<CPakFile>& file) const { const std::unique_ptr<CPakFile>& file) const {
if (CStringExtras::CompareCaseInsensitive(file->GetPath(), path)) { if (CStringExtras::CompareCaseInsensitive(file->GetPath(), path)) {
auto& depList = file->GetDepList(); const auto& depList = file->GetDepList();
out.reserve(depList.size()); out.reserve(depList.size());
for (const auto& dep : depList) { for (const auto& dep : depList) {
auto resInfo = file->GetResInfo(dep); const auto* const resInfo = file->GetResInfo(dep);
out.emplace_back(resInfo->GetType(), dep); out.emplace_back(resInfo->GetType(), dep);
} }
return true; return true;

View File

@ -187,12 +187,15 @@ void CGuiFrame::LoadWidgetsInGame(CInputStream& in, CSimplePool* sp) {
} }
void CGuiFrame::ProcessUserInput(const CFinalInput& input) const { void CGuiFrame::ProcessUserInput(const CFinalInput& input) const {
if (input.ControllerIdx() != 0) if (input.ControllerIdx() != 0) {
return; return;
for (auto& widget : x2c_widgets) { }
if (widget->GetIsActive())
for (const auto& widget : x2c_widgets) {
if (widget->GetIsActive()) {
widget->ProcessUserInput(input); widget->ProcessUserInput(input);
} }
}
} }
bool CGuiFrame::ProcessMouseInput(const CFinalInput& input, const CGuiWidgetDrawParms& parms) { bool CGuiFrame::ProcessMouseInput(const CFinalInput& input, const CGuiWidgetDrawParms& parms) {

View File

@ -33,12 +33,15 @@ void CGuiSliderGroup::StartIncreasing() {
} }
bool CGuiSliderGroup::TestCursorHit(const zeus::CMatrix4f& vp, const zeus::CVector2f& point) const { 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; return false;
}
CGuiModel* bar = static_cast<CGuiModel*>(xcc_sliderRangeWidgets[0]); CGuiModel* bar = static_cast<CGuiModel*>(xcc_sliderRangeWidgets[0]);
auto& modelTok = bar->GetModel(); const auto& modelTok = bar->GetModel();
if (!modelTok || !modelTok.IsLoaded()) if (!modelTok || !modelTok.IsLoaded()) {
return false; return false;
}
const zeus::CVector3f& s0 = xcc_sliderRangeWidgets[0]->GetIdlePosition(); const zeus::CVector3f& s0 = xcc_sliderRangeWidgets[0]->GetIdlePosition();
const zeus::CVector3f& s1 = xcc_sliderRangeWidgets[1]->GetIdlePosition(); const zeus::CVector3f& s1 = xcc_sliderRangeWidgets[1]->GetIdlePosition();

View File

@ -68,7 +68,7 @@ float CGuiTextSupport::GetCurrentAnimationOverAge() const {
if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) {
if (x50_typeEnable) { if (x50_typeEnable) {
if (x40_primStartTimes.size()) { 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); ret = std::max(ret, (buf->GetPrimitiveCount() - lastTime.second) / x58_chRate + lastTime.first);
} else { } else {
ret = std::max(ret, buf->GetPrimitiveCount() / x58_chRate); ret = std::max(ret, buf->GetPrimitiveCount() / x58_chRate);

View File

@ -13,23 +13,23 @@
namespace urde { namespace urde {
constexpr std::array BaseMenuNames{ constexpr std::array BaseMenuNames{
"BaseWidget_VisorMenu", "BaseWidget_VisorMenu"sv,
"BaseWidget_BeamMenu", "BaseWidget_BeamMenu"sv,
}; };
constexpr std::array TextNames{ constexpr std::array TextNames{
"TextPane_VisorMenu", "TextPane_VisorMenu"sv,
"TextPane_BeamMenu", "TextPane_BeamMenu"sv,
}; };
constexpr std::array BaseTitleNames{ constexpr std::array BaseTitleNames{
"basewidget_visormenutitle", "basewidget_visormenutitle"sv,
"basewidget_beammenutitle", "basewidget_beammenutitle"sv,
}; };
constexpr std::array ModelNames{ constexpr std::array ModelNames{
"model_visor", "model_visor"sv,
"model_beam", "model_beam"sv,
}; };
constexpr std::array<std::array<char, 4>, 2> MenuItemOrders{{ constexpr std::array<std::array<char, 4>, 2> MenuItemOrders{{

View File

@ -326,16 +326,20 @@ void CAuxWeapon::RenderMuzzleFx() const {
} }
TUniqueId CAuxWeapon::HasTarget(const CStateManager& mgr) const { TUniqueId CAuxWeapon::HasTarget(const CStateManager& mgr) const {
if (x74_firingBeamId == CPlayerState::EBeamId::Wave) if (x74_firingBeamId == CPlayerState::EBeamId::Wave) {
if (auto* wb = static_cast<const CWaveBuster*>(mgr.GetObjectById(x70_waveBusterId))) if (const auto* wb = static_cast<const CWaveBuster*>(mgr.GetObjectById(x70_waveBusterId))) {
return wb->GetHomingTargetId(); return wb->GetHomingTargetId();
}
}
return kInvalidUniqueId; return kInvalidUniqueId;
} }
void CAuxWeapon::SetNewTarget(TUniqueId targetId, CStateManager& mgr) { void CAuxWeapon::SetNewTarget(TUniqueId targetId, CStateManager& mgr) {
if (x74_firingBeamId == CPlayerState::EBeamId::Wave) if (x74_firingBeamId == CPlayerState::EBeamId::Wave) {
if (auto* wb = static_cast<CWaveBuster*>(mgr.ObjectById(x70_waveBusterId))) if (auto* wb = static_cast<CWaveBuster*>(mgr.ObjectById(x70_waveBusterId))) {
wb->SetNewTarget(targetId); wb->SetNewTarget(targetId);
}
}
} }
} // namespace urde } // namespace urde

View File

@ -1515,12 +1515,13 @@ void CPlayerGun::UpdateWeaponFire(float dt, const CPlayerState& playerState, CSt
if (!x835_31_actorAttached) { if (!x835_31_actorAttached) {
x835_28_bombReady = true; x835_28_bombReady = true;
if (x53a_powerBomb != kInvalidUniqueId && !mgr.CanCreateProjectile(x538_playerId, EWeaponType::PowerBomb, 1)) { if (x53a_powerBomb != kInvalidUniqueId && !mgr.CanCreateProjectile(x538_playerId, EWeaponType::PowerBomb, 1)) {
auto* pb = static_cast<const CPowerBomb*>(mgr.GetObjectById(x53a_powerBomb)); const auto* pb = static_cast<const CPowerBomb*>(mgr.GetObjectById(x53a_powerBomb));
if (pb && pb->GetCurTime() <= 4.25f) if (pb && pb->GetCurTime() <= 4.25f) {
x835_28_bombReady = false; x835_28_bombReady = false;
else } else {
x53a_powerBomb = kInvalidUniqueId; x53a_powerBomb = kInvalidUniqueId;
} }
}
if (((pressedStates & 0x1) != 0 || x32c_chargePhase != EChargePhase::NotCharging) && if (((pressedStates & 0x1) != 0 || x32c_chargePhase != EChargePhase::NotCharging) &&
mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::MorphBallBombs)) { mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::MorphBallBombs)) {
if (x835_28_bombReady) if (x835_28_bombReady)
@ -2088,9 +2089,9 @@ void CPlayerGun::PreRender(const CStateManager& mgr, const zeus::CFrustum& frust
} }
void CPlayerGun::RenderEnergyDrainEffects(const CStateManager& mgr) const { void CPlayerGun::RenderEnergyDrainEffects(const CStateManager& mgr) const {
if (TCastToConstPtr<CPlayer> player = mgr.GetObjectById(x538_playerId)) { if (const TCastToConstPtr<CPlayer> player = mgr.GetObjectById(x538_playerId)) {
for (const auto& source : player->GetEnergyDrain().GetEnergyDrainSources()) { for (const auto& source : player->GetEnergyDrain().GetEnergyDrainSources()) {
if (auto* metroid = CPatterned::CastTo<MP1::CMetroidBeta>(mgr.GetObjectById(source.GetEnergyDrainSourceId()))) { if (const auto* metroid = CPatterned::CastTo<MP1::CMetroidBeta>(mgr.GetObjectById(source.GetEnergyDrainSourceId()))) {
metroid->RenderHitGunEffect(); metroid->RenderHitGunEffect();
return; return;
} }

View File

@ -643,7 +643,7 @@ std::optional<zeus::CAABox> CFishCloud::GetTouchBounds() const {
void CFishCloud::CreateBoidDeathParticle(CBoid& b) const { void CFishCloud::CreateBoidDeathParticle(CBoid& b) const {
auto it = x21c_deathParticleCounts.begin(); auto it = x21c_deathParticleCounts.begin();
for (auto& p : x1f8_particleGens) { for (const auto& p : x1f8_particleGens) {
p->SetParticleEmission(true); p->SetParticleEmission(true);
p->SetTranslation(b.x0_pos); p->SetTranslation(b.x0_pos);
p->ForceParticleCreation(*it); p->ForceParticleCreation(*it);

View File

@ -1267,7 +1267,7 @@ static CAssetId UpdatePersistentScanPercent(u32 prevLogScans, u32 logScans, u32
if (scanPercentProgStep > prevScanPercentProgStep) { if (scanPercentProgStep > prevScanPercentProgStep) {
const char* const messageResBase = UnlockMessageResBases[zeus::clamp(0, scanPercentProgStep - 1, 1)]; const char* const messageResBase = UnlockMessageResBases[zeus::clamp(0, scanPercentProgStep - 1, 1)];
const auto message = std::string(messageResBase).append(1, firstTime ? '1' : '2'); 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) { if (id != nullptr) {
return id->id; return id->id;
} }

View File

@ -381,8 +381,8 @@ void CScriptGunTurret::SetupCollisionManager(CStateManager& mgr) {
x49c_collisionManager->SetActive(mgr, GetActive()); x49c_collisionManager->SetActive(mgr, GetActive());
for (int i = 0; i < x49c_collisionManager->GetNumCollisionActors(); ++i) { for (int i = 0; i < x49c_collisionManager->GetNumCollisionActors(); ++i) {
auto& desc = x49c_collisionManager->GetCollisionDescFromIndex(i); const auto& desc = x49c_collisionManager->GetCollisionDescFromIndex(i);
if (TCastToPtr<CCollisionActor> cAct = mgr.ObjectById(desc.GetCollisionActorId())) { if (const TCastToPtr<CCollisionActor> cAct = mgr.ObjectById(desc.GetCollisionActorId())) {
cAct->AddMaterial(EMaterialTypes::ProjectilePassthrough, mgr); cAct->AddMaterial(EMaterialTypes::ProjectilePassthrough, mgr);
cAct->SetMaterialFilter(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Player}, cAct->SetMaterialFilter(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Player},
{EMaterialTypes::Character, EMaterialTypes::NoStaticCollision, EMaterialTypes::NoPlatformCollision})); {EMaterialTypes::Character, EMaterialTypes::NoStaticCollision, EMaterialTypes::NoPlatformCollision}));

View File

@ -53,11 +53,12 @@ void CWallWalker::AlignToFloor(CStateManager& mgr, float radius, const zeus::CVe
zeus::CAABox aabb(newPos - margin, newPos + margin); zeus::CAABox aabb(newPos - margin, newPos + margin);
CAreaCollisionCache ccache(aabb); CAreaCollisionCache ccache(aabb);
CGameCollision::BuildAreaCollisionCache(mgr, ccache); CGameCollision::BuildAreaCollisionCache(mgr, ccache);
if (x5d6_25_hasAlignSurface) if (x5d6_25_hasAlignSurface) {
x5d6_25_hasAlignSurface = PointOnSurface(x568_alignNormal, newPos); x5d6_25_hasAlignSurface = PointOnSurface(x568_alignNormal, newPos);
}
if (!x5d6_25_hasAlignSurface || !(x5d4_thinkCounter & 0x3)) { if (!x5d6_25_hasAlignSurface || !(x5d4_thinkCounter & 0x3)) {
for (auto& leaf : ccache) { for (const auto& leaf : ccache) {
for (auto& node : leaf) { for (const auto& node : leaf) {
CAreaOctTree::TriListReference triArr = node.GetTriangleArray(); CAreaOctTree::TriListReference triArr = node.GetTriangleArray();
for (u16 i = 0; i < triArr.GetSize(); ++i) { for (u16 i = 0; i < triArr.GetSize(); ++i) {
u16 triIdx = triArr.GetAt(i); u16 triIdx = triArr.GetAt(i);