diff --git a/src/Core/GameProject/AssetNameGeneration.cpp b/src/Core/GameProject/AssetNameGeneration.cpp index 9d6a7229..acf631a6 100644 --- a/src/Core/GameProject/AssetNameGeneration.cpp +++ b/src/Core/GameProject/AssetNameGeneration.cpp @@ -527,10 +527,8 @@ void GenerateAssetNames(CGameProject *pProj) } } - for (uint32 iOverlay = 0; iOverlay < pkChar->OverlayModels.size(); iOverlay++) + for (const auto& rkOverlay : pkChar->OverlayModels) { - const SOverlayModel& rkOverlay = pkChar->OverlayModels[iOverlay]; - if (rkOverlay.ModelID.IsValid() || rkOverlay.SkinID.IsValid()) { TString TypeName = ( @@ -564,17 +562,16 @@ void GenerateAssetNames(CGameProject *pProj) std::set AnimPrimitives; pSet->GetUniquePrimitives(AnimPrimitives); - for (auto It = AnimPrimitives.begin(); It != AnimPrimitives.end(); It++) + for (const auto& rkPrim : AnimPrimitives) { - const CAnimPrimitive& rkPrim = *It; CAnimation *pAnim = rkPrim.Animation(); - if (pAnim) + if (pAnim != nullptr) { ApplyGeneratedName(pAnim->Entry(), SetDir, rkPrim.Name()); CAnimEventData *pEvents = pAnim->EventData(); - if (pEvents) + if (pEvents != nullptr) ApplyGeneratedName(pEvents->Entry(), SetDir, rkPrim.Name()); } } diff --git a/src/Core/GameProject/CAssetNameMap.cpp b/src/Core/GameProject/CAssetNameMap.cpp index 518f85ef..22e1c42d 100644 --- a/src/Core/GameProject/CAssetNameMap.cpp +++ b/src/Core/GameProject/CAssetNameMap.cpp @@ -149,13 +149,14 @@ void CAssetNameMap::PostLoadValidate() mIsValid = false; std::set Dupes; - for (auto Iter = mMap.begin(); Iter != mMap.end(); Iter++) + for (auto Iter = mMap.begin(); Iter != mMap.end(); ++Iter) { const SAssetNameInfo& rkInfo = Iter->second; if (mUsedSet.find(rkInfo) != mUsedSet.end()) + { Dupes.insert(rkInfo); - + } else { mUsedSet.insert(rkInfo); @@ -183,15 +184,17 @@ void CAssetNameMap::PostLoadValidate() { errorf("Asset name map is invalid and cannot be used! Duplicate asset entries detected:"); - for (auto Iter = Dupes.begin(); Iter != Dupes.end(); Iter++) + for (const auto& dupe : Dupes) { - warnf("\t%s", *Iter->FullPath()); + warnf("\t%s", *dupe.FullPath()); } mMap.clear(); } else + { mIsValid = !FoundErrors; + } } TString CAssetNameMap::DefaultNameMapPath(EIDLength IDLength) diff --git a/src/Core/GameProject/CDependencyTree.cpp b/src/Core/GameProject/CDependencyTree.cpp index db18b45e..befe5e4e 100644 --- a/src/Core/GameProject/CDependencyTree.cpp +++ b/src/Core/GameProject/CDependencyTree.cpp @@ -238,8 +238,8 @@ std::unique_ptr CSetCharacterDependency::BuildTree(cons for (const auto& vec : particleVectors) { - for (uint32 iPart = 0; iPart < vec->size(); iPart++) - pTree->AddDependency(vec->at(iPart)); + for (const auto& dependency : *vec) + pTree->AddDependency(dependency); } for (const SOverlayModel& overlay : rkChar.OverlayModels) @@ -331,7 +331,7 @@ void CAreaDependencyTree::AddScriptLayer(CScriptLayer *pLayer, const std::vector for (uint32 iInst = 0; iInst < pLayer->NumInstances(); iInst++) { - auto pTree = CScriptInstanceDependency::BuildTree( pLayer->InstanceByIndex(iInst) ); + auto pTree = CScriptInstanceDependency::BuildTree(pLayer->InstanceByIndex(iInst)); ASSERT(pTree != nullptr); // Note: MP2+ need to track all instances (not just instances with dependencies) to be able to build the layer module list @@ -342,8 +342,8 @@ void CAreaDependencyTree::AddScriptLayer(CScriptLayer *pLayer, const std::vector } } - for (uint32 iDep = 0; iDep < rkExtraDeps.size(); iDep++) - AddDependency(rkExtraDeps[iDep]); + for (const auto& dep : rkExtraDeps) + AddDependency(dep); } void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector& rModuleDepsOut, std::vector& rModuleLayerOffsetsOut) const @@ -352,35 +352,34 @@ void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector // Output module list will be split per-script layer // The output offset list contains two offsets per layer - start index and end index - for (uint32 iLayer = 0; iLayer < mLayerOffsets.size(); iLayer++) + for (size_t iLayer = 0; iLayer < mLayerOffsets.size(); iLayer++) { - uint32 StartIdx = mLayerOffsets[iLayer]; - uint32 EndIdx = (iLayer == mLayerOffsets.size() - 1 ? mChildren.size() : mLayerOffsets[iLayer + 1]); + const size_t StartIdx = mLayerOffsets[iLayer]; + const size_t EndIdx = (iLayer == mLayerOffsets.size() - 1 ? mChildren.size() : mLayerOffsets[iLayer + 1]); - uint32 ModuleStartIdx = rModuleDepsOut.size(); + const auto ModuleStartIdx = static_cast(rModuleDepsOut.size()); rModuleLayerOffsetsOut.push_back(ModuleStartIdx); // Keep track of which types we've already checked on this layer to speed things up a little... std::set UsedObjectTypes; - for (uint32 iInst = StartIdx; iInst < EndIdx; iInst++) + for (size_t iInst = StartIdx; iInst < EndIdx; iInst++) { - auto& pNode = mChildren[iInst]; + const auto& pNode = mChildren[iInst]; if (pNode->Type() != EDependencyNodeType::ScriptInstance) continue; const auto *pInst = static_cast(pNode.get()); - uint32 ObjType = pInst->ObjectType(); + const uint32 ObjType = pInst->ObjectType(); if (UsedObjectTypes.find(ObjType) == UsedObjectTypes.end()) { // Get the module list for this object type and check whether any of them are new before adding them to the output list - CScriptTemplate *pTemplate = pGame->TemplateByID(ObjType); + const CScriptTemplate *pTemplate = pGame->TemplateByID(ObjType); const std::vector& rkModules = pTemplate->RequiredModules(); - for (uint32 iMod = 0; iMod < rkModules.size(); iMod++) + for (const auto& ModuleName : rkModules) { - TString ModuleName = rkModules[iMod]; bool NewModule = true; for (uint32 iUsed = ModuleStartIdx; iUsed < rModuleDepsOut.size(); iUsed++) @@ -400,6 +399,6 @@ void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector } } - rModuleLayerOffsetsOut.push_back(rModuleDepsOut.size()); + rModuleLayerOffsetsOut.push_back(static_cast(rModuleDepsOut.size())); } } diff --git a/src/Core/GameProject/CGameInfo.cpp b/src/Core/GameProject/CGameInfo.cpp index 8b0a80c3..d1a8bc18 100644 --- a/src/Core/GameProject/CGameInfo.cpp +++ b/src/Core/GameProject/CGameInfo.cpp @@ -1,6 +1,7 @@ #include "CGameInfo.h" #include "CResourceStore.h" #include +#include constexpr char gkGameInfoDir[] = "resources/gameinfo"; constexpr char gkGameInfoExt[] = "xml"; @@ -23,14 +24,17 @@ bool CGameInfo::LoadGameInfo(TString Path) Serialize(Reader); return true; } - else return false; + + return false; } -bool CGameInfo::SaveGameInfo(TString Path /*= ""*/) +bool CGameInfo::SaveGameInfo(TString Path) { ASSERT(mGame != EGame::Invalid); // can't save game info that was never loaded - if (Path.IsEmpty()) Path = GetDefaultGameInfoPath(mGame); + if (Path.IsEmpty()) + Path = GetDefaultGameInfoPath(mGame); + CXMLWriter Writer(Path, "GameInfo", 0, mGame); Serialize(Writer); return Writer.Save(); @@ -53,21 +57,19 @@ void CGameInfo::Serialize(IArchive& rArc) TString CGameInfo::GetBuildName(float BuildVer, ERegion Region) const { - for (uint32 iBuild = 0; iBuild < mBuilds.size(); iBuild++) - { - const SBuildInfo& rkBuildInfo = mBuilds[iBuild]; + const auto it = std::find_if(mBuilds.cbegin(), mBuilds.cend(), + [=](const auto& entry) { return entry.Version == BuildVer && entry.Region == Region; }); - if (rkBuildInfo.Version == BuildVer && rkBuildInfo.Region == Region) - return rkBuildInfo.Name; - } + if (it == mBuilds.cend()) + return "Unknown Build"; - return "Unknown Build"; + return it->Name; } TString CGameInfo::GetAreaName(const CAssetID &rkID) const { - auto Iter = mAreaNameMap.find(rkID); - return (Iter == mAreaNameMap.end() ? "" : Iter->second); + const auto Iter = mAreaNameMap.find(rkID); + return Iter == mAreaNameMap.cend() ? "" : Iter->second; } // ************ STATIC ************ @@ -86,7 +88,7 @@ TString CGameInfo::GetDefaultGameInfoPath(EGame Game) if (Game == EGame::Invalid) return ""; - TString GameName = GetGameShortName(Game); + const TString GameName = GetGameShortName(Game); return TString::Format("%s/%s/GameInfo%s.%s", *gDataDir, *gkGameInfoDir, *GameName, *gkGameInfoExt); } diff --git a/src/Core/OpenGL/CVertexArrayManager.cpp b/src/Core/OpenGL/CVertexArrayManager.cpp index 715a2494..e46377e6 100644 --- a/src/Core/OpenGL/CVertexArrayManager.cpp +++ b/src/Core/OpenGL/CVertexArrayManager.cpp @@ -22,8 +22,10 @@ CVertexArrayManager::~CVertexArrayManager() sVAManagers.erase(sVAManagers.begin() + mVectorIndex); if (sVAManagers.size() > mVectorIndex) + { for (auto it = sVAManagers.begin() + mVectorIndex; it != sVAManagers.end(); it++) (*it)->mVectorIndex--; + } } // ************ PUBLIC ************ @@ -34,15 +36,16 @@ void CVertexArrayManager::SetCurrent() void CVertexArrayManager::BindVAO(CVertexBuffer *pVBO) { - auto it = mVBOMap.find(pVBO); + const auto it = mVBOMap.find(pVBO); - if (it != mVBOMap.end()) + if (it != mVBOMap.cend()) + { glBindVertexArray(it->second); - + } else { - GLuint VAO = pVBO->CreateVAO(); - mVBOMap[pVBO] = VAO; + const GLuint VAO = pVBO->CreateVAO(); + mVBOMap.insert_or_assign(pVBO, VAO); glBindVertexArray(VAO); } } @@ -50,40 +53,41 @@ void CVertexArrayManager::BindVAO(CVertexBuffer *pVBO) void CVertexArrayManager::BindVAO(CDynamicVertexBuffer *pVBO) { // Overload for CDynamicVertexBuffer - auto it = mDynamicVBOMap.find(pVBO); + const auto it = mDynamicVBOMap.find(pVBO); - if (it != mDynamicVBOMap.end()) + if (it != mDynamicVBOMap.cend()) + { glBindVertexArray(it->second); - + } else { - GLuint VAO = pVBO->CreateVAO(); - mDynamicVBOMap[pVBO] = VAO; + const GLuint VAO = pVBO->CreateVAO(); + mDynamicVBOMap.insert_or_assign(pVBO, VAO); glBindVertexArray(VAO); } } void CVertexArrayManager::DeleteVAO(CVertexBuffer *pVBO) { - auto it = mVBOMap.find(pVBO); + const auto it = mVBOMap.find(pVBO); - if (it != mVBOMap.end()) - { - glDeleteVertexArrays(1, &it->second); - mVBOMap.erase(it); - } + if (it == mVBOMap.cend()) + return; + + glDeleteVertexArrays(1, &it->second); + mVBOMap.erase(it); } void CVertexArrayManager::DeleteVAO(CDynamicVertexBuffer *pVBO) { // Overload for CDynamicVertexBuffer - auto it = mDynamicVBOMap.find(pVBO); + const auto it = mDynamicVBOMap.find(pVBO); - if (it != mDynamicVBOMap.end()) - { - glDeleteVertexArrays(1, &it->second); - mDynamicVBOMap.erase(it); - } + if (it == mDynamicVBOMap.cend()) + return; + + glDeleteVertexArrays(1, &it->second); + mDynamicVBOMap.erase(it); } // ************ STATIC ************ @@ -94,12 +98,12 @@ CVertexArrayManager* CVertexArrayManager::Current() void CVertexArrayManager::DeleteAllArraysForVBO(CVertexBuffer *pVBO) { - for (uint32 iVAM = 0; iVAM < sVAManagers.size(); iVAM++) - sVAManagers[iVAM]->DeleteVAO(pVBO); + for (auto* vam : sVAManagers) + vam->DeleteVAO(pVBO); } void CVertexArrayManager::DeleteAllArraysForVBO(CDynamicVertexBuffer *pVBO) { - for (uint32 iVAM = 0; iVAM < sVAManagers.size(); iVAM++) - sVAManagers[iVAM]->DeleteVAO(pVBO); + for (auto* vam : sVAManagers) + vam->DeleteVAO(pVBO); } diff --git a/src/Core/Resource/Animation/CAnimSet.h b/src/Core/Resource/Animation/CAnimSet.h index 33ecff2d..b7889476 100644 --- a/src/Core/Resource/Animation/CAnimSet.h +++ b/src/Core/Resource/Animation/CAnimSet.h @@ -177,10 +177,9 @@ public: CAnimation* FindAnimationAsset(uint32 AnimID) const { - if (AnimID >= 0 && AnimID < mAnimPrimitives.size()) + if (AnimID < mAnimPrimitives.size()) { - CAnimPrimitive Prim = mAnimPrimitives[AnimID]; - return Prim.Animation(); + return mAnimPrimitives[AnimID].Animation(); } return nullptr; @@ -188,8 +187,8 @@ public: void GetUniquePrimitives(std::set& rPrimSet) const { - for (uint32 iAnim = 0; iAnim < mAnimPrimitives.size(); iAnim++) - rPrimSet.insert(mAnimPrimitives[iAnim]); + for (const auto& primitive : mAnimPrimitives) + rPrimSet.insert(primitive); } // Accessors @@ -198,26 +197,25 @@ public: const SSetCharacter* Character(uint32 Index) const { - ASSERT(Index >= 0 && Index < NumCharacters()); + ASSERT(Index < NumCharacters()); return &mCharacters[Index]; } const SAnimation* Animation(uint32 Index) const { - ASSERT(Index >= 0 && Index < NumAnimations()); + ASSERT(Index < NumAnimations()); return &mAnimations[Index]; } CAnimEventData* AnimationEventData(uint32 Index) const { - ASSERT(Index >= 0 && Index < NumAnimations()); + ASSERT(Index < NumAnimations()); if (Game() <= EGame::Prime) { const CAnimPrimitive& rkPrim = mAnimPrimitives[Index]; return rkPrim.Animation() ? rkPrim.Animation()->EventData() : nullptr; } - else { return (Index < mAnimEvents.size() ? mAnimEvents[Index].get() : nullptr); diff --git a/src/Core/Resource/Area/CGameArea.cpp b/src/Core/Resource/Area/CGameArea.cpp index 62fd333b..57ac4c11 100644 --- a/src/Core/Resource/Area/CGameArea.cpp +++ b/src/Core/Resource/Area/CGameArea.cpp @@ -122,17 +122,20 @@ uint32 CGameArea::TotalInstanceCount() const { uint32 Num = 0; - for (uint32 iLyr = 0; iLyr < mScriptLayers.size(); iLyr++) - Num += mScriptLayers[iLyr]->NumInstances(); + for (const auto& layer : mScriptLayers) + Num += layer->NumInstances(); return Num; } CScriptObject* CGameArea::InstanceByID(uint32 InstanceID) { - auto it = mObjectMap.find(InstanceID); - if (it != mObjectMap.end()) return it->second; - else return nullptr; + const auto it = mObjectMap.find(InstanceID); + + if (it != mObjectMap.cend()) + return it->second; + + return nullptr; } uint32 CGameArea::FindUnusedInstanceID() const diff --git a/src/Core/Resource/CLight.cpp b/src/Core/Resource/CLight.cpp index bc965ac8..3d356563 100644 --- a/src/Core/Resource/CLight.cpp +++ b/src/Core/Resource/CLight.cpp @@ -1,8 +1,8 @@ #include "CLight.h" #include "Core/Render/CGraphics.h" #include +#include #include -#include constexpr uint32_t CLIGHT_NO_RADIUS = 0x40; constexpr uint32_t CLIGHT_NO_INTENSITY = 0x80; diff --git a/src/Core/Resource/Cooker/CMaterialCooker.cpp b/src/Core/Resource/Cooker/CMaterialCooker.cpp index 4ea46ecb..a7a707d7 100644 --- a/src/Core/Resource/Cooker/CMaterialCooker.cpp +++ b/src/Core/Resource/Cooker/CMaterialCooker.cpp @@ -33,17 +33,16 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut) { // Gather texture list from the materials before starting mTextureIDs.clear(); - uint32 NumMats = mpSet->mMaterials.size(); + const size_t NumMats = mpSet->mMaterials.size(); - for (uint32 iMat = 0; iMat < NumMats; iMat++) + for (size_t iMat = 0; iMat < NumMats; iMat++) { - CMaterial *pMat = mpSet->mMaterials[iMat].get(); + const CMaterial *pMat = mpSet->mMaterials[iMat].get(); - uint32 NumPasses = pMat->PassCount(); - for (uint32 iPass = 0; iPass < NumPasses; iPass++) + const size_t NumPasses = pMat->PassCount(); + for (size_t iPass = 0; iPass < NumPasses; iPass++) { - CTexture *pTex = pMat->Pass(iPass)->Texture(); - if (pTex) + if (const CTexture* pTex = pMat->Pass(iPass)->Texture()) mTextureIDs.push_back(pTex->ID().ToLong()); } } @@ -53,23 +52,23 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut) mTextureIDs.erase(std::unique(mTextureIDs.begin(), mTextureIDs.end()), mTextureIDs.end()); // Write texture IDs - rOut.WriteLong(mTextureIDs.size()); + rOut.WriteULong(static_cast(mTextureIDs.size())); - for (uint32 iTex = 0; iTex < mTextureIDs.size(); iTex++) - rOut.WriteLong(mTextureIDs[iTex]); + for (const auto id : mTextureIDs) + rOut.WriteULong(id); // Write material offset filler - rOut.WriteLong(NumMats); - uint32 MatOffsetsStart = rOut.Tell(); + rOut.WriteULong(static_cast(NumMats)); + const uint32 MatOffsetsStart = rOut.Tell(); - for (uint32 iMat = 0; iMat < NumMats; iMat++) - rOut.WriteLong(0); + for (size_t iMat = 0; iMat < NumMats; iMat++) + rOut.WriteULong(0); // Write materials - uint32 MatsStart = rOut.Tell(); + const uint32 MatsStart = rOut.Tell(); std::vector MatEndOffsets(NumMats); - for (uint32 iMat = 0; iMat < NumMats; iMat++) + for (size_t iMat = 0; iMat < NumMats; iMat++) { mpMat = mpSet->mMaterials[iMat].get(); WriteMaterialPrime(rOut); @@ -77,11 +76,11 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut) } // Write material offsets - uint32 MatsEnd = rOut.Tell(); + const uint32 MatsEnd = rOut.Tell(); rOut.Seek(MatOffsetsStart, SEEK_SET); - for (uint32 iMat = 0; iMat < NumMats; iMat++) - rOut.WriteLong(MatEndOffsets[iMat]); + for (size_t iMat = 0; iMat < NumMats; iMat++) + rOut.WriteULong(MatEndOffsets[iMat]); // Done! rOut.Seek(MatsEnd, SEEK_SET); diff --git a/src/Core/Resource/Cooker/CStringCooker.cpp b/src/Core/Resource/Cooker/CStringCooker.cpp index d063b4de..f9157ce7 100644 --- a/src/Core/Resource/Cooker/CStringCooker.cpp +++ b/src/Core/Resource/Cooker/CStringCooker.cpp @@ -270,10 +270,10 @@ void CStringCooker::WriteNameTable(IOutputStream& STRG) STRG.WriteULong(0); // Dummy name table size const uint32 NameTableOffsetsStart = STRG.Tell(); - for (size_t NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++) + for (const auto& entry : NameEntries) { STRG.WriteULong(0); // Dummy name offset - STRG.WriteULong(NameEntries[NameIdx].Index); + STRG.WriteULong(entry.Index); } // Write out names diff --git a/src/Core/Resource/Model/CBasicModel.cpp b/src/Core/Resource/Model/CBasicModel.cpp index f0bbc5d5..2759276a 100644 --- a/src/Core/Resource/Model/CBasicModel.cpp +++ b/src/Core/Resource/Model/CBasicModel.cpp @@ -7,9 +7,11 @@ CBasicModel::CBasicModel(CResourceEntry *pEntry) CBasicModel::~CBasicModel() { - if (mHasOwnSurfaces) - for (uint32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) - delete mSurfaces[iSurf]; + if (!mHasOwnSurfaces) + return; + + for (auto* surface : mSurfaces) + delete surface; } size_t CBasicModel::GetVertexCount() const diff --git a/src/Core/Resource/Model/CModel.cpp b/src/Core/Resource/Model/CModel.cpp index f72539c4..ed0d478b 100644 --- a/src/Core/Resource/Model/CModel.cpp +++ b/src/Core/Resource/Model/CModel.cpp @@ -5,7 +5,7 @@ #include "Core/OpenGL/GLCommon.h" #include -CModel::CModel(CResourceEntry *pEntry /*= 0*/) +CModel::CModel(CResourceEntry *pEntry) : CBasicModel(pEntry) { mHasOwnMaterials = true; @@ -27,8 +27,8 @@ CModel::~CModel() if (!mHasOwnMaterials) return; - for (size_t iMat = 0; iMat < mMaterialSets.size(); iMat++) - delete mMaterialSets[iMat]; + for (auto* set : mMaterialSets) + delete set; } @@ -92,8 +92,8 @@ void CModel::BufferGL() } } - for (size_t iIBO = 0; iIBO < mSurfaceIndexBuffers[iSurf].size(); iIBO++) - mSurfaceIndexBuffers[iSurf][iIBO].Buffer(); + for (auto& ibo : mSurfaceIndexBuffers[iSurf]) + ibo.Buffer(); } mBuffered = true; @@ -143,10 +143,9 @@ void CModel::DrawSurface(FRenderOptions Options, size_t Surface, size_t MatSet) mVBO.Bind(); glLineWidth(1.f); - for (size_t iIBO = 0; iIBO < mSurfaceIndexBuffers[Surface].size(); iIBO++) + for (auto& ibo : mSurfaceIndexBuffers[Surface]) { - CIndexBuffer *pIBO = &mSurfaceIndexBuffers[Surface][iIBO]; - pIBO->DrawElements(); + ibo.DrawElements(); } mVBO.Unbind(); @@ -315,10 +314,10 @@ CIndexBuffer* CModel::InternalGetIBO(size_t Surface, EPrimitiveType Primitive) std::vector& pIBOs = mSurfaceIndexBuffers[Surface]; const GLenum Type = GXPrimToGLPrim(Primitive); - for (size_t iIBO = 0; iIBO < pIBOs.size(); iIBO++) + for (auto& ibo : pIBOs) { - if (pIBOs[iIBO].GetPrimitiveType() == Type) - return &pIBOs[iIBO]; + if (ibo.GetPrimitiveType() == Type) + return &ibo; } return &pIBOs.emplace_back(Type); diff --git a/src/Core/Resource/Script/CScriptObject.cpp b/src/Core/Resource/Script/CScriptObject.cpp index 0decbb13..b0be9f05 100644 --- a/src/Core/Resource/Script/CScriptObject.cpp +++ b/src/Core/Resource/Script/CScriptObject.cpp @@ -38,8 +38,8 @@ CScriptObject::~CScriptObject() mpTemplate->RemoveObject(this); // Note: Incoming links will be deleted by the sender. - for (uint32 iLink = 0; iLink < mOutLinks.size(); iLink++) - delete mOutLinks[iLink]; + for (auto* link : mOutLinks) + delete link; } // ************ DATA MANIPULATION ************ diff --git a/src/Core/Resource/Script/NPropertyMap.cpp b/src/Core/Resource/Script/NPropertyMap.cpp index 30b468a7..411d50bb 100644 --- a/src/Core/Resource/Script/NPropertyMap.cpp +++ b/src/Core/Resource/Script/NPropertyMap.cpp @@ -382,9 +382,9 @@ void ChangeTypeName(IProperty* pProperty, const char* pkOldTypeName, const char* IProperty* pArchetype = pProperty->RootArchetype(); pArchetype->GatherAllSubInstances(Properties, true); - for (auto Iter = Properties.begin(); Iter != Properties.end(); ++Iter) + for (auto* property : Properties) { - pProperty = *Iter; + pProperty = property; if (pProperty->UsesNameMap()) { diff --git a/src/Core/Resource/Script/Property/CPropertyNameGenerator.cpp b/src/Core/Resource/Script/Property/CPropertyNameGenerator.cpp index 118f4ebc..15d9ad4e 100644 --- a/src/Core/Resource/Script/Property/CPropertyNameGenerator.cpp +++ b/src/Core/Resource/Script/Property/CPropertyNameGenerator.cpp @@ -140,7 +140,7 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r break; // Now that all words are updated, calculate the new hashes. - CCRC32 LastValidHash = (RecalcIndex > 0 ? WordCache[RecalcIndex-1].Hash : PrefixHash); + CCRC32 LastValidHash = (RecalcIndex > 0 ? WordCache[RecalcIndex - 1].Hash : PrefixHash); for (; RecalcIndex < WordCache.size(); RecalcIndex++) { @@ -169,12 +169,12 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r CCRC32 BaseHash = LastValidHash; BaseHash.Hash( *rkParams.Suffix ); - for (int TypeIdx = 0; TypeIdx < mTypeNames.size(); TypeIdx++) + for (const auto& typeName : mTypeNames) { CCRC32 FullHash = BaseHash; - const char* pkTypeName = *mTypeNames[TypeIdx]; + const char* pkTypeName = *typeName; FullHash.Hash( pkTypeName ); - uint32 PropertyID = FullHash.Digest(); + const uint32 PropertyID = FullHash.Digest(); // Check if this hash is a property ID if (IsValidPropertyID(PropertyID, pkTypeName, rkParams)) @@ -185,9 +185,9 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r // Generate a string with the complete name. (We wait to do this until now to avoid needless string allocation) PropertyName.Name = rkParams.Prefix; - for (int WordIdx = 0; WordIdx < WordCache.size(); WordIdx++) + for (size_t WordIdx = 0; WordIdx < WordCache.size(); WordIdx++) { - int Index = WordCache[WordIdx].WordIndex; + const int Index = WordCache[WordIdx].WordIndex; if (WordIdx > 0 && rkParams.Casing == ENameCasing::Snake_Case) { @@ -225,9 +225,9 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r { TString DelimitedXmlList; - for (auto Iter = PropertyName.XmlList.begin(); Iter != PropertyName.XmlList.end(); Iter++) + for (const auto& xml : PropertyName.XmlList) { - DelimitedXmlList += *Iter + "\n"; + DelimitedXmlList += xml + '\n'; } debugf("%s [%s] : 0x%08X\n%s", *PropertyName.Name, *PropertyName.Type, PropertyName.ID, *DelimitedXmlList); diff --git a/src/Core/Resource/Script/Property/IProperty.cpp b/src/Core/Resource/Script/Property/IProperty.cpp index 5ced8b6e..95a3282f 100644 --- a/src/Core/Resource/Script/Property/IProperty.cpp +++ b/src/Core/Resource/Script/Property/IProperty.cpp @@ -472,14 +472,13 @@ bool IProperty::ConvertType(EPropertyType NewType, IProperty* pNewArchetype) } // Swap out our parent's reference to us to point to the new property. - if (mpParent) + if (mpParent != nullptr) { - for (size_t SiblingIdx = 0; SiblingIdx < mpParent->mChildren.size(); SiblingIdx++) + for (auto& sibling : mpParent->mChildren) { - IProperty* pSibling = mpParent->mChildren[SiblingIdx]; - if (pSibling == this) + if (sibling == this) { - mpParent->mChildren[SiblingIdx] = pNewProperty; + sibling = pNewProperty; break; } }