diff --git a/src/Core/GameProject/AssetNameGeneration.cpp b/src/Core/GameProject/AssetNameGeneration.cpp index f9e26464..897a469e 100644 --- a/src/Core/GameProject/AssetNameGeneration.cpp +++ b/src/Core/GameProject/AssetNameGeneration.cpp @@ -280,7 +280,7 @@ void GenerateAssetNames(CGameProject *pProj) } // Generate names from script instance names - for (uint32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) { CScriptLayer *pLayer = pArea->ScriptLayer(iLyr); diff --git a/src/Core/Resource/Area/CGameArea.h b/src/Core/Resource/Area/CGameArea.h index e4215fc8..036c925f 100644 --- a/src/Core/Resource/Area/CGameArea.h +++ b/src/Core/Resource/Area/CGameArea.h @@ -78,11 +78,12 @@ public: uint32 TotalInstanceCount() const; CScriptObject* InstanceByID(uint32 InstanceID); uint32 FindUnusedInstanceID() const; - CScriptObject* SpawnInstance(CScriptTemplate *pTemplate, CScriptLayer *pLayer, + CScriptObject* SpawnInstance(CScriptTemplate* pTemplate, CScriptLayer* pLayer, const CVector3f& rkPosition = CVector3f::Zero(), const CQuaternion& rkRotation = CQuaternion::Identity(), const CVector3f& rkScale = CVector3f::One(), - uint32 SuggestedID = -1, uint32 SuggestedLayerIndex = -1); + uint32 SuggestedID = UINT32_MAX, + uint32 SuggestedLayerIndex = UINT32_MAX); void AddInstanceToArea(CScriptObject *pInstance); void DeleteInstance(CScriptObject *pInstance); void ClearExtraDependencies(); @@ -91,16 +92,16 @@ public: uint32 WorldIndex() const { return mWorldIndex; } CTransform4f Transform() const { return mTransform; } CMaterialSet* Materials() const { return mpMaterialSet; } - uint32 NumWorldModels() const { return mWorldModels.size(); } - uint32 NumStaticModels() const { return mStaticWorldModels.size(); } - CModel* TerrainModel(uint32 iMdl) const { return mWorldModels[iMdl].get(); } - CStaticModel* StaticModel(uint32 iMdl) const { return mStaticWorldModels[iMdl].get(); } + size_t NumWorldModels() const { return mWorldModels.size(); } + size_t NumStaticModels() const { return mStaticWorldModels.size(); } + CModel* TerrainModel(size_t iMdl) const { return mWorldModels[iMdl].get(); } + CStaticModel* StaticModel(size_t iMdl) const { return mStaticWorldModels[iMdl].get(); } CCollisionMeshGroup* Collision() const { return mpCollision.get(); } - uint32 NumScriptLayers() const { return mScriptLayers.size(); } - CScriptLayer* ScriptLayer(uint32 Index) const { return mScriptLayers[Index].get(); } - uint32 NumLightLayers() const { return mLightLayers.size(); } - uint32 NumLights(uint32 LayerIndex) const { return (LayerIndex < mLightLayers.size() ? mLightLayers[LayerIndex].size() : 0); } - CLight* Light(uint32 LayerIndex, uint32 LightIndex) { return &mLightLayers[LayerIndex][LightIndex]; } + size_t NumScriptLayers() const { return mScriptLayers.size(); } + CScriptLayer* ScriptLayer(size_t Index) const { return mScriptLayers[Index].get(); } + size_t NumLightLayers() const { return mLightLayers.size(); } + size_t NumLights(size_t LayerIndex) const { return (LayerIndex < mLightLayers.size() ? mLightLayers[LayerIndex].size() : 0); } + CLight* Light(size_t LayerIndex, size_t LightIndex) { return &mLightLayers[LayerIndex][LightIndex]; } CAssetID PathID() const { return mPathID; } CPoiToWorld* PoiToWorldMap() const { return mpPoiToWorldMap; } CAssetID PortalAreaID() const { return mPortalAreaID; } diff --git a/src/Core/Resource/CWorld.cpp b/src/Core/Resource/CWorld.cpp index a458e493..34e96f62 100644 --- a/src/Core/Resource/CWorld.cpp +++ b/src/Core/Resource/CWorld.cpp @@ -41,7 +41,7 @@ void CWorld::SetAreaLayerInfo(CGameArea *pArea) SArea& AreaInfo = mAreas[pArea->WorldIndex()]; - for (uint32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) { if (AreaInfo.Layers.size() <= iLyr) break; diff --git a/src/Core/Resource/Factory/CAreaLoader.cpp b/src/Core/Resource/Factory/CAreaLoader.cpp index e207acc0..90e137d5 100644 --- a/src/Core/Resource/Factory/CAreaLoader.cpp +++ b/src/Core/Resource/Factory/CAreaLoader.cpp @@ -642,15 +642,15 @@ void CAreaLoader::ReadEGMC() void CAreaLoader::SetUpObjects(CScriptLayer *pGenLayer) { // Create instance map - for (uint32 LayerIdx = 0; LayerIdx < mpArea->NumScriptLayers(); LayerIdx++) + for (size_t LayerIdx = 0; LayerIdx < mpArea->NumScriptLayers(); LayerIdx++) { auto& pLayer = mpArea->mScriptLayers[LayerIdx]; - for (uint32 InstIdx = 0; InstIdx < pLayer->NumInstances(); InstIdx++) + for (size_t InstIdx = 0; InstIdx < pLayer->NumInstances(); InstIdx++) { CScriptObject *pInst = pLayer->InstanceByIndex(InstIdx); - uint32 InstanceID = pInst->InstanceID(); - CScriptObject *pExisting = mpArea->InstanceByID(InstanceID); + const uint32 InstanceID = pInst->InstanceID(); + [[maybe_unused]] CScriptObject *pExisting = mpArea->InstanceByID(InstanceID); ASSERT(pExisting == nullptr); mpArea->mObjectMap[InstanceID] = pInst; } @@ -673,11 +673,10 @@ void CAreaLoader::SetUpObjects(CScriptLayer *pGenLayer) pGenLayer->RemoveInstance(pInst); delete pInst; } - else { - uint32 LayerIdx = (InstanceID >> 26) & 0x3F; - pInst->SetLayer( mpArea->ScriptLayer(LayerIdx) ); + const uint32 LayerIdx = (InstanceID >> 26) & 0x3F; + pInst->SetLayer(mpArea->ScriptLayer(LayerIdx)); mpArea->mObjectMap[InstanceID] = pInst; } } diff --git a/src/Core/Resource/Script/CScriptLayer.h b/src/Core/Resource/Script/CScriptLayer.h index 340a3103..57a29923 100644 --- a/src/Core/Resource/Script/CScriptLayer.h +++ b/src/Core/Resource/Script/CScriptLayer.h @@ -106,7 +106,7 @@ public: return iLyr; } - return -1; + return UINT32_MAX; } // Operators diff --git a/src/Core/Scene/CScene.cpp b/src/Core/Scene/CScene.cpp index 60feea3a..67937f7c 100644 --- a/src/Core/Scene/CScene.cpp +++ b/src/Core/Scene/CScene.cpp @@ -183,36 +183,36 @@ void CScene::SetActiveArea(CWorld *pWorld, CGameArea *pArea) mpAreaRootNode = new CRootNode(this, -1, mpSceneRootNode); // Create static nodes - uint32 Count = mpArea->NumStaticModels(); + size_t Count = mpArea->NumStaticModels(); - for (uint32 iMdl = 0; iMdl < Count; iMdl++) + for (size_t iMdl = 0; iMdl < Count; iMdl++) { CStaticNode *pNode = CreateStaticNode(mpArea->StaticModel(iMdl)); - pNode->SetName("Static World Model " + TString::FromInt32(iMdl, 0, 10)); + pNode->SetName("Static World Model " + std::to_string(iMdl)); } // Create model nodes Count = mpArea->NumWorldModels(); - for (uint32 iMdl = 0; iMdl < Count; iMdl++) + for (size_t iMdl = 0; iMdl < Count; iMdl++) { CModel *pModel = mpArea->TerrainModel(iMdl); CModelNode *pNode = CreateModelNode(pModel); - pNode->SetName("World Model " + TString::FromInt32(iMdl, 0, 10)); + pNode->SetName("World Model " + std::to_string(iMdl)); pNode->SetWorldModel(true); } CreateCollisionNode(mpArea->Collision()); - uint32 NumLayers = mpArea->NumScriptLayers(); + const size_t NumLayers = mpArea->NumScriptLayers(); - for (uint32 iLyr = 0; iLyr < NumLayers; iLyr++) + for (size_t iLyr = 0; iLyr < NumLayers; iLyr++) { CScriptLayer *pLayer = mpArea->ScriptLayer(iLyr); - uint32 NumObjects = pLayer->NumInstances(); + const size_t NumObjects = pLayer->NumInstances(); mNodes[ENodeType::Script].reserve(mNodes[ENodeType::Script].size() + NumObjects); - for (uint32 iObj = 0; iObj < NumObjects; iObj++) + for (size_t iObj = 0; iObj < NumObjects; iObj++) { CScriptObject *pObj = pLayer->InstanceByIndex(iObj); CreateScriptNode(pObj); @@ -227,14 +227,14 @@ void CScene::SetActiveArea(CWorld *pWorld, CGameArea *pArea) pScript->BuildLightList(mpArea); } - uint32 NumLightLayers = mpArea->NumLightLayers(); + const size_t NumLightLayers = mpArea->NumLightLayers(); CGraphics::sAreaAmbientColor = CColor::TransparentBlack(); - for (uint32 iLyr = 0; iLyr < NumLightLayers; iLyr++) + for (size_t iLyr = 0; iLyr < NumLightLayers; iLyr++) { - uint32 NumLights = mpArea->NumLights(iLyr); + const size_t NumLights = mpArea->NumLights(iLyr); - for (uint32 iLit = 0; iLit < NumLights; iLit++) + for (size_t iLit = 0; iLit < NumLights; iLit++) { CLight *pLight = mpArea->Light(iLyr, iLit); diff --git a/src/Core/Scene/CSceneNode.cpp b/src/Core/Scene/CSceneNode.cpp index 26add07b..1af89403 100644 --- a/src/Core/Scene/CSceneNode.cpp +++ b/src/Core/Scene/CSceneNode.cpp @@ -121,8 +121,9 @@ void CSceneNode::BuildLightList(CGameArea *pArea) mLightCount = 0; mAmbientColor = CColor::TransparentBlack(); - uint32 Index = mLightLayerIndex; - if ((pArea->NumLightLayers() <= Index) || (pArea->NumLights(Index) == 0)) Index = 0; + size_t Index = mLightLayerIndex; + if (pArea->NumLightLayers() <= Index || pArea->NumLights(Index) == 0) + Index = 0; struct SLightEntry { CLight *pLight; @@ -138,11 +139,11 @@ void CSceneNode::BuildLightList(CGameArea *pArea) std::vector LightEntries; // Default ambient color to white if there are no lights on the selected layer - uint32 NumLights = pArea->NumLights(Index); + const size_t NumLights = pArea->NumLights(Index); if (NumLights == 0) mAmbientColor = CColor::TransparentWhite(); - for (uint32 iLight = 0; iLight < NumLights; iLight++) + for (size_t iLight = 0; iLight < NumLights; iLight++) { CLight* pLight = pArea->Light(Index, iLight); diff --git a/src/Editor/CQuickplayPropertyEditor.cpp b/src/Editor/CQuickplayPropertyEditor.cpp index dac1cf1c..a6a266fe 100644 --- a/src/Editor/CQuickplayPropertyEditor.cpp +++ b/src/Editor/CQuickplayPropertyEditor.cpp @@ -152,15 +152,15 @@ void CQuickplayPropertyEditor::OnWorldEditorAreaChanged(CWorld* pWorld, CGameAre if (pArea) { - for (uint LayerIdx = 0; LayerIdx < pArea->NumScriptLayers(); LayerIdx++) + for (size_t LayerIdx = 0; LayerIdx < pArea->NumScriptLayers(); LayerIdx++) { CScriptLayer* pLayer = pArea->ScriptLayer(LayerIdx); bool bActive = pLayer->IsActive(); QListWidgetItem* pItem = new QListWidgetItem(); - pItem->setText( TO_QSTRING(pLayer->Name()) ); - pItem->setCheckState( bActive ? Qt::Checked : Qt::Unchecked ); - mpUI->LayerList->addItem( pItem ); + pItem->setText(TO_QSTRING(pLayer->Name())); + pItem->setCheckState(bActive ? Qt::Checked : Qt::Unchecked); + mpUI->LayerList->addItem(pItem); if (bActive) { diff --git a/src/Editor/WorldEditor/CInstancesModel.cpp b/src/Editor/WorldEditor/CInstancesModel.cpp index 1d90164e..39ea8bf5 100644 --- a/src/Editor/WorldEditor/CInstancesModel.cpp +++ b/src/Editor/WorldEditor/CInstancesModel.cpp @@ -98,8 +98,8 @@ QModelIndex CInstancesModel::index(int Row, int Column, const QModelIndex& rkPar { if (mModelType == EInstanceModelType::Layers) { - CScriptLayer *pLayer = mpArea->ScriptLayer(rkParent.row()); - if ((uint32) Row >= pLayer->NumInstances()) + CScriptLayer *pLayer = mpArea->ScriptLayer(static_cast(rkParent.row())); + if (static_cast(Row) >= pLayer->NumInstances()) return QModelIndex(); else return createIndex(Row, Column, (*pLayer)[Row]); @@ -108,8 +108,10 @@ QModelIndex CInstancesModel::index(int Row, int Column, const QModelIndex& rkPar else if (mModelType == EInstanceModelType::Types) { const std::list& list = mTemplateList[rkParent.row()]->ObjectList(); - if ((uint32) Row >= list.size()) + if (static_cast(Row) >= list.size()) + { return QModelIndex(); + } else { auto it = std::next(list.begin(), Row); @@ -148,7 +150,7 @@ QModelIndex CInstancesModel::parent(const QModelIndex& rkChild) const { CScriptLayer *pLayer = pObj->Layer(); - for (uint32 iLyr = 0; iLyr < mpArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < mpArea->NumScriptLayers(); iLyr++) { if (mpArea->ScriptLayer(iLyr) == pLayer) return createIndex(iLyr, 0, (iLyr << TYPES_ROW_INDEX_SHIFT) | 1); @@ -159,10 +161,10 @@ QModelIndex CInstancesModel::parent(const QModelIndex& rkChild) const { CScriptTemplate *pTemp = pObj->Template(); - for (int iTemp = 0; iTemp < mTemplateList.size(); iTemp++) + for (size_t iTemp = 0; iTemp < mTemplateList.size(); iTemp++) { if (mTemplateList[iTemp] == pTemp) - return createIndex(iTemp, 0, (iTemp << TYPES_ROW_INDEX_SHIFT) | 1); + return createIndex(static_cast(iTemp), 0, static_cast((iTemp << TYPES_ROW_INDEX_SHIFT) | 1)); } } } @@ -176,8 +178,9 @@ int CInstancesModel::rowCount(const QModelIndex& rkParent) const // Node types if (Type == EIndexType::Root) + { return mBaseItems.count(); - + } // Object types else if (Type == EIndexType::NodeType) { @@ -192,19 +195,17 @@ int CInstancesModel::rowCount(const QModelIndex& rkParent) const else return 0; } - // Instances else if (Type == EIndexType::ObjectType) { - 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) return (mpArea ? mpArea->ScriptLayer(RowIndex)->NumInstances() : 0); else return mTemplateList[RowIndex]->NumObjects(); } - else - return 0; + return 0; } int CInstancesModel::columnCount(const QModelIndex& /*rkParent*/) const @@ -235,7 +236,7 @@ QVariant CInstancesModel::data(const QModelIndex& rkIndex, int Role) const if (rkIndex.column() == 0) { if (mModelType == EInstanceModelType::Layers) - return TO_QSTRING(mpEditor->ActiveArea()->ScriptLayer(rkIndex.row())->Name()); + return TO_QSTRING(mpEditor->ActiveArea()->ScriptLayer(static_cast(rkIndex.row()))->Name()); else return TO_QSTRING(mTemplateList[rkIndex.row()]->Name()); } @@ -338,7 +339,7 @@ CScriptLayer* CInstancesModel::IndexLayer(const QModelIndex& rkIndex) const if ((mModelType != EInstanceModelType::Layers) || (IndexNodeType(rkIndex) != ENodeType::Script) || (IndexType(rkIndex) != EIndexType::ObjectType)) return nullptr; - uint32 RowIndex = ((rkIndex.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); + const uint32 RowIndex = ((rkIndex.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); return mpArea->ScriptLayer(RowIndex); } @@ -347,7 +348,7 @@ CScriptTemplate* CInstancesModel::IndexTemplate(const QModelIndex& rkIndex) cons if ((mModelType != EInstanceModelType::Types) || (IndexNodeType(rkIndex) != ENodeType::Script) || (IndexType(rkIndex) != EIndexType::ObjectType)) return nullptr; - uint32 RowIndex = ((rkIndex.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); + const uint32 RowIndex = ((rkIndex.internalId() & TYPES_ROW_INDEX_MASK) >> TYPES_ROW_INDEX_SHIFT); return mTemplateList[RowIndex]; } diff --git a/src/Editor/WorldEditor/CLayerModel.cpp b/src/Editor/WorldEditor/CLayerModel.cpp index 6358c4dd..bfea6c4f 100644 --- a/src/Editor/WorldEditor/CLayerModel.cpp +++ b/src/Editor/WorldEditor/CLayerModel.cpp @@ -33,11 +33,13 @@ void CLayerModel::SetArea(CGameArea *pArea) CScriptLayer* CLayerModel::Layer(const QModelIndex& index) const { - if (!mpArea) return nullptr; - uint32 NumLayers = mpArea->NumScriptLayers(); + if (!mpArea) + return nullptr; - if (index.row() < (int) NumLayers) - return mpArea->ScriptLayer(index.row()); + const size_t NumLayers = mpArea->NumScriptLayers(); + + if (index.row() < static_cast(NumLayers)) + return mpArea->ScriptLayer(static_cast(index.row())); return nullptr; } diff --git a/src/Editor/WorldEditor/WCreateTab.cpp b/src/Editor/WorldEditor/WCreateTab.cpp index 739ab177..532a7f9f 100644 --- a/src/Editor/WorldEditor/WCreateTab.cpp +++ b/src/Editor/WorldEditor/WCreateTab.cpp @@ -76,7 +76,7 @@ void WCreateTab::OnLayersChanged() ui->SpawnLayerComboBox->blockSignals(true); ui->SpawnLayerComboBox->clear(); - for (uint32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) ui->SpawnLayerComboBox->addItem(TO_QSTRING(pArea->ScriptLayer(iLyr)->Name())); ui->SpawnLayerComboBox->setCurrentIndex(0); @@ -88,5 +88,5 @@ void WCreateTab::OnLayersChanged() void WCreateTab::OnSpawnLayerChanged(int LayerIndex) { CGameArea *pArea = mpEditor->ActiveArea(); - mpSpawnLayer = pArea->ScriptLayer(LayerIndex); + mpSpawnLayer = pArea->ScriptLayer(static_cast(LayerIndex)); } diff --git a/src/Editor/WorldEditor/WEditorProperties.cpp b/src/Editor/WorldEditor/WEditorProperties.cpp index 9053758f..802ed9ef 100644 --- a/src/Editor/WorldEditor/WEditorProperties.cpp +++ b/src/Editor/WorldEditor/WEditorProperties.cpp @@ -79,11 +79,11 @@ void WEditorProperties::SetLayerComboBox() { CScriptNode *pScript = static_cast(mpDisplayNode); CScriptLayer *pLayer = pScript->Instance()->Layer(); - for (uint32 iLyr = 0; iLyr < mpEditor->ActiveArea()->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < mpEditor->ActiveArea()->NumScriptLayers(); iLyr++) { if (mpEditor->ActiveArea()->ScriptLayer(iLyr) == pLayer) { - mpLayersComboBox->setCurrentIndex(iLyr); + mpLayersComboBox->setCurrentIndex(static_cast(iLyr)); break; } } @@ -170,7 +170,7 @@ void WEditorProperties::OnLayersModified() if (pArea) { - for (uint32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) mpLayersComboBox->addItem(TO_QSTRING(pArea->ScriptLayer(iLyr)->Name())); } @@ -215,12 +215,12 @@ void WEditorProperties::OnInstanceNameEditFinished() void WEditorProperties::OnLayerChanged() { - int Index = mpLayersComboBox->currentIndex(); + const int Index = mpLayersComboBox->currentIndex(); - if (Index >= 0) - { - CScriptLayer *pLayer = mpEditor->ActiveArea()->ScriptLayer(Index); - mpEditor->SetSelectionLayer(pLayer); - } + if (Index < 0) + return; + + CScriptLayer *pLayer = mpEditor->ActiveArea()->ScriptLayer(static_cast(Index)); + mpEditor->SetSelectionLayer(pLayer); } diff --git a/src/Editor/WorldEditor/WInstancesTab.cpp b/src/Editor/WorldEditor/WInstancesTab.cpp index 74cecfd4..f6e80c3a 100644 --- a/src/Editor/WorldEditor/WInstancesTab.cpp +++ b/src/Editor/WorldEditor/WInstancesTab.cpp @@ -288,10 +288,10 @@ void WInstancesTab::OnHideAllExceptTypeAction() { CGameArea *pArea = mpEditor->ActiveArea(); - for (uint32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) { CScriptLayer *pLayer = pArea->ScriptLayer(iLyr); - pLayer->SetVisible( pLayer == mpMenuLayer ? true : false ); + pLayer->SetVisible(pLayer == mpMenuLayer); } mpLayersModel->dataChanged( mpLayersModel->index(0, 2, TypeParent), mpLayersModel->index(mpLayersModel->rowCount(TypeParent) - 1, 2, TypeParent) ); @@ -322,12 +322,11 @@ void WInstancesTab::OnUnhideAllTypes() { CGameArea *pArea = mpEditor->ActiveArea(); - for (uint32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) pArea->ScriptLayer(iLyr)->SetVisible(true); mpLayersModel->dataChanged( mpLayersModel->index(0, 2, TypeParent), mpLayersModel->index(mpLayersModel->rowCount(TypeParent) - 1, 2, TypeParent) ); } - else { EGame Game = mpEditor->CurrentGame(); @@ -353,7 +352,7 @@ void WInstancesTab::OnUnhideAll() { CGameArea *pArea = mpEditor->ActiveArea(); - for (uint32 iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) + for (size_t iLyr = 0; iLyr < pArea->NumScriptLayers(); iLyr++) pArea->ScriptLayer(iLyr)->SetVisible(true); mpLayersModel->dataChanged( mpLayersModel->index(0, 2, LayersRoot), mpLayersModel->index(mpLayersModel->rowCount(LayersRoot) - 1, 2, LayersRoot) );