18 Rendering: Core Data Structures
This tour covers the core data structures that power DOOM’s software renderer: the map geometry types in the BSP tree
, the deferred wall segment type for sprite clipping, and the key view state variables
used during rendering.
The next steps examine the map geometry types in r_defs.h
, which define how DOOM represents its 3D world structure.
sector_t
File: linuxdoom-1.10/r_defs.h (lines 101–135)
Represents a 3D space in the game world, defining its geometry and properties.
side_t
File: linuxdoom-1.10/r_defs.h (lines 144–161)
Defines the texturing and positioning for one side of a linedef.
line_t
File: linuxdoom-1.10/r_defs.h (lines 179–215)
Represents a map linedef - a line segment that divides the map into sectors.
subsector_t
File: linuxdoom-1.10/r_defs.h (lines 227–233)
Defines a convex map section by its sector and line segments.
seg_t
File: linuxdoom-1.10/r_defs.h (lines 240–258)
Represents a wall segment in the BSP tree, storing geometry and references needed for rendering a portion of a wall.
node_t
File: linuxdoom-1.10/r_defs.h (lines 265–277)
A BSP node containing a partition line and references to its two child regions.
Next we’ll look at drawseg_t
and the view state globals that control how walls and sprites are rendered to the screen.
BSP traversal logic
File: linuxdoom-1.10/r_bsp.c (lines 567–570)
In R_RenderBSPNode
, bsp
is set to the address of the BSP node by indexing the global nodes
array with bspnum
. Then R_PointOnSide
tests the viewer’s viewx
/viewy
against this node’s partition to choose which child subtree to traverse.
subsector lookup
File: linuxdoom-1.10/r_bsp.c (lines 509–512)
Accesses a subsector by indexing the global subsectors
array, then uses its sector
and numlines
fields to determine which sector to render and how many segments to process.
segment processing
File: linuxdoom-1.10/r_bsp.c (lines 268–272)
R_AddLine
processes a segment by storing it in curline
and converting its endpoints into view angles using R_PointToAngle
.
drawseg_t
File: linuxdoom-1.10/r_defs.h (lines 322–347)
Holds wall segment data during rendering for deferred drawing operations.
R_StoreWallRange
File: linuxdoom-1.10/r_segs.c (lines 413–415)
Stores the wall’s screen coordinates and the source segment in the drawseg_t
structure.
R_RenderMaskedSegRange
File: linuxdoom-1.10/r_segs.c (lines 117–120)
Retrieves line segment data from the drawseg: the curline, front and back sectors, and midtexture from the side definition.
View state globals
File: linuxdoom-1.10/r_state.h (lines 103–120)
viewx
and viewy
store the viewer’s position. rw_distance
holds the calculated wall distance and rw_normalangle
stores the normal angle to each segment during rendering.
And that’s it for DOOM’s core rendering structures!