DependencyListBuilders: Make use of ranged for where applicable
This commit is contained in:
parent
a0ec0d938f
commit
24bfee8528
|
@ -19,8 +19,10 @@ bool CCharacterUsageMap::IsCharacterUsed(const CAssetID& rkID, size_t CharacterI
|
||||||
|
|
||||||
bool CCharacterUsageMap::IsAnimationUsed(const CAssetID& rkID, CSetAnimationDependency *pAnim) const
|
bool CCharacterUsageMap::IsAnimationUsed(const CAssetID& rkID, CSetAnimationDependency *pAnim) const
|
||||||
{
|
{
|
||||||
auto Find = mUsageMap.find(rkID);
|
const auto Find = mUsageMap.find(rkID);
|
||||||
if (Find == mUsageMap.end()) return false;
|
if (Find == mUsageMap.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
const std::vector<bool>& rkUsageList = Find->second;
|
const std::vector<bool>& rkUsageList = Find->second;
|
||||||
|
|
||||||
for (uint32 iChar = 0; iChar < rkUsageList.size(); iChar++)
|
for (uint32 iChar = 0; iChar < rkUsageList.size(); iChar++)
|
||||||
|
@ -82,9 +84,9 @@ void CCharacterUsageMap::FindUsagesForLayer(CResourceEntry *pAreaEntry, uint32 L
|
||||||
ASSERT(pTree->Type() == EDependencyNodeType::Area);
|
ASSERT(pTree->Type() == EDependencyNodeType::Area);
|
||||||
|
|
||||||
// Only examine dependencies of the particular layer specified by the caller
|
// Only examine dependencies of the particular layer specified by the caller
|
||||||
bool IsLastLayer = (mLayerIndex == pTree->NumScriptLayers() - 1);
|
const bool IsLastLayer = mLayerIndex == pTree->NumScriptLayers() - 1;
|
||||||
uint32 StartIdx = pTree->ScriptLayerOffset(mLayerIndex);
|
const uint32 StartIdx = pTree->ScriptLayerOffset(mLayerIndex);
|
||||||
uint32 EndIdx = (IsLastLayer ? pTree->NumChildren() : pTree->ScriptLayerOffset(mLayerIndex + 1));
|
const uint32 EndIdx = IsLastLayer ? pTree->NumChildren() : pTree->ScriptLayerOffset(mLayerIndex + 1);
|
||||||
|
|
||||||
for (uint32 iInst = StartIdx; iInst < EndIdx; iInst++)
|
for (uint32 iInst = StartIdx; iInst < EndIdx; iInst++)
|
||||||
ParseDependencyNode(pTree->ChildByIndex(iInst));
|
ParseDependencyNode(pTree->ChildByIndex(iInst));
|
||||||
|
@ -94,7 +96,7 @@ void CCharacterUsageMap::Clear()
|
||||||
{
|
{
|
||||||
mUsageMap.clear();
|
mUsageMap.clear();
|
||||||
mStillLookingIDs.clear();
|
mStillLookingIDs.clear();
|
||||||
mLayerIndex = -1;
|
mLayerIndex = UINT32_MAX;
|
||||||
mIsInitialArea = true;
|
mIsInitialArea = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,16 +104,14 @@ void CCharacterUsageMap::Clear()
|
||||||
|
|
||||||
void CCharacterUsageMap::DebugPrintContents()
|
void CCharacterUsageMap::DebugPrintContents()
|
||||||
{
|
{
|
||||||
for (auto Iter = mUsageMap.begin(); Iter != mUsageMap.end(); Iter++)
|
for (auto& [ID, usedList] : mUsageMap)
|
||||||
{
|
{
|
||||||
CAssetID ID = Iter->first;
|
const CAnimSet *pSet = mpStore->LoadResource<CAnimSet>(ID);
|
||||||
std::vector<bool>& rUsedList = Iter->second;
|
|
||||||
CAnimSet *pSet = mpStore->LoadResource<CAnimSet>(ID);
|
|
||||||
|
|
||||||
for (uint32 iChar = 0; iChar < pSet->NumCharacters(); iChar++)
|
for (uint32 iChar = 0; iChar < pSet->NumCharacters(); iChar++)
|
||||||
{
|
{
|
||||||
bool Used = (rUsedList.size() > iChar && rUsedList[iChar]);
|
const bool Used = usedList.size() > iChar && usedList[iChar];
|
||||||
TString CharName = pSet->Character(iChar)->Name;
|
const TString CharName = pSet->Character(iChar)->Name;
|
||||||
debugf("%s : Char %d : %s : %s", *ID.ToString(), iChar, *CharName, (Used ? "USED" : "UNUSED"));
|
debugf("%s : Char %d : %s : %s", *ID.ToString(), iChar, *CharName, (Used ? "USED" : "UNUSED"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,57 +120,57 @@ void CCharacterUsageMap::DebugPrintContents()
|
||||||
// ************ PROTECTED ************
|
// ************ PROTECTED ************
|
||||||
void CCharacterUsageMap::ParseDependencyNode(IDependencyNode *pNode)
|
void CCharacterUsageMap::ParseDependencyNode(IDependencyNode *pNode)
|
||||||
{
|
{
|
||||||
if (!pNode) return;
|
if (!pNode)
|
||||||
EDependencyNodeType Type = pNode->Type();
|
return;
|
||||||
|
|
||||||
|
const EDependencyNodeType Type = pNode->Type();
|
||||||
|
|
||||||
if (Type == EDependencyNodeType::CharacterProperty)
|
if (Type == EDependencyNodeType::CharacterProperty)
|
||||||
{
|
{
|
||||||
CCharPropertyDependency *pDep = static_cast<CCharPropertyDependency*>(pNode);
|
auto *pDep = static_cast<CCharPropertyDependency*>(pNode);
|
||||||
CAssetID ResID = pDep->ID();
|
const CAssetID ResID = pDep->ID();
|
||||||
auto Find = mUsageMap.find(ResID);
|
const auto Find = mUsageMap.find(ResID);
|
||||||
|
|
||||||
if (!mIsInitialArea && mStillLookingIDs.find(ResID) == mStillLookingIDs.end())
|
if (!mIsInitialArea && mStillLookingIDs.find(ResID) == mStillLookingIDs.cend())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Find != mUsageMap.end())
|
if (Find != mUsageMap.cend())
|
||||||
{
|
{
|
||||||
if (!mIsInitialArea && mCurrentAreaAllowsDupes)
|
if (!mIsInitialArea && mCurrentAreaAllowsDupes)
|
||||||
{
|
{
|
||||||
mStillLookingIDs.erase( mStillLookingIDs.find(ResID) );
|
mStillLookingIDs.erase(mStillLookingIDs.find(ResID));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!mIsInitialArea) return;
|
if (!mIsInitialArea)
|
||||||
mUsageMap[ResID] = std::vector<bool>();
|
return;
|
||||||
|
|
||||||
|
mUsageMap.insert_or_assign(ResID, std::vector<bool>());
|
||||||
mStillLookingIDs.insert(ResID);
|
mStillLookingIDs.insert(ResID);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<bool>& rUsageList = mUsageMap[ResID];
|
std::vector<bool>& rUsageList = mUsageMap[ResID];
|
||||||
uint32 UsedChar = pDep->UsedChar();
|
const uint32 UsedChar = pDep->UsedChar();
|
||||||
|
|
||||||
if (rUsageList.size() <= UsedChar)
|
if (rUsageList.size() <= UsedChar)
|
||||||
rUsageList.resize(UsedChar + 1, false);
|
rUsageList.resize(UsedChar + 1, false);
|
||||||
|
|
||||||
rUsageList[UsedChar] = true;
|
rUsageList[UsedChar] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse dependencies of the referenced resource if it's a type that can reference animsets
|
// Parse dependencies of the referenced resource if it's a type that can reference animsets
|
||||||
else if (Type == EDependencyNodeType::Resource || Type == EDependencyNodeType::ScriptProperty)
|
else if (Type == EDependencyNodeType::Resource || Type == EDependencyNodeType::ScriptProperty)
|
||||||
{
|
{
|
||||||
CResourceDependency *pDep = static_cast<CResourceDependency*>(pNode);
|
auto* pDep = static_cast<CResourceDependency*>(pNode);
|
||||||
CResourceEntry *pEntry = mpStore->FindEntry(pDep->ID());
|
CResourceEntry* pEntry = mpStore->FindEntry(pDep->ID());
|
||||||
|
|
||||||
if (pEntry && pEntry->ResourceType() == EResourceType::Scan)
|
if (pEntry && pEntry->ResourceType() == EResourceType::Scan)
|
||||||
{
|
{
|
||||||
ParseDependencyNode(pEntry->Dependencies());
|
ParseDependencyNode(pEntry->Dependencies());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else // Look for sub-dependencies of the current node
|
||||||
// Look for sub-dependencies of the current node
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
for (uint32 iChild = 0; iChild < pNode->NumChildren(); iChild++)
|
for (uint32 iChild = 0; iChild < pNode->NumChildren(); iChild++)
|
||||||
ParseDependencyNode(pNode->ChildByIndex(iChild));
|
ParseDependencyNode(pNode->ChildByIndex(iChild));
|
||||||
|
@ -216,9 +216,12 @@ void CPackageDependencyListBuilder::BuildDependencyList(bool AllowDuplicates, st
|
||||||
|
|
||||||
void CPackageDependencyListBuilder::AddDependency(CResourceEntry *pCurEntry, const CAssetID& rkID, std::list<CAssetID>& rOut)
|
void CPackageDependencyListBuilder::AddDependency(CResourceEntry *pCurEntry, const CAssetID& rkID, std::list<CAssetID>& rOut)
|
||||||
{
|
{
|
||||||
if (pCurEntry && pCurEntry->ResourceType() == EResourceType::DependencyGroup) return;
|
if (pCurEntry && pCurEntry->ResourceType() == EResourceType::DependencyGroup)
|
||||||
|
return;
|
||||||
|
|
||||||
CResourceEntry *pEntry = mpStore->FindEntry(rkID);
|
CResourceEntry *pEntry = mpStore->FindEntry(rkID);
|
||||||
if (!pEntry) return;
|
if (!pEntry)
|
||||||
|
return;
|
||||||
|
|
||||||
EResourceType ResType = pEntry->ResourceType();
|
EResourceType ResType = pEntry->ResourceType();
|
||||||
|
|
||||||
|
@ -228,13 +231,16 @@ void CPackageDependencyListBuilder::AddDependency(CResourceEntry *pCurEntry, con
|
||||||
(ResType != EResourceType::World || !pCurEntry) &&
|
(ResType != EResourceType::World || !pCurEntry) &&
|
||||||
(ResType != EResourceType::Area || !pCurEntry || pCurEntry->ResourceType() == EResourceType::World);
|
(ResType != EResourceType::Area || !pCurEntry || pCurEntry->ResourceType() == EResourceType::World);
|
||||||
|
|
||||||
if (!IsValid) return;
|
if (!IsValid)
|
||||||
|
|
||||||
if ( ( mCurrentAreaHasDuplicates && mAreaUsedAssets.find(rkID) != mAreaUsedAssets.end()) ||
|
|
||||||
(!mCurrentAreaHasDuplicates && mPackageUsedAssets.find(rkID) != mPackageUsedAssets.end()) ||
|
|
||||||
(!mIsUniversalAreaAsset && mUniversalAreaAssets.find(rkID) != mUniversalAreaAssets.end() ) )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if ((mCurrentAreaHasDuplicates && mAreaUsedAssets.find(rkID) != mAreaUsedAssets.end()) ||
|
||||||
|
(!mCurrentAreaHasDuplicates && mPackageUsedAssets.find(rkID) != mPackageUsedAssets.end()) ||
|
||||||
|
(!mIsUniversalAreaAsset && mUniversalAreaAssets.find(rkID) != mUniversalAreaAssets.end()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Entry is valid, parse its sub-dependencies
|
// Entry is valid, parse its sub-dependencies
|
||||||
mPackageUsedAssets.insert(rkID);
|
mPackageUsedAssets.insert(rkID);
|
||||||
mAreaUsedAssets.insert(rkID);
|
mAreaUsedAssets.insert(rkID);
|
||||||
|
@ -260,10 +266,11 @@ void CPackageDependencyListBuilder::AddDependency(CResourceEntry *pCurEntry, con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animset - keep track of the current animset ID
|
// Animset - keep track of the current animset ID
|
||||||
else if (ResType == EResourceType::AnimSet)
|
else if (ResType == EResourceType::AnimSet)
|
||||||
|
{
|
||||||
mCurrentAnimSetID = rkID;
|
mCurrentAnimSetID = rkID;
|
||||||
|
}
|
||||||
|
|
||||||
// Evaluate dependencies of this entry
|
// Evaluate dependencies of this entry
|
||||||
CDependencyTree *pTree = pEntry->Dependencies();
|
CDependencyTree *pTree = pEntry->Dependencies();
|
||||||
|
@ -273,7 +280,6 @@ void CPackageDependencyListBuilder::AddDependency(CResourceEntry *pCurEntry, con
|
||||||
// Revert current animset ID
|
// Revert current animset ID
|
||||||
if (ResType == EResourceType::AnimSet)
|
if (ResType == EResourceType::AnimSet)
|
||||||
mCurrentAnimSetID = CAssetID::InvalidID(mGame);
|
mCurrentAnimSetID = CAssetID::InvalidID(mGame);
|
||||||
|
|
||||||
// Revert duplicate flag
|
// Revert duplicate flag
|
||||||
else if (ResType == EResourceType::Area)
|
else if (ResType == EResourceType::Area)
|
||||||
mCurrentAreaHasDuplicates = false;
|
mCurrentAreaHasDuplicates = false;
|
||||||
|
@ -420,28 +426,30 @@ void CAreaDependencyListBuilder::BuildDependencyList(std::list<CAssetID>& rAsset
|
||||||
|
|
||||||
if (pNode->Type() == EDependencyNodeType::ScriptInstance)
|
if (pNode->Type() == EDependencyNodeType::ScriptInstance)
|
||||||
{
|
{
|
||||||
CScriptInstanceDependency *pInst = static_cast<CScriptInstanceDependency*>(pNode);
|
auto* pInst = static_cast<CScriptInstanceDependency*>(pNode);
|
||||||
mIsPlayerActor = (pInst->ObjectType() == 0x4C || pInst->ObjectType() == FOURCC('PLAC'));
|
mIsPlayerActor = (pInst->ObjectType() == 0x4C || pInst->ObjectType() == FOURCC('PLAC'));
|
||||||
|
|
||||||
for (uint32 iDep = 0; iDep < pInst->NumChildren(); iDep++)
|
for (uint32 iDep = 0; iDep < pInst->NumChildren(); iDep++)
|
||||||
{
|
{
|
||||||
CPropertyDependency *pDep = static_cast<CPropertyDependency*>(pInst->ChildByIndex(iDep));
|
auto* pDep = static_cast<CPropertyDependency*>(pInst->ChildByIndex(iDep));
|
||||||
|
|
||||||
// For MP3, exclude the CMDL/CSKR properties for the suit assets - only include default character assets
|
// For MP3, exclude the CMDL/CSKR properties for the suit assets - only include default character assets
|
||||||
if (mGame == EGame::Corruption && mIsPlayerActor)
|
if (mGame == EGame::Corruption && mIsPlayerActor)
|
||||||
{
|
{
|
||||||
TString PropID = pDep->PropertyID();
|
TString PropID = pDep->PropertyID();
|
||||||
|
|
||||||
if ( PropID == "0x846397A8" || PropID == "0x685A4C01" ||
|
if (PropID == "0x846397A8" || PropID == "0x685A4C01" ||
|
||||||
PropID == "0x9834ECC9" || PropID == "0x188B8960" ||
|
PropID == "0x9834ECC9" || PropID == "0x188B8960" ||
|
||||||
PropID == "0x134A81E3" || PropID == "0x4ABF030C" ||
|
PropID == "0x134A81E3" || PropID == "0x4ABF030C" ||
|
||||||
PropID == "0x9BF030DC" || PropID == "0x981263D3" ||
|
PropID == "0x9BF030DC" || PropID == "0x981263D3" ||
|
||||||
PropID == "0x8A8D5AA5" || PropID == "0xE4734608" ||
|
PropID == "0x8A8D5AA5" || PropID == "0xE4734608" ||
|
||||||
PropID == "0x3376814D" || PropID == "0x797CA77E" ||
|
PropID == "0x3376814D" || PropID == "0x797CA77E" ||
|
||||||
PropID == "0x0EBEC440" || PropID == "0xBC0952D8" ||
|
PropID == "0x0EBEC440" || PropID == "0xBC0952D8" ||
|
||||||
PropID == "0xA8778E57" || PropID == "0x1CB10DBE" )
|
PropID == "0xA8778E57" || PropID == "0x1CB10DBE")
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AddDependency(pDep->ID(), rAssetsOut, pAudioGroupsOut);
|
AddDependency(pDep->ID(), rAssetsOut, pAudioGroupsOut);
|
||||||
}
|
}
|
||||||
|
@ -473,9 +481,10 @@ void CAreaDependencyListBuilder::BuildDependencyList(std::list<CAssetID>& rAsset
|
||||||
void CAreaDependencyListBuilder::AddDependency(const CAssetID& rkID, std::list<CAssetID>& rOut, std::set<CAssetID> *pAudioGroupsOut)
|
void CAreaDependencyListBuilder::AddDependency(const CAssetID& rkID, std::list<CAssetID>& rOut, std::set<CAssetID> *pAudioGroupsOut)
|
||||||
{
|
{
|
||||||
CResourceEntry *pEntry = mpStore->FindEntry(rkID);
|
CResourceEntry *pEntry = mpStore->FindEntry(rkID);
|
||||||
if (!pEntry) return;
|
if (!pEntry)
|
||||||
|
return;
|
||||||
|
|
||||||
EResourceType ResType = pEntry->ResourceType();
|
const EResourceType ResType = pEntry->ResourceType();
|
||||||
|
|
||||||
// If this is an audio group, for MP1, save it in the output set. For MP2, treat audio groups as a normal dependency.
|
// If this is an audio group, for MP1, save it in the output set. For MP2, treat audio groups as a normal dependency.
|
||||||
if (mGame <= EGame::Prime && ResType == EResourceType::AudioGroup)
|
if (mGame <= EGame::Prime && ResType == EResourceType::AudioGroup)
|
||||||
|
@ -579,11 +588,12 @@ void CAssetDependencyListBuilder::BuildDependencyList(std::vector<CAssetID>& Out
|
||||||
void CAssetDependencyListBuilder::AddDependency(const CAssetID& kID, std::vector<CAssetID>& Out)
|
void CAssetDependencyListBuilder::AddDependency(const CAssetID& kID, std::vector<CAssetID>& Out)
|
||||||
{
|
{
|
||||||
CResourceEntry *pEntry = mpResourceEntry->ResourceStore()->FindEntry(kID);
|
CResourceEntry *pEntry = mpResourceEntry->ResourceStore()->FindEntry(kID);
|
||||||
if (!pEntry) return;
|
if (!pEntry)
|
||||||
|
return;
|
||||||
|
|
||||||
EResourceType ResType = pEntry->ResourceType();
|
const EResourceType ResType = pEntry->ResourceType();
|
||||||
|
|
||||||
if (mUsedAssets.find(kID) != mUsedAssets.end())
|
if (mUsedAssets.find(kID) != mUsedAssets.cend())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Dependency is valid! Evaluate the node tree
|
// Dependency is valid! Evaluate the node tree
|
||||||
|
|
Loading…
Reference in New Issue