# parrotpotato/bread architecture

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

- Interactive diagram: https://gitdiagram.com/parrotpotato/bread
- Repository: https://github.com/parrotpotato/bread

## Overview

##### Project type and purpose
- This is a native C++ 2D game engine and demo game (“Bread”) built from scratch.
- It uses SDL2 for windowing/input, OpenGL (with GLEW) for rendering, and ImGui for in-engine debugging/tools (tile editor).
- Core features: tile‐map editor, simple physics (SAT collisions), hot code reloading.

##### File structure
- Top-level: CMakeLists.txt, compile_commands.json, README.md for build/config.
- external/imgui: third-party Immediate UI library used in debugging/tooling.
- images: asset folder for screenshots and in-editor sprites.
- src/: all engine & game code, subdivided by feature/file naming:
- main.cc: application entry point & game loop
- gamespace.{cc,hh}: high-level game state manager
- events.hh: input/events abstraction
- platform.{cc,hh}: OS abstractions (SDL2 wrappers)
- physics.{cc,hh}: 2D collision detection & response
- memory.{cc,hh}: custom allocators/memory pools
- util.{cc,hh}: shared utilities/helpers

##### README
- Confirms technology stack: SDL2, OpenGL, GLEW, ImGui.
- Highlights functional modules: tile editor, physics engine, hot code reload.

##### Main components and their relationships
a. Components
1) Platform Layer: SDL2 window/input, time, file I/O wrappers (src/platform)
2) Renderer: OpenGL context, shader management, sprite batcher (in util or gamespace)
3) Asset/Tile Manager: loads spritesheets, textures (part of gamespace or util)
4) Event System: abstracts SDL2 events into engine events (src/events)
5) Game Space Manager: world/state, tile editor, entity management (src/gamespace)
6) Physics Engine: collision detection & response (src/physics)
7) Memory Manager: custom allocators for fast alloc/free (src/memory)
8) UI/Debug Tools: ImGui integration (external/imgui + src/platform/util)
9) Application Layer: main loop, subsystem initialization & orchestration (src/main.cc)

b. Interactions
- main.cc initializes Platform → Renderer → Asset Manager → Physics → Event System → Game Space → UI
- Every frame:
1) Platform polls SDL events → Event System
2) Event System dispatches to Game Space & UI
3) Game Space updates physics, world state
4) Renderer draws world & UI
5) Memory Manager services all dynamic allocations
- Hot code reload hooks into Platform and Game Space to swap DLL/so modules at runtime.

c. Architectural patterns & principles
- Layered architecture: clear separation between platform/OS, core engine, game logic, and tools.
- Single game loop orchestrator (main.cc) controlling subsystems.
- Dependency inversion for better testability: subsystems depend on abstract interfaces (events.hh, platform.hh).
- Asset hot-reloading plugged into platform file-watcher.

d. Key technologies
- SDL2: window, input, timing
- OpenGL + GLEW: GPU rendering
- ImGui: Immediate-mode UI for tile editor & debugging
- CMake: build system

## Diagram (Mermaid)

```mermaid
graph TB
    %% Subgraphs for layered architecture
    subgraph "Application Layer"
        App["Application\n(src/main.cc)"]:::app
    end

    subgraph "Game Logic & Tools"
        GameSpace["Game Space Manager\n(src/gamespace)"]:::app
        UI["UI/Debug Tools\n(external/imgui)"]:::app
    end

    subgraph "Core Engine"
        EventSystem["Event System\n(src/events.hh)"]:::core
        Renderer["Renderer Utilities\n(src/util)"]:::core
        Physics["Physics Engine\n(src/physics)"]:::core
    end

    subgraph "Low-Level Services"
        Memory["Memory Manager\n(src/memory)"]:::low
    end

    subgraph "Platform Layer"
        Platform["Platform Layer\n(src/platform)"]:::low
    end

    HotReload["Hot Code Reload"]:::tool

    %% Application orchestration
    App -->|"init"| Platform
    App -->|"init"| Renderer
    App -->|"init"| Physics
    App -->|"init"| EventSystem
    App -->|"init"| Memory
    App -->|"init"| GameSpace
    App -->|"init"| UI

    %% Frame loop interactions
    Platform -->|"SDL events"| EventSystem
    EventSystem -->|"EngineEvent"| GameSpace
    EventSystem -->|"EngineEvent"| UI
    GameSpace -->|"state update"| Physics
    GameSpace -->|"scene data"| Renderer
    GameSpace -->|"alloc/free"| Memory
    Renderer -->|"draw calls"| Platform

    %% Hot reload interactions
    HotReload -.->|hooks| Platform
    HotReload -.->|hooks| GameSpace

    %% Click Events
    click App "https://github.com/parrotpotato/bread/blob/main/src/main.cc"
    click Platform "https://github.com/parrotpotato/bread/tree/main/src/platform"
    click EventSystem "https://github.com/parrotpotato/bread/blob/main/src/events.hh"
    click Renderer "https://github.com/parrotpotato/bread/blob/main/src/util.cc"
    click Physics "https://github.com/parrotpotato/bread/blob/main/src/physics.cc"
    click Memory "https://github.com/parrotpotato/bread/blob/main/src/memory.cc"
    click GameSpace "https://github.com/parrotpotato/bread/blob/main/src/gamespace.cc"
    click UI "https://github.com/parrotpotato/bread/tree/main/external/imgui/"

    %% Styles
    classDef low fill:#bbdefb,stroke:#1e88e5,stroke-width:2px
    classDef core fill:#c8e6c9,stroke:#388e3c,stroke-width:2px
    classDef app fill:#ffe0b2,stroke:#fb8c00,stroke-width:2px
    classDef tool fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px
```
