# e2dk4r/handmadehero architecture

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

- Interactive diagram: https://gitdiagram.com/e2dk4r/handmadehero
- Repository: https://github.com/e2dk4r/handmadehero

## Overview

##### Main Components

A. Core Engine Layer
- Core subsystems:
- Memory Management (memory_arena.h)
- Entity System (entity.h)
- World Simulation (world.h)
- Math System (math.h)
- Random Number Generator (random.h)

B. Platform Abstraction Layer
- This as a wrapper around the core engine
- Platform-specific implementation (handmadehero_linux.c)
- Integration with:
- Wayland (Display System)
- Pipewire (Audio System)

C. Rendering System
- This as a major subsystem
- Components from render_group.h
- Connection to platform's display system

D. Audio System
- Parallel to the rendering system
- Audio.h components
- To Pipewire implementation

E. Asset System
- This as a supporting subsystem
- Asset builder tool connection
- Asset loading and management flow

F. Development Tools
- As auxiliary systems
- Include:
- Asset Builder (hh_asset_builder)
- Record Reader (hh_record_read)

**┌─────────────────────────────────────────────┐**
- Platform Layer                 │
- ┌─────────────────────────────────────┐   │
- Core Engine               │   │
- ┌─────────┐ ┌─────────┐           │   │
- Entity  │ │ World   │           │   │
- System  │ │ System  │           │   │
- ┘ └─────────┘           │   │
- ┌─────────┐ ┌─────────┐           │   │
- Memory  │ │ Math    │           │   │
- System  │ │ System  │           │   │
- ┘ └─────────┘           │   │
- ┘   │

- ┌──────────────┐      ┌──────────────┐   │
- Render     │      │    Audio     │   │
- System     │      │    System    │   │
- ┘      └──────────────┘   │
- ┘

##### Important Details to Capture
- Separation between platform-independent and platform-specific code
- Asset pipeline flow from tools to runtime
- Demonstrate the simulation region system's relationship with the world system
- Debug/development features (debugf.h, analysis.h)

##### Implementation Notes
- Maintain consistent spacing and alignment
- Clear labels for all components
- Brief descriptions for major subsystems

Remember to emphasize the modular nature of the engine and how the platform abstraction layer enables the port to Wayland and Pipewire while maintaining the core game engine's platform independence.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Platform["Platform Abstraction Layer"]
        PlatformInterface["Platform Interface"]
        LinuxImpl["Linux Implementation"]
        WaylandSys["Wayland Display"]
        PipewireSys["Pipewire Audio"]
    end

    subgraph Core["Core Engine Layer"]
        MemSys["Memory Management"]
        EntitySys["Entity System"]
        WorldSys["World Simulation"]
        MathSys["Math System"]
        RandSys["Random Number Generator"]
        SimRegion["Simulation Region"]
    end

    subgraph Render["Rendering System"]
        RenderGroup["Render Group"]
        ColorSys["Color System"]
    end

    subgraph Audio["Audio System"]
        AudioInterface["Audio Interface"]
        AudioImpl["Audio Implementation"]
    end

    subgraph Assets["Asset System"]
        AssetInterface["Asset Interface"]
        AssetImpl["Asset Implementation"]
        FileFormats["File Formats"]
    end

    subgraph DevTools["Development Tools"]
        AssetBuilder["Asset Builder"]
        RecordReader["Record Reader"]
        DebugSys["Debug System"]
        Analysis["Analysis Tools"]
    end

    %% Core relationships
    MemSys --> EntitySys
    MemSys --> WorldSys
    EntitySys --> WorldSys
    MathSys --> WorldSys
    RandSys --> WorldSys
    WorldSys --> SimRegion

    %% Platform relationships
    PlatformInterface --> LinuxImpl
    LinuxImpl --> WaylandSys
    LinuxImpl --> PipewireSys

    %% Render relationships
    RenderGroup --> ColorSys
    RenderGroup --> WaylandSys

    %% Audio relationships
    AudioInterface --> AudioImpl
    AudioImpl --> PipewireSys

    %% Asset relationships
    AssetInterface --> AssetImpl
    AssetImpl --> FileFormats
    AssetBuilder --> FileFormats

    %% Development tool relationships
    DebugSys -.-> Core
    Analysis -.-> Core
    RecordReader -.-> Core

    %% Component mappings
    click MemSys "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/memory_arena.h"
    click EntitySys "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/entity.h"
    click WorldSys "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/world.h"
    click MathSys "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/math.h"
    click RandSys "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/random.h"
    click PlatformInterface "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/platform.h"
    click LinuxImpl "https://github.com/e2dk4r/handmadehero/blob/master/src/handmadehero_linux.c"
    click RenderGroup "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/render_group.h"
    click ColorSys "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/color.h"
    click AudioInterface "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/audio.h"
    click AudioImpl "https://github.com/e2dk4r/handmadehero/blob/master/src/handmadehero_audio.c"
    click AssetInterface "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/asset.h"
    click AssetImpl "https://github.com/e2dk4r/handmadehero/blob/master/src/handmadehero_asset.c"
    click FileFormats "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/fileformats.h"
    click AssetBuilder "https://github.com/e2dk4r/handmadehero/tree/master/tool/hh_asset_builder"
    click RecordReader "https://github.com/e2dk4r/handmadehero/tree/master/tool/hh_record_read"
    click DebugSys "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/debugf.h"
    click Analysis "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/analysis.h"
    click SimRegion "https://github.com/e2dk4r/handmadehero/blob/master/include/handmadehero/sim_region.h"

    classDef core fill:#a8d1f0
    classDef platform fill:#90EE90
    classDef render fill:#FFB347
    classDef audio fill:#FFB347
    classDef asset fill:#DEB887
    classDef dev fill:#DDA0DD

    class MemSys,EntitySys,WorldSys,MathSys,RandSys,SimRegion core
    class PlatformInterface,LinuxImpl,WaylandSys,PipewireSys platform
    class RenderGroup,ColorSys render
    class AudioInterface,AudioImpl audio
    class AssetInterface,AssetImpl,FileFormats asset
    class AssetBuilder,RecordReader,DebugSys,Analysis dev
```
