CScriptLayer: Make use of size_t where applicable

This commit is contained in:
Lioncash
2020-06-28 00:48:14 -04:00
parent d1939eea95
commit c6263433a9
7 changed files with 36 additions and 33 deletions

View File

@@ -118,9 +118,9 @@ void CGameArea::ClearScriptLayers()
mScriptLayers.clear();
}
uint32 CGameArea::TotalInstanceCount() const
size_t CGameArea::TotalInstanceCount() const
{
uint32 Num = 0;
size_t Num = 0;
for (const auto& layer : mScriptLayers)
Num += layer->NumInstances();
@@ -164,30 +164,30 @@ CScriptObject* CGameArea::SpawnInstance(CScriptTemplate *pTemplate,
uint32 SuggestedLayerIndex /*= -1*/ )
{
// Verify we can fit another instance in this area.
uint32 NumInstances = TotalInstanceCount();
const size_t NumInstances = TotalInstanceCount();
if (NumInstances >= 0xFFFF)
{
errorf("Unable to spawn a new script instance; too many instances in area (%d)", NumInstances);
errorf("Unable to spawn a new script instance; too many instances in area (%zu)", NumInstances);
return nullptr;
}
// Check whether the suggested instance ID is valid
uint32 InstanceID = SuggestedID;
if (InstanceID != -1)
if (InstanceID != UINT32_MAX)
{
if (mObjectMap.find(InstanceID) == mObjectMap.end())
InstanceID = -1;
if (mObjectMap.find(InstanceID) == mObjectMap.cend())
InstanceID = UINT32_MAX;
}
// If not valid (or if there's no suggested ID) then determine a new instance ID
if (InstanceID == -1)
if (InstanceID == UINT32_MAX)
{
// Determine layer index
uint32 LayerIndex = pLayer->AreaIndex();
const uint32 LayerIndex = pLayer->AreaIndex();
if (LayerIndex == -1)
if (LayerIndex == UINT32_MAX)
{
errorf("Unable to spawn a new script instance; invalid script layer passed in");
return nullptr;
@@ -198,13 +198,14 @@ CScriptObject* CGameArea::SpawnInstance(CScriptTemplate *pTemplate,
}
// Spawn instance
CScriptObject *pInstance = new CScriptObject(InstanceID, this, pLayer, pTemplate);
auto* pInstance = new CScriptObject(InstanceID, this, pLayer, pTemplate);
pInstance->EvaluateProperties();
pInstance->SetPosition(rkPosition);
pInstance->SetRotation(rkRotation.ToEuler());
pInstance->SetScale(rkScale);
pInstance->SetName(pTemplate->Name());
if (pTemplate->Game() < EGame::EchoesDemo) pInstance->SetActive(true);
if (pTemplate->Game() < EGame::EchoesDemo)
pInstance->SetActive(true);
pLayer->AddInstance(pInstance, SuggestedLayerIndex);
mObjectMap[InstanceID] = pInstance;
return pInstance;

View File

@@ -75,7 +75,7 @@ public:
void MergeTerrain();
void ClearTerrain();
void ClearScriptLayers();
uint32 TotalInstanceCount() const;
size_t TotalInstanceCount() const;
CScriptObject* InstanceByID(uint32 InstanceID);
uint32 FindUnusedInstanceID() const;
CScriptObject* SpawnInstance(CScriptTemplate* pTemplate, CScriptLayer* pLayer,

View File

@@ -276,7 +276,7 @@ void CScriptCooker::WriteLayer(IOutputStream& rOut, CScriptLayer *pLayer)
uint32 NumWrittenInstances = 0;
rOut.WriteLong(0);
for (uint32 iInst = 0; iInst < pLayer->NumInstances(); iInst++)
for (size_t iInst = 0; iInst < pLayer->NumInstances(); iInst++)
{
CScriptObject *pInstance = pLayer->InstanceByIndex(iInst);

View File

@@ -53,7 +53,7 @@ public:
mInstances.erase(it);
}
void RemoveInstanceByIndex(uint32 Index)
void RemoveInstanceByIndex(size_t Index)
{
mInstances.erase(mInstances.begin() + Index);
}
@@ -69,7 +69,7 @@ public:
mInstances.erase(it);
}
void Reserve(uint32 Amount)
void Reserve(size_t Amount)
{
mInstances.reserve(Amount);
}
@@ -79,8 +79,8 @@ public:
TString Name() const { return mLayerName; }
bool IsActive() const { return mActive; }
bool IsVisible() const { return mVisible; }
uint32 NumInstances() const { return mInstances.size(); }
CScriptObject* InstanceByIndex(uint32 Index) const { return mInstances[Index]; }
size_t NumInstances() const { return mInstances.size(); }
CScriptObject* InstanceByIndex(size_t Index) const { return mInstances[Index]; }
CScriptObject* InstanceByID(uint32 ID) const
{
@@ -109,8 +109,8 @@ public:
}
// Operators
CScriptObject* operator[](uint32 Index) { return InstanceByIndex(Index); }
const CScriptObject* operator[](uint32 Index) const { return InstanceByIndex(Index); }
CScriptObject* operator[](size_t Index) { return InstanceByIndex(Index); }
const CScriptObject* operator[](size_t Index) const { return InstanceByIndex(Index); }
};
#endif // CSCRIPTLAYER_H