diff --git a/src/Core/GameProject/AssetNameGeneration.cpp b/src/Core/GameProject/AssetNameGeneration.cpp index efebbdbc..c244a866 100644 --- a/src/Core/GameProject/AssetNameGeneration.cpp +++ b/src/Core/GameProject/AssetNameGeneration.cpp @@ -198,7 +198,7 @@ void GenerateAssetNames(CGameProject *pProj) } // Areas - for (uint32 iArea = 0; iArea < pWorld->NumAreas(); iArea++) + for (size_t iArea = 0; iArea < pWorld->NumAreas(); iArea++) { // Determine area name TString AreaName = pWorld->AreaInternalName(iArea); @@ -209,7 +209,9 @@ void GenerateAssetNames(CGameProject *pProj) // Rename area stuff CResourceEntry *pAreaEntry = pStore->FindEntry(AreaID); - if (!pAreaEntry) continue; // Some DKCR worlds reference areas that don't exist + // Some DKCR worlds reference areas that don't exist + if (!pAreaEntry) + continue; ApplyGeneratedName(pAreaEntry, WorldMasterDir, AreaName); CStringTable *pAreaNameTable = pWorld->AreaName(iArea); diff --git a/src/Core/GameProject/CGameExporter.cpp b/src/Core/GameProject/CGameExporter.cpp index 7acf9b27..4fc7db54 100644 --- a/src/Core/GameProject/CGameExporter.cpp +++ b/src/Core/GameProject/CGameExporter.cpp @@ -580,12 +580,12 @@ void CGameExporter::ExportResourceEditorData() CWorld *pWorld = (CWorld*) It->Load(); // Set area duplicate flags - for (uint32 iArea = 0; iArea < pWorld->NumAreas(); iArea++) + for (size_t iArea = 0; iArea < pWorld->NumAreas(); iArea++) { CAssetID AreaID = pWorld->AreaResourceID(iArea); auto Find = mAreaDuplicateMap.find(AreaID); - if (Find != mAreaDuplicateMap.end()) + if (Find != mAreaDuplicateMap.cend()) pWorld->SetAreaAllowsPakDuplicates(iArea, Find->second); } diff --git a/src/Core/GameProject/DependencyListBuilders.cpp b/src/Core/GameProject/DependencyListBuilders.cpp index ffccea16..04754417 100644 --- a/src/Core/GameProject/DependencyListBuilders.cpp +++ b/src/Core/GameProject/DependencyListBuilders.cpp @@ -1,15 +1,20 @@ #include "DependencyListBuilders.h" // ************ CCharacterUsageMap ************ -bool CCharacterUsageMap::IsCharacterUsed(const CAssetID& rkID, uint32 CharacterIndex) const +bool CCharacterUsageMap::IsCharacterUsed(const CAssetID& rkID, size_t CharacterIndex) const { - if (mpStore->Game() >= EGame::CorruptionProto) return true; - auto Find = mUsageMap.find(rkID); - if (Find == mUsageMap.end()) return false; + if (mpStore->Game() >= EGame::CorruptionProto) + return true; + + const auto Find = mUsageMap.find(rkID); + if (Find == mUsageMap.cend()) + return false; const std::vector& rkUsageList = Find->second; - if (CharacterIndex >= rkUsageList.size()) return false; - else return rkUsageList[CharacterIndex]; + if (CharacterIndex >= rkUsageList.size()) + return false; + + return rkUsageList[CharacterIndex]; } bool CCharacterUsageMap::IsAnimationUsed(const CAssetID& rkID, CSetAnimationDependency *pAnim) const @@ -37,7 +42,7 @@ void CCharacterUsageMap::FindUsagesForArea(CWorld *pWorld, CResourceEntry *pEntr { ASSERT(pEntry->ResourceType() == EResourceType::Area); - for (uint32 iArea = 0; iArea < pWorld->NumAreas(); iArea++) + for (size_t iArea = 0; iArea < pWorld->NumAreas(); iArea++) { if (pWorld->AreaResourceID(iArea) == pEntry->ID()) { @@ -47,17 +52,19 @@ void CCharacterUsageMap::FindUsagesForArea(CWorld *pWorld, CResourceEntry *pEntr } } -void CCharacterUsageMap::FindUsagesForArea(CWorld *pWorld, uint32 AreaIndex) +void CCharacterUsageMap::FindUsagesForArea(CWorld *pWorld, size_t AreaIndex) { // We only need to search forward from this area to other areas that both use the same character(s) + have duplicates enabled Clear(); - for (uint32 iArea = AreaIndex; iArea < pWorld->NumAreas(); iArea++) + for (size_t iArea = AreaIndex; iArea < pWorld->NumAreas(); iArea++) { - if (!mIsInitialArea && mStillLookingIDs.empty()) break; + if (!mIsInitialArea && mStillLookingIDs.empty()) + break; + mCurrentAreaAllowsDupes = pWorld->DoesAreaAllowPakDuplicates(iArea); - CAssetID AreaID = pWorld->AreaResourceID(iArea); + const CAssetID AreaID = pWorld->AreaResourceID(iArea); CResourceEntry *pEntry = mpStore->FindEntry(AreaID); ASSERT(pEntry && pEntry->ResourceType() == EResourceType::Area); @@ -241,7 +248,7 @@ void CPackageDependencyListBuilder::AddDependency(CResourceEntry *pCurEntry, con if (mEnableDuplicates) { - for (uint32 iArea = 0; iArea < mpWorld->NumAreas(); iArea++) + for (size_t iArea = 0; iArea < mpWorld->NumAreas(); iArea++) { if (mpWorld->AreaResourceID(iArea) == rkID) { @@ -272,50 +279,50 @@ void CPackageDependencyListBuilder::AddDependency(CResourceEntry *pCurEntry, con void CPackageDependencyListBuilder::EvaluateDependencyNode(CResourceEntry *pCurEntry, IDependencyNode *pNode, std::list& rOut) { - if (!pNode) return; - EDependencyNodeType Type = pNode->Type(); + if (!pNode) + return; + + const EDependencyNodeType Type = pNode->Type(); bool ParseChildren = false; // Straight resource dependencies should just be added to the tree directly if (Type == EDependencyNodeType::Resource || Type == EDependencyNodeType::ScriptProperty || Type == EDependencyNodeType::CharacterProperty) { - CResourceDependency *pDep = static_cast(pNode); + const auto *pDep = static_cast(pNode); AddDependency(pCurEntry, pDep->ID(), rOut); } - // Anim events should be added if either they apply to characters, or their character index is used else if (Type == EDependencyNodeType::AnimEvent) { - CAnimEventDependency *pDep = static_cast(pNode); - uint32 CharIndex = pDep->CharIndex(); + const auto *pDep = static_cast(pNode); + const uint32 CharIndex = pDep->CharIndex(); - if (CharIndex == -1 || mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, CharIndex)) + if (CharIndex == UINT32_MAX || mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, CharIndex)) AddDependency(pCurEntry, pDep->ID(), rOut); } - // Set characters should only be added if their character index is used else if (Type == EDependencyNodeType::SetCharacter) { - CSetCharacterDependency *pChar = static_cast(pNode); + const auto *pChar = static_cast(pNode); ParseChildren = mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, pChar->CharSetIndex()) || mIsPlayerActor; } - // Set animations should only be added if they're being used by at least one used character else if (Type == EDependencyNodeType::SetAnimation) { - CSetAnimationDependency *pAnim = static_cast(pNode); + auto *pAnim = static_cast(pNode); ParseChildren = mCharacterUsageMap.IsAnimationUsed(mCurrentAnimSetID, pAnim) || (mIsPlayerActor && pAnim->IsUsedByAnyCharacter()); } - else + { ParseChildren = true; + } // Analyze this node's children if (ParseChildren) { if (Type == EDependencyNodeType::ScriptInstance) { - uint32 ObjType = static_cast(pNode)->ObjectType(); + const uint32 ObjType = static_cast(pNode)->ObjectType(); mIsPlayerActor = (ObjType == 0x4C || ObjType == FOURCC('PLAC')); } @@ -351,22 +358,22 @@ void CPackageDependencyListBuilder::FindUniversalAreaAssets() if (pUniverseWorld) { // Area IDs - for (uint32 AreaIdx = 0; AreaIdx < pUniverseWorld->NumAreas(); AreaIdx++) + for (size_t AreaIdx = 0; AreaIdx < pUniverseWorld->NumAreas(); AreaIdx++) { - CAssetID AreaID = pUniverseWorld->AreaResourceID(AreaIdx); + const CAssetID AreaID = pUniverseWorld->AreaResourceID(AreaIdx); if (AreaID.IsValid()) mUniversalAreaAssets.insert(AreaID); } // Map IDs - CDependencyGroup *pMapWorld = (CDependencyGroup*) pUniverseWorld->MapWorld(); + auto *pMapWorld = static_cast(pUniverseWorld->MapWorld()); if (pMapWorld) { - for (uint32 DepIdx = 0; DepIdx < pMapWorld->NumDependencies(); DepIdx++) + for (size_t DepIdx = 0; DepIdx < pMapWorld->NumDependencies(); DepIdx++) { - CAssetID DepID = pMapWorld->DependencyByIndex(DepIdx); + const CAssetID DepID = pMapWorld->DependencyByIndex(DepIdx); if (DepID.IsValid()) mUniversalAreaAssets.insert(DepID); @@ -515,43 +522,43 @@ void CAreaDependencyListBuilder::AddDependency(const CAssetID& rkID, std::list& rOut, std::set *pAudioGroupsOut) { - if (!pNode) return; - EDependencyNodeType Type = pNode->Type(); + if (!pNode) + return; + + const EDependencyNodeType Type = pNode->Type(); bool ParseChildren = false; if (Type == EDependencyNodeType::Resource || Type == EDependencyNodeType::ScriptProperty || Type == EDependencyNodeType::CharacterProperty) { - CResourceDependency *pDep = static_cast(pNode); + const auto* pDep = static_cast(pNode); AddDependency(pDep->ID(), rOut, pAudioGroupsOut); } - else if (Type == EDependencyNodeType::AnimEvent) { - CAnimEventDependency *pDep = static_cast(pNode); - uint32 CharIndex = pDep->CharIndex(); + const auto* pDep = static_cast(pNode); + const uint32 CharIndex = pDep->CharIndex(); - if (CharIndex == -1 || mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, CharIndex)) + if (CharIndex == UINT32_MAX || mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, CharIndex)) AddDependency(pDep->ID(), rOut, pAudioGroupsOut); } - else if (Type == EDependencyNodeType::SetCharacter) { // Note: For MP1/2 PlayerActor, always treat as if Empty Suit is the only used one const uint32 kEmptySuitIndex = (mGame >= EGame::EchoesDemo ? 3 : 5); - CSetCharacterDependency *pChar = static_cast(pNode); - uint32 SetIndex = pChar->CharSetIndex(); + const auto *pChar = static_cast(pNode); + const uint32 SetIndex = pChar->CharSetIndex(); ParseChildren = mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, pChar->CharSetIndex()) || (mIsPlayerActor && SetIndex == kEmptySuitIndex); } - else if (Type == EDependencyNodeType::SetAnimation) { - CSetAnimationDependency *pAnim = static_cast(pNode); + auto *pAnim = static_cast(pNode); ParseChildren = mCharacterUsageMap.IsAnimationUsed(mCurrentAnimSetID, pAnim) || (mIsPlayerActor && pAnim->IsUsedByAnyCharacter()); } - else + { ParseChildren = true; + } if (ParseChildren) { @@ -598,39 +605,39 @@ void CAssetDependencyListBuilder::AddDependency(const CAssetID& kID, std::vector void CAssetDependencyListBuilder::EvaluateDependencyNode(CResourceEntry* pCurEntry, IDependencyNode* pNode, std::vector& Out) { - if (!pNode) return; - EDependencyNodeType Type = pNode->Type(); + if (!pNode) + return; + + const EDependencyNodeType Type = pNode->Type(); bool ParseChildren = false; if (Type == EDependencyNodeType::Resource || Type == EDependencyNodeType::ScriptProperty || Type == EDependencyNodeType::CharacterProperty) { - CResourceDependency* pDep = static_cast(pNode); + const auto* pDep = static_cast(pNode); AddDependency(pDep->ID(), Out); } - else if (Type == EDependencyNodeType::AnimEvent) { - CAnimEventDependency* pDep = static_cast(pNode); - uint32 CharIndex = pDep->CharIndex(); + const auto* pDep = static_cast(pNode); + const uint32 CharIndex = pDep->CharIndex(); - if (CharIndex == -1 || mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, CharIndex)) + if (CharIndex == UINT32_MAX || mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, CharIndex)) AddDependency(pDep->ID(), Out); } - else if (Type == EDependencyNodeType::SetCharacter) { - CSetCharacterDependency* pChar = static_cast(pNode); + const auto* pChar = static_cast(pNode); ParseChildren = mCharacterUsageMap.IsCharacterUsed(mCurrentAnimSetID, pChar->CharSetIndex()); } - else if (Type == EDependencyNodeType::SetAnimation) { - CSetAnimationDependency* pAnim = static_cast(pNode); + auto* pAnim = static_cast(pNode); ParseChildren = mCharacterUsageMap.IsAnimationUsed(mCurrentAnimSetID, pAnim); } - else + { ParseChildren = true; + } if (ParseChildren) { diff --git a/src/Core/GameProject/DependencyListBuilders.h b/src/Core/GameProject/DependencyListBuilders.h index 6176dbfc..5aa8976d 100644 --- a/src/Core/GameProject/DependencyListBuilders.h +++ b/src/Core/GameProject/DependencyListBuilders.h @@ -22,11 +22,11 @@ public: : mpStore(pStore) {} - bool IsCharacterUsed(const CAssetID& rkID, uint32 CharacterIndex) const; + bool IsCharacterUsed(const CAssetID& rkID, size_t CharacterIndex) const; bool IsAnimationUsed(const CAssetID& rkID, CSetAnimationDependency *pAnim) const; void FindUsagesForAsset(CResourceEntry *pEntry); void FindUsagesForArea(CWorld *pWorld, CResourceEntry *pEntry); - void FindUsagesForArea(CWorld *pWorld, uint32 AreaIndex); + void FindUsagesForArea(CWorld *pWorld, size_t AreaIndex); void FindUsagesForLayer(CResourceEntry *pAreaEntry, uint32 LayerIndex); void Clear(); void DebugPrintContents(); diff --git a/src/Core/Resource/CDependencyGroup.h b/src/Core/Resource/CDependencyGroup.h index 4de0e5e2..130ab744 100644 --- a/src/Core/Resource/CDependencyGroup.h +++ b/src/Core/Resource/CDependencyGroup.h @@ -13,7 +13,7 @@ public: void Clear() { mDependencies.clear(); } uint32 NumDependencies() const { return mDependencies.size(); } - CAssetID DependencyByIndex(uint32 Index) const { return mDependencies[Index]; } + CAssetID DependencyByIndex(size_t Index) const { return mDependencies[Index]; } void AddDependency(const CAssetID& rkID) { diff --git a/src/Core/Resource/CWorld.h b/src/Core/Resource/CWorld.h index 46baf489..f175cc89 100644 --- a/src/Core/Resource/CWorld.h +++ b/src/Core/Resource/CWorld.h @@ -115,16 +115,16 @@ public: CModel* DefaultSkybox() const { return mpDefaultSkybox; } CResource* MapWorld() const { return mpMapWorld; } - uint32 NumAreas() const { return mAreas.size(); } - CAssetID AreaResourceID(uint32 AreaIndex) const { return mAreas[AreaIndex].AreaResID; } - uint32 AreaAttachedCount(uint32 AreaIndex) const { return mAreas[AreaIndex].AttachedAreaIDs.size(); } - uint32 AreaAttachedID(uint32 AreaIndex, uint32 AttachedIndex) const { return mAreas[AreaIndex].AttachedAreaIDs[AttachedIndex]; } - TString AreaInternalName(uint32 AreaIndex) const { return mAreas[AreaIndex].InternalName; } - CStringTable* AreaName(uint32 AreaIndex) const { return mAreas[AreaIndex].pAreaName; } - bool DoesAreaAllowPakDuplicates(uint32 AreaIndex) const { return mAreas[AreaIndex].AllowPakDuplicates; } + size_t NumAreas() const { return mAreas.size(); } + CAssetID AreaResourceID(size_t AreaIndex) const { return mAreas[AreaIndex].AreaResID; } + uint32 AreaAttachedCount(size_t AreaIndex) const { return mAreas[AreaIndex].AttachedAreaIDs.size(); } + uint32 AreaAttachedID(size_t AreaIndex, size_t AttachedIndex) const { return mAreas[AreaIndex].AttachedAreaIDs[AttachedIndex]; } + TString AreaInternalName(size_t AreaIndex) const { return mAreas[AreaIndex].InternalName; } + CStringTable* AreaName(size_t AreaIndex) const { return mAreas[AreaIndex].pAreaName; } + bool DoesAreaAllowPakDuplicates(size_t AreaIndex) const { return mAreas[AreaIndex].AllowPakDuplicates; } void SetName(TString rkName) { mName = std::move(rkName); } - void SetAreaAllowsPakDuplicates(uint32 AreaIndex, bool Allow) { mAreas[AreaIndex].AllowPakDuplicates = Allow; } + void SetAreaAllowsPakDuplicates(size_t AreaIndex, bool Allow) { mAreas[AreaIndex].AllowPakDuplicates = Allow; } }; #endif // CWORLD_H diff --git a/src/Core/Resource/Factory/CUnsupportedFormatLoader.cpp b/src/Core/Resource/Factory/CUnsupportedFormatLoader.cpp index 53b071e0..844faecf 100644 --- a/src/Core/Resource/Factory/CUnsupportedFormatLoader.cpp +++ b/src/Core/Resource/Factory/CUnsupportedFormatLoader.cpp @@ -434,13 +434,13 @@ std::unique_ptr CUnsupportedFormatLoader::LoadMAPA(IInputStream& /*rMA // Find a MapWorld that contains this MapArea CAssetID MapWorldID; - uint32 WorldIndex = -1; + size_t WorldIndex = SIZE_MAX; for (TResourceIterator It; It; ++It) { CDependencyGroup *pGroup = (CDependencyGroup*) It->Load(); - for (uint32 AreaIdx = 0; AreaIdx < pGroup->NumDependencies(); AreaIdx++) + for (size_t AreaIdx = 0; AreaIdx < pGroup->NumDependencies(); AreaIdx++) { if (pGroup->DependencyByIndex(AreaIdx) == MapAreaID) { @@ -450,12 +450,12 @@ std::unique_ptr CUnsupportedFormatLoader::LoadMAPA(IInputStream& /*rMA } } - if (WorldIndex != -1) + if (WorldIndex != SIZE_MAX) break; } // Find a world that contains this MapWorld - if (WorldIndex != -1) + if (WorldIndex != SIZE_MAX) { for (TResourceIterator It; It; ++It) { diff --git a/src/Core/Resource/Factory/CWorldLoader.cpp b/src/Core/Resource/Factory/CWorldLoader.cpp index f1278b57..27771abf 100644 --- a/src/Core/Resource/Factory/CWorldLoader.cpp +++ b/src/Core/Resource/Factory/CWorldLoader.cpp @@ -263,16 +263,16 @@ void CWorldLoader::LoadReturnsMLVL(IInputStream& rMLVL) void CWorldLoader::GenerateEditorData() { - CGameInfo *pGameInfo = mpWorld->Entry()->ResourceStore()->Project()->GameInfo(); + const CGameInfo *pGameInfo = mpWorld->Entry()->ResourceStore()->Project()->GameInfo(); - if (mVersion <= EGame::Prime) + if (mVersion > EGame::Prime) + return; + + for (size_t iArea = 0; iArea < mpWorld->NumAreas(); iArea++) { - for (uint32 iArea = 0; iArea < mpWorld->NumAreas(); iArea++) - { - CWorld::SArea& rArea = mpWorld->mAreas[iArea]; - rArea.InternalName = pGameInfo->GetAreaName(rArea.AreaResID); - ASSERT(!rArea.InternalName.IsEmpty()); - } + CWorld::SArea& rArea = mpWorld->mAreas[iArea]; + rArea.InternalName = pGameInfo->GetAreaName(rArea.AreaResID); + ASSERT(!rArea.InternalName.IsEmpty()); } } diff --git a/src/Editor/WorldEditor/CWorldInfoSidebar.cpp b/src/Editor/WorldEditor/CWorldInfoSidebar.cpp index 22bbc39f..76fe14bf 100644 --- a/src/Editor/WorldEditor/CWorldInfoSidebar.cpp +++ b/src/Editor/WorldEditor/CWorldInfoSidebar.cpp @@ -128,10 +128,10 @@ void CWorldInfoSidebar::OnWorldTreeClicked(QModelIndex Index) mpUI->AttachedAreasList->clear(); - for (uint32 iAtt = 0; iAtt < pWorld->AreaAttachedCount(AreaIndex); iAtt++) + for (size_t iAtt = 0; iAtt < pWorld->AreaAttachedCount(AreaIndex); iAtt++) { - uint32 AttachedIdx = pWorld->AreaAttachedID(AreaIndex, iAtt); - QString Name = TO_QSTRING( pWorld->AreaInGameName(AttachedIdx) ); + const uint32 AttachedIdx = pWorld->AreaAttachedID(AreaIndex, iAtt); + const QString Name = TO_QSTRING(pWorld->AreaInGameName(AttachedIdx)); mpUI->AttachedAreasList->addItem(Name); } } diff --git a/src/Editor/WorldEditor/CWorldTreeModel.cpp b/src/Editor/WorldEditor/CWorldTreeModel.cpp index 4f2c3140..45ad3243 100644 --- a/src/Editor/WorldEditor/CWorldTreeModel.cpp +++ b/src/Editor/WorldEditor/CWorldTreeModel.cpp @@ -241,7 +241,7 @@ void CWorldTreeModel::OnProjectChanged(CGameProject *pProj) Info.pWorld = pWorld; // Add areas - for (uint32 iArea = 0; iArea < pWorld->NumAreas(); iArea++) + for (size_t iArea = 0; iArea < pWorld->NumAreas(); iArea++) { CAssetID AreaID = pWorld->AreaResourceID(iArea); CResourceEntry *pAreaEntry = pWorld->Entry()->ResourceStore()->FindEntry(AreaID);