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

@ -284,7 +284,7 @@ void GenerateAssetNames(CGameProject *pProj)
{
CScriptLayer *pLayer = pArea->ScriptLayer(iLyr);
for (uint32 iInst = 0; iInst < pLayer->NumInstances(); iInst++)
for (size_t iInst = 0; iInst < pLayer->NumInstances(); iInst++)
{
CScriptObject* pInst = pLayer->InstanceByIndex(iInst);
CStructProperty* pProperties = pInst->Template()->Properties();

View File

@ -329,7 +329,7 @@ void CAreaDependencyTree::AddScriptLayer(CScriptLayer *pLayer, const std::vector
mLayerOffsets.push_back(mChildren.size());
std::set<CAssetID> UsedIDs;
for (uint32 iInst = 0; iInst < pLayer->NumInstances(); iInst++)
for (size_t iInst = 0; iInst < pLayer->NumInstances(); iInst++)
{
auto pTree = CScriptInstanceDependency::BuildTree(pLayer->InstanceByIndex(iInst));
ASSERT(pTree != nullptr);

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

View File

@ -174,35 +174,37 @@ QModelIndex CInstancesModel::parent(const QModelIndex& rkChild) const
int CInstancesModel::rowCount(const QModelIndex& rkParent) const
{
EIndexType Type = IndexType(rkParent);
const EIndexType Type = IndexType(rkParent);
// Node types
if (Type == EIndexType::Root)
{
return mBaseItems.count();
}
// Object types
else if (Type == EIndexType::NodeType)
if (Type == EIndexType::NodeType)
{
// Script Objects
if (rkParent.row() == 0)
{
if (mModelType == EInstanceModelType::Layers)
return (mpArea ? mpArea->NumScriptLayers() : 0);
else
return mTemplateList.size();
return mpArea ? static_cast<int>(mpArea->NumScriptLayers()) : 0;
return static_cast<int>(mTemplateList.size());
}
else
return 0;
return 0;
}
// Instances
else if (Type == EIndexType::ObjectType)
if (Type == EIndexType::ObjectType)
{
const uint32 RowIndex = ((rkParent.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT);
if (mModelType == EInstanceModelType::Layers)
return (mpArea ? mpArea->ScriptLayer(RowIndex)->NumInstances() : 0);
else
return mTemplateList[RowIndex]->NumObjects();
return mpArea ? static_cast<int>(mpArea->ScriptLayer(RowIndex)->NumInstances()) : 0;
return static_cast<int>(mTemplateList[RowIndex]->NumObjects());
}
return 0;