RuntimeCommon: Const qualify auto references where source is const

Marks references that would be deduced as const automatically with const
to be explicit to the reader.
This commit is contained in:
Lioncash 2020-05-12 20:25:30 -04:00
parent 8e77d6175c
commit 4b5074b298
9 changed files with 61 additions and 50 deletions

View File

@ -106,24 +106,27 @@ void CAnimSourceReaderBase::UpdatePOIStates() {
const std::vector<CSoundPOINode>& soundNodes = x4_sourceInfo->GetSoundPOIStream();
while (x14_passedBoolCount < boolNodes.size() && boolNodes[x14_passedBoolCount].GetTime() <= xc_curTime) {
auto& node = boolNodes[x14_passedBoolCount];
if (node.GetIndex() >= 0)
const auto& node = boolNodes[x14_passedBoolCount];
if (node.GetIndex() >= 0) {
x24_boolStates[node.GetIndex()].second = node.GetValue();
}
++x14_passedBoolCount;
}
while (x18_passedIntCount < int32Nodes.size() && int32Nodes[x18_passedIntCount].GetTime() <= xc_curTime) {
auto& node = int32Nodes[x18_passedIntCount];
if (node.GetIndex() >= 0)
const auto& node = int32Nodes[x18_passedIntCount];
if (node.GetIndex() >= 0) {
x34_int32States[node.GetIndex()].second = node.GetValue();
}
++x18_passedIntCount;
}
while (x1c_passedParticleCount < particleNodes.size() &&
particleNodes[x1c_passedParticleCount].GetTime() <= xc_curTime) {
auto& node = particleNodes[x1c_passedParticleCount];
if (node.GetIndex() >= 0)
const auto& node = particleNodes[x1c_passedParticleCount];
if (node.GetIndex() >= 0) {
x44_particleStates[node.GetIndex()].second = node.GetParticleData().GetParentedMode();
}
++x1c_passedParticleCount;
}

View File

@ -25,10 +25,11 @@ void CAnimTreeTweenBase::VGetSegStatementSet(const CSegIdList& list, CSegStateme
if (w >= 1.f) {
x18_b->VGetSegStatementSet(list, setOut);
} else if (sStack > 3) {
auto& n = w > 0.5f ? x18_b : x14_a;
const auto& n = w > 0.5f ? x18_b : x14_a;
auto ptr = n->GetBestUnblendedChild();
if (!ptr)
if (!ptr) {
ptr = n;
}
ptr->VGetSegStatementSet(list, setOut);
} else {
CSegStatementSet setA, setB;
@ -61,7 +62,7 @@ void CAnimTreeTweenBase::VGetSegStatementSet(const CSegIdList& list, CSegStateme
if (w >= 1.f) {
x18_b->VGetSegStatementSet(list, setOut, time);
} else if (sStack > 3) {
auto& n = w > 0.5f ? x18_b : x14_a;
const auto& n = w > 0.5f ? x18_b : x14_a;
n->GetBestUnblendedChild()->VGetSegStatementSet(list, setOut, time);
} else {
CSegStatementSet setA, setB;

View File

@ -27,12 +27,13 @@ void CMetaAnimRandom::GetUniquePrimitives(std::set<CPrimitive>& primsOut) const
std::shared_ptr<CAnimTreeNode> CMetaAnimRandom::VGetAnimationTree(const CAnimSysContext& animSys,
const CMetaAnimTreeBuildOrders& orders) const {
u32 r = animSys.x8_random->Range(1, 100);
const u32 r = animSys.x8_random->Range(1, 100);
const std::pair<std::shared_ptr<IMetaAnim>, u32>* useRd = nullptr;
for (auto& rd : x4_randomData) {
for (const auto& rd : x4_randomData) {
useRd = &rd;
if (r <= rd.second)
if (r <= rd.second) {
break;
}
}
return useRd->first->GetAnimationTree(animSys, orders);

View File

@ -205,36 +205,39 @@ void CParticleDatabase::Update(float dt, const CPoseAsTransforms& pose, const CC
}
void CParticleDatabase::RenderParticleGenMap(const std::map<std::string, std::unique_ptr<CParticleGenInfo>>& map) {
for (auto& e : map) {
for (const auto& e : map) {
e.second->Render();
}
}
void CParticleDatabase::RenderParticleGenMapMasked(const std::map<std::string, std::unique_ptr<CParticleGenInfo>>& map,
int mask, int target) {
for (auto& e : map) {
if ((e.second->GetFlags() & mask) == target)
for (const auto& e : map) {
if ((e.second->GetFlags() & mask) == target) {
e.second->Render();
}
}
}
void CParticleDatabase::AddToRendererClippedParticleGenMap(
const std::map<std::string, std::unique_ptr<CParticleGenInfo>>& map, const zeus::CFrustum& frustum) {
for (auto& e : map) {
auto bounds = e.second->GetBounds();
if (bounds && frustum.aabbFrustumTest(*bounds))
for (const auto& e : map) {
const auto bounds = e.second->GetBounds();
if (bounds && frustum.aabbFrustumTest(*bounds)) {
e.second->AddToRenderer();
}
}
}
void CParticleDatabase::AddToRendererClippedParticleGenMapMasked(
const std::map<std::string, std::unique_ptr<CParticleGenInfo>>& map, const zeus::CFrustum& frustum, int mask,
int target) {
for (auto& e : map) {
for (const auto& e : map) {
if ((e.second->GetFlags() & mask) == target) {
auto bounds = e.second->GetBounds();
if (bounds && frustum.aabbFrustumTest(*bounds))
const auto bounds = e.second->GetBounds();
if (bounds && frustum.aabbFrustumTest(*bounds)) {
e.second->AddToRenderer();
}
}
}
}

View File

@ -340,12 +340,13 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
};
if (!g_DummyTextures) {
for (const auto& ch : mat.chunks) {
if (auto pass = ch.get_if<MaterialSet::Material::PASS>()) {
if (const auto* const pass = ch.get_if<MaterialSet::Material::PASS>()) {
auto search = x1c_textures.find(pass->texId.toUint32());
boo::ObjToken<boo::ITexture> btex;
if (search != x1c_textures.cend() && (btex = search->second.GetObj()->GetBooTexture()))
if (search != x1c_textures.cend() && (btex = search->second.GetObj()->GetBooTexture())) {
texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex;
} else if (auto pass = ch.get_if<MaterialSet::Material::CLR>()) {
}
} else if (const auto* const pass = ch.get_if<MaterialSet::Material::CLR>()) {
boo::ObjToken<boo::ITexture> btex = g_Renderer->GetColorTexture(zeus::CColor(pass->color));
texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex;
}
@ -424,7 +425,7 @@ void CBooModel::MakeTexturesFromMats(const MaterialSet& matSet,
IObjectStore& store) {
for (const auto& mat : matSet.materials) {
for (const auto& chunk : mat.chunks) {
if (auto pass = chunk.get_if<MaterialSet::Material::PASS>()) {
if (const auto* const pass = chunk.get_if<MaterialSet::Material::PASS>()) {
toksOut.emplace(std::make_pair(pass->texId.toUint32(), store.GetObj({SBIG('TXTR'), pass->texId.toUint32()})));
}
}
@ -485,8 +486,8 @@ bool CBooModel::TryLockTextures() {
}
if (allLoad) {
for (auto& pipeline : *m_pipelines) {
for (auto& subpipeline : *pipeline.second) {
for (const auto& pipeline : *m_pipelines) {
for (const auto& subpipeline : *pipeline.second) {
if (!subpipeline->isReady()) {
allLoad = false;
break;
@ -682,7 +683,7 @@ void CBooModel::WarmupDrawSurface(const CBooSurface& surf) const {
return;
const ModelInstance& inst = m_instances[m_uniUpdateCount - 1];
for (auto& binding : inst.m_shaderDataBindings[surf.selfIdx]) {
for (const auto& binding : inst.m_shaderDataBindings[surf.selfIdx]) {
CGraphics::SetShaderDataBinding(binding);
CGraphics::DrawArrayIndexed(surf.m_data.idxStart, std::min(u32(3), surf.m_data.idxCount));
}
@ -865,7 +866,7 @@ void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet
}
u8* bufOrig = bufOut;
for (const auto& chunk : mat.chunks) {
if (auto pass = chunk.get_if<MaterialSet::Material::PASS>()) {
if (const auto* const pass = chunk.get_if<MaterialSet::Material::PASS>()) {
ProcessAnimation(bufOut, *pass);
}
}
@ -1289,14 +1290,14 @@ bool CModel::IsLoaded(int shaderIdx) const {
size_t CModel::GetPoolVertexOffset(size_t idx) const { return m_hmdlMeta.vertStride * idx; }
zeus::CVector3f CModel::GetPoolVertex(size_t idx) const {
auto* floats = reinterpret_cast<const float*>(m_dynamicVertexData.get() + GetPoolVertexOffset(idx));
const auto* floats = reinterpret_cast<const float*>(m_dynamicVertexData.get() + GetPoolVertexOffset(idx));
return {floats};
}
size_t CModel::GetPoolNormalOffset(size_t idx) const { return m_hmdlMeta.vertStride * idx + 12; }
zeus::CVector3f CModel::GetPoolNormal(size_t idx) const {
auto* floats = reinterpret_cast<const float*>(m_dynamicVertexData.get() + GetPoolNormalOffset(idx));
const auto* floats = reinterpret_cast<const float*>(m_dynamicVertexData.get() + GetPoolNormalOffset(idx));
return {floats};
}

View File

@ -151,13 +151,13 @@ void CRainSplashGenerator::Update(float dt, CStateManager& mgr) {
u32 CRainSplashGenerator::GetNextBestPt(u32 pt, const std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn,
CRandom16& rand, float minZ) {
auto& refVert = vn[pt];
const auto& refVert = vn[pt];
float maxDist = 0.f;
u32 nextPt = pt;
for (int i = 0; i < 3; ++i) {
auto idx = u32(rand.Range(0, int(vn.size() - 1)));
auto& vert = vn[idx];
float distSq = (refVert.first - vert.first).magSquared();
const auto idx = u32(rand.Range(0, int(vn.size() - 1)));
const auto& vert = vn[idx];
const float distSq = (refVert.first - vert.first).magSquared();
if (distSq > maxDist && vert.second.dot(zeus::skUp) >= 0.f &&
(vert.first.z() <= 0.f || vert.first.z() > minZ)) {
nextPt = idx;

View File

@ -289,7 +289,7 @@ void CMFGameLoader::MakeLoadDependencyList() {
static constexpr std::array loadDepPAKs{"TestAnim", "SamusGun", "SamGunFx"};
std::vector<SObjectTag> tags;
for (const auto pak : loadDepPAKs) {
for (const auto* const pak : loadDepPAKs) {
g_ResFactory->GetTagListForFile(pak, tags);
}

View File

@ -248,10 +248,10 @@ void CElitePirate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta
void CElitePirate::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
CPatterned::PreRender(mgr, frustum);
auto modelData = GetModelData();
auto* modelData = GetModelData();
x6f8_boneTracking.PreRender(mgr, *modelData->GetAnimationData(), GetTransform(), modelData->GetScale(),
*x450_bodyController);
auto numMaterialSets = modelData->GetNumMaterialSets();
const auto numMaterialSets = modelData->GetNumMaterialSets();
xb4_drawFlags.x1_matSetIdx =
numMaterialSets - 1 < x7cc_activeMaterialSet ? numMaterialSets - 1 : x7cc_activeMaterialSet;
}
@ -757,7 +757,7 @@ void CElitePirate::SetupHealthInfo(CStateManager& mgr) {
x7b4_hp = health->GetHP();
if (HasWeakPointHead()) {
if (TCastToPtr<CCollisionActor> actor = mgr.ObjectById(x770_collisionHeadId)) {
auto actHealth = actor->HealthInfo(mgr);
auto* actHealth = actor->HealthInfo(mgr);
actHealth->SetHP(health->GetHP());
actHealth->SetKnockbackResistance(health->GetKnockbackResistance());
actor->SetDamageVulnerability(x56c_vulnerability);
@ -940,13 +940,15 @@ void CElitePirate::CreateEnergyAbsorb(CStateManager& mgr, const zeus::CTransform
void CElitePirate::SetupLauncherHealthInfo(CStateManager& mgr, TUniqueId uid) {
const CHealthInfo* const health = HealthInfo(mgr);
if (uid != kInvalidUniqueId) {
if (TCastToPtr<CCollisionActor> actor = mgr.ObjectById(uid)) {
auto actHealth = actor->HealthInfo(mgr);
actHealth->SetHP(x5d8_data.GetLauncherHP());
actHealth->SetKnockbackResistance(health->GetKnockbackResistance());
actor->SetDamageVulnerability(x56c_vulnerability);
}
if (uid == kInvalidUniqueId) {
return;
}
if (const TCastToPtr<CCollisionActor> actor = mgr.ObjectById(uid)) {
auto* actHealth = actor->HealthInfo(mgr);
actHealth->SetHP(x5d8_data.GetLauncherHP());
actHealth->SetKnockbackResistance(health->GetKnockbackResistance());
actor->SetDamageVulnerability(x56c_vulnerability);
}
}
@ -954,7 +956,7 @@ void CElitePirate::SetLauncherActive(CStateManager& mgr, bool val, TUniqueId uid
if (uid == kInvalidUniqueId) {
return;
}
if (auto entity = mgr.ObjectById(uid)) {
if (auto* entity = mgr.ObjectById(uid)) {
mgr.SendScriptMsg(entity, GetUniqueId(), val ? EScriptObjectMessage::Start : EScriptObjectMessage::Stop);
}
}

View File

@ -162,9 +162,9 @@ void CPhazonHealingNodule::UpdateParticleElectric(CStateManager& mgr) {
if (!x57c_particleElectric) {
return;
}
if (auto entity = static_cast<const CPatterned*>(mgr.GetObjectById(x56e_connId))) {
auto electricityLctrXf = GetLctrTransform("Electricity_LCTR"sv);
auto actorLctrXf = entity->GetLctrTransform(x58c_actorLctr);
if (auto* entity = static_cast<const CPatterned*>(mgr.GetObjectById(x56e_connId))) {
const auto electricityLctrXf = GetLctrTransform("Electricity_LCTR"sv);
const auto actorLctrXf = entity->GetLctrTransform(x58c_actorLctr);
x57c_particleElectric->SetOverrideIPos(electricityLctrXf.origin);
x57c_particleElectric->SetOverrideFPos(actorLctrXf.origin);
}