# 1111windows/supertux architecture

> Architecture diagram of the GitHub repository 1111windows/supertux, 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/1111windows/supertux
- Repository: https://github.com/1111windows/supertux

## Overview

SuperTux is a C++ game engine plus content bundle, not just a single executable. The runtime is organized around a core engine in `src/` and a large, data-driven game world under `data/` containing levels, sprites, sounds, music, translations, and scripts.

1. **Entry point and top-level orchestration**  
   Execution starts in `src/main.cpp` and `src/supertux/main.cpp`, then hands off to the game/session and screen management layer. The central control flow is screen-based: `screen_manager`, `game_manager`, and `game_session` coordinate transitions between title screen, menus, level play, world map, editor, cutscenes, and other modes.

2. **Game state and level runtime**  
   The core runtime model lives in `src/supertux/`. `level`, `sector`, `world`, `levelset`, `player_status`, `savegame`, and `statistics` represent the playable state. Level loading is parser-driven (`level_parser`, `sector_parser`, `worldmap_sector_parser`) and converts files in `data/levels/**` into runtime objects.

3. **Object and entity system**  
   Gameplay is built from a large object hierarchy in `src/object/`, `src/badguy/`, and `src/trigger/`. These cover the player, enemies, interactive blocks, particles, triggers, doors, switches, platforms, and scripted objects. `game_object_factory` and `object_factory` are the main construction boundaries between parsed content and instantiated gameplay entities.

4. **Physics and collision boundary**  
   Movement and interaction are handled by `src/physic/` and `src/collision/`. The collision system is separated from rendering and scripting, with movement managers, collision objects, and collision groups mediating how players, enemies, blocks, and triggers physically interact.

5. **Rendering pipeline**  
   Graphics are abstracted through `src/video/`, which provides a renderer/video-system boundary with multiple backends: SDL-based, OpenGL-based, and a null backend for non-graphical contexts. Fonts, textures, surfaces, compositing, and viewport management are all separate layers, so game logic does not depend directly on a particular graphics API.

6. **Input and controller handling**  
   Input is centralized in `src/control/`. Keyboard, joystick/gamepad, mobile, and code-driven controls are normalized through `input_manager`, controller abstractions, and per-device configs. This feeds the gameplay and menu systems through a common control layer.

7. **Audio subsystem**  
   `src/audio/` wraps sound files and playback with backend-specific sources. The repo includes OpenAL-backed playback plus dummy/streaming implementations, and supports WAV and OGG assets from `data/sounds/`, `data/music/`, and `data/speech/`.

8. **Scripting and extensibility**  
   SuperTux uses Squirrel for gameplay and menu scripting. `src/squirrel/` provides the VM, scheduler, thread queue, serialization, and API bridge (`supertux_api`). Game content also includes `.nut` scripts in level folders and global scripts in `data/scripts/`.

9. **Menus, UI, and in-game tools**  
   Menu and UI logic is split between `src/gui/`, `src/interface/`, and `src/supertux/menu/`. These layers drive the title menu, options, language selection, add-on browser, cheat menus, and editor menus. The level editor is embedded in the same codebase under `src/editor/` and uses the same resource and object systems as gameplay.

10. **World map and campaign structure**  
    World-map gameplay is a distinct subsystem in `src/worldmap/`. It has its own camera, movement, teleports, level tiles, and state machine, and it reads `*.stwm` worldmap files from `data/levels/**`. This is separate from in-level sector gameplay, but shares resources, scripting, and presentation infrastructure.

11. **Assets, localization, and filesystem access**  
    Game content is organized under `data/` by asset type: images, sprites, tilesets, fonts, levels, locale files, shaders, sounds, and music. File access is abstracted through `src/physfs/` and `src/util/file_system.hpp`, which allows packaged assets, mods, and add-ons to be mounted consistently. Translations use gettext (`src/util/gettext.cpp`, `tinygettext`, `data/locale/*.po`).

12. **Add-ons and external services**  
    `src/addon/` handles downloadable content, add-on metadata, and installation; there is also an SDK integration layer in `src/sdk/` including Discord presence. This forms the network-facing boundary of the project, distinct from the offline core game loop.

13. **Build and platform packaging**  
    The project is built with CMake and a large set of platform-specific scripts and workflows. There are dedicated paths for Android, Emscripten/WebAssembly, Flatpak, Windows, macOS, GNU/Linux, and FreeBSD, plus bundled third-party libraries in `external/`. This matters architecturally because the same engine is compiled into multiple deployment targets with different frontend/runtime wrappers.

14. **Testing and tooling**  
    Unit tests live under `tests/unit/` and focus on core utilities, math, file system, parsing, collision, and object options. Tooling under `tools/` supports level conversion, string extraction, documentation generation, asset processing, and packaging, reinforcing that most of the game is data-driven and heavily asset-processed rather than hand-coded scene graphs.

Main entry points: [`src/supertux/screen_manager.cpp`](https://github.com/1111windows/supertux/blob/master/src/supertux/screen_manager.cpp) (Screen Flow), [`data`](https://github.com/1111windows/supertux/tree/master/data) (Assets), [`src/supertux/level.cpp`](https://github.com/1111windows/supertux/blob/master/src/supertux/level.cpp) (Level Runtime), [`src/object/player.cpp`](https://github.com/1111windows/supertux/blob/master/src/object/player.cpp) (Entities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_entry["Entry<br/>startup<br/>[main.cpp]"]
  node_app["App Core<br/>orchestration<br/>[main.cpp]"]
  node_screens["Screen Flow<br/>state machine<br/>[screen_manager.cpp]"]
  node_session["Game State<br/>session<br/>[game_session.cpp]"]
  node_level_runtime["Level Runtime<br/>world model<br/>[level.cpp]"]
  node_factory["Factory<br/>entity boundary"]
  node_entities["Entities<br/>gameplay objects<br/>[player.cpp]"]
  node_physics["Physics<br/>movement/collision<br/>[physic.cpp]"]
  node_collision["Collision"]
  node_rendering["Video<br/>rendering backend<br/>[video_system.cpp]"]
  node_input["Input<br/>controller layer<br/>[input_manager.cpp]"]
  node_audio["Audio<br/>sound system<br/>[sound_manager.cpp]"]
  node_scripts["Scripting<br/>Squirrel VM"]
  node_ui["UI & Menus<br/>menus/editor<br/>[main_menu.cpp]"]
  node_worldmap["World Map<br/>map mode<br/>[worldmap.cpp]"]
  node_fs["Filesystem<br/>resource access"]
  node_addons["Add-ons<br/>network/content<br/>[addon_manager.cpp]"]
end

subgraph group_content["Content"]
  node_assets[("Assets<br/>game content")]
end

subgraph group_platform["Platform"]
  node_build["Build & Ports<br/>toolchain<br/>[CMakeLists.txt]"]
end

node_entry -->|"boots"| node_app
node_app -->|"drives"| node_screens
node_screens -->|"uses"| node_session
node_screens -->|"opens"| node_ui
node_screens -->|"switches to"| node_level_runtime
node_level_runtime -->|"instantiates"| node_factory
node_factory -->|"creates"| node_entities
node_entities -->|"moves via"| node_physics
node_physics -->|"queries"| node_collision
node_level_runtime -->|"runs"| node_scripts
node_ui -->|"consumes"| node_input
node_ui -->|"draws via"| node_rendering
node_entities -->|"draws via"| node_rendering
node_audio -->|"loads"| node_assets
node_rendering -->|"loads"| node_assets
node_scripts -->|"executes"| node_assets
node_fs -->|"mounts"| node_assets
node_addons -->|"installs through"| node_fs
node_build -->|"packages"| node_entry

click node_entry "https://github.com/1111windows/supertux/blob/master/src/main.cpp"
click node_app "https://github.com/1111windows/supertux/blob/master/src/supertux/main.cpp"
click node_screens "https://github.com/1111windows/supertux/blob/master/src/supertux/screen_manager.cpp"
click node_session "https://github.com/1111windows/supertux/blob/master/src/supertux/game_session.cpp"
click node_level_runtime "https://github.com/1111windows/supertux/blob/master/src/supertux/level.cpp"
click node_factory "https://github.com/1111windows/supertux/blob/master/src/supertux/game_object_factory.cpp"
click node_entities "https://github.com/1111windows/supertux/blob/master/src/object/player.cpp"
click node_physics "https://github.com/1111windows/supertux/blob/master/src/supertux/physic.cpp"
click node_collision "https://github.com/1111windows/supertux/blob/master/src/collision/collision_system.cpp"
click node_rendering "https://github.com/1111windows/supertux/blob/master/src/video/video_system.cpp"
click node_input "https://github.com/1111windows/supertux/blob/master/src/control/input_manager.cpp"
click node_audio "https://github.com/1111windows/supertux/blob/master/src/audio/sound_manager.cpp"
click node_scripts "https://github.com/1111windows/supertux/blob/master/src/squirrel/squirrel_virtual_machine.cpp"
click node_ui "https://github.com/1111windows/supertux/blob/master/src/supertux/menu/main_menu.cpp"
click node_worldmap "https://github.com/1111windows/supertux/blob/master/src/worldmap/worldmap.cpp"
click node_assets "https://github.com/1111windows/supertux/tree/master/data"
click node_fs "https://github.com/1111windows/supertux/blob/master/src/physfs/physfs_file_system.cpp"
click node_addons "https://github.com/1111windows/supertux/blob/master/src/addon/addon_manager.cpp"
click node_build "https://github.com/1111windows/supertux/blob/master/CMakeLists.txt"

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_entry,node_app,node_screens,node_session,node_level_runtime,node_factory,node_entities,node_physics,node_collision,node_rendering,node_input,node_audio,node_scripts,node_ui,node_worldmap,node_fs,node_addons toneBlue
class node_assets toneAmber
class node_build toneMint
```

## Components

### Runtime

Core engine and gameplay flow

- [Entry](https://github.com/1111windows/supertux/blob/master/src/main.cpp): startup · Process entry and bootstrapping · `src/main.cpp`
- [App Core](https://github.com/1111windows/supertux/blob/master/src/supertux/main.cpp): orchestration · Application setup and main control handoff · `src/supertux/main.cpp`
- [Screen Flow](https://github.com/1111windows/supertux/blob/master/src/supertux/screen_manager.cpp): state machine · Screen-based game flow and transitions · `src/supertux/screen_manager.cpp`
- [Game State](https://github.com/1111windows/supertux/blob/master/src/supertux/game_session.cpp): session · Persistent game, profile, and save data · `src/supertux/game_session.cpp`
- [Level Runtime](https://github.com/1111windows/supertux/blob/master/src/supertux/level.cpp): world model · Levels, sectors, world map, and parsers · `src/supertux/level.cpp`
- [Factory](https://github.com/1111windows/supertux/blob/master/src/supertux/game_object_factory.cpp): entity boundary · Creates gameplay objects from parsed content · `src/supertux/game_object_factory.cpp`
- [Entities](https://github.com/1111windows/supertux/blob/master/src/object/player.cpp): gameplay objects · Player, enemies, blocks, triggers, and objects · `src/object/player.cpp`
- [Physics](https://github.com/1111windows/supertux/blob/master/src/supertux/physic.cpp): movement/collision · Movement and collision coordination · `src/supertux/physic.cpp`
- [Collision](https://github.com/1111windows/supertux/blob/master/src/collision/collision_system.cpp): collision system · Collision objects, groups, and resolution · `src/collision/collision_system.cpp`
- [Video](https://github.com/1111windows/supertux/blob/master/src/video/video_system.cpp): rendering backend · Renderer abstraction and backend implementations · `src/video/video_system.cpp`
- [Input](https://github.com/1111windows/supertux/blob/master/src/control/input_manager.cpp): controller layer · Keyboard, joystick, mobile, and code-driven input · `src/control/input_manager.cpp`
- [Audio](https://github.com/1111windows/supertux/blob/master/src/audio/sound_manager.cpp): sound system · Sound file loading and playback backends · `src/audio/sound_manager.cpp`
- [Scripting](https://github.com/1111windows/supertux/blob/master/src/squirrel/squirrel_virtual_machine.cpp): Squirrel VM · Squirrel runtime and API bridge · `src/squirrel/squirrel_virtual_machine.cpp`
- [UI & Menus](https://github.com/1111windows/supertux/blob/master/src/supertux/menu/main_menu.cpp): menus/editor · Menus, dialogs, interface widgets, and editor tooling · `src/supertux/menu/main_menu.cpp`
- [World Map](https://github.com/1111windows/supertux/blob/master/src/worldmap/worldmap.cpp): map mode · Campaign world-map gameplay and parsing · `src/worldmap/worldmap.cpp`
- [Filesystem](https://github.com/1111windows/supertux/blob/master/src/physfs/physfs_file_system.cpp): resource access · Virtual filesystem, PhysFS wrappers, gettext, and file utilities · `src/physfs/physfs_file_system.cpp`
- [Add-ons](https://github.com/1111windows/supertux/blob/master/src/addon/addon_manager.cpp): network/content · Downloadable content and integration services · `src/addon/addon_manager.cpp`

### Content

Data-driven assets and level content

- [Assets](https://github.com/1111windows/supertux/tree/master/data): game content · Images, sounds, music, levels, locale, shaders, and scripts · `data`

### Platform

Build, packaging, and external dependencies

- [Build & Ports](https://github.com/1111windows/supertux/blob/master/CMakeLists.txt): toolchain · CMake, platform packaging, external libraries, and tooling · `CMakeLists.txt`

## Connections

- Entry → App Core: boots · Program startup enters the application layer
- App Core → Screen Flow: drives · Application hands control to the screen/state manager
- Screen Flow → Game State: uses · Screen flow reads and mutates session state
- Screen Flow → UI & Menus: opens · Menus and editor screens are managed as screens
- Screen Flow → Level Runtime: switches to · Gameplay screens load levels and world maps
- Level Runtime → Factory: instantiates · Parsed level content becomes runtime objects
- Factory → Entities: creates · Factory materializes gameplay entities
- Entities → Physics: moves via · Objects rely on movement and physics helpers
- Physics → Collision: queries · Movement is constrained by collision resolution
- Level Runtime → Scripting: runs · Level and world content can invoke Squirrel scripts
- UI & Menus → Input: consumes · Menus, editor, and in-game tools respond to normalized input
- UI & Menus → Video: draws via · UI is rendered through the video abstraction
- Entities → Video: draws via · Game objects use the rendering pipeline for sprites and effects
- Audio → Assets: loads · Playback sources consume sound and music assets
- Video → Assets: loads · Textures, fonts, shaders, and images come from data files
- Scripting → Assets: executes · Scripts live in the data bundle alongside levels
- Filesystem → Assets: mounts · Filesystem layer exposes packaged content and mods
- Add-ons → Filesystem: installs through · Add-ons are fetched and installed through the filesystem boundary
- Build & Ports → Entry: packages · Build and port infrastructure produce the runtime binaries
