# pshocker/sdlms architecture

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

- Interactive diagram: https://gitdiagram.com/pshocker/sdlms
- Repository: https://github.com/pshocker/sdlms

## Overview

##### Project’s Purpose and Architectural Style
- The project is a game engine or game framework aimed at re-implementing MapleStory’s experience.
- It is built on an ECS (Entity Component System) architecture. Notice the “Core/ECSSystem.h”, the “Components” directory (which contains game behaviors like AnimatedSprite, Avatar, Camera, etc.), the “Entities” which represent game objects (like Characters, Portals, Background, etc.), and the “Systems” which manage runtime functionalities (InputSystem, RenderSystem, SoundSystem, etc.).

##### Main Components
a. External Libraries & Dependencies:
- 3rdparty libraries, such as SDL (for rendering/input/audio) and Freetype (for fonts), and wzlibcpp (likely for resource handling).
- Mention FFMPEG configuration as noted in the README for multimedia support.
b. Core Engine Components:
- “Core” module: Manages essential utilities such as file handling, input management, window creation, world management, and helper utilities (e.g., MathHelper).
- “Resource” module: Manages assets and resource loading (e.g., Wz.cpp/Wz.h).
c. Entity Component System Modules:
- “Components”: Defines various individual behaviors (e.g., AnimatedSprite, Camera, Player, etc.)
- “Entities”: Specifies game objects (e.g., Characters, Backgrounds, NPCs, Tiles) that are composed of components.
- “Systems”: Implements game loop processes like input handling (InputSystem), rendering (RenderSystem, SpriteSystem, VideoSystem), physics (PhysicSystem), and other frame-specific tasks (DeltaTimeSystem, CameraSystem, TransformSystem).
d. Build and Platform-Specific Configurations:
- Build scripts via CMake (CMakeLists.txt at both the project and subdirectory levels).

##### Relationships and Data Flow
- The External Libraries layer that provides foundational support (SDL, Freetype, FFMPEG, etc.).
- The Core/ECS layer which drives the engine mechanics – core functionalities and the ECS framework that orchestrates the Systems, Components, and Entities.
- The Game Content layer representing game-specific entities integrated from “Entities” and ‘Components’, manipulated by various “Systems”.
- How the Core layer calls into external libraries.
- The flow from Systems (e.g., InputSystem, RenderSystem, PhysicSystem) to update Entities based on Component data.
- Resource management flowing from the Resource module to Entities and Components.
- Interactions such as Input -> System update -> Entity state changes -> Render output.

##### Architectural Patterns and Design Principles
- Separation of concerns:
- The ECS architecture clearly distinguishes between data (Components), behavior (Systems), and aggregates (Entities).
- Core services (like window management and file I/O) are abstracted away from game-specific logic.
- Modularity and platform independence:
- Use of CMake for cross-platform builds is a key design decision.
- The documentation files (doc/Android.md, etc.) point to platform-tailored configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Libraries & Dependencies"
        E1("SDL"):::external
        E2("Freetype"):::external
        E3("wzlibcpp"):::external
        E4("FFMPEG"):::external
        E5("3rdparty"):::external
    end

    subgraph "Core Engine Components"
        C1("Core (Input,Window,FileI/O,World)"):::core
        C2("Resource Management (Assets,Wz)"):::resource
    end

    subgraph "ECS Framework"
        ECS1("Components (AnimatedSprite,Avatar,Camera,...)"):::ecs
        ECS2("Entities (Character,Portal,Background,...)"):::ecs
        ECS3("Systems (InputSystem,RenderSystem,PhysicSystem,...)"):::ecs
    end

    subgraph "Build & Platform Config"
        B1("CMakeLists.txt (root)"):::build
        B2("CMakeLists.txt (sdlms)"):::build
        B3("Documentation (doc)"):::build
    end

    %% Relationships
    E1 --> C1
    E2 --> C1
    E3 --> C1
    E4 --> C1

    C1 --> ECS3
    ECS1 --> ECS3
    ECS2 --> ECS3
    C2 --> ECS2

    B1 --> C1
    B2 --> C1
    B3 --> B1

    ECS3 --> ECS2
    ECS3 --> ECS1

    %% Click Events
    click E5 "https://github.com/pshocker/sdlms/tree/main/3rdparty"
    click B1 "https://github.com/pshocker/sdlms/blob/main/CMakeLists.txt"
    click B2 "https://github.com/pshocker/sdlms/blob/main/sdlms/CMakeLists.txt"
    click B3 "https://github.com/pshocker/sdlms/tree/main/doc"
    click C1 "https://github.com/pshocker/sdlms/tree/main/sdlms/Core"
    click C2 "https://github.com/pshocker/sdlms/tree/main/sdlms/Resource"
    click ECS1 "https://github.com/pshocker/sdlms/tree/main/sdlms/Components"
    click ECS2 "https://github.com/pshocker/sdlms/tree/main/sdlms/Entities"
    click ECS3 "https://github.com/pshocker/sdlms/tree/main/sdlms/Systems"

    %% Styles
    classDef external fill:#f9d6ae,stroke:#333,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef resource fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef ecs fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef build fill:#e2e3e5,stroke:#333,stroke-width:2px;
```
