Geoms, classes and properties¶
This page describes the engine's object model as the decompiled source shows it: the geoms that make up a scene, the registry that creates them from a numeric class id, the run-time type ids behind every type test, the references objects use to find each other, and the property records through which a level file or a saved game fills in an object's fields. It comes from the C++ in src/, which compiles back to the original executable, and from the debug record dumped in analysis/recovered-types.h.
- For the bytes of the scene members, see scene archives, the geometry list, the property stream and the static buffer.
- For controllers, events and messages, see events. For actors and the player, see characters.
- For level control, scene scripts and saved games, see missions. For startup, memory and files, see the engine core.
- For how the class infos and the property graph are defined in source, see data defined in source.
A geom has two halves¶
Every scene object is split across two allocations. ZBaseGeom (src/engine/zstdlib/zbasegeom.h, 0x70 bytes, no vtable) holds the transform, the bounds, the control bits and the links into the scene tree. It comes from a fixed-size pool owned by ZGeomBuffer: ZBaseGeom::operator new calls ZGeomBuffer::AllocBaseGeom, and operator delete has an empty body. ZGEOM (src/engine/geomsbase/zgeom.h) is the polymorphic half. Its subclasses carry the class-specific state, and each instance lives in the extra-geom buffer (ZGeomBuffer::AllocExtraGeom, src/engine/enginedata/geombuffer.cpp:88). The constructor ties the two together:
ZGEOM::ZGEOM(const char *pName, ZBaseGeom *pBaseGeom) {
pBaseGeom->m_pExtraGeom = this;
m_pBaseGeom = pBaseGeom;
SetName(pName);
pExData = 0;
m_lGeomControl = 0;
}
The code that walks the tree (groups, lights, rooms, draw lists) mostly works on ZBaseGeom and reaches the class object through m_pExtraGeom. Behaviour lives in ZGEOM's virtual functions.
ZBaseGeom (0x70 bytes)¶
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0x00 | M33 |
m_mMat |
rotation, relative to the parent |
| 0x24 | V3 |
m_vPos |
position, relative to the parent |
| 0x30 | V3 |
m_vCen |
bound centre |
| 0x3c | uint32 |
m_lControl |
EBaseGeomControl bits; the low byte is the ECollisionMask |
| 0x40 | V3 |
m_vSize |
bound size |
| 0x4c | V1 |
m_fRadius |
bound radius |
| 0x50 | ZBaseGeom * |
m_pParent |
the parent group's base geom |
| 0x54 | bitfield | m_uListID (24 bits), m_lPotentialLightListChange (7), m_bFreezeLightList (1) |
light list, from the .GMS tree entry |
| 0x58 | uint16 |
m_lDrawId / m_lDrawEntryId |
draw id |
| 0x5a | uint16 |
m_iRoomListNr / m_iDynamicParentNr |
room list number, or the dynamic parent's slot |
| 0x5c | uint16 |
m_iPrev |
previous sibling, as pool slot + 1 |
| 0x5e | uint16 |
m_iNext |
next sibling, as pool slot + 1 |
| 0x60 | ZGEOM * |
m_pExtraGeom |
the class object |
| 0x64 | CQuadtreeObj * |
m_pDynId |
entry in a dynamic container |
| 0x68 | uint32 |
m_lPrim |
prim handle in the .PRM |
| 0x6c | const char * |
m_Name |
name, usually a pointer into the .BUF |
EBaseGeomControl names the control bits, among them BASEGEOM_Inactive (0x400), BASEGEOM_Hidden (0x800), BASEGEOM_AutoRoomAssign (0x4000), BASEGEOM_Dynamic (0x40000), BASEGEOM_OwnerDraw (0x200000), BASEGEOM_InMovedList (0x20000000) and BASEGEOM_Destroyed (0x80000000). CreateGeoms takes bits 0 to 19 from the .GMS record's lGeomAndGroupCon.
ZGEOM (0x10 bytes)¶
| Offset | Type | Field | Meaning |
|---|---|---|---|
| 0x0 | vtable pointer | from ZSerializable |
|
| 0x4 | ZBaseGeom * |
m_pBaseGeom |
the base half |
| 0x8 | ExGeomData * |
pExData |
optional extension, made on demand by CreateExData |
| 0xc | uint16 |
m_lGeomControl |
EGeomControl: GEOMCTRL_Display, GEOMCTRL_Select, GEOMCTRL_Frozen, GEOMCTRL_CustomDraw and others |
| 0xe | uint8 |
m_Status |
EStatus, how far initialisation has gone |
ExGeomData (0xc bytes) holds _lControl (EXGEOM_WantCameraMsg, EXGEOM_MovingObject) at 0x0, the controller list _Events (a 4-byte ZGeomEventList) at 0x2, and at 0x8 _ExtraInitData, the CHUNKFILE in the .BUF that the .GMS record's lExData names.
ZGEOM derives from RTP::cBase, which derives from ZSerializable and the empty ZSerializableBase. Its vtable has 119 slots (python3 tools/vtable_evidence.py ZGEOM). Slots 0 to 12 are the ones ZSerializable declares (PreLoad, PostLoad, PostProcess, LoadObject and the rest), 13 is GetProperties, 14 to 16 are GetObjectId, GetObjectIdAndMask and GetOldClassInfo, 17 is DoInit and 18 is the pure CalcCenSize. The remaining slots cover transforms, display flags, controllers (AddEvent, CallEvents), messages (SendCommand, ClassCommand), the four init steps, the per-frame updates (ClassFrameUpdate, ClassTimeUpdate), collision queries and duplication. ZGROUP has 148 slots, ZLNKOBJ 193 and ZHM3Actor 450.
The class tree¶
161 geom classes register a producer in src/, one ZGEOMCLASSINFO(...) each: 104 under src/engine/ and 57 under src/hitman3/. The ELF has 161 m_OldClassInfo symbols. Each class names its registered parent by string, and the first level of that tree is:
| Class | Class id | Size | Unit (src/engine/) |
Registered subclasses, direct / all | C++ subclasses in the debug record |
|---|---|---|---|---|---|
ZGEOM |
0 | 0x10 | geomsbase/zgeom.cpp |
6 / 160 | 163 |
ZSTDOBJ |
0x200002 | 0x10 | geomsbase/zstdobj.cpp |
54 / 89 | 92 |
ZGROUP |
0x100001 | 0x4c | geomsbase/zgroup.cpp |
16 / 51 | 51 |
ZLIGHT |
0x80800004 | 0x20 | geomsbase/zlight.cpp |
5 / 8 | 8 |
ZCAMERA |
0x400003 | 0x18c | geomsbase/zcamera.cpp |
3 / 4 | 4 |
ZLIST |
0x800001a | 0x14 | geomsbase/zlist.cpp |
2 / 2 | 2 |
ZSHAPE |
0x4000022 | 0x28 | geomsbase/zshape.cpp |
0 / 0 | 0 |
ZSTDOBJadds no fields. It is the class of plain meshes (108,513 of the disc's 198,583 geoms, per gms.md) and the base of everything drawn or animated: particles (ZParticleEmitter), projected marks,ZSNDOBJ,ZBOUND, the window objects underZWINOBJ, andZLNKOBJ.ZLNKOBJ(0xf4 bytes,src/engine/geomsextend/zlnkobj.cpp) is the boned, animated object: pose and motion data, the ground bonem_Ground, the mesh variantm_lVariantId, the animation collection name andm_pAttachedTo. 19 registered classes derive from it. The character chain isZLNKOBJ→ZIKLNKOBJ(0x17c) →ZCTRLIKLNKOBJ(0x18c) →ZLNKWHANDS(0x384), which splits intoZActor(0x8b0) →ZHM3Actor(0xb00, class id 0x2003e9) andZPlayer(0x718) →ZHitman3(0x1400, class id 0x2003e8). The vehicles are the other branch:ZLinkBase→ZVehicle→ZDriving/ZSailing→ZCar/ZBoat.ZGROUPholds children.ZTreeGroup(0x100020) is the group that receives bound trees,ZROOM(0x100021, 0x13c bytes) derives from it andZBackdropfromZROOM. The scene root is aZROOM. The item classes (ZItem,ZItemTemplateand their weapon, ammo and container subclasses, 21 classes) and the window groups (ZWINGROUPand 12 below it) are groups too.ZLIGHThas a pure producer, so no plain light is ever created. The omni, spot, square spot, user and environment lights derive from it, and three gate lights derive from the first three.
The registered parent can skip a C++ base. ZBloodSplatters, ZBulletMarks, ZBloodStains and ZBloodTrails derive from ZProjectMarks in C++, and ZBloodSpray from ZBoneParticle, yet all of them register "ZSTDOBJ". ZProjectMarks, ZBoneParticle and ZHFlowLnkObjTest have no producer, which accounts for the 163 against 160. Type tests follow the registered tree.
The class id is ZGEOMCLASSINFO::m_lType, and in all 161 producers the factory key equals it. The .GMS stores it in SCompiledGeom::lGeomType and a saved game as GeomType. Its high bits group the classes. 52 ids carry 0x100000, 88 carry 0x200000, 8 carry 0x800000, 5 carry 0x400000, 3 carry 0x8000000 and ZSHAPE carries 0x4000000. ZLIGHT, ZPlayer and ZCONTROL add bit 31 to 0x800000, 0x200000 and 0x100000. CreateGeoms counts any record with bit 0x100000 as a group (enginedatabase.cpp:734); ZLaserAim (0x100462) is the one class with that bit registered outside the ZGROUP tree.
Class information and producers¶
Each class defines its statics and producer in its own unit:
ZFactoryProducer<ZROOM> ZROOM_Producer(0x100021,
ZGEOMCLASSINFO("ZROOM", sizeof(ZROOM), 0, 0x100021, 0, "ZTreeGroup",
ZGeomValidator<ZROOM>::SetTypeIDAndMask, &ZROOM::m_Id, &ZROOM::m_Mask));
ZGEOMCLASSINFO &ZROOM::m_OldClassInfo = ZROOM_Producer.m_Data;
The producer's constructor runs in the unit's static initializer (GENERATED-FUNCTIONS.md) and adds m_Data to ZGEOM::GetFactory(), a function-local ZFactory<ZGEOM> (zgeom.cpp:1384). m_Data is a ZFactory<ZGEOM>::ProducerData (src/common/basic/zfactory.h): the ZGEOMCLASSINFO (src/engine/globals/classinfo.h) followed by the key, the create function and a bucket link. m_OldClassInfo is a reference bound to it, and each class's GetOldClassInfo() returns its address. src/engine/globals/classinfo.cpp holds ZGEOMCLASSINFO::SetTypeIDAndMask (it calls the stored hook), the ZNonResourceClassInfo constructor and the ZFactory<ZGEOM> iterator instances.
| Offset | Field | Value | Use |
|---|---|---|---|
| 0x00 | m_szClassInfoName |
class name | parents are matched against it |
| 0x04 | m_iClassInfoType |
CIT_GeomClass (0) |
|
| 0x08 | m_lSceneInstanceCount |
0 | incremented per instance by CreateGeoms, passed to RegisterInstance |
| 0x0c | Parent |
set by CreateGeomClassInfoData |
the registered parent's class info |
| 0x10, 0x14 | Prev, Next |
0 | |
| 0x18 | m_lSize |
sizeof(T) |
extra-geom size, read by FreeGeom and CountNrGeoms |
| 0x1c | m_bResourceLinked |
false | |
| 0x20 | m_pSetTypeIDAndMask |
ZGeomValidator<T>::SetTypeIDAndMask |
writes T::m_Id and T::m_Mask |
| 0x24 | m_lType |
class id | |
| 0x28 | m_lGeomCases |
0 in all 161 | |
| 0x2c | m_szParentClass |
parent name, 0 for ZGEOM |
|
| 0x30, 0x34 | m_pClassId, m_pMaskId |
&T::m_Id, &T::m_Mask |
GetClassId, GetMaskId |
| 0x38 | m_iClassInfoNr |
set by CalcClassInfoNrs |
|
| 0x3c | m_ProductId |
class id | factory key |
| 0x40 | m_pCreator |
ZFactoryProducer<T>::Create |
|
| 0x44 | m_pNext |
next producer in the bucket |
The whole object is 0x48 bytes, the size of every geom X_Producer symbol in the ELF. The factory hashes the key into 16 buckets (ZProductDescription<ZGEOM, uint32, 16, ZGEOMCLASSINFO, ZGeomCreator>), and Add refuses a key it already holds. Four producers are ZFactoryProducerPure (src/openblood/zfactoryproducerpure.h), whose Create returns 0: ZGEOM, ZLIGHT, ZFONT and ZPlayer.
Controllers have a parallel registry, ZROUTCLASSINFO and ZFactory<ZBaseConRout>, keyed by name (src/engine/geomsbase/baseevent.h:139). Each of the 182 controller classes registers two producers, a long and a short name (ZGEOM_DialogControl and DialogControl), so the ELF holds 525 producers in all. events.md covers them.
Run-time type ids¶
T::m_Id and T::m_Mask are zero in the executable. ZSysInterface::Initialize (src/engine/system/sysinterface.cpp:129) fills them in at startup:
CreateGeomClassInfoDataresets every instance count and points each class info'sParentat the class whose name matches itsm_szParentClass(strcasecmp).CalcClassInfoNrsnumbers the geom classes in factory order, then the controller classes, intom_iClassInfoNr.CalcDeriveIdsputs every class into astd::map<int, SClassInfoHolder>keyed by class id, chains each holder under its parent's, and callsSClassInfoHolder::Validate(0, 0, 0)on class id 0,ZGEOM.
Validate gives a class with n subclasses GetMaskWidth(n) more low bits, the number of bits needed to write n. The k-th subclass gets the parent's id plus k shifted past the parent's bits, and a mask over both (the PS2 branch):
uint32 n_required_bits = GetMaskWidth(n_subclasses);
TypeID inc = 1 << length;
length += n_required_bits;
mask = 0xffffffff >> -length;
for (SClassInfoHolder *p = m_pFirstChild; p; p = p->m_pNext) {
id += inc;
p->Validate(id, mask, length);
}
A type test is then one AND and one compare. IsGeomType<T> (zgeom.h:302) tests (pGeom->GetObjectId() & T::m_Mask) == T::m_Id, and ZGEOMCLASSINFO::IsDerivedFrom does the same with two class infos, so an object passes for its own class and every registered ancestor. A ZBaseGeom without a class object passes only IsGeomType<ZSTDOBJ> (IsDerivedFromStdObj); CreateGeoms never leaves one, because ForceExtraGeom returns true.
Holders are chained by prepending in ascending order of the class id read as a signed int, so among siblings the highest id is numbered first and ZLIGHT, whose id is negative as an int, last. Applying these rules to the 161 producers gives:
| Class | Run-time id | Mask |
|---|---|---|
ZLIST, ZSHAPE, ZCAMERA |
0x1, 0x2, 0x3 | 0x7 |
ZSTDOBJ, ZGROUP, ZLIGHT |
0x4, 0x5, 0x6 | 0x7 |
ZLNKOBJ |
0x1ac | 0x1ff |
ZHM3Actor |
0x2ebac | 0x3ffff |
ZHitman3 |
0x36bac | 0x3ffff |
The table comes from applying these rules to the source and has not been checked against a running game. The .GMS and saved games store m_lType, so a new class shifts its siblings' run-time ids without changing anything those files hold.
Creating a geom¶
ZGeomBuffer::AllocGeom (src/engine/enginedata/geombuffer.cpp:408) is where geoms come from:
if (!pBaseGeom) {
pBaseGeom = new ZBaseGeom();
}
g_pGeomName = szName;
g_pBaseGeom = pBaseGeom;
ZFactory<ZGEOM>::ProducerData *pProducer = ZGEOM::GetFactory().Find(lGeomType);
if (pProducer) {
pProducer->m_pCreator(*pProducer);
}
ZFactoryProducer<T>::Create (src/engine/geomsextend/zfactoryproducer.h:46) takes sizeof(T) zeroed bytes of extra-geom buffer and constructs T(g_pGeomName, g_pBaseGeom) in place. The name and base geom travel through the two globals because Create receives only the class info, and a static lock makes a nested AllocGeom a ZDebugBreak. An id without a producer, or with a pure one, returns the base geom with no class object.
Every geom in src/ is created from a class id through this function:
ZGROUP::CreateGeom(pName, iGeomClassId, bCalcMinMax)allocates and attaches;CreateAndInitGeomalso runsDoInit. Engine code passes constants such asGEOMCLASS_List,GEOMCLASS_CameraorGEOMCLASS_OmniLight(the default camera atenginedatabase.cpp:950).ZGEOM::Duplicatecreates the copy withGetOldClassInfo()->Type().ZEngineDataBase::AllocRootGroupcreatesROOT, class id 0x100021.ZGeomBuffer::LoadObjectre-creates the geoms of a saved game from their saved name, REF andGeomType.
Controllers are created by name: ZGEOM::AddEvent(name) finds the ZBaseConRout producer by name, creates the controller and attaches it to the geom.
References and lookup¶
A REF is a uintptr (src/openblood/engine_types.h). For geoms it is a handle into the base-geom pool, a ZFixedSizeMemoryManager<ZBaseGeom> (src/engine/zstdlib/fixed_size_memory_manager.h) that keeps a signed 16-bit id per slot in m_ID. A free slot holds a negative id; Alloc stores ~id and Free stores ~id - 1, so the id counts up each time the slot is reused (-1 free, 0 first use, -2 free, 1 second use). The REF packs the id with the slot index:
uint32 Ptr2Index(const void *memblock) const {
const uint32 index = (static_cast<const char *>(memblock) - m_Buffer) / m_BlockSize;
const int16 id = m_ID[index];
return id < 0 ? 0xffffffff : id * m_NumberOfBlocks + index;
}
Ptr2REF adds 1, so 0 is the null REF. REF2Ptr returns 0 unless the slot's current id matches the one in the REF, so a REF to a deleted geom stays null after its slot is reused.
| Call | Result |
|---|---|
ZGEOM::GetRef(), ZBaseGeom::GetRef() |
ZGeomBuffer::GeomPtrToRef, the pool's Ptr2REF |
ZGEOM::RefToPtr(ref) |
GeomRefToPtr: the base geom's m_pExtraGeom, or 0 |
ZBaseGeom::RefToPtr(ref) |
GeomRefToBasePtr |
ZGEOM::SendCommand(REF, ZMSG, void *) |
resolves the REF and sends the message if the target exists |
GeomRefToBasePtr also takes a static form: with bit 30 set (STATIC_GEOM_REF) the low 30 bits are a byte offset into the pool, divided by 0x70 and not checked against the id. The light lists use it (gms.md). Sibling links and m_iDynamicParentNr use a third form, slot + 1 in 16 bits with no id check.
A level file names geoms by path. ZEngineDataBase::GetREFByName (enginedatabase.cpp:2070) calls m_pRoot->FindGeom(path, 0) and returns the REF. ZGROUP::FindGeom (src/engine/geomsbase/zgroup.cpp:762) answers ROOT with the root, strips a leading ROOT\, and descends one \-separated component at a time into the first child group whose name matches without regard to case; the last component may name any child. Groups flagged GROUP_FIND_MASTER or GROUP_FIND_LOAD_WORLD are skipped. Given a geom as pZGeomContinue, it searches that geom's later siblings for the last component instead. FindGeom depends on the child order. ZGROUP::AttachGeom puts a group at the front of its parent's list and any other geom at the back, and while matching an inner component FindGeom stops at the first non-group (ForGroupsCheck).
REFTAB (src/engine/zstdlib/reftab.h:25, 0x1c bytes) is the engine's list of references. It keeps a chain of TabBlk blocks of m_lRefsPrBlk elements, and an element is a REF followed by EleSize - 1 words of user data (REFTAB(pPoolSize, pUserData) sets EleSize = pUserData + 1). Add returns a pointer to the user data after the stored REF, and a RefRun cursor walks the table (RunInitNxtRef, RunNxtRef).
| Class | Size | Difference |
|---|---|---|
REFTAB |
0x1c | blocks from new |
REFTAB32 |
0xac | the first block, 32 references, inside the object |
STATICREFTAB |
0x20 | keeps freed blocks on a free stack (m_pFreeStack) |
STRREFTAB |
0x20 | string lookups (FindStr, AddStr, Sort), m_bCaseSensitive |
LINKREFTAB |
0x28 | elements carry PrevNext links |
LINKSORTREFTAB |
0x2c | each element ends in a float sort key (AddSort, GetSort) |
ZLIST (0x14 bytes) is a geom whose one field is REFTAB *m_pZList; its GeomList property is how a level file builds waypoint lists and other sets of geoms. ZGROUP keeps its ZBOUND children in m_pZBounds (LinkBound, called from AttachGeom).
Groups¶
| Offset | Type | Field |
|---|---|---|
| 0x10 | float[3] |
m_vSizeInsideCheck |
| 0x1c | float[3] |
m_vCenInsideCheck |
| 0x28 | uint32 |
m_lGroupCon, ZGROUPControlFlag bits; the top byte comes from the .GMS record |
| 0x2c | float[2] |
m_OverRideNearFar |
| 0x34 | REFTAB * |
m_pZBounds |
| 0x38 | uintptr |
m_LightList, the group's lights in a ZBaseGeomLists chain |
| 0x3c, 0x40 | ZBaseGeom * |
m_pGroupFirst, m_pGroupLast |
| 0x44 | float |
m_fPFResMultiplier |
| 0x48 | uint16 |
m_NrAttachGeom |
AttachGeom (zgroup.cpp:396) also adds lights to m_LightList, links bounds, passes the geom to its tree group and dynamic tree group, propagates GROUP_CONTROL_BOUNDS_INVALID and GROUP_CONTROL_CONTAINS_LIGHT up the parents, and attaches the geom to the room draw lists. RecurGetNext walks a subtree depth first. GetBoundTreeType places a class in a global bound tree: GT_StdObjs for ZSTDOBJ, GT_Lights for ZLIGHT, GT_Groups for ZGROUP, GT_None for ZGEOM and ZBOUND. A ZBOUND sets BASEGEOM_NoDraw in its PostLoad and draws nothing.
Properties¶
Every serializable class has a static ZPropertyInfo Info (src/engine/geomsbase/zpropertyinfo.h): First, the first property node; Super, the base class's Info; and Name, 0 in every record. GetProperties() returns it, and RTP::LoadSerializable (src/engine/serializerlib/rtp.cpp:26) loads the base class's properties before the class's own:
if (properties.Super) {
LoadSerializable(serializable, *properties.Super, stream);
}
for (cNode *property = properties.First; property; property = property->m_Next) {
if (stream.TestStreamFilter(property->m_Filter)) {
cProperty *pProperty = reinterpret_cast<cProperty *>(property);
pProperty->m_VirtualTable.Load(*pProperty, stream, serializable);
}
}
The records are data. tools/property_records.py generated them from the ELF into src/hitman3/hitman3/cproperties.h, the struct cProperties with one static member per node, and into the tail of src/hitman3/hitman3/hm3properties.cpp, in the original data order (the property graph). There are 402 Info records, RTP::cBase::Info in rtp.cpp and 401 in hm3properties.cpp, and 330 have a property list. All 161 geom classes have a record and 111 add properties of their own; 164 records sit directly under ZEventBase::Info. ZGEOM's list starts with an enum property:
ZPropertyInfo ZGEOM::Info = { &cProperties::NamespaceItem_3529.m_Node, &RTP::cBase::Info, 0 };
ZVirtualEnumProperty<EBoundingBox> cProperties::NamespaceItem_3529 = {
{ &NamespaceItem_3530.m_Node, 0, FILTER_LevelFile }, &VirtualTable_VP__197,
static_cast<void (ZSerializableBase::*)(EBoundingBox &)>(&ZGEOM::GetBoundingBox),
static_cast<void (ZSerializableBase::*)(const EBoundingBox &)>(&ZGEOM::SetBoundingBox),
&NamespaceItem_3525
};
Each node starts with a cNode (m_Next, m_Name, m_Filter; m_Name is 0 throughout the release ELF) and, at 0x0c, a pointer to one of 139 tVirtualTables, each a Load and a Save function. The four node kinds are declared in src/hitman3/hitman3/hm3properties.h:
| Kind | Nodes | Fields from 0x10 | Load |
|---|---|---|---|
ZDataProperty<T> |
2,411 | m_Offset, a pointer to the member |
stream.Exchange(name, object.*m_Offset) |
ZVirtualProperty<T> |
167 | m_Get, m_Set at 0x18 (member function pointers) |
reads a T and calls m_Set |
ZEnumProperty |
89 | m_Offset, m_Info at 0x14 |
ExchangeEnum with the ZEnumInfo |
ZVirtualEnumProperty<T> |
13 | m_Get, m_Set, m_EnumInfo at 0x20 |
ExchangeEnum, then m_Set |
The C++ type picks the stored type (ZPropertyStorage<T>): ZGEOMREF is a REF, ZMsg a uint16, ZCOLOR, ZAUDIOREF and ZMESHVARIANT a uint32, ZANIM and ZFILENAME a ZRTString. ZGEOMREF and ZMsg are empty tag structs that select an Exchanger, and the exchanger decides the encoding by stream content. Exchanger<ZGEOMREF>::Load (hm3properties.cpp:2404):
bool bSavedGame = stream.IsSavedGame();
if (bSavedGame) {
stream.Exchange(name, ref);
} else {
const char *path;
stream.Exchange(name, path);
ref = g_pEngineData->GetREFByName(path);
}
A level file names a geom by path and a saved game stores the REF number. REFTAB properties (Exchanger<REFTAB>::Load, line 2307) and pointer properties (ZDataProperty<T *>) follow the same split, and a ZMsg is a message name, registered with RegisterZMsg, in a level file. prp.md lists every encoding as it appears on the disc.
m_Filter chooses the streams a property belongs to. ISerializerStream::TestStreamFilter tests (1 << m_Content) & filter, and EPropertyFilter in cproperties.h names the bits:
| Flag | Value | Stream content | Nodes |
|---|---|---|---|
FILTER_LevelFile |
1 | CONTENT_LevelFile (0), a scene .PRP |
1,495 |
FILTER_SavedGame |
2 | CONTENT_SavedGame (1), a saved game |
1,372 |
FILTER_SimpleRepack |
4 | CONTENT_SimpleRepack (2) |
11 |
1,298 nodes are level-file only, 1,185 saved-game only and 186 both; 10 combine level file and simple repack, and one has all three bits. The level file and the saved game therefore load mostly different fields of the same class. ZGEOM's Matrix and Position are among the 11 simple-repack nodes, but no code in src/ opens a stream with CONTENT_SimpleRepack.
Enum properties store enumerator names. A ZEnumInfo (src/engine/serializerlib/enumdescription.h, 0xc bytes) holds m_Last, the last ZEnumEntry of a chain linked through m_Prev, the enum's m_Name and m_Size, the width of the stored value. The graph has 86 descriptors and 539 entries. In a level file, ZPackedInput::ExchangeData(void *, const ZEnumInfo &) looks the name up with FindItem(name, 0), so an unknown name loads as 0, and stores 1, 2 or 4 bytes by m_Size. ZBitfield<E> properties use the same descriptors.
The serializer library¶
src/engine/serializerlib/ has 28 units. 15 of them, serializer.cpp, serializerstream2xml.cpp, filestream.cpp and bitfield.cpp among them, are empty files: no function in the executable belongs to them. The rest stack in layers:
| Layer | Classes | Headers |
|---|---|---|
| bytes | IInputStream, IOutputStream; ZIOInputStream (a file in a mounted ZIP), ZMemoryInputStream, ZCompressedInputStream (zlib), ZCRCInputStream (16 KB blocks with a CRC) and their output twins |
streambase.h, zipstream.h, memorystream.h, compressed_stream.h, crcstream.h |
| typed values | ZInputStream, ZOutputStream |
high_level_stream.h |
| tokens | ZTokenTable_Serializerlib, ZPackedDictionary_Serializerlib, ZDictionary_Serializerlib, ZFastDictionary_Serializerlib |
dictionary.h |
| properties | ISerializerStream, IInputSerializerStream, IOutputSerializerStream |
serializerstream.h |
| format | ZPackedInput, ZPackedOutput |
packed_stream.h |
| objects | ZSerializable, RTP::cBase, ZEnumInfo |
src/engine/enginedata/zserializable.h, rtp.h, enumdescription.h |
ISerializerStream carries m_Type, a set of EType bits (tags, dictionary, string enums, string table), and m_Content. A scene .PRP is TYPE_LevelFile (13) with CONTENT_LevelFile, read through ZIOInputStream (CreatePropertyInputStream), ZInputStream and ZPackedInput. ZEngineDataBase::SaveGame writes TYPE_StringTable with CONTENT_SavedGame through CRC streams, with the data stream compressed.
IInputSerializerStream::_ExchangeObject (serializerstream.cpp:102) loads an object with PreLoad, LoadObject and PostLoad, and in a saved game also LoadSave. An object whose PostLoad returns false is queued, and PostProcess calls its PostProcess(filter, pass) in rounds until every queued object returns true. ZGEOM::LoadObject loads the property list through RTP::cBase::LoadObject, then, in a saved game only, the base geom, the control word, the extra init data offset and the controller list.
From the scene archive to live objects¶
ZEngineDataBase::AllocSequence (src/engine/enginedata/enginedatabase.cpp:984) loads the members in the order scene.md gives and calls CreateGeoms (line 551) with the unpacked .GMS, the .BUF and a stream on the .PRP:
| Step | Code | Work |
|---|---|---|
| 1 | CountNrGeoms |
sizes the base-geom, extra-geom and event buffers from the .GMS type counts |
| 2 | new ZGeomBuffer |
creates the pools; the base pool has buffer size / 0x70 slots |
| 3 | AllocRootGroup |
creates ROOT and makes it a dynamic container |
| 4 | each SPackedGeomsTree entry |
closes the groups the entry names; on a group's first child, allocates the group's base geoms in one run and hands them out by list type; then AllocGeom(name, lGeomType, pBaseGeom) |
| 5 | same entry | sets the extra init data, light list and control bits, AttachGeom to the current group, the group control byte, and pRemaps[m_iGeomNr - 1] = REF |
| 6 | ZPackedInput, LoadZDefines |
scene variables into the scene CCom |
| 7 | RemapDoorRefs, g_pGameData->RemapRefs |
geom numbers to REFs |
| 8 | LoadProperties, LoadPropertiesRecursive |
per geom, depth first: its object, its controllers by name through AddEvent (an unknown name skips the object), its children |
| 9 | in.End() |
the PostProcess rounds |
| 10 | ZROOM::RemapRefs, CListUser, InitResourceGeoms, RemapGeoms |
room references, the light table, resource geoms, the material database |
AllocSequence then builds the room and bound trees, makes dynamic geoms dynamic and runs the init passes. Init (two passes), PostInit and PostInit2 each set ZGEOM::m_PreferedStatus and call DoInit on the root; a saved game is loaded between Init and PostInit (lines 1207 to 1240). ZGEOM::DoInit steps m_Status towards the preferred status through ClassInit, ClassInit2, PostClassInit and PostClassInit2, and stops if the geom no longer resolves from its REF after a step. ZGROUP::DoInit does the same for each child, last child first, through REFs collected beforehand.
Once the scene runs, ZEngineGeomControl (src/engine/enginedata/enginegeomcontrol.cpp) tracks motion. ZBaseGeom::SetMat, SetPos and SetMatPos call GeomMoved when the value changes, and CopyMatPos always does. GeomMoved sets BASEGEOM_LightDirty, BASEGEOM_UpdateLight and BASEGEOM_InMovedList and records the REF, up to 128 at a time. UpdateMovedGeoms runs before each frame update unless the game is frozen (enginedatabase.cpp:1978), and when the list is full. It calls UpdateMovedGeom on each geom that still exists, and JonsLights collects the moved lights, including those inside moved groups, for LightNotifyPotentialDetachment. AllocSequence turns this change detection on once the scene is built, and turns it off while a saved game loads.
Unknown¶
- What
m_lGeomCasesand theszParametersargument were for. Every producer passes 0 for both, and theZNonResourceClassInfoconstructor discardsszParameters. - What bit 31 of the class ids of
ZLIGHT,ZPlayerandZCONTROLmeans, and whyZLaserAimhas the group bit. - What reads or writes
CONTENT_SimpleRepackstreams. Nothing in this build does; the engine only reads theSimpleRepackflag at the end of a level file. - What
ZGROUP::m_pZBoundsis for.LinkBoundandRemoveBoundmaintain it, and nothing else insrc/reads it.