# aheadley/homeworld architecture

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

- Interactive diagram: https://gitdiagram.com/aheadley/homeworld
- Repository: https://github.com/aheadley/homeworld

## Overview

1. This repository is the source release of the original Homeworld PC game. Architecturally it is a classic Windows game split into a runtime executable, a large shared game engine, a content repository, and a separate production/tooling pipeline.

2. The runtime entry point is the Win32 layer under `src/Win32`, which contains `main.c`, render/audio/input glue, DirectDraw/Direct3D setup, optional 3dfx/Glide support, windowing, screenshots, and low-level platform services. This layer is the boundary between the OS and the game engine.

3. The core gameplay engine lives in `src/Game`. It owns the universe simulation, object model, physics, combat, selection/camera, UI, save/load, objectives, resources, taskbar/menus, and single-player/multiplayer session control. Most higher-level systems are exposed here as C modules and headers rather than as a modern subsystem framework.

4. AI is a major internal subsystem inside `src/Game`, organized into dedicated managers for attack, defense, fleets, resources, teams, movement, and orders. The AI layer talks to the rest of the engine through shared object, command, and team abstractions rather than directly manipulating rendering or platform code.

5. Ship behavior is factored into `src/Ships`, where each ship or structure type has its own module plus a shared default implementation. These modules plug into the game object system and define race-specific variants, production units, support units, and special structures.

6. Campaign and scenario logic is driven by scripting and mission data. `src/SinglePlayer` contains mission scripts and mission databases, while `src/Game/KAS*` implements the KAS scripting runtime and helpers. The tutorial system and mission objectives connect scripted events to in-engine triggers and state changes.

7. Multiplayer is a distinct subsystem. `src/Game/Multiplayer*`, `titannet`, `CommandNetwork`, and related modules implement session flow, networking, chat, commands, and synchronization. The `src/Titan` tree provides the underlying network/auth/message framework used by Homeworld’s online services and multiplayer transport.

8. Rendering and media are supported by several specialized code paths. `src/rgl` is the low-level graphics layer with software, Direct3D, and Glide-era backends, while `src/JPG` provides JPEG decoding. The tree also includes Bink/Smacker libraries and sound banks, showing that video, audio, and speech are integrated as separate asset pipelines rather than being generated at runtime.

9. The content side is large and format-driven. `EB Levels` holds built level assets such as `.level`, `.mdr`, `.HSF`, `.btg`, `.missphere`, and `.dist` files, while `sound/` stores speech and SFX bank definitions. The game runtime loads these authored assets directly, so the diagram should show a strong “data files into engine” path.

10. `tools/win32` is the production toolchain that feeds the game. It includes exporters and editors for missions, textures, fonts, sound effects, bigfile packing, CD keys, video tweaks, and object/level conversion (`MissionMan`, `Biggie`, `BTG`, `Paco`, `FEMan`, `SFXTool`, `SPTool`, etc.). These tools generate the formats consumed by the runtime and are part of the build/content pipeline, not the shipped game loop.

11. The repository also carries external dependencies and platform libraries under `Lib/` and `src/Titan/`/`src/rgl/`, including DirectX, Glide, and custom WON/Titan networking components. These dependencies materially shape the architecture because they define the game’s rendering, networking, and service integration boundaries.

12. For an architecture diagram, the clearest top-level view is: Windows executable and low-level drivers on one side; the core game engine in the middle; ship/AI/script/multiplayer modules around it; and a separate asset/tool pipeline feeding mission, level, sound, and archive data into the runtime.

Main entry points: [`src/Game`](https://github.com/aheadley/homeworld/tree/master/src/Game) (Game core), [`src/SinglePlayer`](https://github.com/aheadley/homeworld/tree/master/src/SinglePlayer) (Single player), [`src/Win32/main.c`](https://github.com/aheadley/homeworld/blob/master/src/Win32/main.c) (Win32 layer), [`src/Win32/render.c`](https://github.com/aheadley/homeworld/blob/master/src/Win32/render.c) (Device glue)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_exe_homeworld["Homeworld.exe<br/>runtime binary<br/>[Homeworld.exe]"]
  node_win32_main["Win32 layer<br/>platform glue<br/>[main.c]"]
  node_win32_render["Device glue<br/>graphics/audio I/O<br/>[render.c]"]
  node_rgl["rgl<br/>graphics backend"]
end

subgraph group_engine["Game Engine"]
  node_game_core["Game core<br/>simulation engine"]
  node_ai["AI managers<br/>decision logic<br/>[AIHandler.c]"]
  node_ship_behaviors["Ship modules<br/>ship behaviors"]
  node_singleplayer["Single player<br/>mission runtime"]
  node_kas_runtime["KAS runtime<br/>scripting engine<br/>[KAS.c]"]
  node_multiplayer["Multiplayer<br/>network session<br/>[MultiplayerGame.c]"]
  node_titannet["Titan network<br/>net/auth framework"]
end

subgraph group_content["Content"]
  node_levels[("EB Levels<br/>level assets")]
  node_sound[("Sound banks<br/>audio assets")]
  node_tutorials["Tutorials<br/>tutorial data"]
end

subgraph group_tooling["Toolchain"]
  node_mission_tools["Mission tools<br/>scenario editors"]
  node_asset_tools["Asset tools<br/>exporters"]
  node_audio_tools["Audio tools<br/>audio pipeline"]
end

subgraph group_deps["Dependencies"]
  node_deps_dx["DirectX libs<br/>platform libs"]
  node_deps_titan["Titan libs<br/>network libs"]
end

node_exe_homeworld -->|"starts in"| node_win32_main
node_win32_main -->|"configures"| node_win32_render
node_win32_render -->|"drives"| node_rgl
node_win32_main -->|"boots"| node_game_core
node_game_core -->|"hosts"| node_ai
node_game_core -->|"invokes"| node_ship_behaviors
node_game_core -->|"runs"| node_singleplayer
node_singleplayer -->|"scripts via"| node_kas_runtime
node_game_core -->|"coordinates"| node_multiplayer
node_multiplayer -->|"uses"| node_titannet
node_win32_render -->|"links"| node_deps_dx
node_multiplayer -->|"links"| node_deps_titan
node_levels -->|"loaded by"| node_game_core
node_sound -->|"loaded by"| node_game_core
node_tutorials -->|"feeds"| node_singleplayer
node_mission_tools -->|"generates"| node_singleplayer
node_asset_tools -->|"produces"| node_levels
node_audio_tools -->|"produces"| node_sound
node_asset_tools -.->|"supports"| node_rgl

click node_exe_homeworld "https://github.com/aheadley/homeworld/blob/master/exe/Homeworld.exe"
click node_win32_main "https://github.com/aheadley/homeworld/blob/master/src/Win32/main.c"
click node_win32_render "https://github.com/aheadley/homeworld/blob/master/src/Win32/render.c"
click node_rgl "https://github.com/aheadley/homeworld/tree/master/src/rgl"
click node_game_core "https://github.com/aheadley/homeworld/tree/master/src/Game"
click node_ai "https://github.com/aheadley/homeworld/blob/master/src/Game/AIHandler.c"
click node_ship_behaviors "https://github.com/aheadley/homeworld/tree/master/src/Ships"
click node_singleplayer "https://github.com/aheadley/homeworld/tree/master/src/SinglePlayer"
click node_kas_runtime "https://github.com/aheadley/homeworld/blob/master/src/Game/KAS.c"
click node_multiplayer "https://github.com/aheadley/homeworld/blob/master/src/Game/MultiplayerGame.c"
click node_titannet "https://github.com/aheadley/homeworld/tree/master/src/Titan"
click node_levels "https://github.com/aheadley/homeworld/tree/master/EB Levels"
click node_sound "https://github.com/aheadley/homeworld/tree/master/sound"
click node_tutorials "https://github.com/aheadley/homeworld/tree/master/src/Tutorials"
click node_mission_tools "https://github.com/aheadley/homeworld/tree/master/tools/win32/Mission"
click node_asset_tools "https://github.com/aheadley/homeworld/tree/master/tools/win32"
click node_audio_tools "https://github.com/aheadley/homeworld/tree/master/tools/bin/SFXTool"
click node_deps_dx "https://github.com/aheadley/homeworld/tree/master/Lib/d3d"
click node_deps_titan "https://github.com/aheadley/homeworld/tree/master/Lib/Titan"

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_exe_homeworld,node_win32_main,node_win32_render,node_rgl toneBlue
class node_game_core,node_ai,node_ship_behaviors,node_singleplayer,node_kas_runtime,node_multiplayer,node_titannet toneAmber
class node_levels,node_sound,node_tutorials toneMint
class node_mission_tools,node_asset_tools,node_audio_tools toneRose
class node_deps_dx,node_deps_titan toneIndigo
```

## Components

### Runtime

Windows executable and platform layer

- [Homeworld.exe](https://github.com/aheadley/homeworld/blob/master/exe/Homeworld.exe): runtime binary · Shipped Windows game executable · `exe/Homeworld.exe`
- [Win32 layer](https://github.com/aheadley/homeworld/blob/master/src/Win32/main.c): platform glue · OS boundary, launcher, and low-level platform services · `src/Win32/main.c`
- [Device glue](https://github.com/aheadley/homeworld/blob/master/src/Win32/render.c): graphics/audio I/O · DirectDraw, Direct3D, Glide, sound, input, and screenshots · `src/Win32/render.c`
- [rgl](https://github.com/aheadley/homeworld/tree/master/src/rgl): graphics backend · Software, Direct3D, and Glide-era rendering layer · `src/rgl`

### Game Engine

Core simulation, AI, scripts, multiplayer, and ship behavior

- [Game core](https://github.com/aheadley/homeworld/tree/master/src/Game): simulation engine · Universe, objects, physics, combat, UI, save/load, and session control · `src/Game`
- [AI managers](https://github.com/aheadley/homeworld/blob/master/src/Game/AIHandler.c): decision logic · Attack, defense, fleets, movement, orders, teams, and resource AI · `src/Game/AIHandler.c`
- [Ship modules](https://github.com/aheadley/homeworld/tree/master/src/Ships): ship behaviors · Per-ship and per-structure behavior modules plus defaults · `src/Ships`
- [Single player](https://github.com/aheadley/homeworld/tree/master/src/SinglePlayer): mission runtime · Mission scripts, mission databases, tutorial flow, and objectives · `src/SinglePlayer`
- [KAS runtime](https://github.com/aheadley/homeworld/blob/master/src/Game/KAS.c): scripting engine · Mission scripting runtime and helper functions · `src/Game/KAS.c`
- [Multiplayer](https://github.com/aheadley/homeworld/blob/master/src/Game/MultiplayerGame.c): network session · Session flow, chat, commands, and synchronization · `src/Game/MultiplayerGame.c`
- [Titan network](https://github.com/aheadley/homeworld/tree/master/src/Titan): net/auth framework · Underlying WON/Titan networking and service integration · `src/Titan`

### Content

Authored assets and mission data loaded by the game

- [EB Levels](https://github.com/aheadley/homeworld/tree/HEAD/EB%20Levels): level assets · Authored level, mission, geometry, and scenario data · `EB Levels`
- [Sound banks](https://github.com/aheadley/homeworld/tree/master/sound): audio assets · Speech and SFX bank definitions consumed by the runtime · `sound`
- [Tutorials](https://github.com/aheadley/homeworld/tree/master/src/Tutorials): tutorial data · Tutorial mission scripts and databases · `src/Tutorials`

### Toolchain

Editors and exporters that produce runtime data

- [Mission tools](https://github.com/aheadley/homeworld/tree/master/tools/win32/Mission): scenario editors · MissionMan and mission-format tooling for authored scenarios · `tools/win32/Mission`
- [Asset tools](https://github.com/aheadley/homeworld/tree/master/tools/win32): exporters · Geometry, texture, font, and package conversion tools · `tools/win32`
- [Audio tools](https://github.com/aheadley/homeworld/tree/master/tools/bin/SFXTool): audio pipeline · Speech and SFX bank builders and related asset editors · `tools/bin/SFXTool`

### Dependencies

External libraries and service SDKs

- [DirectX libs](https://github.com/aheadley/homeworld/tree/master/Lib/d3d): platform libs · DirectDraw, Direct3D, DirectInput, and sound libraries · `Lib/d3d`
- [Titan libs](https://github.com/aheadley/homeworld/tree/master/Lib/Titan): network libs · Compiled Titan/WON client libraries · `Lib/Titan`

## Connections

- Homeworld.exe → Win32 layer: starts in · Executable enters through the Win32 platform layer
- Win32 layer → Device glue: configures · Initializes graphics, audio, input, and window services
- Device glue → rgl: drives · Platform layer delegates rendering to the graphics backend
- Win32 layer → Game core: boots · Platform layer hands control to the game engine
- Game core → AI managers: hosts · Core simulation provides shared state and command/object abstractions to AI
- Game core → Ship modules: invokes · Object model resolves ship- and structure-specific behavior modules
- Game core → Single player: runs · Core engine executes mission and campaign flow
- Single player → KAS runtime: scripts via · Mission logic is executed through KAS scripting support
- Game core → Multiplayer: coordinates · Session control and in-game multiplayer state live in the engine
- Multiplayer → Titan network: uses · Multiplayer/network features depend on Titan/WON messaging and transport
- Device glue → DirectX libs: links · Rendering and device setup are backed by DirectX-era libraries
- Multiplayer → Titan libs: links · Online services and transport use Titan libraries
- EB Levels → Game core: loaded by · Runtime loads level and mission assets directly into the engine
- Sound banks → Game core: loaded by · Speech and SFX banks are consumed by runtime audio systems
- Tutorials → Single player: feeds · Tutorial data is consumed by the single-player mission flow
- Mission tools → Single player: generates · Mission editors produce .kas and mission database content
- Asset tools → EB Levels: produces · Exporters and packers generate level, geometry, and archive assets
- Audio tools → Sound banks: produces · Audio tools build the speech and SFX bank assets
- Asset tools → rgl: supports · Texture and geometry tools align with rendering formats and pipelines
