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

@@ -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<CAnimPrimitive>& 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);

View File

@@ -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

View File

@@ -1,8 +1,8 @@
#include "CLight.h"
#include "Core/Render/CGraphics.h"
#include <Common/Common.h>
#include <cfloat>
#include <cmath>
#include <float.h>
constexpr uint32_t CLIGHT_NO_RADIUS = 0x40;
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
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<uint32>(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<uint32>(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<uint32> 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);

View File

@@ -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

View File

@@ -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

View File

@@ -5,7 +5,7 @@
#include "Core/OpenGL/GLCommon.h"
#include <Common/Macros.h>
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<CIndexBuffer>& 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);

View File

@@ -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 ************

View File

@@ -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())
{

View File

@@ -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);

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.
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;
}
}