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 using Z_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 and P_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]