Skip to content

Commit

Permalink
Try to sort objects in all pages before export
Browse files Browse the repository at this point in the history
Co-Authored-By: Adam Johnson <[email protected]>
  • Loading branch information
dpogue and Hoikas committed Sep 6, 2023
1 parent 140fe92 commit 3acfabb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions Sources/Tools/MaxMain/plPluginResManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -387,6 +399,9 @@ class plWritePageIterator : public plRegistryPageIterator

void plPluginResManager::WriteAllPages()
{
plObjectIDSortingPageIterator idSort;
IteratePages(&idSort);

plWritePageIterator iter;
IteratePages(&iter);
}
Expand Down

0 comments on commit 3acfabb

Please sign in to comment.