diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp index f4fd2cfec1..1ff9f75795 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp @@ -204,6 +204,15 @@ void plRegistryPageNode::UnloadKeys() fLoadedTypes = 0; } +void plRegistryPageNode::PrepForWrite() +{ + if (!fIsNewPage) + return; + + for (auto [idx, keyList] : fKeyLists) + keyList->PrepForWrite(); +} + //// plWriteIterator ///////////////////////////////////////////////////////// // Key iterator for writing objects class plWriteIterator : public plRegistryKeyIterator @@ -241,9 +250,6 @@ void plRegistryPageNode::Write() for (it = fKeyLists.begin(); it != fKeyLists.end(); it++) { plRegistryKeyList* keyList = it->second; - if (fIsNewPage) - keyList->PrepForWrite(); - int ver = plVersion::GetCreatableVersion(keyList->GetClassType()); fPageInfo.AddClassVersion(keyList->GetClassType(), ver); } diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h index de466b37ed..39acf7433a 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h +++ b/Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h @@ -139,6 +139,10 @@ class plRegistryPageNode hsStream* OpenStream(); void CloseStream(); + // Export time only. Before we write to disk, assign all the loaded keys + // sequential object IDs that they can use to do fast lookups at load time. + void PrepForWrite(); + // Takes care of everything involved in writing this page to disk void Write(); void DeleteSource(); diff --git a/Sources/Tools/MaxMain/plPluginResManager.cpp b/Sources/Tools/MaxMain/plPluginResManager.cpp index 06eaf680d1..3693c02726 100644 --- a/Sources/Tools/MaxMain/plPluginResManager.cpp +++ b/Sources/Tools/MaxMain/plPluginResManager.cpp @@ -373,6 +373,18 @@ plLocation plPluginResManager::ICreateLocation(const ST::string& age, const ST:: return newLoc; } +class plObjectIDSortingPageIterator : public plRegistryPageIterator +{ +public: + plObjectIDSortingPageIterator() {} + bool EatPage(plRegistryPageNode *page) override + { + if (page->GetPageInfo().GetLocation() != plLocation::kGlobalFixedLoc) + page->PrepForWrite(); + return true; + } +}; + class plWritePageIterator : public plRegistryPageIterator { public: @@ -387,6 +399,9 @@ class plWritePageIterator : public plRegistryPageIterator void plPluginResManager::WriteAllPages() { + plObjectIDSortingPageIterator idSort; + IteratePages(&idSort); + plWritePageIterator iter; IteratePages(&iter); }