# priler/dino3d architecture

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

- Interactive diagram: https://gitdiagram.com/priler/dino3d
- Repository: https://github.com/priler/dino3d

## Overview

##### Main Components
- Entry Points: Begin with the HTML files (“index.html” for the default version and “low.html” for an alternate quality setting).
- Core Initiation & Loop: The game initialization (js/src/init.js) and the main loop (js/src/_loop.js).
- Managers: Several manager modules exist which are key to the game’s operation:
- Game Manager (js/src/game_manager.js): Coordinates the overall game flow.
- Input Manager (js/src/input_manager.js): Handles user input (keyboard keys for jump, bend down, etc.).
- Player Manager (js/src/player_manager.js): Manages the player’s state and behaviors.
- Enemy Manager (js/src/enemy_manager.js): Spawns and manages obstacles or enemies.
- Audio Manager (js/src/audio_manager.js): Integrates sound effects (using Howler.js together with sound files in the sound folder).
- Interface Manager (js/src/interface_manager.js): Manages the user interface elements.
- Load Manager (js/src/load_manager.js): Deals with asset loading (e.g., textures, .vox models).
- Others: Nature Manager, Effects Manager, Camera & Camera Controls, Score Manager, Log Manager, and particles (js/src/particles.js) for visual effects.
- Rendering & Scene: Utilizes Three.js with supporting libraries (libs/three) including controls (OrbitControls.js), loaders (GLTFLoader, OBJLoader) and many shader and postprocessing files.
- Assets & Resources: The “objects” directory holds voxel (.vox) models that are loaded at runtime. Additionally, there are CSS stylesheets and SCSS files, and a gulpfile.js for build tasks.

##### Relationships and Interactions
- The HTML entry points load the JavaScript application, which first initializes the Three.js scene (setting up camera, lights, geometries, etc.).
- The Load Manager reads in assets (textures, voxel models from the “objects” directory) and passes them to the Game Manager.
- The Input Manager captures keyboard events (mapped to jump, bend, etc.) and informs the Game Manager, which then directs the Player Manager and Enemy Manager.
- The Game Manager acts as the central orchestrator, triggering state updates, processing collisions, and timing game loops (from _loop.js).
- The Audio Manager plays sound effects in response to game events.
- The Interface Manager updates on-screen UI elements (such as the score and game over screens).
- External libraries (e.g., Howler.js for audio, Nebula for particles, dat.gui for debugging) integrate into the core system to provide additional functionality.

##### Architectural Patterns and Design Principles
- Modular Manager Pattern: Several separate “manager” files are used for different concerns (game state, input, rendering, audio, etc.), demonstrating a separation of concerns.
- Event-Driven Architecture: User inputs and game events trigger updates across different systems, which are coordinated by the Game Manager.
- Asset Pipeline & Preprocessing: There are build scripts (gulpfile.js) and a modular organization that separates source code from assets (voxel objects, textures, sounds).
- Library Integration: The game architecture relies on established libraries (Three.js, Howler.js) and custom wrappers/modules to integrate external functionalities smoothly.

##### Incorporate Relevant Technologies and Their Roles
- Three.js: Core 3D rendering engine.
- Howler.js: Audio library for playing sound effects.
- dat.gui: Likely used for debugging and tweaking runtime parameters.
- Nebula: Provides particle effects in the game.
- vox.js: Parses .vox files generated from MagicaVoxel to build Three.js meshes.

##### Specific Elements
- Game Initialization (index.html, low.html) → js/src/init.js.
- Main Loop (js/src/_loop.js) that feeds into the Game Manager.
- Game Manager coordinating among:
- Input Manager,
- Player Manager,
- Enemy Manager,
- Nature and Effects Managers,
- Score Manager, etc.
- Audio Manager (integrating Howler.js and sound assets).
- Asset Loader and Resources (pointing to “objects” for voxel models and textures).
- UI and Interface Manager (rendering game state and score displays).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Entry Points"
        A1["index.html"]:::entry
        A2["low.html"]:::entry
    end

    subgraph "Initialization"
        B1["Game Initialization (js/src/init.js)"]:::init
        B2["Main Loop (js/src/_loop.js)"]:::init
    end

    subgraph "Game Engine Managers"
        C1["Game Manager"]:::engine
        C2["Input Manager"]:::engine
        C3["Player Manager"]:::engine
        C4["Enemy Manager"]:::engine
        C5["Audio Manager"]:::engine
        C6["Interface Manager"]:::engine
        C7["Load Manager"]:::engine
        C8["Nature Manager"]:::engine
        C9["Effects Manager"]:::engine
        C10["Log Manager"]:::engine
        C11["Particles"]:::engine
        C12["Camera"]:::engine
        C13["Camera Controls"]:::engine
    end

    subgraph "Rendering & External Libraries"
        D1["Three.js Integration"]:::render
        D2["Howler.js"]:::external
        D3["dat.gui"]:::external
        D4["Nebula"]:::external
        D5["vox.js"]:::external
    end

    subgraph "Build & Assets Pipeline"
        E1["Build Tasks (gulpfile.js)"]:::build
        E2["CSS/SCSS (css/)"]:::build
        E3["Textures"]:::build
        E4["Voxel Models"]:::build
    end

    %% Entry Points to Initialization
    A1 -->|"loads"| B1
    A2 -->|"loads"| B1

    %% Initialization to Main Loop and Game Engine
    B1 -->|"starts"| B2
    B2 -->|"orchestrates"| C1

    %% Game Engine internal communications
    C2 -->|"triggers"| C1
    C7 -->|"supplies assets"| C1
    C1 -->|"updates"| C3
    C1 -->|"updates"| C4
    C1 -->|"triggers"| C5
    C1 -->|"updates"| C6
    C1 -->|"manages"| C8
    C1 -->|"manages"| C9
    C1 -->|"logs"| C10
    C1 -->|"drives"| C11

    %% Camera and Controls feeding Rendering
    C12 --> D1
    C13 --> D1
    C7 -->|"provides assets"| D1
    C1 -->|"updates scene"| D1

    %% External Libraries Integration
    C5 -->|"plays audio with"| D2
    C11 -->|"uses particles from"| D4
    C1 -->|"debugs via"| D3
    C7 -->|"parses models using"| D5

    %% Build & Assets Pipeline links
    E3 -->|"loaded by"| C7
    E4 -->|"loaded by"| C7
    E1 --> E2
    E1 --> E3
    E1 --> E4

    %% Styles
    classDef entry fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef init fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef engine fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef render fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef build fill:#cceeff,stroke:#333,stroke-width:2px;
    classDef external fill:#ffddcc,stroke:#333,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/priler/dino3d/blob/master/index.html"
    click A2 "https://github.com/priler/dino3d/blob/master/low.html"
    click B1 "https://github.com/priler/dino3d/blob/master/js/src/init.js"
    click B2 "https://github.com/priler/dino3d/blob/master/js/src/_loop.js"
    click C1 "https://github.com/priler/dino3d/blob/master/js/src/game_manager.js"
    click C2 "https://github.com/priler/dino3d/blob/master/js/src/input_manager.js"
    click C3 "https://github.com/priler/dino3d/blob/master/js/src/player_manager.js"
    click C4 "https://github.com/priler/dino3d/blob/master/js/src/enemy_manager.js"
    click C5 "https://github.com/priler/dino3d/blob/master/js/src/audio_manager.js"
    click C6 "https://github.com/priler/dino3d/blob/master/js/src/interface_manager.js"
    click C7 "https://github.com/priler/dino3d/blob/master/js/src/load_manager.js"
    click C8 "https://github.com/priler/dino3d/blob/master/js/src/nature_manager.js"
    click C9 "https://github.com/priler/dino3d/blob/master/js/src/effects_manager.js"
    click C10 "https://github.com/priler/dino3d/blob/master/js/src/log_manager.js"
    click C11 "https://github.com/priler/dino3d/blob/master/js/src/particles.js"
    click C12 "https://github.com/priler/dino3d/blob/master/js/src/camera.js"
    click C13 "https://github.com/priler/dino3d/blob/master/js/src/camera_controls.js"
    click D1 "https://github.com/priler/dino3d/tree/master/libs/three/"
    click D2 "https://github.com/priler/dino3d/blob/master/libs/howler/howler.js"
    click D3 "https://github.com/priler/dino3d/tree/master/libs/dat.gui/"
    click D4 "https://github.com/priler/dino3d/blob/master/libs/nebula/three-nebula.js"
    click D5 "https://github.com/priler/dino3d/blob/master/libs/vox/vox.js"
    click E1 "https://github.com/priler/dino3d/blob/master/gulpfile.js"
    click E2 "https://github.com/priler/dino3d/tree/master/css/"
    click E3 "https://github.com/priler/dino3d/tree/master/textures/"
    click E4 "https://github.com/priler/dino3d/tree/master/objects/"
```
