7  WAD I/O Functions

This tour examines Doom’s WAD I/O system. It shows how w_wad.h defines WAD file structures and how w_wad.c handles file operations like initialization, loading, reloading, lookup, and caching.

7.1 WAD File Format Structures

The next two steps show the WAD file format structures: wadinfo_t defines the file header, while filelump_t and lumpinfo_t describe directory entries.

7.1.1 wadinfo_t

This struct represents a WAD file header. identification stores the WAD type (‘IWAD’ or ‘PWAD’), numlumps stores the count of lumps in the file, and infotableofs stores where to find the lump directory.

// linuxdoom-1.10/w_wad.h (lines 35–42)

7.1.2 filelump_t and lumpinfo_t

filelump_t represents how lumps are stored in WAD files on disk, while lumpinfo_t holds the directory information for lumps in memory during gameplay.

// linuxdoom-1.10/w_wad.h (lines 45–63)

7.2 WAD File Operations in w_wad.c

The wadinfo_t, filelump_t, and lumpinfo_t structures work together in w_wad.c to manage WAD directory reading and data loading.

  • Header Reading & Endianness Conversion
// linuxdoom-1.10/w_wad.c (lines 196–198)
  • Directory Reading
// linuxdoom-1.10/w_wad.c (lines 199–201)
  • Data Loading
// linuxdoom-1.10/w_wad.c (lines 456–457)
  • WAD Resource Count
// linuxdoom-1.10/w_wad.c (line 62)
  • Multiple File Support
// linuxdoom-1.10/w_wad.c (lines 61, 64)
  • Reloadable WAD Support
// linuxdoom-1.10/w_wad.c (lines 292–300)
  • Single-Lump Files
// linuxdoom-1.10/w_wad.c (lines 301–304)
  • WAD Type Check
// linuxdoom-1.10/w_wad.c (lines 155–161)
  • Lump Directory Expansion and Metadata Copy
// linuxdoom-1.10/w_wad.c (lines 172–190)
  • WAD Reloading
// linuxdoom-1.10/w_wad.c (lines 206–222)
  • Name Lookup Functions
// linuxdoom-1.10/w_wad.c (lines 236–244, 261–269)
  • Name Comparison Optimization
// linuxdoom-1.10/w_wad.c (lines 351–359, 376–384)
  • Lump Lookup by Name
// linuxdoom-1.10/w_wad.c (lines 364–373)
  • Lump Length Retrieval
// linuxdoom-1.10/w_wad.c (lines 381–383)
  • Lump Reading
// linuxdoom-1.10/w_wad.c (lines 399–407, 416–422, 432–439)

7.3 WAD Lump Caching

7.3.1 W_CacheLumpNum and W_CacheLumpName

// linuxdoom-1.10/w_wad.c (lines 456–465)

When a lump isn’t cached, allocates zone memory and reads the lump data into it.

// linuxdoom-1.10/w_wad.c (lines 475–483, 489–493)

7.3.2 Finalization

// linuxdoom-1.10/w_wad.c (lines 494–499)

And that’s it - you’ve seen how Doom’s WAD I/O system loads and manages game data through a clean, efficient interface.