How xonotic/darkplaces works
Purpose and Entry Points
DarkPlaces is a C11, Quake 1-derived engine that runs multiple Quake-family games, extensions, maps, and model formats. The primary executable lifecycle is hosted by host.c, with platform initialization supplied by sys_*.c. Game selection comes from executable naming or command-line options and determines behavior/cvar defaults through com_game.c.
Paths: host.c, sys_shared.c, com_game.c
Platform, Build, and Runtime Targets
The source supports SDL desktop clients, dedicated/headless modes, Windows, macOS, iOS, and WebAssembly. Core build definitions are in the root makefiles, while Visual Studio and Xcode projects provide platform-specific entry paths. SDL provides windowing/input/audio-platform integration; Emscripten produces browser artifacts with preloadable game data.
Paths: makefile, makefile.inc, sys_sdl.c, sys_wasm.c, wasm/index.html
Host Loop, Commands, and Configuration
The host coordinates initialization, frame timing, client/server execution, and shutdown. Console and command infrastructure parse startup/runtime commands; cvars hold engine/game settings. This forms the main control plane used by local play, dedicated servers, scripting, and user console interaction.
Paths: host.c, cmd.c, cvar.c, console.c
Virtual Filesystem and Asset Loading
All game content is accessed through a hierarchical virtual filesystem. It merges base/game directories and packaged/archive sources, selects a writable primary game directory, and exposes a common asset boundary to models, textures, sounds, scripts, demos, and saves. Game mode setup precedes filesystem-dependent content loading.
Paths: fs.c, fs.h, com_game.c, wad.c, vpk.h
Client, Rendering, and Media Pipeline
The client consumes network/demo state, builds entities and view state, then submits world/model/sprite effects to the OpenGL renderer. The renderer owns texture management, surface/world rendering, shaders, lighting/shadows, and backend draw execution. Video playback, image codecs, fonts, and capture are adjacent client media subsystems.
Paths: cl_main.c, cl_ents.c, gl_rmain.c, gl_backend.c, r_shadow.c
Server Simulation and Networking
The server owns authoritative world state, client commands, movement, physics, save/demo behavior, and snapshot/entity transmission. Network connections and protocol encoding form the transport boundary between client and server; the engine can run both roles in-process or as a dedicated server.
Paths: sv_main.c, sv_phys.c, sv_send.c, netconn.c, protocol.c
QuakeC Virtual Machines
Game logic is executed through programmable VMs rather than compiled into engine gameplay. The general program VM supplies bytecode execution and entity storage; server, client-side, and menu VM command bridges expose engine capabilities to QuakeC. Generated/definition headers establish the engine-script ABI.
Paths: prvm_exec.c, prvm_edict.c, svvm_cmds.c, clvm_cmds.c, dpdefs/progsdefs.qc
External Libraries and Optional Services
SDL is material for client platform support; OpenGL is the rendering backend. Optional libraries support JPEG/PNG, FreeType fonts, Ogg/Vorbis/XMP audio, libcurl networking/download features, and Libav media handling. Engine cryptography and HTTP-related integration are internal abstractions around relevant external capabilities.
Paths: snd_sdl.c, libcurl.c, av_backend_libav.c, image_png.c, ft2.c
Main entry points: host.c Host lifecycle · sv_main.c Server world · cl_main.c Client state · fs.c Virtual filesystem
Components 19
Bootstrap & content
- Platform runtime · Initializes desktop and WebAssembly runtime targets.
sys_sdl.c - Build targets · Defines core desktop and dedicated build variants.
makefile - Game selection · Chooses game behavior and defaults before content loading.
com_game.c - Virtual filesystem · Merges game directories and archives behind one asset boundary.
fs.c - Archive formats
wad.c
Host control plane
- Host lifecycle · Coordinates initialization, frames, local roles, and shutdown.
host.c - Commands & console · Parses startup and runtime commands for console and scripts.
cmd.c - Configuration variables
cvar.c
Simulation & networking
- Server world · Owns world state, clients, saves, and demo behavior.
sv_main.c - Server physics
sv_phys.c - Network transport · Carries client/server connections and protocol messages.
netconn.c - Entity snapshots
sv_send.c
Client & rendering
- Client state · Consumes network or demo state and manages client execution.
cl_main.c - View & entities · Builds view state and renderable entities.
cl_ents.c - OpenGL renderer · Owns world, models, textures, shaders, and lighting submission.
gl_rmain.c - Draw backend
gl_backend.c
QuakeC runtime
- Program VM · Executes bytecode and stores script entities.
prvm_exec.c - Server VM bridge · Exposes server engine capabilities to game scripts.
svvm_cmds.c - Client VM bridge · Exposes client engine capabilities to scripts.
clvm_cmds.c
Connections 22
- Build targets → Platform runtime: builds
- Platform runtime → Host lifecycle: starts
- Game selection → Virtual filesystem: selects content roots
- Archive formats → Virtual filesystem: mounted by
- Host lifecycle → Game selection: initializes
- Host lifecycle → Commands & console: runs
- Commands & console → Configuration variables: updates
- Host lifecycle → Server world: ticks
- Host lifecycle → Client state: ticks
- Server world → Server physics: simulates
- Server world → Entity snapshots: produces
- Entity snapshots → Network transport: sends through
- Network transport → Client state: delivers state
- Client state → View & entities: builds
- View & entities → OpenGL renderer: submits scene
- OpenGL renderer → Draw backend: executes draws
- Virtual filesystem → Client state: loads assets for
- Virtual filesystem → Server world: loads maps for
- Server world → Program VM: runs game logic
- Client state → Program VM: runs client scripts
- Program VM → Server VM bridge: uses server API
- Program VM → Client VM bridge: uses client API