# sezero/uhexen2 architecture

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

- Interactive diagram: https://gitdiagram.com/sezero/uhexen2
- Repository: https://github.com/sezero/uhexen2

## Overview

#### Purpose and Deliverables
uHexen2 is a C-based, cross-platform source port of *Hexen II* and *HexenWorld*. It produces:
- Hexen II client and dedicated-server executables.
- HexenWorld multiplayer client and server executables.
- Content/build utilities, including QuakeC compilers, map tools, patching, and server administration tools.

Primary build entry points are `engine/hexen2/Makefile`, `engine/hexenworld/build.sh`, and `utils/build.sh`.

#### Engine Product Split
The repository separates game variants rather than using one uniform executable:
- **Hexen II client** owns host lifecycle, local client/server integration, menus, input, effects, and rendering: `engine/hexen2/host.c`, `engine/hexen2/cl_main.c`, `engine/hexen2/sv_main.c`.
- **Hexen II dedicated server** is a smaller platform-hosted target: `engine/hexen2/server/host.c`, `engine/hexen2/server/sys_unix.c`.
- **HexenWorld** explicitly separates multiplayer client, server, and shared protocol/movement code: `engine/hexenworld/client/cl_main.c`, `engine/hexenworld/server/sv_main.c`, `engine/hexenworld/shared/net_chan.c`.

#### Shared Engine Core and Runtime Loop
`engine/h2shared` is the core substrate used by the game targets. It provides command/cvar state, filesystem access, memory management, model loading, serialization, and script execution:
- Command/configuration and host-facing state: `engine/h2shared/cmd.c`, `engine/h2shared/cvar.c`, `engine/h2shared/cfgfile.c`.
- Virtual game filesystem and packed assets: `engine/h2shared/quakefs.c`, `engine/h2shared/wad.c`, `common/pakfile.h`.
- QuakeC VM boundary: engine code loads and executes compiled game programs through `engine/h2shared/pr_exec.c`, `engine/h2shared/pr_edict.c`, `engine/h2shared/progs.h`.

Control flow is broadly platform initialization → host/client or server frame loop → input/network processing → simulation/QuakeC execution → render/audio output.

#### Simulation, Networking, and Protocol Boundaries
The server owns authoritative world state, collision, physics, client command handling, and replication:
`engine/hexen2/sv_phys.c`, `engine/hexen2/sv_move.c`, `engine/hexen2/sv_user.c`.

Clients encode input, receive and parse server state, interpolate/predict where applicable, then render:
`engine/hexen2/cl_input.c`, `engine/hexen2/cl_parse.c`, `engine/hexenworld/client/cl_pred.c`.

Networking is datagram-oriented with loopback and OS-specific transports. Hexen II networking is centered in `engine/hexen2/net_main.c`, `engine/hexen2/net_udp.c`, and `engine/hexen2/protocol.h`; HexenWorld adds shared channel framing and Huffman compression in `engine/hexenworld/shared/net_chan.c` and `engine/hexenworld/shared/huffman.c`.

#### Rendering, Media, and Platform Adapters
Rendering has OpenGL and software-renderer paths. Common model/BSP and software rasterization live in `engine/h2shared/model.c`, `engine/h2shared/r_bsp.c`, and `engine/h2shared/d_surf.c`; product-level render orchestration is in `engine/hexen2/gl_rmain.c` and `engine/hexen2/r_main.c`.

System boundaries are selected per platform:
- SDL video/input/system integration: `engine/h2shared/vid_sdl.c`, `engine/h2shared/in_sdl.c`, `engine/h2shared/sys_sdl.c`.
- Native Windows/DOS/Amiga/OS2 alternatives are co-located in `engine/h2shared/vid_win.c`, `engine/h2shared/vid_dos.c`, and target-specific `sys_*.c`.
- Audio combines mixer/codec layers with platform backends: `engine/h2shared/snd_mix.c`, `engine/h2shared/snd_codec.c`, `engine/h2shared/snd_sdl.c`.

Bundled dependencies include SDL 1.2, OpenGL/DirectX-era headers, and audio codecs (FLAC, Ogg/Vorbis, Opus, MP3, MikMod, mpg123, xmp) under `oslibs/`.

#### Game Content and Build Pipeline
Game behavior is authored in QuakeC-like `.hc` sources, partitioned by original game and expansions/modes:
`gamecode/hc/h2/progs.src`, `gamecode/hc/hw/progs.src`, `gamecode/hc/portals/progs.src`.

These compile into VM program data consumed by the engine’s `pr_*` subsystem. Two compiler implementations are supplied: `utils/hcc/hcc.c` and `utils/dcc/dcc.c`.

Map/content production is a separate offline pipeline: BSP compilation (`utils/qbsp/qbsp.c`), visibility (`utils/vis/vis.c`), lighting (`utils/light/light.c`), and asset packaging (`utils/pak/pakfile.c`). Map entity overrides are shipped under `gamecode/mapfixes/`.

#### Operations and Supporting Executables
`h2patch/h2patch3.c` applies distribution patches using the vendored xdelta3 implementation in `libs/xdelta3/xdelta3.c`. HexenWorld server discovery/administration is supported by a master server and query/RCON tools: `hw_utils/hwmaster/master.c`, `hw_utils/hwmquery/hwmquery.c`, and `hw_utils/hwrcon/hwrcon.c`.

CI currently includes a Linux build workflow at `.github/workflows/build-linux.yml`.

Main entry points: [`engine/hexen2/Makefile`](https://github.com/sezero/uhexen2/blob/master/engine/hexen2/Makefile) (Build entry points), [`engine/hexen2/host.c`](https://github.com/sezero/uhexen2/blob/master/engine/hexen2/host.c) (Hexen II client), [`engine/h2shared/cmd.c`](https://github.com/sezero/uhexen2/blob/master/engine/h2shared/cmd.c) (Shared engine core), [`engine/hexenworld/server/sv_main.c`](https://github.com/sezero/uhexen2/blob/master/engine/hexenworld/server/sv_main.c) (HexenWorld server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_products["Engine Products"]
  node_h2_client["Hexen II client<br/>client executable<br/>[host.c]"]
  node_h2_dedicated["Hexen II dedicated server<br/>server executable<br/>[host.c]"]
  node_hw_client["HexenWorld client<br/>multiplayer client<br/>[cl_main.c]"]
  node_hw_server["HexenWorld server<br/>multiplayer server<br/>[sv_main.c]"]
  node_h2_server_sim["Hexen II simulation<br/>authoritative simulation<br/>[sv_phys.c]"]
  node_h2_network["Hexen II networking<br/>datagram protocol<br/>[net_main.c]"]
  node_hw_protocol["HexenWorld protocol<br/>channel framing<br/>[net_chan.c]"]
end

subgraph group_core["Shared Runtime"]
  node_shared_core["Shared engine core<br/>runtime substrate<br/>[cmd.c]"]
  node_vfs_assets[("Virtual filesystem<br/>asset access<br/>[quakefs.c]")]
  node_quakec_vm{{"QuakeC VM<br/>script runtime<br/>[pr_exec.c]"}}
  node_render_media["Rendering and audio<br/>media subsystem<br/>[model.c]"]
  node_platform_adapters["Platform adapters<br/>system integration<br/>[vid_sdl.c]"]
end

subgraph group_content["Content Pipeline"]
  node_game_sources["Game QuakeC sources<br/>game behavior source<br/>[progs.src]"]
  node_qc_compilers["QuakeC compilers<br/>build utility<br/>[hcc.c]"]
  node_vm_programs["Compiled game programs<br/>VM data<br/>[progs.src]"]
  node_map_toolchain["Map toolchain<br/>offline build tools<br/>[qbsp.c]"]
end

subgraph group_operations["Operations"]
  node_patcher["Distribution patcher<br/>patch utility<br/>[h2patch3.c]"]
  node_hw_operations["HexenWorld operations<br/>master and admin tools<br/>[master.c]"]
end

node_build_entrypoints["Build entry points<br/>build scripts"]
node_linux_ci["Linux CI<br/>build workflow<br/>[build-linux.yml]"]

node_build_entrypoints -->|"builds"| node_h2_client
node_build_entrypoints -->|"builds"| node_h2_dedicated
node_build_entrypoints -->|"builds"| node_hw_client
node_build_entrypoints -->|"builds"| node_hw_server
node_build_entrypoints -->|"builds"| node_qc_compilers
node_linux_ci -->|"runs"| node_build_entrypoints
node_h2_client -->|"uses"| node_shared_core
node_h2_dedicated -->|"uses"| node_shared_core
node_hw_client -->|"uses"| node_shared_core
node_hw_server -->|"uses"| node_shared_core
node_shared_core -->|"loads assets through"| node_vfs_assets
node_shared_core -->|"hosts"| node_quakec_vm
node_h2_client -.->|"local server loop"| node_h2_server_sim
node_h2_dedicated -->|"runs"| node_h2_server_sim
node_h2_client -->|"sends input and receives state"| node_h2_network
node_h2_server_sim -->|"replicates state"| node_h2_network
node_hw_client -->|"uses"| node_hw_protocol
node_hw_server -->|"uses"| node_hw_protocol
node_h2_client -->|"renders and plays audio"| node_render_media
node_render_media -->|"uses backends"| node_platform_adapters
node_platform_adapters -.->|"initializes runtime"| node_h2_client
node_game_sources -->|"compiled by"| node_qc_compilers
node_qc_compilers -->|"produces"| node_vm_programs
node_vm_programs -->|"executed by"| node_quakec_vm
node_map_toolchain -->|"produces packaged content"| node_vfs_assets
node_patcher -.->|"patches distributions"| node_vfs_assets
node_hw_operations -->|"discovers and administers"| node_hw_server

click node_h2_client "https://github.com/sezero/uhexen2/blob/master/engine/hexen2/host.c"
click node_h2_dedicated "https://github.com/sezero/uhexen2/blob/master/engine/hexen2/server/host.c"
click node_hw_client "https://github.com/sezero/uhexen2/blob/master/engine/hexenworld/client/cl_main.c"
click node_hw_server "https://github.com/sezero/uhexen2/blob/master/engine/hexenworld/server/sv_main.c"
click node_shared_core "https://github.com/sezero/uhexen2/blob/master/engine/h2shared/cmd.c"
click node_vfs_assets "https://github.com/sezero/uhexen2/blob/master/engine/h2shared/quakefs.c"
click node_quakec_vm "https://github.com/sezero/uhexen2/blob/master/engine/h2shared/pr_exec.c"
click node_h2_server_sim "https://github.com/sezero/uhexen2/blob/master/engine/hexen2/sv_phys.c"
click node_h2_network "https://github.com/sezero/uhexen2/blob/master/engine/hexen2/net_main.c"
click node_hw_protocol "https://github.com/sezero/uhexen2/blob/master/engine/hexenworld/shared/net_chan.c"
click node_render_media "https://github.com/sezero/uhexen2/blob/master/engine/h2shared/model.c"
click node_platform_adapters "https://github.com/sezero/uhexen2/blob/master/engine/h2shared/vid_sdl.c"
click node_game_sources "https://github.com/sezero/uhexen2/blob/master/gamecode/hc/h2/progs.src"
click node_qc_compilers "https://github.com/sezero/uhexen2/blob/master/utils/hcc/hcc.c"
click node_vm_programs "https://github.com/sezero/uhexen2/blob/master/gamecode/hc/hw/progs.src"
click node_map_toolchain "https://github.com/sezero/uhexen2/blob/master/utils/qbsp/qbsp.c"
click node_patcher "https://github.com/sezero/uhexen2/blob/master/h2patch/h2patch3.c"
click node_hw_operations "https://github.com/sezero/uhexen2/blob/master/hw_utils/hwmaster/master.c"
click node_build_entrypoints "https://github.com/sezero/uhexen2/blob/master/engine/hexen2/Makefile"
click node_linux_ci "https://github.com/sezero/uhexen2/blob/master/.github/workflows/build-linux.yml"

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_h2_client,node_h2_dedicated,node_hw_client,node_hw_server,node_h2_server_sim,node_h2_network,node_hw_protocol toneBlue
class node_shared_core,node_vfs_assets,node_quakec_vm,node_render_media,node_platform_adapters toneAmber
class node_game_sources,node_qc_compilers,node_vm_programs,node_map_toolchain toneMint
class node_patcher,node_hw_operations toneRose
class node_build_entrypoints,node_linux_ci toneNeutral
```

## Components

### Engine Products

- [Hexen II client](https://github.com/sezero/uhexen2/blob/master/engine/hexen2/host.c): client executable · Integrated local client/server game runtime. · `engine/hexen2/host.c`
- [Hexen II dedicated server](https://github.com/sezero/uhexen2/blob/master/engine/hexen2/server/host.c): server executable · `engine/hexen2/server/host.c`
- [HexenWorld client](https://github.com/sezero/uhexen2/blob/master/engine/hexenworld/client/cl_main.c): multiplayer client · `engine/hexenworld/client/cl_main.c`
- [HexenWorld server](https://github.com/sezero/uhexen2/blob/master/engine/hexenworld/server/sv_main.c): multiplayer server · `engine/hexenworld/server/sv_main.c`
- [Hexen II simulation](https://github.com/sezero/uhexen2/blob/master/engine/hexen2/sv_phys.c): authoritative simulation · Physics, movement, commands, and replication. · `engine/hexen2/sv_phys.c`
- [Hexen II networking](https://github.com/sezero/uhexen2/blob/master/engine/hexen2/net_main.c): datagram protocol · Loopback and UDP transports with game protocol. · `engine/hexen2/net_main.c`
- [HexenWorld protocol](https://github.com/sezero/uhexen2/blob/master/engine/hexenworld/shared/net_chan.c): channel framing · Shared framing and Huffman compression. · `engine/hexenworld/shared/net_chan.c`

### Shared Runtime

- [Shared engine core](https://github.com/sezero/uhexen2/blob/master/engine/h2shared/cmd.c): runtime substrate · Commands, cvars, memory, files, models, and serialization. · `engine/h2shared/cmd.c`
- [Virtual filesystem](https://github.com/sezero/uhexen2/blob/master/engine/h2shared/quakefs.c): asset access · Loads game files and packed assets. · `engine/h2shared/quakefs.c`
- [QuakeC VM](https://github.com/sezero/uhexen2/blob/master/engine/h2shared/pr_exec.c): script runtime · Loads and executes compiled game programs. · `engine/h2shared/pr_exec.c`
- [Rendering and audio](https://github.com/sezero/uhexen2/blob/master/engine/h2shared/model.c): media subsystem · OpenGL/software rendering plus mixer and codecs. · `engine/h2shared/model.c`
- [Platform adapters](https://github.com/sezero/uhexen2/blob/master/engine/h2shared/vid_sdl.c): system integration · SDL and native video, input, system, and audio backends. · `engine/h2shared/vid_sdl.c`

### Content Pipeline

- [Game QuakeC sources](https://github.com/sezero/uhexen2/blob/master/gamecode/hc/h2/progs.src): game behavior source · Base, HexenWorld, and Portal of Praevus programs. · `gamecode/hc/h2/progs.src`
- [QuakeC compilers](https://github.com/sezero/uhexen2/blob/master/utils/hcc/hcc.c): build utility · Two supplied compilers produce VM programs. · `utils/hcc/hcc.c`
- [Compiled game programs](https://github.com/sezero/uhexen2/blob/master/gamecode/hc/hw/progs.src): VM data · `gamecode/hc/hw/progs.src`
- [Map toolchain](https://github.com/sezero/uhexen2/blob/master/utils/qbsp/qbsp.c): offline build tools · BSP, visibility, lighting, and package generation. · `utils/qbsp/qbsp.c`

### Operations

- [Distribution patcher](https://github.com/sezero/uhexen2/blob/master/h2patch/h2patch3.c): patch utility · Applies patches through vendored xdelta3. · `h2patch/h2patch3.c`
- [HexenWorld operations](https://github.com/sezero/uhexen2/blob/master/hw_utils/hwmaster/master.c): master and admin tools · Server discovery, query, and RCON support. · `hw_utils/hwmaster/master.c`

### Other components

- [Build entry points](https://github.com/sezero/uhexen2/blob/master/engine/hexen2/Makefile): build scripts · Builds engine variants and utilities. · `engine/hexen2/Makefile`
- [Linux CI](https://github.com/sezero/uhexen2/blob/master/.github/workflows/build-linux.yml): build workflow · `.github/workflows/build-linux.yml`

## Connections

- Build entry points → Hexen II client: builds
- Build entry points → Hexen II dedicated server: builds
- Build entry points → HexenWorld client: builds
- Build entry points → HexenWorld server: builds
- Build entry points → QuakeC compilers: builds
- Linux CI → Build entry points: runs
- Hexen II client → Shared engine core: uses
- Hexen II dedicated server → Shared engine core: uses
- HexenWorld client → Shared engine core: uses
- HexenWorld server → Shared engine core: uses
- Shared engine core → Virtual filesystem: loads assets through
- Shared engine core → QuakeC VM: hosts
- Hexen II client → Hexen II simulation: local server loop
- Hexen II dedicated server → Hexen II simulation: runs
- Hexen II client → Hexen II networking: sends input and receives state
- Hexen II simulation → Hexen II networking: replicates state
- HexenWorld client → HexenWorld protocol: uses
- HexenWorld server → HexenWorld protocol: uses
- Hexen II client → Rendering and audio: renders and plays audio
- Rendering and audio → Platform adapters: uses backends
- Platform adapters → Hexen II client: initializes runtime
- Game QuakeC sources → QuakeC compilers: compiled by
- QuakeC compilers → Compiled game programs: produces
- Compiled game programs → QuakeC VM: executed by
- Map toolchain → Virtual filesystem: produces packaged content
- Distribution patcher → Virtual filesystem: patches distributions
- HexenWorld operations → HexenWorld server: discovers and administers
