General: Make use of ranged for where applicable

This commit is contained in:
Lioncash 2020-06-22 02:56:45 -04:00
parent 8dd4fb24d9
commit ea86654935
16 changed files with 138 additions and 133 deletions

View File

@ -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()) if (rkOverlay.ModelID.IsValid() || rkOverlay.SkinID.IsValid())
{ {
TString TypeName = ( TString TypeName = (
@ -564,17 +562,16 @@ void GenerateAssetNames(CGameProject *pProj)
std::set<CAnimPrimitive> AnimPrimitives; std::set<CAnimPrimitive> AnimPrimitives;
pSet->GetUniquePrimitives(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(); CAnimation *pAnim = rkPrim.Animation();
if (pAnim) if (pAnim != nullptr)
{ {
ApplyGeneratedName(pAnim->Entry(), SetDir, rkPrim.Name()); ApplyGeneratedName(pAnim->Entry(), SetDir, rkPrim.Name());
CAnimEventData *pEvents = pAnim->EventData(); CAnimEventData *pEvents = pAnim->EventData();
if (pEvents) if (pEvents != nullptr)
ApplyGeneratedName(pEvents->Entry(), SetDir, rkPrim.Name()); ApplyGeneratedName(pEvents->Entry(), SetDir, rkPrim.Name());
} }
} }

View File

@ -149,13 +149,14 @@ void CAssetNameMap::PostLoadValidate()
mIsValid = false; mIsValid = false;
std::set<SAssetNameInfo> Dupes; std::set<SAssetNameInfo> Dupes;
for (auto Iter = mMap.begin(); Iter != mMap.end(); Iter++) for (auto Iter = mMap.begin(); Iter != mMap.end(); ++Iter)
{ {
const SAssetNameInfo& rkInfo = Iter->second; const SAssetNameInfo& rkInfo = Iter->second;
if (mUsedSet.find(rkInfo) != mUsedSet.end()) if (mUsedSet.find(rkInfo) != mUsedSet.end())
{
Dupes.insert(rkInfo); Dupes.insert(rkInfo);
}
else else
{ {
mUsedSet.insert(rkInfo); mUsedSet.insert(rkInfo);
@ -183,15 +184,17 @@ void CAssetNameMap::PostLoadValidate()
{ {
errorf("Asset name map is invalid and cannot be used! Duplicate asset entries detected:"); 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(); mMap.clear();
} }
else else
{
mIsValid = !FoundErrors; mIsValid = !FoundErrors;
}
} }
TString CAssetNameMap::DefaultNameMapPath(EIDLength IDLength) TString CAssetNameMap::DefaultNameMapPath(EIDLength IDLength)

View File

@ -238,8 +238,8 @@ std::unique_ptr<CSetCharacterDependency> CSetCharacterDependency::BuildTree(cons
for (const auto& vec : particleVectors) for (const auto& vec : particleVectors)
{ {
for (uint32 iPart = 0; iPart < vec->size(); iPart++) for (const auto& dependency : *vec)
pTree->AddDependency(vec->at(iPart)); pTree->AddDependency(dependency);
} }
for (const SOverlayModel& overlay : rkChar.OverlayModels) 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++) 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); ASSERT(pTree != nullptr);
// Note: MP2+ need to track all instances (not just instances with dependencies) to be able to build the layer module list // 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++) for (const auto& dep : rkExtraDeps)
AddDependency(rkExtraDeps[iDep]); AddDependency(dep);
} }
void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector<TString>& rModuleDepsOut, std::vector<uint32>& rModuleLayerOffsetsOut) const void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector<TString>& rModuleDepsOut, std::vector<uint32>& rModuleLayerOffsetsOut) const
@ -352,35 +352,34 @@ void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector<TString>
// Output module list will be split per-script layer // Output module list will be split per-script layer
// The output offset list contains two offsets per layer - start index and end index // 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]; const size_t StartIdx = mLayerOffsets[iLayer];
uint32 EndIdx = (iLayer == mLayerOffsets.size() - 1 ? mChildren.size() : mLayerOffsets[iLayer + 1]); const size_t EndIdx = (iLayer == mLayerOffsets.size() - 1 ? mChildren.size() : mLayerOffsets[iLayer + 1]);
uint32 ModuleStartIdx = rModuleDepsOut.size(); const auto ModuleStartIdx = static_cast<uint32>(rModuleDepsOut.size());
rModuleLayerOffsetsOut.push_back(ModuleStartIdx); rModuleLayerOffsetsOut.push_back(ModuleStartIdx);
// Keep track of which types we've already checked on this layer to speed things up a little... // Keep track of which types we've already checked on this layer to speed things up a little...
std::set<uint32> UsedObjectTypes; std::set<uint32> 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) if (pNode->Type() != EDependencyNodeType::ScriptInstance)
continue; continue;
const auto *pInst = static_cast<CScriptInstanceDependency*>(pNode.get()); const auto *pInst = static_cast<CScriptInstanceDependency*>(pNode.get());
uint32 ObjType = pInst->ObjectType(); const uint32 ObjType = pInst->ObjectType();
if (UsedObjectTypes.find(ObjType) == UsedObjectTypes.end()) 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 // 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<TString>& rkModules = pTemplate->RequiredModules(); const std::vector<TString>& rkModules = pTemplate->RequiredModules();
for (uint32 iMod = 0; iMod < rkModules.size(); iMod++) for (const auto& ModuleName : rkModules)
{ {
TString ModuleName = rkModules[iMod];
bool NewModule = true; bool NewModule = true;
for (uint32 iUsed = ModuleStartIdx; iUsed < rModuleDepsOut.size(); iUsed++) for (uint32 iUsed = ModuleStartIdx; iUsed < rModuleDepsOut.size(); iUsed++)
@ -400,6 +399,6 @@ void CAreaDependencyTree::GetModuleDependencies(EGame Game, std::vector<TString>
} }
} }
rModuleLayerOffsetsOut.push_back(rModuleDepsOut.size()); rModuleLayerOffsetsOut.push_back(static_cast<uint32>(rModuleDepsOut.size()));
} }
} }

View File

@ -1,6 +1,7 @@
#include "CGameInfo.h" #include "CGameInfo.h"
#include "CResourceStore.h" #include "CResourceStore.h"
#include <Common/FileUtil.h> #include <Common/FileUtil.h>
#include <algorithm>
constexpr char gkGameInfoDir[] = "resources/gameinfo"; constexpr char gkGameInfoDir[] = "resources/gameinfo";
constexpr char gkGameInfoExt[] = "xml"; constexpr char gkGameInfoExt[] = "xml";
@ -23,14 +24,17 @@ bool CGameInfo::LoadGameInfo(TString Path)
Serialize(Reader); Serialize(Reader);
return true; 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 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); CXMLWriter Writer(Path, "GameInfo", 0, mGame);
Serialize(Writer); Serialize(Writer);
return Writer.Save(); return Writer.Save();
@ -53,21 +57,19 @@ void CGameInfo::Serialize(IArchive& rArc)
TString CGameInfo::GetBuildName(float BuildVer, ERegion Region) const TString CGameInfo::GetBuildName(float BuildVer, ERegion Region) const
{ {
for (uint32 iBuild = 0; iBuild < mBuilds.size(); iBuild++) const auto it = std::find_if(mBuilds.cbegin(), mBuilds.cend(),
{ [=](const auto& entry) { return entry.Version == BuildVer && entry.Region == Region; });
const SBuildInfo& rkBuildInfo = mBuilds[iBuild];
if (rkBuildInfo.Version == BuildVer && rkBuildInfo.Region == Region) if (it == mBuilds.cend())
return rkBuildInfo.Name; return "Unknown Build";
}
return "Unknown Build"; return it->Name;
} }
TString CGameInfo::GetAreaName(const CAssetID &rkID) const TString CGameInfo::GetAreaName(const CAssetID &rkID) const
{ {
auto Iter = mAreaNameMap.find(rkID); const auto Iter = mAreaNameMap.find(rkID);
return (Iter == mAreaNameMap.end() ? "" : Iter->second); return Iter == mAreaNameMap.cend() ? "" : Iter->second;
} }
// ************ STATIC ************ // ************ STATIC ************
@ -86,7 +88,7 @@ TString CGameInfo::GetDefaultGameInfoPath(EGame Game)
if (Game == EGame::Invalid) if (Game == EGame::Invalid)
return ""; return "";
TString GameName = GetGameShortName(Game); const TString GameName = GetGameShortName(Game);
return TString::Format("%s/%s/GameInfo%s.%s", *gDataDir, *gkGameInfoDir, *GameName, *gkGameInfoExt); return TString::Format("%s/%s/GameInfo%s.%s", *gDataDir, *gkGameInfoDir, *GameName, *gkGameInfoExt);
} }

View File

@ -22,8 +22,10 @@ CVertexArrayManager::~CVertexArrayManager()
sVAManagers.erase(sVAManagers.begin() + mVectorIndex); sVAManagers.erase(sVAManagers.begin() + mVectorIndex);
if (sVAManagers.size() > mVectorIndex) if (sVAManagers.size() > mVectorIndex)
{
for (auto it = sVAManagers.begin() + mVectorIndex; it != sVAManagers.end(); it++) for (auto it = sVAManagers.begin() + mVectorIndex; it != sVAManagers.end(); it++)
(*it)->mVectorIndex--; (*it)->mVectorIndex--;
}
} }
// ************ PUBLIC ************ // ************ PUBLIC ************
@ -34,15 +36,16 @@ void CVertexArrayManager::SetCurrent()
void CVertexArrayManager::BindVAO(CVertexBuffer *pVBO) 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); glBindVertexArray(it->second);
}
else else
{ {
GLuint VAO = pVBO->CreateVAO(); const GLuint VAO = pVBO->CreateVAO();
mVBOMap[pVBO] = VAO; mVBOMap.insert_or_assign(pVBO, VAO);
glBindVertexArray(VAO); glBindVertexArray(VAO);
} }
} }
@ -50,40 +53,41 @@ void CVertexArrayManager::BindVAO(CVertexBuffer *pVBO)
void CVertexArrayManager::BindVAO(CDynamicVertexBuffer *pVBO) void CVertexArrayManager::BindVAO(CDynamicVertexBuffer *pVBO)
{ {
// Overload for CDynamicVertexBuffer // 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); glBindVertexArray(it->second);
}
else else
{ {
GLuint VAO = pVBO->CreateVAO(); const GLuint VAO = pVBO->CreateVAO();
mDynamicVBOMap[pVBO] = VAO; mDynamicVBOMap.insert_or_assign(pVBO, VAO);
glBindVertexArray(VAO); glBindVertexArray(VAO);
} }
} }
void CVertexArrayManager::DeleteVAO(CVertexBuffer *pVBO) void CVertexArrayManager::DeleteVAO(CVertexBuffer *pVBO)
{ {
auto it = mVBOMap.find(pVBO); const auto it = mVBOMap.find(pVBO);
if (it != mVBOMap.end()) if (it == mVBOMap.cend())
{ return;
glDeleteVertexArrays(1, &it->second);
mVBOMap.erase(it); glDeleteVertexArrays(1, &it->second);
} mVBOMap.erase(it);
} }
void CVertexArrayManager::DeleteVAO(CDynamicVertexBuffer *pVBO) void CVertexArrayManager::DeleteVAO(CDynamicVertexBuffer *pVBO)
{ {
// Overload for CDynamicVertexBuffer // Overload for CDynamicVertexBuffer
auto it = mDynamicVBOMap.find(pVBO); const auto it = mDynamicVBOMap.find(pVBO);
if (it != mDynamicVBOMap.end()) if (it == mDynamicVBOMap.cend())
{ return;
glDeleteVertexArrays(1, &it->second);
mDynamicVBOMap.erase(it); glDeleteVertexArrays(1, &it->second);
} mDynamicVBOMap.erase(it);
} }
// ************ STATIC ************ // ************ STATIC ************
@ -94,12 +98,12 @@ CVertexArrayManager* CVertexArrayManager::Current()
void CVertexArrayManager::DeleteAllArraysForVBO(CVertexBuffer *pVBO) void CVertexArrayManager::DeleteAllArraysForVBO(CVertexBuffer *pVBO)
{ {
for (uint32 iVAM = 0; iVAM < sVAManagers.size(); iVAM++) for (auto* vam : sVAManagers)
sVAManagers[iVAM]->DeleteVAO(pVBO); vam->DeleteVAO(pVBO);
} }
void CVertexArrayManager::DeleteAllArraysForVBO(CDynamicVertexBuffer *pVBO) void CVertexArrayManager::DeleteAllArraysForVBO(CDynamicVertexBuffer *pVBO)
{ {
for (uint32 iVAM = 0; iVAM < sVAManagers.size(); iVAM++) for (auto* vam : sVAManagers)
sVAManagers[iVAM]->DeleteVAO(pVBO); vam->DeleteVAO(pVBO);
} }

View File

@ -177,10 +177,9 @@ public:
CAnimation* FindAnimationAsset(uint32 AnimID) const CAnimation* FindAnimationAsset(uint32 AnimID) const
{ {
if (AnimID >= 0 && AnimID < mAnimPrimitives.size()) if (AnimID < mAnimPrimitives.size())
{ {
CAnimPrimitive Prim = mAnimPrimitives[AnimID]; return mAnimPrimitives[AnimID].Animation();
return Prim.Animation();
} }
return nullptr; return nullptr;
@ -188,8 +187,8 @@ public:
void GetUniquePrimitives(std::set<CAnimPrimitive>& rPrimSet) const void GetUniquePrimitives(std::set<CAnimPrimitive>& rPrimSet) const
{ {
for (uint32 iAnim = 0; iAnim < mAnimPrimitives.size(); iAnim++) for (const auto& primitive : mAnimPrimitives)
rPrimSet.insert(mAnimPrimitives[iAnim]); rPrimSet.insert(primitive);
} }
// Accessors // Accessors
@ -198,26 +197,25 @@ public:
const SSetCharacter* Character(uint32 Index) const const SSetCharacter* Character(uint32 Index) const
{ {
ASSERT(Index >= 0 && Index < NumCharacters()); ASSERT(Index < NumCharacters());
return &mCharacters[Index]; return &mCharacters[Index];
} }
const SAnimation* Animation(uint32 Index) const const SAnimation* Animation(uint32 Index) const
{ {
ASSERT(Index >= 0 && Index < NumAnimations()); ASSERT(Index < NumAnimations());
return &mAnimations[Index]; return &mAnimations[Index];
} }
CAnimEventData* AnimationEventData(uint32 Index) const CAnimEventData* AnimationEventData(uint32 Index) const
{ {
ASSERT(Index >= 0 && Index < NumAnimations()); ASSERT(Index < NumAnimations());
if (Game() <= EGame::Prime) if (Game() <= EGame::Prime)
{ {
const CAnimPrimitive& rkPrim = mAnimPrimitives[Index]; const CAnimPrimitive& rkPrim = mAnimPrimitives[Index];
return rkPrim.Animation() ? rkPrim.Animation()->EventData() : nullptr; return rkPrim.Animation() ? rkPrim.Animation()->EventData() : nullptr;
} }
else else
{ {
return (Index < mAnimEvents.size() ? mAnimEvents[Index].get() : nullptr); return (Index < mAnimEvents.size() ? mAnimEvents[Index].get() : nullptr);

View File

@ -122,17 +122,20 @@ uint32 CGameArea::TotalInstanceCount() const
{ {
uint32 Num = 0; uint32 Num = 0;
for (uint32 iLyr = 0; iLyr < mScriptLayers.size(); iLyr++) for (const auto& layer : mScriptLayers)
Num += mScriptLayers[iLyr]->NumInstances(); Num += layer->NumInstances();
return Num; return Num;
} }
CScriptObject* CGameArea::InstanceByID(uint32 InstanceID) CScriptObject* CGameArea::InstanceByID(uint32 InstanceID)
{ {
auto it = mObjectMap.find(InstanceID); const auto it = mObjectMap.find(InstanceID);
if (it != mObjectMap.end()) return it->second;
else return nullptr; if (it != mObjectMap.cend())
return it->second;
return nullptr;
} }
uint32 CGameArea::FindUnusedInstanceID() const uint32 CGameArea::FindUnusedInstanceID() const

View File

@ -1,8 +1,8 @@
#include "CLight.h" #include "CLight.h"
#include "Core/Render/CGraphics.h" #include "Core/Render/CGraphics.h"
#include <Common/Common.h> #include <Common/Common.h>
#include <cfloat>
#include <cmath> #include <cmath>
#include <float.h>
constexpr uint32_t CLIGHT_NO_RADIUS = 0x40; constexpr uint32_t CLIGHT_NO_RADIUS = 0x40;
constexpr uint32_t CLIGHT_NO_INTENSITY = 0x80; constexpr uint32_t CLIGHT_NO_INTENSITY = 0x80;

View File

@ -33,17 +33,16 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut)
{ {
// Gather texture list from the materials before starting // Gather texture list from the materials before starting
mTextureIDs.clear(); 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(); const size_t NumPasses = pMat->PassCount();
for (uint32 iPass = 0; iPass < NumPasses; iPass++) for (size_t iPass = 0; iPass < NumPasses; iPass++)
{ {
CTexture *pTex = pMat->Pass(iPass)->Texture(); if (const CTexture* pTex = pMat->Pass(iPass)->Texture())
if (pTex)
mTextureIDs.push_back(pTex->ID().ToLong()); 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()); mTextureIDs.erase(std::unique(mTextureIDs.begin(), mTextureIDs.end()), mTextureIDs.end());
// Write texture IDs // Write texture IDs
rOut.WriteLong(mTextureIDs.size()); rOut.WriteULong(static_cast<uint32>(mTextureIDs.size()));
for (uint32 iTex = 0; iTex < mTextureIDs.size(); iTex++) for (const auto id : mTextureIDs)
rOut.WriteLong(mTextureIDs[iTex]); rOut.WriteULong(id);
// Write material offset filler // Write material offset filler
rOut.WriteLong(NumMats); rOut.WriteULong(static_cast<uint32>(NumMats));
uint32 MatOffsetsStart = rOut.Tell(); const uint32 MatOffsetsStart = rOut.Tell();
for (uint32 iMat = 0; iMat < NumMats; iMat++) for (size_t iMat = 0; iMat < NumMats; iMat++)
rOut.WriteLong(0); rOut.WriteULong(0);
// Write materials // Write materials
uint32 MatsStart = rOut.Tell(); const uint32 MatsStart = rOut.Tell();
std::vector<uint32> MatEndOffsets(NumMats); std::vector<uint32> MatEndOffsets(NumMats);
for (uint32 iMat = 0; iMat < NumMats; iMat++) for (size_t iMat = 0; iMat < NumMats; iMat++)
{ {
mpMat = mpSet->mMaterials[iMat].get(); mpMat = mpSet->mMaterials[iMat].get();
WriteMaterialPrime(rOut); WriteMaterialPrime(rOut);
@ -77,11 +76,11 @@ void CMaterialCooker::WriteMatSetPrime(IOutputStream& rOut)
} }
// Write material offsets // Write material offsets
uint32 MatsEnd = rOut.Tell(); const uint32 MatsEnd = rOut.Tell();
rOut.Seek(MatOffsetsStart, SEEK_SET); rOut.Seek(MatOffsetsStart, SEEK_SET);
for (uint32 iMat = 0; iMat < NumMats; iMat++) for (size_t iMat = 0; iMat < NumMats; iMat++)
rOut.WriteLong(MatEndOffsets[iMat]); rOut.WriteULong(MatEndOffsets[iMat]);
// Done! // Done!
rOut.Seek(MatsEnd, SEEK_SET); rOut.Seek(MatsEnd, SEEK_SET);

View File

@ -270,10 +270,10 @@ void CStringCooker::WriteNameTable(IOutputStream& STRG)
STRG.WriteULong(0); // Dummy name table size STRG.WriteULong(0); // Dummy name table size
const uint32 NameTableOffsetsStart = STRG.Tell(); 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(0); // Dummy name offset
STRG.WriteULong(NameEntries[NameIdx].Index); STRG.WriteULong(entry.Index);
} }
// Write out names // Write out names

View File

@ -7,9 +7,11 @@ CBasicModel::CBasicModel(CResourceEntry *pEntry)
CBasicModel::~CBasicModel() CBasicModel::~CBasicModel()
{ {
if (mHasOwnSurfaces) if (!mHasOwnSurfaces)
for (uint32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) return;
delete mSurfaces[iSurf];
for (auto* surface : mSurfaces)
delete surface;
} }
size_t CBasicModel::GetVertexCount() const size_t CBasicModel::GetVertexCount() const

View File

@ -5,7 +5,7 @@
#include "Core/OpenGL/GLCommon.h" #include "Core/OpenGL/GLCommon.h"
#include <Common/Macros.h> #include <Common/Macros.h>
CModel::CModel(CResourceEntry *pEntry /*= 0*/) CModel::CModel(CResourceEntry *pEntry)
: CBasicModel(pEntry) : CBasicModel(pEntry)
{ {
mHasOwnMaterials = true; mHasOwnMaterials = true;
@ -27,8 +27,8 @@ CModel::~CModel()
if (!mHasOwnMaterials) if (!mHasOwnMaterials)
return; return;
for (size_t iMat = 0; iMat < mMaterialSets.size(); iMat++) for (auto* set : mMaterialSets)
delete mMaterialSets[iMat]; delete set;
} }
@ -92,8 +92,8 @@ void CModel::BufferGL()
} }
} }
for (size_t iIBO = 0; iIBO < mSurfaceIndexBuffers[iSurf].size(); iIBO++) for (auto& ibo : mSurfaceIndexBuffers[iSurf])
mSurfaceIndexBuffers[iSurf][iIBO].Buffer(); ibo.Buffer();
} }
mBuffered = true; mBuffered = true;
@ -143,10 +143,9 @@ void CModel::DrawSurface(FRenderOptions Options, size_t Surface, size_t MatSet)
mVBO.Bind(); mVBO.Bind();
glLineWidth(1.f); glLineWidth(1.f);
for (size_t iIBO = 0; iIBO < mSurfaceIndexBuffers[Surface].size(); iIBO++) for (auto& ibo : mSurfaceIndexBuffers[Surface])
{ {
CIndexBuffer *pIBO = &mSurfaceIndexBuffers[Surface][iIBO]; ibo.DrawElements();
pIBO->DrawElements();
} }
mVBO.Unbind(); mVBO.Unbind();
@ -315,10 +314,10 @@ CIndexBuffer* CModel::InternalGetIBO(size_t Surface, EPrimitiveType Primitive)
std::vector<CIndexBuffer>& pIBOs = mSurfaceIndexBuffers[Surface]; std::vector<CIndexBuffer>& pIBOs = mSurfaceIndexBuffers[Surface];
const GLenum Type = GXPrimToGLPrim(Primitive); const GLenum Type = GXPrimToGLPrim(Primitive);
for (size_t iIBO = 0; iIBO < pIBOs.size(); iIBO++) for (auto& ibo : pIBOs)
{ {
if (pIBOs[iIBO].GetPrimitiveType() == Type) if (ibo.GetPrimitiveType() == Type)
return &pIBOs[iIBO]; return &ibo;
} }
return &pIBOs.emplace_back(Type); return &pIBOs.emplace_back(Type);

View File

@ -38,8 +38,8 @@ CScriptObject::~CScriptObject()
mpTemplate->RemoveObject(this); mpTemplate->RemoveObject(this);
// Note: Incoming links will be deleted by the sender. // Note: Incoming links will be deleted by the sender.
for (uint32 iLink = 0; iLink < mOutLinks.size(); iLink++) for (auto* link : mOutLinks)
delete mOutLinks[iLink]; delete link;
} }
// ************ DATA MANIPULATION ************ // ************ DATA MANIPULATION ************

View File

@ -382,9 +382,9 @@ void ChangeTypeName(IProperty* pProperty, const char* pkOldTypeName, const char*
IProperty* pArchetype = pProperty->RootArchetype(); IProperty* pArchetype = pProperty->RootArchetype();
pArchetype->GatherAllSubInstances(Properties, true); pArchetype->GatherAllSubInstances(Properties, true);
for (auto Iter = Properties.begin(); Iter != Properties.end(); ++Iter) for (auto* property : Properties)
{ {
pProperty = *Iter; pProperty = property;
if (pProperty->UsesNameMap()) if (pProperty->UsesNameMap())
{ {

View File

@ -140,7 +140,7 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r
break; break;
// Now that all words are updated, calculate the new hashes. // 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++) for (; RecalcIndex < WordCache.size(); RecalcIndex++)
{ {
@ -169,12 +169,12 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r
CCRC32 BaseHash = LastValidHash; CCRC32 BaseHash = LastValidHash;
BaseHash.Hash( *rkParams.Suffix ); BaseHash.Hash( *rkParams.Suffix );
for (int TypeIdx = 0; TypeIdx < mTypeNames.size(); TypeIdx++) for (const auto& typeName : mTypeNames)
{ {
CCRC32 FullHash = BaseHash; CCRC32 FullHash = BaseHash;
const char* pkTypeName = *mTypeNames[TypeIdx]; const char* pkTypeName = *typeName;
FullHash.Hash( pkTypeName ); FullHash.Hash( pkTypeName );
uint32 PropertyID = FullHash.Digest(); const uint32 PropertyID = FullHash.Digest();
// Check if this hash is a property ID // Check if this hash is a property ID
if (IsValidPropertyID(PropertyID, pkTypeName, rkParams)) 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) // Generate a string with the complete name. (We wait to do this until now to avoid needless string allocation)
PropertyName.Name = rkParams.Prefix; 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) if (WordIdx > 0 && rkParams.Casing == ENameCasing::Snake_Case)
{ {
@ -225,9 +225,9 @@ void CPropertyNameGenerator::Generate(const SPropertyNameGenerationParameters& r
{ {
TString DelimitedXmlList; 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); debugf("%s [%s] : 0x%08X\n%s", *PropertyName.Name, *PropertyName.Type, PropertyName.ID, *DelimitedXmlList);

View File

@ -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. // 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 (sibling == this)
if (pSibling == this)
{ {
mpParent->mChildren[SiblingIdx] = pNewProperty; sibling = pNewProperty;
break; break;
} }
} }