# jakobwesthoff/pixel_loop architecture

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

- Interactive diagram: https://gitdiagram.com/jakobwesthoff/pixel_loop
- Repository: https://github.com/jakobwesthoff/pixel_loop

## Overview

##### Main Components

a) Game Loop Core
- Fixed timestep update loop
- Variable render loop

b) Canvas System (Abstract Interface)
- Three implementations:
- PixelsCanvas (Hardware-accelerated)
- CrosstermCanvas (Terminal-based)
- InMemoryCanvas (Buffer-based)

c) Input System
- Input abstraction layer
- Both Crossterm and Pixels input implementations

##### Component Relationships

a) Primary Flow:
- Game Loop → Update Function (Fixed timestep)
- Game Loop → Render Function (Variable timestep)
- Both functions connecting to Canvas and Input systems

b) Implementation Details:
- Canvas implementations with different backends
- Input implementations to their respective platforms

**┌─────────────────────────────────────────┐**
- Game Loop Core             │

- ┌─────────────┐        ┌────────────┐  │
- Fixed Update │        │   Render   │  │
- (60 FPS)  │        │ (Variable) │  │
- ┘        └────────────┘  │
- ┘
- ▲                    ▲

- ▼                    ▼
**┌─────────────────┐    ┌─────────────────┐**
- Input System   │    │  Canvas System  │

- ┌─────────────┐ │    │ ┌─────────────┐ │
- Crossterm  │ │    │ │   Pixels    │ │
- ┘ │    │ └─────────────┘ │
- ┌─────────────┐ │    │ ┌─────────────┐ │
- Pixels    │ │    │ │  Crossterm  │ │
- ┘ │    │ └─────────────┘ │
- ┌─────────────┐ │
- InMemory    │ │
- ┘ │
- ┘    └─────────────────┘

##### Additional Details

Important aspects:

a) External Dependencies:
- Connections to pixels and crossterm libraries
- Optional feature flags

b) Configuration Options:
- FPS configuration input
- Feature flag dependencies

##### Notes for Implementation

- Keep the game loop central as it's the core feature
- Small code snippets for key interfaces
- Error handling flow

Remember to include version information and note that this is a work in progress, as mentioned in the README.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core
        GameLoop["Game Loop Core"]
        FixedUpdate["Fixed Update (60 FPS)"]
        VarRender["Render (Variable)"]
        GameLoop --> FixedUpdate
        GameLoop --> VarRender
    end
    
    subgraph InputSystem["Input System"]
        InputInterface["Input Interface"]
        CrosstermInput["Crossterm Input"]
        PixelsInput["Pixels Input"]
        InputInterface --> CrosstermInput
        InputInterface --> PixelsInput
    end
    
    subgraph CanvasSystem["Canvas System"]
        CanvasInterface["Canvas Interface"]
        PixelsCanvas["Pixels Canvas"]
        CrosstermCanvas["Crossterm Canvas"]
        InMemoryCanvas["InMemory Canvas"]
        CanvasInterface --> PixelsCanvas
        CanvasInterface --> CrosstermCanvas
        CanvasInterface --> InMemoryCanvas
    end
    
    subgraph Support
        ColorSystem["Color System"]
        WindowMgmt["Window Management"]
    end
    
    subgraph Examples
        TerminalDemo["Terminal Demo"]
        HWAccelDemo["Hardware Accelerated Demo"]
    end
    
    GameLoop --> InputInterface
    GameLoop --> CanvasInterface
    CanvasInterface --> ColorSystem
    PixelsCanvas --> WindowMgmt
    
    classDef core fill:#2374ab
    classDef input fill:#ff7f50
    classDef canvas fill:#4caf50
    classDef support fill:#9c27b0
    classDef example fill:#795548
    
    class GameLoop,FixedUpdate,VarRender core
    class InputInterface,CrosstermInput,PixelsInput input
    class CanvasInterface,PixelsCanvas,CrosstermCanvas,InMemoryCanvas canvas
    class ColorSystem,WindowMgmt support
    class TerminalDemo,HWAccelDemo example
    
    click GameLoop "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/lib.rs"
    click InputInterface "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/input/mod.rs"
    click CrosstermInput "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/input/crossterm.rs"
    click PixelsInput "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/input/pixels.rs"
    click CanvasInterface "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/canvas/mod.rs"
    click PixelsCanvas "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/canvas/pixels.rs"
    click CrosstermCanvas "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/canvas/crossterm.rs"
    click InMemoryCanvas "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/canvas/in_memory.rs"
    click ColorSystem "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/color.rs"
    click WindowMgmt "https://github.com/jakobwesthoff/pixel_loop/blob/main/src/pixel_loop/tao.rs"
    click TerminalDemo "https://github.com/jakobwesthoff/pixel_loop/tree/main/examples/trivial_cli_demo"
    click HWAccelDemo "https://github.com/jakobwesthoff/pixel_loop/tree/main/examples/trivial_pixels_demo"
```
