36 Map Object Lifecycle
This tour shows how Doom manages map objects (mobjs
) through their lifecycleβfrom creation to removal.
36.1 π§ Data Structure: mobj_t
File: p_mobj.h
- Defines the moving object (mobj) data structure.
mobj_t
represents a game-world object.
// mobj struct definition
[Lines 207β208]
- Thinker link and coordinates:
[Lines 209β214]
- Flags, health, and animation state:
[Lines 254β258]
36.2 π© Object Flags: mobjflag_t
MF_SPECIAL
: Enables touch triggers.MF_SHOOTABLE
: Allows damage.
[Lines 201β203]
MF_CORPSE
: Marks a dead, non-solid body.
[Lines 119β123]
36.3 βοΈ Object Lifecycle Implementation
File: p_mobj.c
- Mobj lifecycle logic lives here.
[Lines 173β175]
P_SpawnMobj
: Allocates and initializes objects usingZ_Malloc
.
[Lines 1β7]
- Floor alignment via
ONFLOORZ
:
[Lines 493β500]
- Adds new thinker:
[Lines 532β535]
36.4 π Thinker Management
File: p_tick.c
P_MobjThinker
: Called every frame.
[Lines 67β70]
- Thinkers progress via state machines when timers expire.
36.5 β Removal
P_RemoveMobj
unlinks and clears sector/block references.
[Lines 441β447]
36.6 π₯ Visual Effects
P_SpawnPuff
andP_SpawnBlood
:
[Lines 558β563]
P_SpawnPuff
logic:
[Lines 812β819]
36.7 β Wrap-Up
Doomβs map object system handles: - Allocation and initialization - Per-tick logic via thinkers - Cleanup and removal - Visual feedback on interaction
[Lines 844β851]