Skip to content

Commit

Permalink
Merge pull request #280 from Hoikas/preserve_obj_ids
Browse files Browse the repository at this point in the history
Really preserve ObjIDs.
  • Loading branch information
zrax authored Oct 19, 2023
2 parents 9286854 + b8b5e77 commit bba1f7e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
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; }

/**
* 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

0 comments on commit bba1f7e

Please sign in to comment.