# hottabxp/re3 architecture

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

- Interactive diagram: https://gitdiagram.com/hottabxp/re3
- Repository: https://github.com/hottabxp/re3

## Overview

##### Project Type & Purpose
- re3 is a reverse-engineered, cross-platform game engine that reimplements GTA III/VC logic and rendering.
- It’s written in C++98, with no C++11+ features, and targets Windows, Linux, MacOS, FreeBSD, arm/arm64, x86/amd64.
- Core responsibilities: game loop, asset streaming, physics/collision, audio, rendering (via original RenderWare or librw), input, scripting, save management.

##### High-Level Layers & Top-Level Directories
- Build & Config
- CMakeLists.txt, premake5.lua, conanfile.py, .github workflows, autoconf scripts
- Platform Abstraction
- src/skel (glfw, win, posix)
- Assets
- gamefiles/ (models, TEXT, data, neo, etc.)
- res/images (logo, UI)
- Source Code (src/) subdivided by subsystem:
- core/         ↳ main loop, file I/O, streaming, world, time
- animation/    ↳ skeletal, blend, cutscenes
- audio/        ↳ AudioManager, DMAudio (MSS), OpenAL backends, script objects
- collision/    ↳ ColSphere, ColModel, VuCollision (PS2 VU microcode)
- control/      ↳ AI (CarAI, PedAI), scripting engine (Script*.cpp), game logic
- entities/     ↳ Entity base, Physical, Dummy
- math/         ↳ Vector, Matrix, Quaternion
- modelinfo/    ↳ metadata loaders for DFF models
- objects/      ↳ in-game world objects, particles, cutscene objects
- peds/         ↳ Ped classes, population generation, routing
- vehicles/     ↳ Vehicle classes, transmissions, damage, handling
- weapons/      ↳ WeaponInfo, Projectile, Explosion
- fakerw/       ↳ fake RenderWare headers & stubs for linking
- rw/           ↳ low-level RenderWare clone code, texture pools, memory manager
- save/         ↳ PCSave, MemoryCard, GenericGameStorage
- text/         ↳ localization, message pager
- extras/       ↳ debug menus, post-processing, shaders (GLSL/HLSL)
- utils/gxt     ↳ text conversion tool for game TEXT files
- Third-Party
- vendor/ (submodules e.g. librw)

##### README for Dependencies & Runtime Architecture
- Rendering: D3D8 (original RW) or librw (GL3, D3D9, GLES2)
- Audio: Microsoft’s MSS or OpenAL
- Input: XInput (Windows), GLFW (other platforms)
- Build: CMake+Conan or Premake+Visual Studio / CodeWarrior

##### Components
A. Platform Layer
- OS / Windowing (src/skel: Win/GLFW)
- Low-level services: Threads, FileSystem, Networking (if any)
B. Build & Config
- CMake / Premake build pipeline (external)
- config.h toggles (FPS, render options)
C. Asset Storage
- gamefiles/ on disk
- streaming subsystem (core/Streaming, FileLoader)
D. Engine Core
- Game Loop (core/main.cpp)
- Input Manager (core/Pad, ControllerConfig)
- File Manager & Streaming
- World & Zones (core/World, Zones, ZoneCull)
- Entity Manager (entities/, peds/, vehicles/, objects/)
- Physics & Collision (collision/, control/AutoPilot)
- Animation (animation/)
- AI & Scripting (control/, Script*.cpp)
- Audio Subsystem (audio/, DM audio/OpenAL backends)
- Rendering Subsystem (renderer/, extras/, rw/)
- Save/Load Manager (save/)
- UI & Text (text/, renderer/Hud)
E. Rendering Flow
- Shaders & postFX (extras/shaders)
- fakerw stubs → actual RW calls → librw or D3D8 DLL
F. Audio Flow
- AudioManager → script triggers → backends (MSS DLL or OpenAL library)
G. External Services
- OS file handles, GPU drivers, sound drivers

##### Relationships & Data Flow
- Streaming engine pulls raw asset chunks → ModelInfo & collision data → Entity spawner
- Entities and Control push sound events → AudioManager → audio backend → speakers
- Input → Game Loop → Control / UI
- Save Manager persists state → disk

##### Architectural Patterns & Principles
- Modular, directory-per-subsystem
- Single Game Loop dispatching updates & render phases (typical game-engine pattern)
- Plugin-style backends for rendering & audio (RenderWare vs librw, MSS vs OpenAL)
- Data streaming & on-demand asset loading
- Reversed-code adherence to original PS2 logic (collision microcode, animation pipeline)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Build & Config Layer
    subgraph "Build & Config"
        B1["CMakeLists.txt"]:::config
        B2["premake5.lua"]:::config
        B3["conanfile.py"]:::config
        B4[".github/workflows/"]:::config
    end

    %% Platform Abstraction Layer
    subgraph "Platform Layer"
        P1["src/skel/"]:::platform
    end

    %% Asset Storage
    Assets["gamefiles/"]:::asset
    subgraph "Streaming Subsystem"
        S1["FileLoader"]:::core
        S2["Streaming"]:::core
        S3["FileMgr"]:::core
    end

    %% Engine Core Layer
    subgraph "Engine Core"
        CoreLoop["Game Loop"]:::core
        subgraph "Input Manager"
            I1["Pad"]:::core
            I2["ControllerConfig"]:::core
        end
        subgraph "File & Streaming"
            FS1["FileMgr"]:::core
            FS2["FileLoader"]:::core
            FS3["Streaming"]:::core
        end
        subgraph "World & Zones"
            W1["World"]:::core
            W2["Zones"]:::core
            W3["ZoneCull"]:::core
        end
        subgraph "Entity Manager"
            E1["Entity"]:::core
            E2["Physical"]:::core
            E3["Dummy"]:::core
            E4["peds/"]:::core
            E5["vehicles/"]:::core
            E6["objects/"]:::core
        end
        subgraph "Physics & Collision"
            C1["collision/"]:::core
            C2["AutoPilot"]:::core
        end
        subgraph "Animation"
            A1["animation/"]:::core
        end
        subgraph "AI & Scripting"
            SC1["Script*.cpp"]:::core
            SC2["ScriptCommands.h"]:::core
        end
        subgraph "Save/Load"
            SV1["save/"]:::core
        end
        subgraph "UI & Text"
            T1["text/"]:::core
            T2["Hud & Sprite2d"]:::core
        end
    end

    %% Rendering Subsystem
    subgraph "Rendering Subsystem"
        R1["renderer/"]:::render
        R2["rw/"]:::render
        R3["extras/"]:::render
        R4["fakerw/"]:::render
    end

    %% Audio Subsystem
    subgraph "Audio Subsystem"
        AU1["audio/"]:::audio
        AU2["audio/eax/"]:::audio
        AU3["audio/oal/"]:::audio
        AU4["DMAudio"]:::audio
    end

    %% Third-Party & External
    Vendor["vendor/"]:::external
    OS["OS & Windowing"]:::external
    GPU["GPU Drivers"]:::external
    SD["Sound Drivers"]:::external

    %% Connections
    OS -->|"window events"| P1
    CoreLoop -->|"update()"| I1
    I1 -->|"\u2194 Input"| CoreLoop
    CoreLoop -->|"load assets"| S1
    S1 ---|"stream data"| Assets
    S1 -->|"provide chunks"| FS3
    CoreLoop -->|"update"| W1
    W1 -->|"zone culling"| W3
    CoreLoop -->|"spawn entities"| E1
    E1 -->|"collision query"| C1
    C1 -->|"fallback"| C2
    CoreLoop -->|"animate"| A1
    CoreLoop -->|"script tick"| SC1
    SC1 -->|"commands"| SC2
    CoreLoop -->|"audio event"| AU1
    AU1 -->|"MSS/OpenAL"| AU2
    AU1 -->|"OpenAL"| AU3
    AU1 -->|"Miles stub"| AU4
    CoreLoop -->|"draw"| R1
    R1 -->|"Draw(entity)"| R2
    R1 -->|"postFX"| R3
    R1 -->|"rw stubs"| R4
    R2 -->|"to GPU"| GPU
    AU2 -->|"to sound driver"| SD
    SV1 -->|"persist state"| Assets
    T2 -->|"render UI"| R1

    %% Click Events for component mapping
    click P1 "https://github.com/hottabxp/re3/tree/master/src/skel/"
    click B1 "https://github.com/hottabxp/re3/blob/master/CMakeLists.txt"
    click B2 "https://github.com/hottabxp/re3/blob/master/premake5.lua"
    click B3 "https://github.com/hottabxp/re3/blob/master/conanfile.py"
    click B4 "https://github.com/hottabxp/re3/tree/master/.github/workflows/"
    click Assets "https://github.com/hottabxp/re3/tree/master/gamefiles/"
    click S1 "https://github.com/hottabxp/re3/blob/master/src/core/FileLoader.cpp"
    click S1 "https://github.com/hottabxp/re3/blob/master/src/core/FileLoader.h"
    click S2 "https://github.com/hottabxp/re3/blob/master/src/core/Streaming.cpp"
    click S2 "https://github.com/hottabxp/re3/blob/master/src/core/Streaming.h"
    click S3 "https://github.com/hottabxp/re3/blob/master/src/core/FileMgr.cpp"
    click S3 "https://github.com/hottabxp/re3/blob/master/src/core/FileMgr.h"
    click CoreLoop "https://github.com/hottabxp/re3/blob/master/src/core/main.cpp"
    click I1 "https://github.com/hottabxp/re3/blob/master/src/core/Pad.cpp"
    click I1 "https://github.com/hottabxp/re3/blob/master/src/core/Pad.h"
    click I2 "https://github.com/hottabxp/re3/blob/master/src/core/ControllerConfig.cpp"
    click I2 "https://github.com/hottabxp/re3/blob/master/src/core/ControllerConfig.h"
    click FS1 "https://github.com/hottabxp/re3/blob/master/src/core/FileMgr.cpp"
    click FS1 "https://github.com/hottabxp/re3/blob/master/src/core/FileMgr.h"
    click FS2 "https://github.com/hottabxp/re3/blob/master/src/core/FileLoader.cpp"
    click FS2 "https://github.com/hottabxp/re3/blob/master/src/core/FileLoader.h"
    click FS3 "https://github.com/hottabxp/re3/blob/master/src/core/Streaming.cpp"
    click FS3 "https://github.com/hottabxp/re3/blob/master/src/core/Streaming.h"
    click W1 "https://github.com/hottabxp/re3/blob/master/src/core/World.cpp"
    click W1 "https://github.com/hottabxp/re3/blob/master/src/core/World.h"
    click W2 "https://github.com/hottabxp/re3/blob/master/src/core/Zones.cpp"
    click W2 "https://github.com/hottabxp/re3/blob/master/src/core/Zones.h"
    click W3 "https://github.com/hottabxp/re3/blob/master/src/core/ZoneCull.cpp"
    click W3 "https://github.com/hottabxp/re3/blob/master/src/core/ZoneCull.h"
    click E1 "https://github.com/hottabxp/re3/blob/master/src/entities/Entity.cpp"
    click E1 "https://github.com/hottabxp/re3/blob/master/src/entities/Entity.h"
    click E2 "https://github.com/hottabxp/re3/blob/master/src/entities/Physical.cpp"
    click E2 "https://github.com/hottabxp/re3/blob/master/src/entities/Physical.h"
    click E3 "https://github.com/hottabxp/re3/blob/master/src/entities/Dummy.cpp"
    click E3 "https://github.com/hottabxp/re3/blob/master/src/entities/Dummy.h"
    click E4 "https://github.com/hottabxp/re3/tree/master/src/peds/"
    click E5 "https://github.com/hottabxp/re3/tree/master/src/vehicles/"
    click E6 "https://github.com/hottabxp/re3/tree/master/src/objects/"
    click C1 "https://github.com/hottabxp/re3/tree/master/src/collision/"
    click C2 "https://github.com/hottabxp/re3/blob/master/src/control/AutoPilot.cpp"
    click C2 "https://github.com/hottabxp/re3/blob/master/src/control/AutoPilot.h"
    click A1 "https://github.com/hottabxp/re3/tree/master/src/animation/"
    click SC1 "https://github.com/hottabxp/re3/blob/master/src/control/Script.cpp"
    click SC2 "https://github.com/hottabxp/re3/blob/master/src/control/ScriptCommands.h"
    click AU1 "https://github.com/hottabxp/re3/tree/master/src/audio/"
    click AU2 "https://github.com/hottabxp/re3/tree/master/src/audio/eax/"
    click AU3 "https://github.com/hottabxp/re3/tree/master/src/audio/oal/"
    click AU4 "https://github.com/hottabxp/re3/blob/master/src/audio/DMAudio.cpp"
    click AU4 "https://github.com/hottabxp/re3/blob/master/src/audio/DMAudio.h"
    click R1 "https://github.com/hottabxp/re3/tree/master/src/renderer/"
    click R2 "https://github.com/hottabxp/re3/tree/master/src/rw/"
    click R3 "https://github.com/hottabxp/re3/tree/master/src/extras/"
    click R4 "https://github.com/hottabxp/re3/tree/master/src/fakerw/"
    click SV1 "https://github.com/hottabxp/re3/tree/master/src/save/"
    click T1 "https://github.com/hottabxp/re3/tree/master/src/text/"
    click T2 "https://github.com/hottabxp/re3/blob/master/src/renderer/Hud.cpp"
    click T2 "https://github.com/hottabxp/re3/blob/master/src/renderer/Hud.h"
    click T2 "https://github.com/hottabxp/re3/blob/master/src/renderer/Sprite2d.cpp"
    click T2 "https://github.com/hottabxp/re3/blob/master/src/renderer/Sprite2d.h"
    click Vendor "https://github.com/hottabxp/re3/tree/master/vendor/"

    %% Styles
    classDef core fill:#cce5ff,stroke:#3399ff
    classDef render fill:#d4edda,stroke:#28a745
    classDef audio fill:#fff3cd,stroke:#ffcd39
    classDef platform fill:#e2e3e5,stroke:#6c757d
    classDef asset fill:#fff5cc,stroke:#e6b800
    classDef config fill:#f0f0f0,stroke:#999999
    classDef external fill:#ffffff,stroke:#000000,stroke-dasharray: 5 5
    class CoreLoop,FS1,FS2,FS3,I1,I2,W1,W2,W3,E1,E2,E3,E4,E5,E6,C1,C2,A1,SC1,SC2,SV1,T1,T2 core
    class R1,R2,R3,R4 render
    class AU1,AU2,AU3,AU4 audio
    class P1 platform
    class Assets asset
    class B1,B2,B3,B4 config
    class OS,Vendor,GPU,SD external
```
