34  World Tick & Thinker Chain

This tour covers how DOOM’s world tick and thinker chain work, showing how entities (thinkers) are managed each game tick.


34.1 d_think.h

Function pointer types and thinker structure:

  • Lines 41–44:
    • actionf_v: no-argument callbacks
    • actionf_p1: one-parameter callbacks
    • actionf_p2: two-parameter callbacks
  • Lines 45–50:
    • actionf_t: union enabling various function pointer signatures.
  • Lines 63–68:
    • thinker_t: doubly-linked list node with a function pointer for behavior.

34.2 p_tick.h

  • Declares P_Ticker() at lines 32–36: the main game logic driver for each tick.

34.3 p_tick.c

  • Lines 1–10:
    • Includes logic for managing thinker chains and world state updates.
  • Lines 46–48:
    • thinkercap: sentinel node in the thinker list.
  • Lines 53–56:
    • P_InitThinkers(): initializes the thinker list.
  • Lines 65–70:
    • P_AddThinker(): adds a new thinker to the list.
  • Lines 101–109:
    • P_RunThinkers(): processes all thinkers each tick.
  • Lines 108–116:
    • Handles thinker removal (function = -1).
  • Line 117–118:
    • Executes per-tick logic.
  • Line 120:
    • Advances to next thinker safely before removal.

34.4 Ticker Flow in p_tick.c

  • Lines 130–158:
    • P_Ticker() processes each player via P_PlayerThink().
  • Lines 147–151:
    • Updates level time counter.
  • Lines 152–158:
    • Runs P_RunThinkers, P_UpdateSpecials, P_RespawnSpecials, then increments leveltime.

34.5 Additional Context

  • P_Ticker executes once per game tick in GS_LEVEL state.
  • Also coordinates updates to UI and display systems.