# h4tch/basic-sdl2-demo architecture

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

- Interactive diagram: https://gitdiagram.com/h4tch/basic-sdl2-demo
- Repository: https://github.com/h4tch/basic-sdl2-demo

## Overview

##### Main Components

a) Core Engine Layer:
- Engine class (engine.h/cpp) as the central coordinator
- Window management system (window.h/cpp)
- Timer system (timer.h)

b) Graphics System:
- Sprite rendering (animated_sprite.h/cpp)
- Camera system (camera.h)

c) Game Object System:
- Base Object class (object.h/cpp)
- Component System:
- Base Component (component/component.h)
- Animation Component (component/animation.h/cpp)
- Physics Component (component/physics.h/cpp)

d) Resource Management:
- System (map.h)
- Asset loading (data/images directory)

**[Top Layer]**
**Game Logic Layer**
- Object Management
- Component System

**[Middle Layer]**
**Engine Core**
- Main Game Loop
- Timer System
- Resource Management

**[Bottom Layer]**
**SDL2 Framework**
- Graphics (SDL2_image)
- Text Rendering (SDL2_ttf)
- Window Management

##### Specific Implementation Details

- Component-based architecture pattern
- Separation between engine core and game-specific logic
- Resource management flow
- Rendering pipeline from sprite management to window display

##### Key Architectural Patterns to Highlight

- Component-based design pattern (shown in component/ directory)
- Game loop pattern (in engine.cpp)
- Resource management system
- Event-driven architecture (SDL2 events)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph SDL2["SDL2 Framework"]
        SDL_Core["SDL2 Core"]:::sdl
        SDL_Image["SDL2_image"]:::sdl
        SDL_TTF["SDL2_ttf"]:::sdl
    end

    subgraph Engine["Engine Core Layer"]
        Engine_Core["Engine System"]:::core
        Window["Window Management"]:::core
        Timer["Timer System"]:::core
        ResourceMgr["Resource Manager"]:::core
    end

    subgraph Graphics["Graphics System"]
        Sprite["Sprite Renderer"]:::graphics
        Camera["Camera System"]:::graphics
        Map["Map System"]:::graphics
    end

    subgraph GameObjects["Game Object System"]
        Object["Base Object"]:::gameobj
        
        subgraph Components["Component System"]
            BaseComponent["Base Component"]:::component
            AnimationComp["Animation Component"]:::component
            PhysicsComp["Physics Component"]:::component
        end
    end

    subgraph Assets["Asset Storage"]
        Images["Image Assets"]:::resource
    end

    Main["Main Application"]:::core --> Engine_Core
    Engine_Core --> Window
    Engine_Core --> Timer
    Engine_Core --> ResourceMgr
    
    Window --> SDL_Core
    SDL_Core --> SDL_Image
    SDL_Core --> SDL_TTF
    
    ResourceMgr --> Images
    ResourceMgr --> Map
    
    Object --> BaseComponent
    BaseComponent --> AnimationComp
    BaseComponent --> PhysicsComp
    
    AnimationComp --> Sprite
    PhysicsComp --> Object
    
    Sprite --> Camera
    Camera --> Window
    Map --> Sprite

    %% Click events for component mapping
    click Engine_Core "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/engine.h"
    click Window "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/window.h"
    click Timer "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/timer.h"
    click Sprite "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/animated_sprite.h"
    click Camera "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/camera.h"
    click Object "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/object.h"
    click BaseComponent "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/component/component.h"
    click AnimationComp "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/component/animation.h"
    click PhysicsComp "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/component/physics.h"
    click Map "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/include/map.h"
    click Images "https://github.com/H4tch/Basic-SDL2-Demo/tree/master/data/images"
    click Main "https://github.com/H4tch/Basic-SDL2-Demo/blob/master/src/main.cpp"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef graphics fill:#4CAF50,stroke:#2E7D32,color:white
    classDef gameobj fill:#FFC107,stroke:#FFA000,color:black
    classDef component fill:#FF9800,stroke:#F57C00,color:white
    classDef sdl fill:#9E9E9E,stroke:#616161,color:white
    classDef resource fill:#795548,stroke:#5D4037,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Graphics Components"]:::graphics
        L3["Game Objects"]:::gameobj
        L4["Components"]:::component
        L5["SDL2 Framework"]:::sdl
        L6["Resources"]:::resource
    end
```
