# uge-l3-info-2023-2024/progc-chapelain_laborde architecture

> Architecture diagram of the GitHub repository uge-l3-info-2023-2024/progc-chapelain_laborde, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uge-l3-info-2023-2024/progc-chapelain_laborde
- Repository: https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde

## Overview

##### Project type and purpose
- This is a standalone, monolithic Tower-Defense game (“Gemcraft”) implemented in C, using the libMLV graphics library.
- Its purpose is to run on Linux, read resource files (images, fonts, wave/map definitions), handle player input, simulate game logic (waves, mobs, towers, mana, inventory), and render graphics to the screen.

##### File structure
- Top-level build and doc files: Makefile, Doxyfile, README.md, doc/
- Headers under include/ and specialized subfolders:
- events/ : ButtonAction, DragAndDrop, FieldEvent, InventoryEvent
- graphic/ : Font, Graphic, GraphicButton, etc.
- tools/ : Button, DynamicArray, TimeManager, Utils, Error
- Sources under src/ with mirroring subfolders for events, graphic, tools
- Resources folder for fonts, images, metadata
- Logging stub under log_dev/
- Entry point: src/Main.c

##### README for additional insights
- Confirms use of libMLV for windowing and rendering
- Describes command-line options, game flow (waves, mana, gem combining, traps)

##### Main components
a. Core Game Engine
- Game state and loop (Game.c / Game.h)
- Parser: loads map/wave definitions (Parser.c / Parser.h)
- Pathfinding (Path.c)
b. Event Handling
- Unified Event dispatcher (Event.c / Event.h)
- Specialized events: ButtonAction, DragAndDrop, FieldEvent, InventoryEvent
c. Rendering / Graphic Layer
- Window and drawing primitives (Window.c / Graphic.c / Font.c)
- UI components: GraphicButton, GraphicField, GraphicInventory, GraphicOverlay
d. Utilities
- Data structures and helpers: DynamicArray, Utils, Error, TimeManager, Button (tools/)
e. Resources
- Assets folder (images/, fonts/), metadata.tex
f. External Dependency
- libMLV graphics library

##### Relationships and interactions
- Input (mouse, keyboard) → Event Handler → Game Engine
- Game Engine state updates → Rendering Layer via graphic APIs
- Game Engine requests resource loads via Parser and Tools
- TimeManager drives the main loop tick
- Utilities serve both engine and rendering layers
- libMLV underpins the Window/Graphic modules

##### Architectural patterns / design principles
- Modular separation by concern: core logic, event handling, rendering, utilities
- Header/source mirroring for clear interface boundaries
- Single-threaded, polling game loop driven by TimeManager
- Data-driven configuration via Parser for maps/waves

- Clear, human-readable labels for each module (corresponding to folders/files)
- Code modules vs. resources vs. external dependencies

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "External Dependency"
        libMLV["libMLV"]:::external
    end

    subgraph "Resources & Parser"
        Parser["Parser"]:::parser
        Pathfinding["Pathfinding"]:::parser
        ResourceStore[(Resources)]:::resource
    end

    subgraph "Event Handling"
        EventDispatcher["EventDispatcher"]:::event
        ButtonAction["ButtonAction"]:::event
        DragAndDrop["DragAndDrop"]:::event
        FieldEvent["FieldEvent"]:::event
        InventoryEvent["InventoryEvent"]:::event
    end

    subgraph "Core Game Loop"
        Main["Main.c"]:::core
        GameEngine["Game.c / Game.h"]:::core
    end

    subgraph "Simulation Modules"
        Map["Map"]:::sim
        Wave["Wave"]:::sim
        Mob["Mob"]:::sim
        Tower["Tower"]:::sim
        Trap["Trap"]:::sim
        Projectile["Projectile"]:::sim
        Gemstone["Gemstone"]:::sim
        Inventory["Inventory"]:::sim
        Mana["Mana"]:::sim
        Stats["Stats"]:::sim
        Element["Element"]:::sim
        Color["Color"]:::sim
    end

    subgraph "Rendering / UI"
        Window["Window"]:::ui
        GraphicCore["Graphic"]:::ui
        Font["Font"]:::ui
        GraphicButton["GraphicButton"]:::ui
        GraphicField["GraphicField"]:::ui
        GraphicInventory["GraphicInventory"]:::ui
        GraphicOverlay["GraphicOverlay"]:::ui
    end

    subgraph "Utilities"
        TimeManager["TimeManager"]:::util
        DynamicArray["DynamicArray"]:::util
        Utils["Utils"]:::util
        Error["Error"]:::util
        ButtonHelper["Button"]:::util
    end

    %% Connections
    Input["User Input"]:::external -->|"user input"| EventDispatcher
    EventDispatcher -->|"dispatch event"| Main
    TimeManager -->|"tick"| Main
    Main -->|"update state"| Map
    Main -->|"update state"| Wave
    Main -->|"update state"| Mob
    Main -->|"update state"| Tower
    Main -->|"update state"| Trap
    Main -->|"update state"| Projectile
    Main -->|"update state"| Gemstone
    Main -->|"update state"| Inventory
    Main -->|"update state"| Mana
    Main -->|"update state"| Stats
    Main -->|"update state"| Element
    Main -->|"update state"| Color
    Main -->|"render call"| Window
    Main -->|"render call"| GraphicCore
    Window -->|"MLV API"| libMLV
    GraphicCore -->|"MLV API"| libMLV
    Main -->|"load asset"| Parser
    Parser -->|"parse definitions"| ResourceStore
    Main -->|"find path"| Pathfinding
    Utils -->|"helper functions"| Main
    Utils -->|"helper functions"| EventDispatcher
    Utils -->|"helper functions"| Window

    %% Click Events
    click Main "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Main.c"
    click GameEngine "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Game.c"
    click Map "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Map.c"
    click Wave "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Wave.c"
    click Mob "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Mob.c"
    click Tower "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Tower.c"
    click Trap "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Trap.c"
    click Projectile "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Projectile.c"
    click Gemstone "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Gemstone.c"
    click Inventory "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Inventory.c"
    click Mana "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Mana.c"
    click Stats "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Stats.c"
    click Element "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Element.c"
    click Color "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Color.c"
    click Parser "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Parser.c"
    click Pathfinding "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/Path.c"
    click EventDispatcher "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/events/Event.c"
    click ButtonAction "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/events/ButtonAction.c"
    click DragAndDrop "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/events/DragAndDrop.c"
    click FieldEvent "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/events/FieldEvent.c"
    click InventoryEvent "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/events/InventoryEvent.c"
    click Window "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/graphic/Window.c"
    click GraphicCore "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/graphic/Graphic.c"
    click Font "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/graphic/Font.c"
    click GraphicButton "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/graphic/GraphicButton.c"
    click GraphicField "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/graphic/GraphicField.c"
    click GraphicInventory "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/graphic/GraphicInventory.c"
    click GraphicOverlay "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/graphic/GraphicOverlay.c"
    click TimeManager "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/tools/TimeManager.c"
    click DynamicArray "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/tools/DynamicArray.c"
    click Utils "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/tools/Utils.c"
    click Error "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/tools/Error.c"
    click ButtonHelper "https://github.com/uge-l3-info-2023-2024/progc-chapelain_laborde/blob/main/src/tools/Button.c"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef event fill:#90EE90,stroke:#000,stroke-width:1px
    classDef ui fill:#FFA500,stroke:#000,stroke-width:1px
    classDef util fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef parser fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef resource fill:#E6E6FA,stroke:#000,stroke-width:1px
    classDef external fill:#fff0f5,stroke-dasharray:5 5,stroke:#000,stroke-width:1px
```
