BSP

Doom makes use of a system known as binary space partitioning (BSP). A node builder is used to generate the BSP data for a level beforehand. Depending on the size of the level, this process can take quite some time. It is because of this that it is not possible to move the walls in Doom; while doors and lifts move up and down, none of them ever move sideways.

The level is divided up into a binary tree: each location in the tree is a "node" which represents a particular area of the level (with the root node representing the entire level). At each branch of the tree there is a dividing line which divides the area of the node into two subnodes. At the same time, the dividing line divides linedefs into line segments called segs.

At the leaves of the tree are convex polygons, where it is not useful to divide the level up any further. These convex polygons are referred to as subsectors (or SSECTORS), and are bound to a particular sector. Each subsector has an associated list of segs associated with it.

The BSP system is really a very clever way of sorting the subsectors into the right order for rendering. The algorithm is fairly simple:


 * 1) Start at the root node.
 * 2) Draw the child nodes of this node recursively. The child node closest to the camera is drawn first. This can be found from looking at which side of the node's dividing line the camera is on.
 * 3) When a subsector is reached, draw it.

The process is done when the whole column of pixels is filled (i.e., there are no more gaps left). This ordering ensures that no time is wasted drawing objects that are not visible and as a result maps can become very large without any speed penalty.