35  Play-Loop Infrastructure

This tour shows the key components in p_local.h: macros for game physics, data structures for collision detection, and functions for movement and item handling.

File: linuxdoom-1.10/p_local.h

The p_local.h header file includes r_local.h.

Next we’ll look at four macros that define the game’s spatial dimensions and physics: MAPBLOCKSIZE, PLAYERRADIUS, GRAVITY, and USERANGE.

File: linuxdoom-1.10/p_local.h

MAPBLOCKSIZE defines the width and height of each grid cell used for collision detection.

File: linuxdoom-1.10/p_local.h

PLAYERRADIUS defines the collision boundary size for player movement.

File: linuxdoom-1.10/p_local.h

GRAVITY defines the downward acceleration applied to objects in the game world.

File: linuxdoom-1.10/p_local.h

USERANGE defines the maximum reach for player’s use actions in world units.

File: linuxdoom-1.10/p_local.h

thinkercap maintains the list of active mobile objects (mobjs) in the game.

File: linuxdoom-1.10/p_local.h

These variables track the timing and storage of items that will respawn in the game.

File: linuxdoom-1.10/p_local.h

rejectmatrix stores data for quickly determining if two areas can see each other. blockmap divides the map into a grid for collision detection.

File: linuxdoom-1.10/p_local.h

divline_t holds a line partition: a point (x,y) and direction vector (dx,dy).

File: linuxdoom-1.10/p_local.h

intercept_t represents a ray trace hit with position and target info.

File: linuxdoom-1.10/p_maputl.c

In P_PointOnDivlineSide, dx (line 186) is set to x minus the divline’s origin x, and dy (line 187) to y minus its origin y. A bitwise XOR of line->dy, line->dx, dx, and dy (line 190) then inspects the sign bit to quickly determine which side of the line the point falls on without costly multiplications.

File: linuxdoom-1.10/p_maputl.c

P_TraverseIntercepts uses the frac field of intercept_t to track the nearest intersection point along a trace line. When scan->frac is smaller than the current dist, it updates both dist and the current intersection point.

Next we’ll look at movement and interaction functions: P_CheckPosition, P_TryMove, and P_UseLines. These functions handle player movement and object interaction.

File: linuxdoom-1.10/p_local.h

P_CheckPosition tests if an object can fit at a position, while P_TryMove attempts to actually move the object there, handling any collisions that occur.

File: linuxdoom-1.10/p_local.h

P_UseLines checks if a player is close enough to interact with special lines like doors and switches.

File: linuxdoom-1.10/p_local.h

P_RespawnSpecials handles respawning special items during deathmatch games.

That concludes the core play-loop tour through p_local.h: we’ve seen key macros, externs, data types, and function prototypes driving Doom’s movement, collision, usage, and respawn logic.