# bockanator/sandgame architecture

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

- Interactive diagram: https://gitdiagram.com/bockanator/sandgame
- Repository: https://github.com/bockanator/sandgame

## Overview

SandGame is an SDL falling-sand game, with additional player-platforming, artillery, and network-play systems indicated by its source modules. The main runtime owns the grid, game loop, and rendering; element updates and rigid-body physics provide distinct simulation stages. Artillery adds turn-based weapons and AI, while networking supports multiplayer state. Relationships below are limited to README statements, excerpts, and source-index references; unsampled implementation details are not inferred.

Main entry points: [`SandGame/SandGame.cpp`](https://github.com/bockanator/sandgame/blob/main/SandGame/SandGame.cpp) (Game Loop), [`SandGame/Networking.cpp`](https://github.com/bockanator/sandgame/blob/main/SandGame/Networking.cpp) (Network Manager), [`SandGame/ArtilleryGame.cpp`](https://github.com/bockanator/sandgame/blob/main/SandGame/ArtilleryGame.cpp) (Artillery Turns), [`SandGame/Input.cpp`](https://github.com/bockanator/sandgame/blob/main/SandGame/Input.cpp) (Input Handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game Runtime"]
  node_runtime["Game Loop<br/>[SandGame.cpp]"]
  node_input["Input Handling<br/>[Input.cpp]"]
  node_levels["Level Selection<br/>[SandGame.cpp]"]
  node_renderer["Player Renderer<br/>[PlayerRenderer.cpp]"]
end

subgraph group_simulation["World Simulation"]
  node_elements["Element Simulation<br/>[Elements.cpp]"]
  node_grid[("World Grid<br/>[SandGame.cpp]")]
  node_rigid["Rigid Bodies"]
  node_threadpool["Thread Pool<br/>[BS_thread_pool.hpp]"]
end

subgraph group_player["Player and Artillery"]
  node_artillery["Artillery Turns<br/>[ArtilleryGame.cpp]"]
  node_artilleryui["Artillery UI<br/>[ArtilleryUI.cpp]"]
  node_weapons["Weapons and Abilities<br/>[Weapons.cpp]"]
  node_ai["Artillery AI<br/>[ArtilleryAI.cpp]"]
end

subgraph group_multiplayer["Multiplayer"]
  node_network["Network Manager<br/>[Networking.cpp]"]
  node_remote[("Remote Players<br/>[Networking.h]")]
end

node_user(("Player"))

node_user -->|"provides input"| node_input
node_input -.->|"updates controls"| node_runtime
node_runtime -->|"updates and renders"| node_grid
node_runtime -.->|"steps simulation"| node_elements
node_elements -->|"reads and changes"| node_grid
node_runtime -->|"steps physics"| node_rigid
node_rigid -->|"syncs cells"| node_grid
node_runtime -->|"dispatches rendering"| node_threadpool
node_runtime -->|"renders player"| node_renderer
node_runtime -.->|"selects levels"| node_levels
node_runtime -->|"updates mode"| node_artillery
node_runtime -->|"renders HUD"| node_artilleryui
node_artilleryui -->|"hosts or joins"| node_network
node_artillery -->|"uses weapon rules"| node_weapons
node_artillery -.->|"requests decisions"| node_ai
node_input -.->|"handles actions"| node_artillery
node_input -.->|"uses multiplayer"| node_network
node_network -->|"tracks players"| node_remote
node_network -.->|"synchronizes cells"| node_grid
node_network -.->|"syncs turns"| node_artillery

click node_runtime "https://github.com/bockanator/sandgame/blob/main/SandGame/SandGame.cpp"
click node_input "https://github.com/bockanator/sandgame/blob/main/SandGame/Input.cpp"
click node_levels "https://github.com/bockanator/sandgame/blob/main/SandGame/SandGame.cpp"
click node_renderer "https://github.com/bockanator/sandgame/blob/main/SandGame/PlayerRenderer.cpp"
click node_elements "https://github.com/bockanator/sandgame/blob/main/SandGame/Elements.cpp"
click node_grid "https://github.com/bockanator/sandgame/blob/main/SandGame/SandGame.cpp"
click node_rigid "https://github.com/bockanator/sandgame/blob/main/SandGame/RigidBodySystem.cpp"
click node_threadpool "https://github.com/bockanator/sandgame/blob/main/SandGame/BS_thread_pool.hpp"
click node_artillery "https://github.com/bockanator/sandgame/blob/main/SandGame/ArtilleryGame.cpp"
click node_artilleryui "https://github.com/bockanator/sandgame/blob/main/SandGame/ArtilleryUI.cpp"
click node_weapons "https://github.com/bockanator/sandgame/blob/main/SandGame/Weapons.cpp"
click node_ai "https://github.com/bockanator/sandgame/blob/main/SandGame/ArtilleryAI.cpp"
click node_network "https://github.com/bockanator/sandgame/blob/main/SandGame/Networking.cpp"
click node_remote "https://github.com/bockanator/sandgame/blob/main/SandGame/Networking.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runtime,node_input,node_levels,node_renderer toneBlue
class node_elements,node_grid,node_rigid,node_threadpool toneAmber
class node_artillery,node_artilleryui,node_weapons,node_ai toneMint
class node_network,node_remote toneRose
class node_user toneIndigo
```

## Components

### Game Runtime

- [Game Loop](https://github.com/bockanator/sandgame/blob/main/SandGame/SandGame.cpp): `SandGame/SandGame.cpp`
- [Input Handling](https://github.com/bockanator/sandgame/blob/main/SandGame/Input.cpp): `SandGame/Input.cpp`
- [Level Selection](https://github.com/bockanator/sandgame/blob/main/SandGame/SandGame.cpp): `SandGame/SandGame.cpp`
- [Player Renderer](https://github.com/bockanator/sandgame/blob/main/SandGame/PlayerRenderer.cpp): `SandGame/PlayerRenderer.cpp`

### World Simulation

- [Element Simulation](https://github.com/bockanator/sandgame/blob/main/SandGame/Elements.cpp): `SandGame/Elements.cpp`
- [World Grid](https://github.com/bockanator/sandgame/blob/main/SandGame/SandGame.cpp): `SandGame/SandGame.cpp`
- [Rigid Bodies](https://github.com/bockanator/sandgame/blob/main/SandGame/RigidBodySystem.cpp): `SandGame/RigidBodySystem.cpp`
- [Thread Pool](https://github.com/bockanator/sandgame/blob/main/SandGame/BS_thread_pool.hpp): `SandGame/BS_thread_pool.hpp`

### Player and Artillery

- [Artillery Turns](https://github.com/bockanator/sandgame/blob/main/SandGame/ArtilleryGame.cpp): `SandGame/ArtilleryGame.cpp`
- [Artillery UI](https://github.com/bockanator/sandgame/blob/main/SandGame/ArtilleryUI.cpp): `SandGame/ArtilleryUI.cpp`
- [Weapons and Abilities](https://github.com/bockanator/sandgame/blob/main/SandGame/Weapons.cpp): `SandGame/Weapons.cpp`
- [Artillery AI](https://github.com/bockanator/sandgame/blob/main/SandGame/ArtilleryAI.cpp): `SandGame/ArtilleryAI.cpp`

### Multiplayer

- [Network Manager](https://github.com/bockanator/sandgame/blob/main/SandGame/Networking.cpp): `SandGame/Networking.cpp`
- [Remote Players](https://github.com/bockanator/sandgame/blob/main/SandGame/Networking.h): `SandGame/Networking.h`

### Other components

- **Player**

## Connections

- Player → Input Handling: provides input
- Input Handling → Game Loop: updates controls
- Game Loop → World Grid: updates and renders (evidence: `SandGame/SandGame.cpp`)
- Game Loop → Element Simulation: steps simulation
- Element Simulation → World Grid: reads and changes (evidence: `SandGame/Elements.cpp`)
- Game Loop → Rigid Bodies: steps physics (evidence: `SandGame/SandGame.cpp`)
- Rigid Bodies → World Grid: syncs cells (evidence: `SandGame/RigidBodySystem.cpp`)
- Game Loop → Thread Pool: dispatches rendering (evidence: `SandGame/SandGame.cpp`)
- Game Loop → Player Renderer: renders player (evidence: `SandGame/SandGame.cpp`)
- Game Loop → Level Selection: selects levels (evidence: `SandGame/SandGame.cpp`)
- Game Loop → Artillery Turns: updates mode (evidence: `SandGame/SandGame.cpp`)
- Game Loop → Artillery UI: renders HUD (evidence: `SandGame/SandGame.cpp`)
- Artillery UI → Network Manager: hosts or joins (evidence: `SandGame/ArtilleryUI.cpp`)
- Artillery Turns → Weapons and Abilities: uses weapon rules (evidence: `SandGame/ArtilleryGame.cpp`)
- Artillery Turns → Artillery AI: requests decisions
- Input Handling → Artillery Turns: handles actions
- Input Handling → Network Manager: uses multiplayer
- Network Manager → Remote Players: tracks players (evidence: `SandGame/Networking.h`)
- Network Manager → World Grid: synchronizes cells
- Network Manager → Artillery Turns: syncs turns
