# hedge-dev/unleashedrecomp architecture

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

- Interactive diagram: https://gitdiagram.com/hedge-dev/unleashedrecomp
- Repository: https://github.com/hedge-dev/unleashedrecomp

## Overview

##### Main Components
- Application Entry & Main Loop: Represented by files such as main.cpp, app.cpp, and app.h, this is where the game starts up and coordinates the different systems.
- API and Game Engine Modules: The “api” folder shows multiple internal subsystems including CSD (custom scene and resource management), Hedgehog (which covers core systems like containers, memory management, threading, and math), and SWA (which contains game-specific logic, assets, and modules like Camera, HUD, Player, and more). These indicate a layered design where core engine utilities and game logic coexist.
- Rendering Subsystems: The “gpu” directory splits into several areas: shader programming (both HLSL shader code for various effects like Gaussian blur, motion blur, and MSAA), a rendering hardware abstraction layer via plume (with separate backend implementations for D3D12 and Vulkan), and the video module. Show how these interact with the overall engine.
- Audio, Input, and OS Abstraction: Folders such as “apu” (for audio processing with drivers like SDL2), “hid” (input drivers) in addition to the “os” folder (which contains OS-specific implementations for both Windows and Linux) indicate a separation of platform-specific logic behind abstraction layers.
- Kernel and System Emulation Layers: The “cpu” and “kernel” directories include components like thread handling, memory management, guest thread emulation, and system call hooks that simulate Xbox 360 kernel behavior. These are critical for reproducing the original console’s operations.
- Mod and Installer Support: The presence of “mod” (for mod loader and INI file management), “install” (which handles game file acquisition and integrity checking) and UI components (in the “ui” folder) highlight built-in systems for installation, configuration, and mod support.

##### Relationships and Interactions
- Data Flow: The main application layer initializes the kernel and engine subsystems. Then, it drives the game loop, which calls rendering, audio, and input handling components.
- Platform Adaptation: Represent OS abstraction layers that capture different implementations for Windows, Linux (and potentially macOS later) by including separate directories and drivers.

##### Architectural Patterns and Strategies
- Modular Design: The project is clearly broken into modules such as API, kernel, GPU, audio, etc., each self-contained yet communicating through well-defined interfaces.
- Abstraction Layers: The use of hardware abstraction by plume, and OS-specific implementations in “os” and “apu” (audio, input, media) are prime examples of separation-of-concerns and portability.
- Plugin/Mod Support: The mod loading system forms a bridge for external modifications, which is linked to the installer and configuration modules.
- Asynchronous & Parallel Processing: As emphasized in the README, asynchronous shader compilation and parallel asset streaming are key performance features. This should be clearly marked to denote thread-based and asynchronous processes.

##### Relevant Technologies and Libraries
- C++ as the core language.
- CMake (CMakeLists.txt, CMakePresets.json) for multi-platform builds.
- SDL2 (for input, video and audio drivers in “apu” and “hid”).
- Vulkan and Direct3D 12 via plume, with shader code written in HLSL.
- External libraries such as boost (for smart pointers and utility functions) and third-party dependencies in the “thirdparty” folder.
- Dear ImGui is used in the UI for custom menus and overlays.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Entry Layer
    subgraph "Application Entry"
        A1["Main Application Loop"]:::core
        A2["app.cpp"]:::core
        A3["app.h"]:::core
    end

    %% Kernel & System Emulation Layer
    subgraph "Kernel & Emulation"
        E1["CPU Emulation"]:::kernel
        E2["Kernel Emulation"]:::kernel
    end

    %% Game Engine Modules Layer
    subgraph "Game Engine Modules"
        B1["CSD Subsystem"]:::engine
        B2["Hedgehog Engine"]:::engine
        B3["SWA (Game Logic)"]:::engine
    end

    %% Rendering Subsystem Layer
    subgraph "Rendering Subsystem"
        C1["GPU Engine"]:::rendering
        C2["D3D12 Backend"]:::rendering
        C3["Vulkan Backend"]:::rendering
        C4["Shader Code (HLSL)"]:::rendering
    end

    %% Audio, Input & OS Abstraction Layer
    subgraph "Platform Abstraction"
        D1["Audio Subsystem"]:::audio
        D2["Input (HID)"]:::input
        D3["OS Abstraction"]:::os
    end

    %% Mod Loader & Installer Layer
    subgraph "Mod & Installer"
        F1["Mod Loader"]:::mod
        F2["Installer"]:::mod
    end

    %% UI Components Layer
    subgraph "User Interface"
        G1["UI & Menus"]:::ui
    end

    %% External Tools Layer
    subgraph "External Tools"
        H1["External Tools Integration"]:::external
    end

    %% Connections between Layers
    A1 --> E1
    A1 --> E2
    A1 --> B1
    A1 --> B2
    A1 --> B3

    E2 --> B2

    B2 --> C1
    B3 --> C1

    B2 --> D1
    B2 --> D2

    D3 --- D1
    D3 --- D2

    B3 --> G1
    F1 --> G1
    F2 --> G1

    B3 --> F1

    B3 --> H1
    H1 --> B3

    %% Internal Rendering Subsystem connections
    C1 --> C2
    C1 --> C3
    C1 --> C4

    %% Click Events
    click A1 "https://github.com/hedge-dev/unleashedrecomp/blob/main/UnleashedRecomp/main.cpp"
    click A2 "https://github.com/hedge-dev/unleashedrecomp/blob/main/UnleashedRecomp/app.cpp"
    click A3 "https://github.com/hedge-dev/unleashedrecomp/blob/main/UnleashedRecomp/app.h"

    click B1 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/api/CSD"
    click B2 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/api/Hedgehog"
    click B3 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/api/SWA"

    click C1 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/gpu"
    click C2 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/gpu/rhi/plume_d3d12"
    click C3 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/gpu/rhi/plume_vulkan"
    click C4 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/gpu/shader"

    click D1 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/apu"
    click D2 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/hid"
    click D3 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/os"

    click E1 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/cpu"
    click E2 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/kernel"

    click F1 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/mod"
    click F2 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/install"

    click G1 "https://github.com/hedge-dev/unleashedrecomp/tree/main/UnleashedRecomp/ui"

    click H1 "https://github.com/hedge-dev/unleashedrecomp/tree/main/tools"

    %% Styles
    classDef core fill:#b3d9ff,stroke:#000,stroke-width:1px;
    classDef engine fill:#ccffcc,stroke:#000,stroke-width:1px;
    classDef rendering fill:#ffe6b3,stroke:#000,stroke-width:1px;
    classDef audio fill:#ffffcc,stroke:#000,stroke-width:1px;
    classDef input fill:#ffffcc,stroke:#000,stroke-width:1px;
    classDef os fill:#e6ccff,stroke:#000,stroke-width:1px;
    classDef kernel fill:#ffccff,stroke:#000,stroke-width:1px;
    classDef mod fill:#f2f2f2,stroke:#000,stroke-width:1px;
    classDef ui fill:#cce6ff,stroke:#000,stroke-width:1px;
    classDef external fill:#ffb3ff,stroke:#000,stroke-width:1px;
```
