# bsegovia/cube architecture

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

- Interactive diagram: https://gitdiagram.com/bsegovia/cube
- Repository: https://github.com/bsegovia/cube

## Overview

1. This repository is the Cube game engine/game codebase, written in C++, with a single native desktop executable split into client, server, rendering, world, UI, and tooling subsystems. The source tree is intentionally small and modular, but the runtime is still a full game engine rather than a library.

2. The main architectural boundary is between the thick client and the thin server. The client owns input, rendering, UI, audio, and much of the moment-to-moment gameplay presentation; the server owns authoritative multiplayer state, world state updates, and session coordination. The README explicitly calls out this as a cheat-sensitive design choice.

3. Platform and middleware dependencies are vendored into the repo and materially shape the architecture: SDL handles windowing/input/timing and some system services, OpenGL handles graphics, ENet provides networking, and the bundled headers/libs show support for SDL_image, SDL_mixer, zlib, libpng, and FMOD. The code is therefore a native, dependency-linked game engine, not a managed/runtime-based app.

4. `src/main.cpp` is the process entry point and initialization hub. From there, the engine brings up config, graphics, audio, networking, and the main loop that coordinates client-side rendering/simulation with server-side state handling.

5. The client-side presentation stack is split across several focused renderers: `rendergl.cpp` for OpenGL setup/backend work, `rendercubes.cpp` for cube/world geometry, `renderextras.cpp` for additional scene elements, `rendermd2.cpp` for animated model rendering, `renderparticles.cpp` for effects, and `rendertext.cpp` for text/UI drawing. `menus.cpp`, `console.cpp`, and `serverbrowser.cpp` form the user-facing UI layer on top of that.

6. Game simulation is organized around entity and interaction modules: `entities.cpp`, `monster.cpp`, `weapon.cpp`, `physics.cpp`, and `command.cpp` encode gameplay rules, actor behavior, movement, and command processing. `clientgame.cpp`, `client.cpp`, and `clientextras.cpp` appear to tie simulation state to what the local player sees and controls.

7. World handling is its own subsystem with a clear pipeline. `rndmap.cpp` handles map generation/randomization, `worldio.cpp` loads/saves map data, `worldlight.cpp` computes lighting, `worldocull.cpp` performs visibility/culling, and `worldrender.cpp` bridges world data into the rendering path. This is the main data flow from disk/map representation to visible scene.

8. Editing is a first-class mode, not a separate tool. `editing.cpp` updates the world in-place and connects to the same world I/O and rendering systems, which means the engine supports both play and map editing against the same core data structures.

9. Networking is built around ENet plus Cube-specific protocol code. The bundled `enet/` subtree is the transport layer, while the engine’s own `server.cpp`, `serverutil.cpp`, `serverms.cpp`, and protocol-related code handle game messages, server behavior, and master-server/browsing workflows. The network path is therefore: game state → protocol serialization → ENet transport → remote client/server state.

10. Persistence and replay/demo support exist as separate concerns. `savegamedemo.cpp` suggests save/demo capture, while config is represented by `src/config.cfg`. These are adjacent to, but distinct from, the core gameplay loop.

11. Audio is isolated in `sound.cpp` and backed by the bundled multimedia libraries. Sound is treated as a service consumed by gameplay and UI rather than being embedded in the rendering or physics code.

12. The repo also contains explicit build and distribution boundaries: `src/Makefile` for Unix-like builds, `vcpp/` for Visual Studio projects, plus `include/` and `lib/` folders that package third-party headers/import libraries. The `docs/` and `enet/docs/` trees are documentation, not runtime dependencies, but they help define the public/API and design boundaries of the engine.

Main entry points: [`src/client.cpp`](https://github.com/bsegovia/cube/blob/master/src/client.cpp) (Client), [`src/main.cpp`](https://github.com/bsegovia/cube/blob/master/src/main.cpp) (Main), [`src/clients2c.cpp`](https://github.com/bsegovia/cube/blob/master/src/clients2c.cpp) (Networking), [`src/server.cpp`](https://github.com/bsegovia/cube/blob/master/src/server.cpp) (Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main(("Main<br/>entrypoint<br/>[main.cpp]"))
  node_client["Client<br/>[client.cpp]"]
  node_server["Server<br/>[server.cpp]"]
  node_world["World<br/>[world.cpp]"]
  node_rendergl["GL Render<br/>graphics backend<br/>[rendergl.cpp]"]
  node_renderworld["World Render<br/>scene pipeline<br/>[worldrender.cpp]"]
  node_ui["UI Layer<br/>presentation ui<br/>[menus.cpp]"]
  node_simulation["Gameplay<br/>simulation<br/>[entities.cpp]"]
  node_editing["Editing<br/>edit mode<br/>[editing.cpp]"]
  node_worldio["World I/O<br/>map persistence<br/>[worldio.cpp]"]
  node_worldpipe["World Pipe<br/>[rndmap.cpp]"]
  node_network["Networking<br/>enet protocol<br/>[clients2c.cpp]"]
  node_audio["Audio<br/>sound service<br/>[sound.cpp]"]
  node_demo["Save/Demo<br/>persistence<br/>[savegamedemo.cpp]"]
end

subgraph group_platform["Platform"]
  node_sdl["SDL<br/>platform lib<br/>[SDL.h]"]
  node_enet["ENet<br/>network transport<br/>[enet.h]"]
  node_opengl["OpenGL<br/>graphics api<br/>[SDL_opengl.h]"]
  node_multimedia["Media Libs<br/>vendor libs<br/>[fmod.h]"]
  node_build["Builds<br/>build configs"]
end

subgraph group_docs["Docs"]
  node_docsnode["Docs<br/>documentation<br/>[game.html]"]
end

node_main -->|"starts"| node_client
node_main -->|"starts"| node_server
node_main -->|"initializes"| node_world
node_main -->|"initializes"| node_audio
node_main -->|"initializes"| node_network
node_client -->|"renders with"| node_rendergl
node_client -->|"presents"| node_ui
node_client -->|"drives"| node_simulation
node_client -->|"syncs"| node_network
node_server -->|"communicates"| node_network
node_server -->|"authorizes"| node_world
node_world -->|"processes"| node_worldpipe
node_worldpipe -->|"loads/saves"| node_worldio
node_worldio -->|"supports"| node_editing
node_editing -->|"updates"| node_renderworld
node_renderworld -->|"draws via"| node_rendergl
node_simulation -->|"serializes"| node_network
node_audio -->|"uses"| node_multimedia
node_rendergl -->|"depends on"| node_opengl
node_client -->|"depends on"| node_sdl
node_network -->|"depends on"| node_enet
node_client -->|"supports"| node_demo
node_build -.->|"builds"| node_client
node_docsnode -.->|"describes"| node_worldpipe

click node_main "https://github.com/bsegovia/cube/blob/master/src/main.cpp"
click node_client "https://github.com/bsegovia/cube/blob/master/src/client.cpp"
click node_server "https://github.com/bsegovia/cube/blob/master/src/server.cpp"
click node_world "https://github.com/bsegovia/cube/blob/master/src/world.cpp"
click node_rendergl "https://github.com/bsegovia/cube/blob/master/src/rendergl.cpp"
click node_renderworld "https://github.com/bsegovia/cube/blob/master/src/worldrender.cpp"
click node_ui "https://github.com/bsegovia/cube/blob/master/src/menus.cpp"
click node_simulation "https://github.com/bsegovia/cube/blob/master/src/entities.cpp"
click node_editing "https://github.com/bsegovia/cube/blob/master/src/editing.cpp"
click node_worldio "https://github.com/bsegovia/cube/blob/master/src/worldio.cpp"
click node_worldpipe "https://github.com/bsegovia/cube/blob/master/src/rndmap.cpp"
click node_network "https://github.com/bsegovia/cube/blob/master/src/clients2c.cpp"
click node_audio "https://github.com/bsegovia/cube/blob/master/src/sound.cpp"
click node_demo "https://github.com/bsegovia/cube/blob/master/src/savegamedemo.cpp"
click node_sdl "https://github.com/bsegovia/cube/blob/master/include/SDL/SDL.h"
click node_enet "https://github.com/bsegovia/cube/blob/master/enet/include/enet/enet.h"
click node_opengl "https://github.com/bsegovia/cube/blob/master/include/SDL/SDL_opengl.h"
click node_multimedia "https://github.com/bsegovia/cube/blob/master/include/fmod.h"
click node_build "https://github.com/bsegovia/cube/tree/master/src/Makefile"
click node_docsnode "https://github.com/bsegovia/cube/blob/master/docs/game.html"

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_main,node_client,node_server,node_world,node_rendergl,node_renderworld,node_ui,node_simulation,node_editing,node_worldio,node_worldpipe,node_network,node_audio,node_demo toneBlue
class node_sdl,node_enet,node_opengl,node_multimedia,node_build toneAmber
class node_docsnode toneMint
```

## Components

### Runtime

Core game engine and executable subsystems

- [Main](https://github.com/bsegovia/cube/blob/master/src/main.cpp): entrypoint · Process entry point and engine bootstrap · `src/main.cpp`
- [Client](https://github.com/bsegovia/cube/blob/master/src/client.cpp): game client · Owns local input, presentation, and player-side flow · `src/client.cpp`
- [Server](https://github.com/bsegovia/cube/blob/master/src/server.cpp): authoritative server · Maintains authoritative multiplayer and session state · `src/server.cpp`
- [World](https://github.com/bsegovia/cube/blob/master/src/world.cpp): world core · Shared world state and high-level world coordination · `src/world.cpp`
- [GL Render](https://github.com/bsegovia/cube/blob/master/src/rendergl.cpp): graphics backend · OpenGL setup and backend rendering support · `src/rendergl.cpp`
- [World Render](https://github.com/bsegovia/cube/blob/master/src/worldrender.cpp): scene pipeline · Turns world data into visible scene output · `src/worldrender.cpp`
- [UI Layer](https://github.com/bsegovia/cube/blob/master/src/menus.cpp): presentation ui · Menus, console, and server browser interfaces · `src/menus.cpp`
- [Gameplay](https://github.com/bsegovia/cube/blob/master/src/entities.cpp): simulation · Entity, physics, command, monster, and weapon rules · `src/entities.cpp`
- [Editing](https://github.com/bsegovia/cube/blob/master/src/editing.cpp): edit mode · In-place map editing and world mutation flow · `src/editing.cpp`
- [World I/O](https://github.com/bsegovia/cube/blob/master/src/worldio.cpp): map persistence · Loads and saves map/world data · `src/worldio.cpp`
- [World Pipe](https://github.com/bsegovia/cube/blob/master/src/rndmap.cpp): world pipeline · Map generation, lighting, culling, and visibility · `src/rndmap.cpp`
- [Networking](https://github.com/bsegovia/cube/blob/master/src/clients2c.cpp): enet protocol · Game networking, protocol handling, and master-server flow · `src/clients2c.cpp`
- [Audio](https://github.com/bsegovia/cube/blob/master/src/sound.cpp): sound service · Game and UI audio services · `src/sound.cpp`
- [Save/Demo](https://github.com/bsegovia/cube/blob/master/src/savegamedemo.cpp): persistence · Save-game and demo capture support · `src/savegamedemo.cpp`

### Platform

Vendored native dependencies and build artifacts

- [SDL](https://github.com/bsegovia/cube/blob/master/include/SDL/SDL.h): platform lib · Windowing, input, timing, and system integration · `include/SDL/SDL.h`
- [ENet](https://github.com/bsegovia/cube/blob/master/enet/include/enet/enet.h): network transport · Reliable UDP transport library used by game networking · `enet/include/enet/enet.h`
- [OpenGL](https://github.com/bsegovia/cube/blob/master/include/SDL/SDL_opengl.h): graphics api · Native graphics API used for rendering · `include/SDL/SDL_opengl.h`
- [Media Libs](https://github.com/bsegovia/cube/blob/master/include/fmod.h): vendor libs · Bundled image, mixer, FMOD, and compression headers/libs · `include/fmod.h`
- [Builds](https://github.com/bsegovia/cube/tree/master/src/Makefile): build configs · Unix and Visual Studio build entry points · `src/Makefile`

### Docs

Reference and design documentation

- [Docs](https://github.com/bsegovia/cube/blob/master/docs/game.html): documentation · Repository and engine documentation · `docs/game.html`

## Connections

- Main → Client: starts · Bootstraps client-side systems
- Main → Server: starts · Bootstraps server-side state
- Main → World: initializes · Sets up shared world state
- Main → Audio: initializes · Brings up sound services
- Main → Networking: initializes · Creates networking and session channels
- Client → GL Render: renders with · Client presentation uses OpenGL backend
- Client → UI Layer: presents · Client exposes menus, console, and browsing
- Client → Gameplay: drives · Local game flow and interaction logic
- Client → Networking: syncs · Sends and receives game messages
- Server → Networking: communicates · Server protocol and transport path
- Server → World: authorizes · Server owns authoritative world state
- World → World Pipe: processes · Generates, lights, and culls world data
- World Pipe → World I/O: loads/saves · World data moves through persistence layer
- World I/O → Editing: supports · Editing mutates the same persisted world data
- Editing → World Render: updates · Editor changes feed visible world output
- World Render → GL Render: draws via · World rendering submits through GL backend
- Gameplay → Networking: serializes · Gameplay state is exchanged over protocol
- Audio → Media Libs: uses · Backed by bundled audio/media libraries
- GL Render → OpenGL: depends on · Rendering backend uses OpenGL API
- Client → SDL: depends on · Input/windowing and timing services
- Networking → ENet: depends on · Game networking rides on ENet transport
- Client → Save/Demo: supports · Save and demo functionality on client side
- Builds → Client: builds · Project files and makefile compile the engine
- Docs → World Pipe: describes · Documentation covers world editing and game systems
