# tg-2/sacengine architecture

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

- Interactive diagram: https://gitdiagram.com/tg-2/sacengine
- Repository: https://github.com/tg-2/sacengine

## Overview

##### Project Type and Purpose
- This is a game engine reimplementation built for recreating the classic game Sacrifice.
- The README makes it clear that the engine is built using D (with LDC ≥1.35.0) and is intended to be compiled with Dub.
- Its purpose is to manage game simulation, rendering, audio, networking, user input, asset management, and more.

##### File Structure
- Top-Level Files and Scripts: There is a collection of build scripts for various platforms (Android, OS X, Windows, Linux, PI). These scripts indicate cross-platform build support and deployment considerations.
- The "source" Directory: Contains the primary engine code. Files like app.d, controller.d, renderer.d, audio.d, network.d, and various others (e.g., maps, spells, widgets) indicate a modular design where each file encapsulates a part of the engine’s functionality.
– For instance, files such as:
- app.d likely contains the main entry point or game loop.
- renderer.d and animations.d are responsible for graphics and visual effects.
- audio.d and audioBackend.d highlight the audio system.
- network.d, netutil.d, and possibly nttData.d point towards networking capabilities.
- files related to “sac” (e.g., sacmap.d, sacform.d, sacobject.d, sacspell.d) are likely tied to game-specific logic.
- Other Directories & Files:
– "dlib": Possibly contains additional libraries or helper functions.
– "lists": Contains map files and configurations, suggesting structured data for game levels or AI maps.
– "dub.json": The build/dependency configuration file for the Dub system.
– Build scripts and release files: These scripts make it easier to compile and release the engine for various target platforms.

##### Main Components & Their Relationships
- Core Engine:
– App Core: The main game loop and initialization are defined here (source/app.d).
– Game Logic & Controller: Handling game states, input, and control (source/controller.d, source/levl.d).
- Rendering & Graphics:
– Renderer: Manages drawing, animations (source/renderer.d, source/animations.d).
– Assets Management: Likely integrating map data (source/maps.d) and textures (source/txtr.d).
- Audio System:
– Audio Processing: Managed by source/audio.d and its backend (source/audioBackend.d).
- Networking:
– Networking modules (source/network.d, source/netutil.d) indicate network communication for multiplayer or online services.
- User Interface and Interaction:
– UI components like forms, widgets, and hotkeys (source/form.d, source/hotkeys_.d, source/widg.d).
- Other Specific Systems:
– Specialized modules for handling spells, objects, game state, and more (e.g., source/spells.d, source/obj.d, source/state.d).

##### Architectural Patterns & Design Principles
- Modularity: Each major feature (audio, graphics, networking) is compartmentalized into its own module.
- Multi-platform support: The various build scripts and the use of Dub imply careful configuration for cross-platform compatibility.
- Separation of Concerns: The division between the game simulation (logic, controller), rendering, audio, networking, etc., is enforced by the distinct source files.

##### Final Recommendations
- That labels and flows are clear to help other engineers immediately grasp the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Core Engine Subgraph
    subgraph "Core Engine"
        game_core("Game Core"):::core
        controller_logic("Game Controller & Logic"):::core
    end

    %% Rendering & Graphics Subgraph
    subgraph "Rendering & Graphics"
        rendering("Renderer & Animations"):::rendering
    end

    %% Audio System Subgraph
    subgraph "Audio System"
        audio("Audio Processing"):::audio
    end

    %% Networking Subgraph
    subgraph "Networking"
        networking("Networking Modules"):::network
    end

    %% Sacrifice-Specific Modules Subgraph
    subgraph "Sacrifice-Specific Modules"
        sacrifice("Sacrifice Modules"):::sacrifice
    end

    %% Asset & Map Management Subgraph
    subgraph "Asset & Map Management"
        asset("Asset & Map Management"):::asset
    end

    %% User Interface Subgraph
    subgraph "User Interface"
        ui("UI Components"):::ui
    end

    %% Build & Deployment Subgraph
    subgraph "Build & Deployment"
        build("Build & Deployment"):::build
    end

    %% Connections between components
    game_core -->|"init"| controller_logic
    ui -->|"input"| controller_logic
    controller_logic -->|"render"| rendering
    controller_logic -->|"audio"| audio
    controller_logic -->|"network"| networking
    controller_logic -->|"game_logic"| sacrifice
    controller_logic -->|"asset_load"| asset
    build -.->|"build_target"| game_core

    %% Click Events
    click game_core "https://github.com/tg-2/sacengine/blob/master/source/app.d"
    click controller_logic "https://github.com/tg-2/sacengine/blob/master/source/controller.d"
    click controller_logic "https://github.com/tg-2/sacengine/blob/master/source/levl.d"
    click rendering "https://github.com/tg-2/sacengine/blob/master/source/renderer.d"
    click rendering "https://github.com/tg-2/sacengine/blob/master/source/animations.d"
    click audio "https://github.com/tg-2/sacengine/blob/master/source/audio.d"
    click audio "https://github.com/tg-2/sacengine/blob/master/source/audioBackend.d"
    click networking "https://github.com/tg-2/sacengine/blob/master/source/network.d"
    click networking "https://github.com/tg-2/sacengine/blob/master/source/netutil.d"
    click networking "https://github.com/tg-2/sacengine/blob/master/source/nttData.d"
    click sacrifice "https://github.com/tg-2/sacengine/blob/master/source/sacmap.d"
    click sacrifice "https://github.com/tg-2/sacengine/blob/master/source/sacform.d"
    click sacrifice "https://github.com/tg-2/sacengine/blob/master/source/sacobject.d"
    click sacrifice "https://github.com/tg-2/sacengine/blob/master/source/sacspell.d"
    click asset "https://github.com/tg-2/sacengine/blob/master/source/maps.d"
    click asset "https://github.com/tg-2/sacengine/tree/master/lists/"
    click ui "https://github.com/tg-2/sacengine/blob/master/source/form.d"
    click ui "https://github.com/tg-2/sacengine/blob/master/source/hotkeys_.d"
    click ui "https://github.com/tg-2/sacengine/blob/master/source/widg.d"
    click build "https://github.com/tg-2/sacengine/blob/master/build-android.sh"
    click build "https://github.com/tg-2/sacengine/blob/master/build-osx.sh"
    click build "https://github.com/tg-2/sacengine/blob/master/build-windows.sh"
    click build "https://github.com/tg-2/sacengine/blob/master/build.sh"
    click build "https://github.com/tg-2/sacengine/blob/master/dub.json"

    %% Style definitions
    classDef core fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef rendering fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef audio fill:#FADBD8,stroke:#CD6155,stroke-width:2px;
    classDef network fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef sacrifice fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
    classDef asset fill:#D6EAF8,stroke:#2E86C1,stroke-width:2px;
    classDef ui fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef build fill:#E5E7E9,stroke:#7F8C8D,stroke-width:2px;
```
