Skip to content

Commit

Permalink
Merge pull request #1425 from dpogue/keyring-ordering
Browse files Browse the repository at this point in the history
Assign sequential object IDs at Max export time
  • Loading branch information
Hoikas authored Sep 6, 2023
2 parents 4285442 + 3acfabb commit dc4df39
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/Plasma/PubUtilLib/plResMgr/plRegistryKeyList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ bool plRegistryKeyList::SetKeyUnused(plKeyImp* key, LoadStatus& loadStatusChange
return foundKey != nullptr;
}

void plRegistryKeyList::PrepForWrite()
{
uint32_t objectID = 1;
for (plKeyImp* key : fKeys) {
if (key->ObjectIsLoaded()) {
key->SetObjectID(objectID++);
}
}
}

void plRegistryKeyList::Read(hsStream* s)
{
uint32_t keyListLen = s->ReadLE32();
Expand Down
4 changes: 4 additions & 0 deletions Sources/Plasma/PubUtilLib/plResMgr/plRegistryKeyList.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class plRegistryKeyList
void SetKeyUsed(plKeyImp* key) { ++fReffedKeys; }
bool SetKeyUnused(plKeyImp* key, LoadStatus& loadStatusChange);

// 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();

void Read(hsStream* s);
void Write(hsStream* s);
};
Expand Down
9 changes: 9 additions & 0 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
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 dc4df39

Please sign in to comment.