31 Play-Loop & AI & Game State: Overview
This tour highlights the key source files involved in DOOM’s play-loop, AI, and game-state management. You will see each file’s existence before diving deeper later.
31.1 Game Loop and State Management
g_game.cmanages the game state, processes player input, and drives the main game loop.g_game.hdeclares game loop and state transition functions.
31.2 Simulation Core and Level Setup
These files manage level loading, object interactions, AI, and physics:
p_setup.cloads map data and initializes the game world.p_setup.hdeclaresP_SetupLevelto initialize a level.p_tick.ccontainsP_AddThinkerto register objects for updates.p_tick.hexposesP_Ticker, the main update function for AI and player logic.p_local.hdefines the thinker system for managing updateable game objects.
31.3 Mobile Objects and Interactions
p_mobj.cmanages mobile object state changes.p_mobj.hdefines map object structures and utilities.p_inter.chandles pickups, damage, and death effects.p_inter.hdeclares power-up functions likeP_GivePower.
31.4 Frame Update Pipeline
P_Tickeris called during theGS_LEVELgame state to update the game world, followed by:ST_Tickerfor status barAM_Tickerfor automapHU_Tickerfor HUD
31.5 Player Control and Weapons
p_user.chandles player movement.p_pspr.c/hmanages weapon sprites and firing animations.
31.6 Spatial Queries and Collision Detection
p_maputl.cprovides blockmap traversal (e.g.,P_BlockLinesIterator) for spatial queries.p_map.cimplements movement logic (P_CheckPosition,P_TryMove,P_SlideMove).
31.7 Environmental Interactions
p_doors.cimplements door mechanics.p_floor.chandles floor/ceiling lifts.p_ceilng.cmanages ceiling motions.p_telept.cmanages teleportation viaEV_Teleport.
31.8 Save/Load System
p_saveg.c/himplements DOOM’s savegame system, storing/restoring game state.
31.9 Finale and Intermission Screens
f_finale.c/himplements the ending sequence viaF_Ticker,F_Drawer, etc.f_wipe.c/hhandles screen wipe transitions like melt and color xform.wi_stuff.c/hrenders intermission screens withWI_Ticker.
You’ve seen how DOOM organizes its core game loop, AI systems, and state management across its source files.