# alexdantas/sdl2-platformer architecture

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

- Interactive diagram: https://gitdiagram.com/alexdantas/sdl2-platformer
- Repository: https://github.com/alexdantas/sdl2-platformer

## Overview

##### Overall Project Layers & Components
- Game Engine Core: At the heart is the game loop (seen via main.cpp) with a state-driven design (look at GameStateGame, StateManager) handling transitions and game modes.
- Rendering & SDL Wrapper: The SDL.cpp/SDL.hpp files and Window.cpp/Window.hpp are responsible for SDL initialization, rendering, and window management.
- Physics and Collision: With PhysicsManager handling object motion and possibly stepping collisions (e.g., with Player, Bullet, Block).
- Audio Subsystem: Split into Music and SFX managers to deal with the SDL Mixer libraries, playing sound effects and background music.
- Asset Management: Beyond code, assets in directories (fonts, images, sounds) are fundamental – the config.ini and related helper classes may define asset paths and game configurations.

##### Relationships and Interactions
- The main game loop (in main.cpp) ties together the state management, input processing, physics simulation, and rendering.
- The StateManager dictates which GameState (like GameStateGame) is active; each GameState uses the SDL wrapper, InputManager, and PhysicsManager to update and render the game.
- InputManager receives events through the SDL wrapper and informs game objects (Player, FallingObject, Block, Bullet) about actions to take.
- PhysicsManager interacts with game objects (from classes like Block, Bullet, Player) to handle object movement, collisions, and game dynamics.
- Audio components (SFX and Music) listen to game events (player jumps, collisions) and are triggered via the game logic.
- The helper classes (Utils, Timer, TimerCounter, Log) support debugging, general utilities, and performance timing across the engine.

##### Architectural Patterns and Design Principles
- Modular design: Components are separated into distinct modules (Input, Physics, Audio, Render) making them reusable.
- State management and game loop: The separation of concerns between game states and the engine loop is a key design pattern.
- Encapsulation: Different types of game objects (DamageableObject, FallingObject, Bullet, Block, etc.) indicate an object-oriented hierarchy, promoting reusability and extendability.
- Use of configuration (config.ini) for decoupling game settings from code.

##### Relevant Technologies & Dependencies
- SDL 2.0 and its associated libraries (GFX, Image, Mixer, TTF) are central to the project’s execution.
- C++11 features are used, so modern C++ constructs and best practices for game engine development are applied.
- Doxygen comments in the source help document interactions, further justifying a design that clearly shows interfaces and interactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Main Game Loop (main.cpp)"]:::core
    B["State Manager & Game States (GameStateGame, StateManager)"]:::manager
    C["Input Manager (InputManager)"]:::subsystem
    D["Rendering & SDL/Window Management (SDL, Window)"]:::subsystem
    E["Physics Manager (PhysicsManager)"]:::subsystem
    F["Audio Manager (Music, SFX)"]:::subsystem
    G["Asset Management (config.ini & assets)"]:::asset
    H["Helper Utilities (Log, Timer, TimerCounter, Utils)"]:::utility

    subgraph "Game Objects"
        I("Player"):::gameobj
        J("Block"):::gameobj
        K("Bullet"):::gameobj
    end

    A -->|"initiates"| B
    B -->|"controls"| C
    B -->|"renders"| D
    B -->|"updates"| E
    B -->|"triggers"| F
    A -->|"loads"| G
    A -->|"utilizes"| H

    D -->|"sends_events"| C

    C -->|"controls"| I
    C -->|"controls"| J
    C -->|"controls"| K

    E -->|"collides"| I
    E -->|"collides"| J
    E -->|"collides"| K

    %% Click Events
    click A "https://github.com/alexdantas/sdl2-platformer/blob/master/src/main.cpp"

    click B "https://github.com/alexdantas/sdl2-platformer/blob/master/src/StateManager.cpp"
    click B "https://github.com/alexdantas/sdl2-platformer/blob/master/src/StateManager.hpp"
    click B "https://github.com/alexdantas/sdl2-platformer/blob/master/src/GameStateGame.cpp"
    click B "https://github.com/alexdantas/sdl2-platformer/blob/master/src/GameStateGame.hpp"

    click C "https://github.com/alexdantas/sdl2-platformer/blob/master/src/InputManager.cpp"
    click C "https://github.com/alexdantas/sdl2-platformer/blob/master/src/InputManager.hpp"
    click C "https://github.com/alexdantas/sdl2-platformer/blob/master/src/InputDefinitions.hpp"

    click D "https://github.com/alexdantas/sdl2-platformer/blob/master/src/SDL.cpp"
    click D "https://github.com/alexdantas/sdl2-platformer/blob/master/src/SDL.hpp"
    click D "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Window.cpp"
    click D "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Window.hpp"

    click E "https://github.com/alexdantas/sdl2-platformer/blob/master/src/PhysicsManager.cpp"
    click E "https://github.com/alexdantas/sdl2-platformer/blob/master/src/PhysicsManager.hpp"

    click F "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Music.cpp"
    click F "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Music.hpp"
    click F "https://github.com/alexdantas/sdl2-platformer/blob/master/src/SFX.cpp"
    click F "https://github.com/alexdantas/sdl2-platformer/blob/master/src/SFX.hpp"

    click G "https://github.com/alexdantas/sdl2-platformer/blob/master/config.ini"
    click G "https://github.com/alexdantas/sdl2-platformer/tree/master/assets"

    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Log.cpp"
    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Log.hpp"
    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Timer.cpp"
    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Timer.hpp"
    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/TimerCounter.cpp"
    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/TimerCounter.hpp"
    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Utils.cpp"
    click H "https://github.com/alexdantas/sdl2-platformer/blob/master/src/Utils.hpp"

    %% Styles
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef manager fill:#f9f,stroke:#333,stroke-width:2px;
    classDef subsystem fill:#afa,stroke:#333,stroke-width:2px;
    classDef asset fill:#ffa,stroke:#333,stroke-width:2px;
    classDef utility fill:#fda,stroke:#333,stroke-width:2px;
    classDef gameobj fill:#cfc,stroke:#333,stroke-width:2px;
```
