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.c manages the game state, processes player input, and drives the main game loop.
  • g_game.h declares 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.c loads map data and initializes the game world.
  • p_setup.h declares P_SetupLevel to initialize a level.
  • p_tick.c contains P_AddThinker to register objects for updates.
  • p_tick.h exposes P_Ticker, the main update function for AI and player logic.
  • p_local.h defines the thinker system for managing updateable game objects.

31.3 Mobile Objects and Interactions

  • p_mobj.c manages mobile object state changes.
  • p_mobj.h defines map object structures and utilities.
  • p_inter.c handles pickups, damage, and death effects.
  • p_inter.h declares power-up functions like P_GivePower.

31.4 Frame Update Pipeline

  • P_Ticker is called during the GS_LEVEL game state to update the game world, followed by:
    • ST_Ticker for status bar
    • AM_Ticker for automap
    • HU_Ticker for HUD

31.5 Player Control and Weapons

  • p_user.c handles player movement.
  • p_pspr.c/h manages weapon sprites and firing animations.

31.6 Spatial Queries and Collision Detection

  • p_maputl.c provides blockmap traversal (e.g., P_BlockLinesIterator) for spatial queries.
  • p_map.c implements movement logic (P_CheckPosition, P_TryMove, P_SlideMove).

31.7 Environmental Interactions

  • p_doors.c implements door mechanics.
  • p_floor.c handles floor/ceiling lifts.
  • p_ceilng.c manages ceiling motions.
  • p_telept.c manages teleportation via EV_Teleport.

31.8 Save/Load System

  • p_saveg.c/h implements DOOM’s savegame system, storing/restoring game state.

31.9 Finale and Intermission Screens

  • f_finale.c/h implements the ending sequence via F_Ticker, F_Drawer, etc.
  • f_wipe.c/h handles screen wipe transitions like melt and color xform.
  • wi_stuff.c/h renders intermission screens with WI_Ticker.

You’ve seen how DOOM organizes its core game loop, AI systems, and state management across its source files.