From 09de312ac3136dba774204a40a844be46df75eda Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 18 Jun 2020 08:01:13 -0400 Subject: [PATCH] CPoiToWorld: Make use of size_t where applicable Plays nicer with standard containers. --- src/Core/Resource/CPoiToWorld.h | 4 +-- .../Resource/Cooker/CPoiToWorldCooker.cpp | 15 ++++---- src/Editor/WorldEditor/CPoiMapModel.cpp | 36 ++++++++++--------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Core/Resource/CPoiToWorld.h b/src/Core/Resource/CPoiToWorld.h index 28b1784e..f862c26c 100644 --- a/src/Core/Resource/CPoiToWorld.h +++ b/src/Core/Resource/CPoiToWorld.h @@ -30,12 +30,12 @@ public: void RemovePoi(uint32 PoiID); void RemovePoiMeshMap(uint32 PoiID, uint32 ModelID); - uint32 NumMappedPOIs() const + size_t NumMappedPOIs() const { return mMaps.size(); } - const SPoiMap* MapByIndex(uint32 Index) const + const SPoiMap* MapByIndex(size_t Index) const { return mMaps[Index]; } diff --git a/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp b/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp index 8bbe2894..a3a9dff4 100644 --- a/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp +++ b/src/Core/Resource/Cooker/CPoiToWorldCooker.cpp @@ -10,26 +10,23 @@ bool CPoiToWorldCooker::CookEGMC(CPoiToWorld *pPoiToWorld, IOutputStream& rOut) }; std::vector Mappings; - for (uint32 iPoi = 0; iPoi < pPoiToWorld->NumMappedPOIs(); iPoi++) + for (size_t iPoi = 0; iPoi < pPoiToWorld->NumMappedPOIs(); iPoi++) { const CPoiToWorld::SPoiMap *pkMap = pPoiToWorld->MapByIndex(iPoi); - for (auto it = pkMap->ModelIDs.begin(); it != pkMap->ModelIDs.end(); it++) + for (const auto meshID : pkMap->ModelIDs) { - SPoiMapping Mapping; - Mapping.MeshID = *it; - Mapping.PoiID = pkMap->PoiID; - Mappings.push_back(Mapping); + Mappings.push_back({meshID, pkMap->PoiID}); } } // Write EGMC rOut.WriteLong(Mappings.size()); - for (uint32 iMap = 0; iMap < Mappings.size(); iMap++) + for (const auto& mapping : Mappings) { - rOut.WriteLong(Mappings[iMap].MeshID); - rOut.WriteLong(Mappings[iMap].PoiID); + rOut.WriteLong(mapping.MeshID); + rOut.WriteLong(mapping.PoiID); } return true; diff --git a/src/Editor/WorldEditor/CPoiMapModel.cpp b/src/Editor/WorldEditor/CPoiMapModel.cpp index 2c752a82..2c252db6 100644 --- a/src/Editor/WorldEditor/CPoiMapModel.cpp +++ b/src/Editor/WorldEditor/CPoiMapModel.cpp @@ -23,14 +23,14 @@ QVariant CPoiMapModel::headerData(int Section, Qt::Orientation Orientation, int int CPoiMapModel::rowCount(const QModelIndex& /*rkParent*/) const { - return mpPoiToWorld ? mpPoiToWorld->NumMappedPOIs() : 0; + return mpPoiToWorld ? static_cast(mpPoiToWorld->NumMappedPOIs()) : 0; } QVariant CPoiMapModel::data(const QModelIndex& rkIndex, int Role) const { if (rkIndex.row() < rowCount(QModelIndex())) { - const CPoiToWorld::SPoiMap *pkMap = mpPoiToWorld->MapByIndex(rkIndex.row()); + const CPoiToWorld::SPoiMap *pkMap = mpPoiToWorld->MapByIndex(static_cast(rkIndex.row())); CScriptObject *pPOI = mpArea->InstanceByID(pkMap->PoiID); if (Role == Qt::DisplayRole) @@ -67,17 +67,17 @@ QVariant CPoiMapModel::data(const QModelIndex& rkIndex, int Role) const void CPoiMapModel::AddPOI(CScriptNode *pPOI) { - if (!mModelMap.contains(pPOI)) - { - int NewIndex = mpPoiToWorld->NumMappedPOIs(); - beginInsertRows(QModelIndex(), NewIndex, NewIndex); + if (mModelMap.contains(pPOI)) + return; - QList *pList = new QList; - mModelMap[pPOI] = pList; - mpPoiToWorld->AddPoi(pPOI->Instance()->InstanceID()); + const int NewIndex = static_cast(mpPoiToWorld->NumMappedPOIs()); + beginInsertRows(QModelIndex(), NewIndex, NewIndex); - endInsertRows(); - } + QList *pList = new QList; + mModelMap[pPOI] = pList; + mpPoiToWorld->AddPoi(pPOI->Instance()->InstanceID()); + + endInsertRows(); } void CPoiMapModel::AddMapping(const QModelIndex& rkIndex, CModelNode *pNode) @@ -142,9 +142,11 @@ bool CPoiMapModel::IsModelMapped(const QModelIndex& rkIndex, CModelNode *pNode) CScriptNode* CPoiMapModel::PoiNodePointer(const QModelIndex& rkIndex) const { - if ((uint32) rkIndex.row() < mpPoiToWorld->NumMappedPOIs()) + const auto rowIndex = static_cast(rkIndex.row()); + + if (rowIndex < mpPoiToWorld->NumMappedPOIs()) { - const CPoiToWorld::SPoiMap *pkMap = mpPoiToWorld->MapByIndex(rkIndex.row()); + const CPoiToWorld::SPoiMap *pkMap = mpPoiToWorld->MapByIndex(rowIndex); return mpEditor->Scene()->NodeForInstanceID(pkMap->PoiID); } @@ -180,7 +182,7 @@ void CPoiMapModel::OnMapChange(CWorld*, CGameArea *pArea) } // Create internal model map - for (uint32 iPoi = 0; iPoi < mpPoiToWorld->NumMappedPOIs(); iPoi++) + for (size_t iPoi = 0; iPoi < mpPoiToWorld->NumMappedPOIs(); iPoi++) { const CPoiToWorld::SPoiMap *pkMap = mpPoiToWorld->MapByIndex(iPoi); CScriptNode *pPoiNode = mpEditor->Scene()->NodeForInstanceID(pkMap->PoiID); @@ -189,10 +191,10 @@ void CPoiMapModel::OnMapChange(CWorld*, CGameArea *pArea) { QList *pModelList = new QList; - for (auto it = pkMap->ModelIDs.begin(); it != pkMap->ModelIDs.end(); it++) + for (const auto modelID : pkMap->ModelIDs) { - if (NodeMap.contains(*it)) - *pModelList << NodeMap[*it]; + if (NodeMap.contains(modelID)) + *pModelList << NodeMap[modelID]; } mModelMap[pPoiNode] = pModelList;