How bsegovia/cube works
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: client.cpp Client · main.cpp Main · clients2c.cpp Networking · server.cpp Server
Components 20
Runtime
Core game engine and executable subsystems
- Main · Process entry point and engine bootstrap
src/main.cpp - Client · Owns local input, presentation, and player-side flow
src/client.cpp - Server · Maintains authoritative multiplayer and session state
src/server.cpp - World · Shared world state and high-level world coordination
src/world.cpp - GL Render · OpenGL setup and backend rendering support
src/rendergl.cpp - World Render · Turns world data into visible scene output
src/worldrender.cpp - UI Layer · Menus, console, and server browser interfaces
src/menus.cpp - Gameplay · Entity, physics, command, monster, and weapon rules
src/entities.cpp - Editing · In-place map editing and world mutation flow
src/editing.cpp - World I/O · Loads and saves map/world data
src/worldio.cpp - World Pipe · Map generation, lighting, culling, and visibility
src/rndmap.cpp - Networking · Game networking, protocol handling, and master-server flow
src/clients2c.cpp - Audio · Game and UI audio services
src/sound.cpp - Save/Demo · Save-game and demo capture support
src/savegamedemo.cpp
Platform
Vendored native dependencies and build artifacts
- SDL · Windowing, input, timing, and system integration
include/SDL/SDL.h - ENet · Reliable UDP transport library used by game networking
enet/include/enet/enet.h - OpenGL · Native graphics API used for rendering
include/SDL/SDL_opengl.h - Media Libs · Bundled image, mixer, FMOD, and compression headers/libs
include/fmod.h - Builds · Unix and Visual Studio build entry points
src/Makefile
Connections 24
- 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