CScriptLayer: Make use of size_t where applicable
This commit is contained in:
parent
d1939eea95
commit
c6263433a9
|
@ -284,7 +284,7 @@ void GenerateAssetNames(CGameProject *pProj)
|
||||||
{
|
{
|
||||||
CScriptLayer *pLayer = pArea->ScriptLayer(iLyr);
|
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);
|
CScriptObject* pInst = pLayer->InstanceByIndex(iInst);
|
||||||
CStructProperty* pProperties = pInst->Template()->Properties();
|
CStructProperty* pProperties = pInst->Template()->Properties();
|
||||||
|
|
|
@ -329,7 +329,7 @@ void CAreaDependencyTree::AddScriptLayer(CScriptLayer *pLayer, const std::vector
|
||||||
mLayerOffsets.push_back(mChildren.size());
|
mLayerOffsets.push_back(mChildren.size());
|
||||||
std::set<CAssetID> UsedIDs;
|
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));
|
auto pTree = CScriptInstanceDependency::BuildTree(pLayer->InstanceByIndex(iInst));
|
||||||
ASSERT(pTree != nullptr);
|
ASSERT(pTree != nullptr);
|
||||||
|
|
|
@ -118,9 +118,9 @@ void CGameArea::ClearScriptLayers()
|
||||||
mScriptLayers.clear();
|
mScriptLayers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 CGameArea::TotalInstanceCount() const
|
size_t CGameArea::TotalInstanceCount() const
|
||||||
{
|
{
|
||||||
uint32 Num = 0;
|
size_t Num = 0;
|
||||||
|
|
||||||
for (const auto& layer : mScriptLayers)
|
for (const auto& layer : mScriptLayers)
|
||||||
Num += layer->NumInstances();
|
Num += layer->NumInstances();
|
||||||
|
@ -164,30 +164,30 @@ CScriptObject* CGameArea::SpawnInstance(CScriptTemplate *pTemplate,
|
||||||
uint32 SuggestedLayerIndex /*= -1*/ )
|
uint32 SuggestedLayerIndex /*= -1*/ )
|
||||||
{
|
{
|
||||||
// Verify we can fit another instance in this area.
|
// Verify we can fit another instance in this area.
|
||||||
uint32 NumInstances = TotalInstanceCount();
|
const size_t NumInstances = TotalInstanceCount();
|
||||||
|
|
||||||
if (NumInstances >= 0xFFFF)
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the suggested instance ID is valid
|
// Check whether the suggested instance ID is valid
|
||||||
uint32 InstanceID = SuggestedID;
|
uint32 InstanceID = SuggestedID;
|
||||||
|
|
||||||
if (InstanceID != -1)
|
if (InstanceID != UINT32_MAX)
|
||||||
{
|
{
|
||||||
if (mObjectMap.find(InstanceID) == mObjectMap.end())
|
if (mObjectMap.find(InstanceID) == mObjectMap.cend())
|
||||||
InstanceID = -1;
|
InstanceID = UINT32_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not valid (or if there's no suggested ID) then determine a new instance ID
|
// 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
|
// 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");
|
errorf("Unable to spawn a new script instance; invalid script layer passed in");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -198,13 +198,14 @@ CScriptObject* CGameArea::SpawnInstance(CScriptTemplate *pTemplate,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn instance
|
// Spawn instance
|
||||||
CScriptObject *pInstance = new CScriptObject(InstanceID, this, pLayer, pTemplate);
|
auto* pInstance = new CScriptObject(InstanceID, this, pLayer, pTemplate);
|
||||||
pInstance->EvaluateProperties();
|
pInstance->EvaluateProperties();
|
||||||
pInstance->SetPosition(rkPosition);
|
pInstance->SetPosition(rkPosition);
|
||||||
pInstance->SetRotation(rkRotation.ToEuler());
|
pInstance->SetRotation(rkRotation.ToEuler());
|
||||||
pInstance->SetScale(rkScale);
|
pInstance->SetScale(rkScale);
|
||||||
pInstance->SetName(pTemplate->Name());
|
pInstance->SetName(pTemplate->Name());
|
||||||
if (pTemplate->Game() < EGame::EchoesDemo) pInstance->SetActive(true);
|
if (pTemplate->Game() < EGame::EchoesDemo)
|
||||||
|
pInstance->SetActive(true);
|
||||||
pLayer->AddInstance(pInstance, SuggestedLayerIndex);
|
pLayer->AddInstance(pInstance, SuggestedLayerIndex);
|
||||||
mObjectMap[InstanceID] = pInstance;
|
mObjectMap[InstanceID] = pInstance;
|
||||||
return pInstance;
|
return pInstance;
|
||||||
|
|
|
@ -75,7 +75,7 @@ public:
|
||||||
void MergeTerrain();
|
void MergeTerrain();
|
||||||
void ClearTerrain();
|
void ClearTerrain();
|
||||||
void ClearScriptLayers();
|
void ClearScriptLayers();
|
||||||
uint32 TotalInstanceCount() const;
|
size_t TotalInstanceCount() const;
|
||||||
CScriptObject* InstanceByID(uint32 InstanceID);
|
CScriptObject* InstanceByID(uint32 InstanceID);
|
||||||
uint32 FindUnusedInstanceID() const;
|
uint32 FindUnusedInstanceID() const;
|
||||||
CScriptObject* SpawnInstance(CScriptTemplate* pTemplate, CScriptLayer* pLayer,
|
CScriptObject* SpawnInstance(CScriptTemplate* pTemplate, CScriptLayer* pLayer,
|
||||||
|
|
|
@ -276,7 +276,7 @@ void CScriptCooker::WriteLayer(IOutputStream& rOut, CScriptLayer *pLayer)
|
||||||
uint32 NumWrittenInstances = 0;
|
uint32 NumWrittenInstances = 0;
|
||||||
rOut.WriteLong(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);
|
CScriptObject *pInstance = pLayer->InstanceByIndex(iInst);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
mInstances.erase(it);
|
mInstances.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveInstanceByIndex(uint32 Index)
|
void RemoveInstanceByIndex(size_t Index)
|
||||||
{
|
{
|
||||||
mInstances.erase(mInstances.begin() + Index);
|
mInstances.erase(mInstances.begin() + Index);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public:
|
||||||
mInstances.erase(it);
|
mInstances.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reserve(uint32 Amount)
|
void Reserve(size_t Amount)
|
||||||
{
|
{
|
||||||
mInstances.reserve(Amount);
|
mInstances.reserve(Amount);
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,8 @@ public:
|
||||||
TString Name() const { return mLayerName; }
|
TString Name() const { return mLayerName; }
|
||||||
bool IsActive() const { return mActive; }
|
bool IsActive() const { return mActive; }
|
||||||
bool IsVisible() const { return mVisible; }
|
bool IsVisible() const { return mVisible; }
|
||||||
uint32 NumInstances() const { return mInstances.size(); }
|
size_t NumInstances() const { return mInstances.size(); }
|
||||||
CScriptObject* InstanceByIndex(uint32 Index) const { return mInstances[Index]; }
|
CScriptObject* InstanceByIndex(size_t Index) const { return mInstances[Index]; }
|
||||||
|
|
||||||
CScriptObject* InstanceByID(uint32 ID) const
|
CScriptObject* InstanceByID(uint32 ID) const
|
||||||
{
|
{
|
||||||
|
@ -109,8 +109,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operators
|
// Operators
|
||||||
CScriptObject* operator[](uint32 Index) { return InstanceByIndex(Index); }
|
CScriptObject* operator[](size_t Index) { return InstanceByIndex(Index); }
|
||||||
const CScriptObject* operator[](uint32 Index) const { return InstanceByIndex(Index); }
|
const CScriptObject* operator[](size_t Index) const { return InstanceByIndex(Index); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CSCRIPTLAYER_H
|
#endif // CSCRIPTLAYER_H
|
||||||
|
|
|
@ -174,35 +174,37 @@ QModelIndex CInstancesModel::parent(const QModelIndex& rkChild) const
|
||||||
|
|
||||||
int CInstancesModel::rowCount(const QModelIndex& rkParent) const
|
int CInstancesModel::rowCount(const QModelIndex& rkParent) const
|
||||||
{
|
{
|
||||||
EIndexType Type = IndexType(rkParent);
|
const EIndexType Type = IndexType(rkParent);
|
||||||
|
|
||||||
// Node types
|
// Node types
|
||||||
if (Type == EIndexType::Root)
|
if (Type == EIndexType::Root)
|
||||||
{
|
{
|
||||||
return mBaseItems.count();
|
return mBaseItems.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object types
|
// Object types
|
||||||
else if (Type == EIndexType::NodeType)
|
if (Type == EIndexType::NodeType)
|
||||||
{
|
{
|
||||||
// Script Objects
|
// Script Objects
|
||||||
if (rkParent.row() == 0)
|
if (rkParent.row() == 0)
|
||||||
{
|
{
|
||||||
if (mModelType == EInstanceModelType::Layers)
|
if (mModelType == EInstanceModelType::Layers)
|
||||||
return (mpArea ? mpArea->NumScriptLayers() : 0);
|
return mpArea ? static_cast<int>(mpArea->NumScriptLayers()) : 0;
|
||||||
else
|
|
||||||
return mTemplateList.size();
|
return static_cast<int>(mTemplateList.size());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instances
|
// Instances
|
||||||
else if (Type == EIndexType::ObjectType)
|
if (Type == EIndexType::ObjectType)
|
||||||
{
|
{
|
||||||
const uint32 RowIndex = ((rkParent.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT);
|
const uint32 RowIndex = ((rkParent.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT);
|
||||||
if (mModelType == EInstanceModelType::Layers)
|
if (mModelType == EInstanceModelType::Layers)
|
||||||
return (mpArea ? mpArea->ScriptLayer(RowIndex)->NumInstances() : 0);
|
return mpArea ? static_cast<int>(mpArea->ScriptLayer(RowIndex)->NumInstances()) : 0;
|
||||||
else
|
|
||||||
return mTemplateList[RowIndex]->NumObjects();
|
return static_cast<int>(mTemplateList[RowIndex]->NumObjects());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue