Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign sequential object IDs at Max export time #1425

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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