43  Savegame Loading & Saving

This walkthrough covers Doom’s savegame and demo systems through p_saveg.h/c for archiving, and g_game.h/c for file I/O and demo playback.


43.1 File Highlights

43.1.1 p_saveg.h

  • Declares functions for saving and loading different parts of the game state.
    Lines 32–43

43.1.2 p_saveg.c

  • Defines save_p and PADSAVEP for 4-byte aligned data storage.
    Lines 35–41

43.1.3 g_game.h

  • Provides functions for saving/loading game state, recording/playing demos.
    Lines 45–61

43.2 Save/Load Operations in g_game.c

  • G_SaveGame: Sets up deferred save.
    Lines 1260–1267
  • G_DoSaveGame: Writes description/version info, serializes game state/world data.
    Lines 1270–1320
  • G_LoadGame: Queues game load on next tick.
    Lines 1192–1196
  • G_DoLoadGame: Verifies version, loads save.
    Lines 1210–1218
  • Restores parameters: skill, episode, map, etc.
    Lines 1220–1230
  • P_ArchiveWorld: Archives map state.
  • P_UnArchivePlayers: Reconstructs player state.
    Line 1236

43.3 Demo System

  • G_RecordDemo: Starts demo recording, configures .lmp output.
    Lines 1530–1538
  • G_BeginRecording: Writes settings into demo header.
    Lines 1549–1567
  • G_DoPlayDemo: Loads demo lump, validates version.
    Lines 1582–1607

And that concludes our look at Doom’s save system and demo recording.