# nrednav/game-engine architecture

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

- Interactive diagram: https://gitdiagram.com/nrednav/game-engine
- Repository: https://github.com/nrednav/game-engine

## Overview

##### Main Components
a. External Dependencies & Build System:
- That CMake, Makefile, and supporting files (e.g., CMakeLists.txt) are used to build the project.
- External libraries: OpenGL, GLFW3, GLEW, GLM.
b. Core Engine Modules:
- Module: (src/Display) – Responsible for window/context creation and managing the display.
- Entity System: (src/Entity) – Contains components like Camera, Entity, EntityManager, Light, and Player. This module is key for managing scene objects and gameplay entities.
- Loader Module: (src/Loader) – Handles asset loading including OBJ files (ObjLoader) and other resources.
- Model & Texture Handling: (src/Model, src/Texture) – Manages raw and textured models, as well as terrain textures and texture packs.
- Shader Management: (src/Shader) – Manages shader programs for various components (entities, terrain) and holds shader source files.
- Specialized Components:
▫ Skybox: (src/Skybox) – Manages the skybox with its dedicated renderer and shaders.
▫ Terrain & Floor: (src/Terrain, src/Floor) – Responsible for constructing the ground and environment.
- Utility/Math: (src/Utils) – Contains helper functions for mathematical operations and random number generation.

##### Relationships and Data Flow
- The Display component initializes the OpenGL context. Once set up, the Engine enters its main loop (starting from Main.cpp in src/).
- The Loader reads asset files (models, textures) from the assets folder and passes them to the Model and Texture modules.
- The Entity Manager creates and updates game entities (including players and cameras) and organizes them for rendering.
- The Renderer components (MasterRenderer, EntityRenderer, TerrainRenderer, SkyboxRenderer) receive data from the Entity System and Model/Texture modules, then apply the appropriate shaders (managed by the Shader module) to render the scene.
- The Shader module compiles and configures shader programs that are used by the rendering routines.
- The Utility module supports various other modules with math functions and random number generation essential for transformations and physics.
- The build system (CMake/Makefile) ties all these components together for building and deployment.

##### Architectural Patterns and Principles
- Modularity: Each major function (display management, asset loading, rendering, etc.) is broken into distinct modules.
- Separation of Concerns: Rendering, logic (entity handling), resource loading, and shader management are kept in separate directories.
- Pipeline Design: There is a clear rendering pipeline where assets are loaded → entities are created/managed → shaders are applied → final rendering occurs.
- Abstraction: Specific implementations like ObjLoader abstract away file parsing details.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Build & Dependencies
    subgraph "Build & Dependencies"
        CT("CMakeLists.txt"):::build
        MF("Makefile"):::build
        GL1("OpenGL"):::lib
        GLF("GLFW3"):::lib
        GLE("GLEW"):::lib
        GLM("GLM"):::lib
    end

    %% Initialization
    subgraph "Initialization"
        DISP("Display (src/Display)"):::display
        MAIN("Main Loop (src/Main.cpp)"):::display
    end

    %% Asset Management
    subgraph "Asset Management"
        LOAD("Loader (src/Loader)"):::asset
        MODEL("Model (src/Model)"):::asset
        TEX("Texture (src/Texture)"):::asset
    end

    %% Entity System
    subgraph "Entity System"
        ENTITY("Entity System (src/Entity)"):::engine
    end

    %% Rendering Pipeline
    subgraph "Rendering Pipeline"
        REND("Renderer (src/Renderer)"):::render
        SHAD("Shader Management (src/Shader)"):::render
        SKY("Skybox (src/Skybox)"):::render
        TER("Terrain (src/Terrain)"):::render
        FLOOR("Floor (src/Floor)"):::render
    end

    %% Utilities
    subgraph "Utilities"
        UTIL("Utility/Math (src/Utils)"):::util
    end

    %% Connections from Build & Dependencies to Initialization & Rendering
    CT -->|"initializes"| DISP
    MF -->|"initializes"| DISP
    GL1 -->|"provides"| DISP
    GLF -->|"provides"| DISP
    GLE -->|"provides"| DISP
    GLM -->|"provides"| DISP

    GL1 -->|"enables"| REND
    GLF -->|"enables"| REND
    GLE -->|"enables"| REND
    GLM -->|"enables"| REND

    %% Initialization flow
    DISP -->|"starts"| MAIN

    %% Main Loop distributes control
    MAIN -->|"loads assets"| LOAD
    MAIN -->|"manages entities"| ENTITY
    MAIN -->|"triggers render"| REND

    %% Asset Management flows
    LOAD -->|"loads model data"| MODEL
    LOAD -->|"loads texture data"| TEX

    MODEL -->|"supplies models"| REND
    TEX -->|"supplies textures"| REND

    %% Entity System to Rendering
    ENTITY -->|"provides scene data"| REND

    %% Shader Management integration
    SHAD -->|"configures renderers"| REND

    %% Specialized Rendering components
    SKY -->|"renders skybox"| REND
    TER -->|"renders terrain"| REND
    FLOOR -->|"renders floor"| REND

    %% Utilities support
    UTIL -->|"supports"| ENTITY
    UTIL -->|"supports"| LOAD
    UTIL -->|"supports"| REND
    UTIL -->|"supports"| SHAD

    %% Final display output
    REND -->|"outputs frame"| DISP

    %% Click Events
    click CT "https://github.com/nrednav/game-engine/blob/main/CMakeLists.txt"
    click MF "https://github.com/nrednav/game-engine/tree/main/Makefile"
    click DISP "https://github.com/nrednav/game-engine/tree/main/src/Display"
    click ENTITY "https://github.com/nrednav/game-engine/tree/main/src/Entity"
    click LOAD "https://github.com/nrednav/game-engine/tree/main/src/Loader"
    click MODEL "https://github.com/nrednav/game-engine/tree/main/src/Model"
    click TEX "https://github.com/nrednav/game-engine/tree/main/src/Texture"
    click REND "https://github.com/nrednav/game-engine/tree/main/src/Renderer"
    click SHAD "https://github.com/nrednav/game-engine/tree/main/src/Shader"
    click SKY "https://github.com/nrednav/game-engine/tree/main/src/Skybox"
    click TER "https://github.com/nrednav/game-engine/tree/main/src/Terrain"
    click FLOOR "https://github.com/nrednav/game-engine/tree/main/src/Floor"
    click UTIL "https://github.com/nrednav/game-engine/tree/main/src/Utils"

    %% Styles
    classDef build fill:#ffcccc,stroke:#ff0000,stroke-width:2px;
    classDef lib fill:#ffe6cc,stroke:#ff9900,stroke-width:2px;
    classDef display fill:#cce5ff,stroke:#3399ff,stroke-width:2px;
    classDef asset fill:#ccffcc,stroke:#33cc33,stroke-width:2px;
    classDef engine fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
    classDef render fill:#e6ccff,stroke:#9933ff,stroke-width:2px;
    classDef util fill:#e6e6fa,stroke:#9370db,stroke-width:2px;
```
