# xonotic/darkplaces architecture

> Architecture diagram of the GitHub repository xonotic/darkplaces, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xonotic/darkplaces
- Repository: https://github.com/xonotic/darkplaces

## Overview

#### 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`](https://github.com/xonotic/darkplaces/blob/master/host.c) (Host lifecycle), [`sv_main.c`](https://github.com/xonotic/darkplaces/blob/master/sv_main.c) (Server world), [`cl_main.c`](https://github.com/xonotic/darkplaces/blob/master/cl_main.c) (Client state), [`fs.c`](https://github.com/xonotic/darkplaces/blob/master/fs.c) (Virtual filesystem)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bootstrap["Bootstrap & content"]
  node_platform["Platform runtime<br/>SDL / system<br/>[sys_sdl.c]"]
  node_build["Build targets<br/>make build"]
  node_game_select["Game selection<br/>game profiles<br/>[com_game.c]"]
  node_filesystem[("Virtual filesystem<br/>content mount<br/>[fs.c]")]
  node_archives["Archive formats<br/>content packages<br/>[wad.c]"]
end

subgraph group_control["Host control plane"]
  node_host{{"Host lifecycle<br/>engine loop<br/>[host.c]"}}
  node_commands["Commands & console<br/>control interface<br/>[cmd.c]"]
  node_cvars["Configuration variables<br/>settings registry<br/>[cvar.c]"]
end

subgraph group_simulation["Simulation & networking"]
  node_server["Server world<br/>authoritative simulation<br/>[sv_main.c]"]
  node_physics["Server physics<br/>movement simulation<br/>[sv_phys.c]"]
  node_network["Network transport<br/>connection layer<br/>[netconn.c]"]
  node_snapshots["Entity snapshots<br/>server replication<br/>[sv_send.c]"]
end

subgraph group_client["Client & rendering"]
  node_client_state["Client state<br/>client runtime<br/>[cl_main.c]"]
  node_view_entities["View & entities<br/>scene assembly<br/>[cl_ents.c]"]
  node_renderer["OpenGL renderer<br/>render pipeline<br/>[gl_rmain.c]"]
  node_draw_backend["Draw backend<br/>GPU execution<br/>[gl_backend.c]"]
end

subgraph group_scripting["QuakeC runtime"]
  node_program_vm{{"Program VM<br/>QuakeC bytecode VM<br/>[prvm_exec.c]"}}
  node_server_vm_bridge["Server VM bridge<br/>QuakeC engine API<br/>[svvm_cmds.c]"]
  node_client_vm_bridge["Client VM bridge<br/>QuakeC engine API<br/>[clvm_cmds.c]"]
end

node_build -->|"builds"| node_platform
node_platform -->|"starts"| node_host
node_game_select -->|"selects content roots"| node_filesystem
node_archives -->|"mounted by"| node_filesystem
node_host -->|"initializes"| node_game_select
node_host -->|"runs"| node_commands
node_commands -->|"updates"| node_cvars
node_host -->|"ticks"| node_server
node_host -->|"ticks"| node_client_state
node_server -->|"simulates"| node_physics
node_server -->|"produces"| node_snapshots
node_snapshots -->|"sends through"| node_network
node_network -->|"delivers state"| node_client_state
node_client_state -->|"builds"| node_view_entities
node_view_entities -->|"submits scene"| node_renderer
node_renderer -->|"executes draws"| node_draw_backend
node_filesystem -->|"loads assets for"| node_client_state
node_filesystem -->|"loads maps for"| node_server
node_server -->|"runs game logic"| node_program_vm
node_client_state -->|"runs client scripts"| node_program_vm
node_program_vm -->|"uses server API"| node_server_vm_bridge
node_program_vm -->|"uses client API"| node_client_vm_bridge

click node_platform "https://github.com/xonotic/darkplaces/blob/master/sys_sdl.c"
click node_build "https://github.com/xonotic/darkplaces/tree/master/makefile"
click node_game_select "https://github.com/xonotic/darkplaces/blob/master/com_game.c"
click node_filesystem "https://github.com/xonotic/darkplaces/blob/master/fs.c"
click node_archives "https://github.com/xonotic/darkplaces/blob/master/wad.c"
click node_host "https://github.com/xonotic/darkplaces/blob/master/host.c"
click node_commands "https://github.com/xonotic/darkplaces/blob/master/cmd.c"
click node_cvars "https://github.com/xonotic/darkplaces/blob/master/cvar.c"
click node_server "https://github.com/xonotic/darkplaces/blob/master/sv_main.c"
click node_physics "https://github.com/xonotic/darkplaces/blob/master/sv_phys.c"
click node_network "https://github.com/xonotic/darkplaces/blob/master/netconn.c"
click node_snapshots "https://github.com/xonotic/darkplaces/blob/master/sv_send.c"
click node_client_state "https://github.com/xonotic/darkplaces/blob/master/cl_main.c"
click node_view_entities "https://github.com/xonotic/darkplaces/blob/master/cl_ents.c"
click node_renderer "https://github.com/xonotic/darkplaces/blob/master/gl_rmain.c"
click node_draw_backend "https://github.com/xonotic/darkplaces/blob/master/gl_backend.c"
click node_program_vm "https://github.com/xonotic/darkplaces/blob/master/prvm_exec.c"
click node_server_vm_bridge "https://github.com/xonotic/darkplaces/blob/master/svvm_cmds.c"
click node_client_vm_bridge "https://github.com/xonotic/darkplaces/blob/master/clvm_cmds.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_platform,node_build,node_game_select,node_filesystem,node_archives toneBlue
class node_host,node_commands,node_cvars toneAmber
class node_server,node_physics,node_network,node_snapshots toneMint
class node_client_state,node_view_entities,node_renderer,node_draw_backend toneRose
class node_program_vm,node_server_vm_bridge,node_client_vm_bridge toneIndigo
```

## Components

### Bootstrap & content

- [Platform runtime](https://github.com/xonotic/darkplaces/blob/master/sys_sdl.c): SDL / system · Initializes desktop and WebAssembly runtime targets. · `sys_sdl.c`
- [Build targets](https://github.com/xonotic/darkplaces/tree/master/makefile): make build · Defines core desktop and dedicated build variants. · `makefile`
- [Game selection](https://github.com/xonotic/darkplaces/blob/master/com_game.c): game profiles · Chooses game behavior and defaults before content loading. · `com_game.c`
- [Virtual filesystem](https://github.com/xonotic/darkplaces/blob/master/fs.c): content mount · Merges game directories and archives behind one asset boundary. · `fs.c`
- [Archive formats](https://github.com/xonotic/darkplaces/blob/master/wad.c): content packages · `wad.c`

### Host control plane

- [Host lifecycle](https://github.com/xonotic/darkplaces/blob/master/host.c): engine loop · Coordinates initialization, frames, local roles, and shutdown. · `host.c`
- [Commands & console](https://github.com/xonotic/darkplaces/blob/master/cmd.c): control interface · Parses startup and runtime commands for console and scripts. · `cmd.c`
- [Configuration variables](https://github.com/xonotic/darkplaces/blob/master/cvar.c): settings registry · `cvar.c`

### Simulation & networking

- [Server world](https://github.com/xonotic/darkplaces/blob/master/sv_main.c): authoritative simulation · Owns world state, clients, saves, and demo behavior. · `sv_main.c`
- [Server physics](https://github.com/xonotic/darkplaces/blob/master/sv_phys.c): movement simulation · `sv_phys.c`
- [Network transport](https://github.com/xonotic/darkplaces/blob/master/netconn.c): connection layer · Carries client/server connections and protocol messages. · `netconn.c`
- [Entity snapshots](https://github.com/xonotic/darkplaces/blob/master/sv_send.c): server replication · `sv_send.c`

### Client & rendering

- [Client state](https://github.com/xonotic/darkplaces/blob/master/cl_main.c): client runtime · Consumes network or demo state and manages client execution. · `cl_main.c`
- [View & entities](https://github.com/xonotic/darkplaces/blob/master/cl_ents.c): scene assembly · Builds view state and renderable entities. · `cl_ents.c`
- [OpenGL renderer](https://github.com/xonotic/darkplaces/blob/master/gl_rmain.c): render pipeline · Owns world, models, textures, shaders, and lighting submission. · `gl_rmain.c`
- [Draw backend](https://github.com/xonotic/darkplaces/blob/master/gl_backend.c): GPU execution · `gl_backend.c`

### QuakeC runtime

- [Program VM](https://github.com/xonotic/darkplaces/blob/master/prvm_exec.c): QuakeC bytecode VM · Executes bytecode and stores script entities. · `prvm_exec.c`
- [Server VM bridge](https://github.com/xonotic/darkplaces/blob/master/svvm_cmds.c): QuakeC engine API · Exposes server engine capabilities to game scripts. · `svvm_cmds.c`
- [Client VM bridge](https://github.com/xonotic/darkplaces/blob/master/clvm_cmds.c): QuakeC engine API · Exposes client engine capabilities to scripts. · `clvm_cmds.c`

## Connections

- 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
