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

Really preserve ObjIDs. #280

Merged
merged 3 commits into from
Oct 19, 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
4 changes: 3 additions & 1 deletion Python/PyHSPlasma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4654,7 +4654,9 @@ class plRenderTarget(plBitmap):
width: int = ...

class plResManager:
def __init__(self, version: int = pvUnknown) -> None: ...
preserveObjIDs: bool = ...

def __init__(self, version: int = pvUnknown, preserveObjIDs: bool = False) -> None: ...
def AddAge(self, age: plAgeInfo) -> None: ...
def AddObject(self, location: plLocation, object: hsKeyedObject) -> None: ...
def AddPage(self, page: plPageInfo) -> None: ...
Expand Down
14 changes: 13 additions & 1 deletion Python/ResManager/pyResManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ PY_PLASMA_DEALLOC(ResManager)

PY_PLASMA_INIT_DECL(ResManager)
{
char* kwdlist[] = { "version", "preserveObjIDs", nullptr };

int version = PlasmaVer::pvUnknown;
if (!PyArg_ParseTuple(args, "|i", &version))
bool preserveObjIDs = false;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ib", kwdlist, &version, &preserveObjIDs))
return -1;

self->fThis->setVer((PlasmaVer)version);
self->fThis->setPreserveObjIDs(preserveObjIDs);
return 0;
}

Expand Down Expand Up @@ -654,6 +658,13 @@ static PyMethodDef pyResManager_Methods[] = {
PY_METHOD_TERMINATOR
};

PY_PROPERTY(bool, ResManager, preserveObjIDs, getPreserveObjIDs, setPreserveObjIDs)

static PyGetSetDef pyResManager_GetSet[] = {
pyResManager_preserveObjIDs_getset,
PY_GETSET_TERMINATOR
};

PY_PLASMA_TYPE(ResManager, plResManager, "Resource Manager")

PY_PLASMA_TYPE_INIT(ResManager)
Expand All @@ -662,6 +673,7 @@ PY_PLASMA_TYPE_INIT(ResManager)
pyResManager_Type.tp_init = pyResManager___init__;
pyResManager_Type.tp_new = pyResManager_new;
pyResManager_Type.tp_methods = pyResManager_Methods;
pyResManager_Type.tp_getset = pyResManager_GetSet;
if (PyType_CheckAndReady(&pyResManager_Type) < 0)
return nullptr;

Expand Down
6 changes: 5 additions & 1 deletion core/ResManager/plResManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ plKey plResManager::readUoid(hsStream* S)
k->readUoid(S);
if (!k->getLocation().isValid())
return plKey();
return AddKey(k);

plKey newkey = AddKey(k);
if (preserveIDs)
newkey->setID(k->getID());
return newkey;
}

void plResManager::writeKey(hsStream* S, const plKey& key)
Expand Down
18 changes: 18 additions & 0 deletions core/ResManager/plResManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ class HSPLASMA_EXPORT plResManager
*/
void setVer(PlasmaVer pv, bool force = false);

/**
* Set whether or not keyed object IDs should be preserved from
* PRPs that are read in. By default, key IDs are reordered to be
* consecutive when a PRP is read. This setting doesn't have any
* effect on data already loaded.
* \param preserve Preserve keyed object IDs
* \sa getPreserveObjIDs()
*/
void setPreserveObjIDs(bool preserve) { preserveIDs = preserve; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the original reason I didn't expose this except in the constructor was to ensure we couldn't end up in a situation where we had files open with both preserved key IDs and resequenced key IDs in the same ResMgr session.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking that as well - but I noticed that setVer already had a similar disclaimer, so I felt this was OK.... especially considering it would require re-allocating the res manager it pyResManager__init__() if this function didn't exist.


/**
* Get whether or not keyed object IDs are preserved from PRPs
* that are read in. By default, key IDs are reordered to be
* consecutive when a PRP is read.
* \sa setPreserveObjIDs()
*/
bool getPreserveObjIDs() const { return preserveIDs; }

/**
* Return the version of data files this ResManager expects to
* deal with. Used for reading or writing data to files only.
Expand Down
Loading