# stjr/srb2 architecture

> Architecture diagram of the GitHub repository stjr/srb2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stjr/srb2
- Repository: https://github.com/stjr/srb2

## Overview

##### Project type and purpose
- Project: Sonic Robo Blast 2 (SRB2), a 3D Sonic the Hedgehog fangame and game engine derived from Doom Legacy.
- Purpose: real-time game simulation—rendering, audio, physics, input, networking—cross-platform (Windows, Linux, macOS, Android) in C/C++ with scripting support (Lua).

##### File structure
Top-level directories:
- src/ – core engine source, subdivided into:
– hardware/ & r_opengl/ – renderer and graphics pipeline
– sdl/ & android/ & win32/ – platform abstraction layers, entry points
– netcode/ – multiplayer client/server logic
– blua/ & lua_*.c/h – embedded Lua scripting
– dedicated/, dummy/ – server-only or headless builds
– modules: audio (s_sound.c), input (g_input.c), game logic (g_game.c), etc.
- libs/ – vendored third-party static libraries (SDL2, SDL2_mixer, libupnp, libgme, libopenmpt, libpng, zlib, curl, miniupnpc, iconv, etc.).
- android/ – Eclipse/NDK project wrapper for Android port.
- thirdparty/ – CMake toolchains and patches to download/build dependencies.
- cmake/, scripts/ – build system modules, custom CMake macros and presets.
- tools/ – auxiliary utilities (level converter, IRC bot, master server, wad tools…).
- deployer/, .circleci/, .gitlab/ci/, .travis.yml, appveyor.yml – CI/CD pipelines and deployment scripts.
- assets/ – data packaging templates and resource licenses.
- doc/ – specs, documentation.

##### Extract insights from README
- Core dependencies: SDL2, SDL2-Mixer, libupnp, libgme, libopenmpt on Linux/macOS.
- Multi-platform engine with optional modules (audio backends, networking, dedicated server).
- CI pipelines build on many OS/config permutations.

a. Game Engine Core
– Sub-modules: Game Logic, Physics, Resource Manager, Scripting (Lua).
b. Rendering System
– hardware/r_opengl pipeline, platform-specific window/context creation via SDL or native APIs.
c. Audio System
– s_sound layer → SDL2_Mixer + streaming modules (libgme, libopenmpt)
d. Input System
– g_input layer → SDL2 or platform-raw events
e. Networking System
– netcode module: server/client, protocols, master-server integration (tools/masterserver).
f. Platform Abstraction Layer
– src/sdl, src/android, src/win32 front-ends → call into Core & subsystems
g. Third-Party Libraries
– static link libs in libs/ and via thirdparty/vcpkg overlays
h. Build & CI Pipeline
– scripts/, cmake/, deployer/, .circleci/, .gitlab/, .travis.yml, appveyor.yml

##### Relationships and interactions
– Game Logic ↔ Scripting (Lua).
– Game Logic ↔ Physics & Collision.
– Network module ↔ Game Logic (synchronize state).
– Core ↔ Platform Layer (windowing, threads, timers).
– All subsystems call into or link against Third-Party Libraries.
– Build System drives compilation of src/, thirdparty, and links libs/.

##### Architectural patterns / design principles
- Modular separation: core engine vs. platform vs. subsystems.
- Abstraction layers for portability (SDL vs. native).
- Plugin-style scripting (embedded Lua).
- Client-server model in netcode.
- Conditional builds: dedicated, headless, Android APK, Windows exe.

##### Essential elements
– Component labels (e.g., “Netcode Module”, “Lua VM”).
– Build pipeline overview: CMake → SRC compile + thirdparty → link → package → CI jobs.

##### Final advice
- Platform variants (SDL front-end, dedicated server, Android).
- Don’t overload with file names—focus on modules and subsystems.
- Use layering and grouping to convey architecture depth.
- Iterate with your team to refine interactions and update as new modules appear.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Platform Abstraction Layer"
        direction TB
        PL_SDL["SDL Front-end"]:::platform
        PL_ANDROID["Android Port"]:::platform
        PL_WIN32["Windows Native"]:::platform
        PL_DED["Dedicated Server"]:::platform
        PL_DUM["Headless (Dummy)"]:::platform
    end

    subgraph "Core Engine" 
        direction TB
        GL["Game Logic"]:::core
        PH["Physics & Collision"]:::core
        RM["Resource Manager"]:::core
        SC["Scripting (Lua VM)"]:::core
    end

    subgraph "Subsystems"
        direction TB
        IN["Input System"]:::subsystem
        RE["Rendering System"]:::subsystem
        AU["Audio System"]:::subsystem
        NE["Networking Module"]:::subsystem
    end

    TP_LIBS["Vendored & Third-Party Libs"]:::thirdparty
    CI_PIPELINE["Build & CI Pipeline"]:::ci

    %% Data flow
    PL_SDL -->|initializes| GL
    PL_ANDROID -->|initializes| GL
    PL_WIN32 -->|initializes| GL
    PL_DED -->|initializes| GL
    PL_DUM -->|initializes| GL

    IN -->|input events| GL
    GL -->|calls physics| PH
    PH -->|collision data| GL
    GL -->|loads assets| RM
    GL -->|executes scripts| SC
    SC -->|script callbacks| GL
    GL -->|render calls| RE
    GL -->|audio commands| AU
    GL -->|state sync| NE
    NE -->|network update| GL

    %% Dependencies
    PL_SDL --> TP_LIBS
    PL_ANDROID --> TP_LIBS
    PL_WIN32 --> TP_LIBS
    PL_DED --> TP_LIBS
    PL_DUM --> TP_LIBS
    GL --> TP_LIBS
    IN --> TP_LIBS
    RE --> TP_LIBS
    AU --> TP_LIBS
    NE --> TP_LIBS
    SC --> TP_LIBS
    RM --> TP_LIBS

    CI_PIPELINE -->|builds| PL_SDL
    CI_PIPELINE -->|builds| PL_ANDROID
    CI_PIPELINE -->|builds| PL_WIN32
    CI_PIPELINE -->|builds| PL_DED
    CI_PIPELINE -->|builds| PL_DUM
    CI_PIPELINE -->|builds| GL
    CI_PIPELINE -->|builds| PH
    CI_PIPELINE -->|builds| RM
    CI_PIPELINE -->|builds| SC
    CI_PIPELINE -->|builds| IN
    CI_PIPELINE -->|builds| RE
    CI_PIPELINE -->|builds| AU
    CI_PIPELINE -->|builds| NE

    %% Click Events
    click GL "https://github.com/stjr/srb2/blob/master/src/g_game.c"
    click PH "https://github.com/stjr/srb2/blob/master/src/p_map.c"
    click PH "https://github.com/stjr/srb2/blob/master/src/p_mobj.c"
    click PH "https://github.com/stjr/srb2/blob/master/src/p_setup.c"
    click PH "https://github.com/stjr/srb2/blob/master/src/p_tick.c"
    click PH "https://github.com/stjr/srb2/blob/master/src/p_*.c"
    click RM "https://github.com/stjr/srb2/blob/master/src/w_wad.c"
    click RM "https://github.com/stjr/srb2/blob/master/src/r_data.c"
    click SC "https://github.com/stjr/srb2/tree/master/src/blua/"
    click SC "https://github.com/stjr/srb2/blob/master/src/lua_script.c"
    click SC "https://github.com/stjr/srb2/blob/master/src/lua_*.c"
    click RE "https://github.com/stjr/srb2/tree/master/src/hardware/"
    click RE "https://github.com/stjr/srb2/tree/master/src/hardware/r_opengl/"
    click AU "https://github.com/stjr/srb2/blob/master/src/s_sound.c"
    click AU "https://github.com/stjr/srb2/tree/master/src/hardware/s_openal/"
    click AU "https://github.com/stjr/srb2/tree/master/src/hardware/s_ds3d/"
    click AU "https://github.com/stjr/srb2/tree/master/src/hardware/s_fmod/"
    click IN "https://github.com/stjr/srb2/blob/master/src/g_input.c"
    click NE "https://github.com/stjr/srb2/tree/master/src/netcode/"
    click PL_SDL "https://github.com/stjr/srb2/tree/master/src/sdl/"
    click PL_ANDROID "https://github.com/stjr/srb2/tree/master/src/android/"
    click PL_WIN32 "https://github.com/stjr/srb2/tree/master/src/win32/"
    click PL_DED "https://github.com/stjr/srb2/tree/master/src/dedicated/"
    click PL_DUM "https://github.com/stjr/srb2/tree/master/src/dummy/"
    click TP_LIBS "https://github.com/stjr/srb2/tree/master/libs/"
    click TP_LIBS "https://github.com/stjr/srb2/tree/master/thirdparty/"
    click CI_PIPELINE "https://github.com/stjr/srb2/blob/master/CMakeLists.txt"
    click CI_PIPELINE "https://github.com/stjr/srb2/blob/master/src/CMakeLists.txt"
    click CI_PIPELINE "https://github.com/stjr/srb2/tree/master/cmake/"
    click CI_PIPELINE "https://github.com/stjr/srb2/tree/master/scripts/"
    click CI_PIPELINE "https://github.com/stjr/srb2/blob/master/.circleci/config.yml"
    click CI_PIPELINE "https://github.com/stjr/srb2/blob/master/.gitlab-ci.yml"
    click CI_PIPELINE "https://github.com/stjr/srb2/tree/master/gitlab/ci/"
    click CI_PIPELINE "https://github.com/stjr/srb2/blob/master/.travis.yml"
    click CI_PIPELINE "https://github.com/stjr/srb2/blob/master/appveyor.yml"
    click CI_PIPELINE "https://github.com/stjr/srb2/tree/master/deployer/"

    classDef core fill:#D0E6FF,stroke:#003366
    classDef subsystem fill:#DFFFE0,stroke:#267300
    classDef platform fill:#FFE8B2,stroke:#996600
    classDef thirdparty fill:#E0E0E0,stroke:#666666
    classDef ci fill:#E6D0FF,stroke:#660099
```
