Files
Seele/docs/subsystems/systems-update-loop.md
T

54 lines
5.7 KiB
Markdown
Raw Normal View History

# Component Systems & the Update Loop
> SystemGraph, SystemBase, ComponentSystem<T>, the built-in systems, and how the frame loop drives them from GameView.
This is a **navigation** doc: it tells you where things live, how data actually flows, and the sharp edges — so you can orient in minutes instead of hours. It complements the repository's [AGENTS.md](../../AGENTS.md) (map + rules) and the [cross-repo guide](../cross-repo.md) (engine ↔ demo contract). Everything below is grounded in the checked-out source at commit `d3ed573`.
## Key types & where they live
| Type | Defined in |
|------|------------|
| `SystemBase` | `src/Engine/System/SystemBase.h` |
| `SystemGraph` | `src/Engine/System/SystemGraph.h` |
| `ComponentSystem<Components...>` | `git grep` in `src/` |
| `KeyboardInput` | `src/Engine/Component/KeyboardInput.h` |
| `FluidUpdater` | `src/Engine/System/FluidUpdater.h` |
| `LightGather` | `src/Engine/System/LightGather.h` |
| `MeshUpdater` | `src/Engine/System/MeshUpdater.h` |
| `CameraUpdater` | `src/Engine/System/CameraUpdater.h` |
| `Executor` | `src/Engine/System/Executor.h` |
Paths above are resolved against the actual source tree (namespace ≈ directory in this codebase). A `(search)` marker means the file contains the name but may also define others — open it and grep. `git grep` is always a fallback. The full per-file map is in **Where to look** below.
## Data flow / lifecycle
SystemGraph (src/Engine/System/SystemGraph.h + .cpp, 318B + 259B) is a list of SystemBase pointers with addSystem(OSystemBase) and run(delta). SystemBase (SystemBase.h) holds a PScene scene and virtual run(double)/update(). ComponentSystem<Components...> (ComponentSystem.h) is the template base for all data-driven systems: its run(delta) calls SystemBase::run then setupView(), which iterates the entt registry over the template's component types (plus any Deps from a has_dependencies concept) and calls the virtual update(components...) / update(entity, components...) overloads. Each concrete system (FluidUpdater, LightGather, MeshUpdater, CameraUpdater, KeyboardInput) is a ComponentSystem specialization. KeyboardInput is special — it is NOT a ComponentSystem; it is a SystemBase subclass that receives raw key/mouse/scroll callbacks from GameView and translates them into entt component modifications. GameView::reloadGame() (GameView.cpp lines 96-108) rebuilds the system graph after each game reload: creates new SystemGraph, calls gameInterface.getGame()->setupScene(scene, systemGraph) (the game DLL populates the scene and may add its own systems), then adds the built-in systems: KeyboardInput, FluidUpdater, LightGather, MeshUpdater, CameraUpdater. GameView::update() (lines 54-69) runs the frame: resets all VertexData mesh data (VertexData::getList() — a global list of registered vertex data objects), runs systemGraph->run(updateTime), calls scene->update(updateTime), then re-creates GPU descriptors for all VertexData (vd->createDescriptors()), and commits the LightEnvironment. updateTime is computed from std::chrono::high_resolution_clock deltas between frames.
## Where to look
| Path | What's there |
|------|--------------|
| `src/Engine/System/SystemGraph.h + SystemGraph.cpp` | |
| `src/Engine/System/SystemBase.h` | base class, 532B |
| `src/Engine/System/ComponentSystem.h` | template base, 1282B — full file shown above |
| `src/Engine/System/KeyboardInput.h + .cpp` | raw input -> entt, 998B + 1442B |
| `src/Engine/System/FluidUpdater.h + .cpp` | FluidGrid+Transform -> fluid grid update |
| `src/Engine/System/LightGather.h + .cpp` | collects light components into LightEnvironment |
| `src/Engine/System/MeshUpdater.h + .cpp` | updates mesh GPU data |
| `src/Engine/System/CameraUpdater.h + .cpp` | updates camera matrices from Transform |
| `src/Engine/System/Executor.h + .cpp` | thread pool executor, 208B + 76B — small |
| `src/Engine/Window/GameView.cpp` | frame loop: update() lines 54-69, reloadGame() lines 96-108, render() lines 75-89 |
## Gotchas & sharp edges
- ComponentSystem::setupView has a commented-out thread pool path (lines 15-22 of ComponentSystem.h) — the parallel dispatch is stubbed. All system updates run serially on the main thread.
- KeyboardInput is NOT a ComponentSystem — it is a plain SystemBase subclass. It does not iterate the entt registry; it receives raw input callbacks from GameView and directly mutates components (e.g. calling scene->accessComponent<Transform>(entity).position += ...).
- The system graph is DESTROYED and REBUILT on every reloadGame() call (GameView.cpp line 99: systemGraph = new SystemGraph()). The game DLL's setupScene is the hook for custom systems.
- VertexData::getList() is a STATIC global list (VertexData.h/.cpp, 6.4KB header + 27.5KB impl). Every VertexData instance registers itself on construction. GameView::update() iterates this list to reset mesh data before the system graph runs and to re-create GPU descriptors after. This is a side-channel that bypasses the ECS — VertexData is NOT an entt component.
- updateTime is NOT a fixed timestep — it is the measured wall-clock delta between frames (lines 55-68 of GameView.cpp). There is no fixed-timestep accumulator in the engine.
- FluidUpdater is a ComponentSystem<FluidGrid, Transform> — it requires both components on an entity to fire. If an entity has FluidGrid but no Transform, it is silently skipped.
- The Executor class (Executor.h/.cpp) is a tiny thread-pool wrapper (76B impl) that is NOT used by any of the built-in systems (the parallel code in ComponentSystem is commented out). It exists for the game DLL to use.
---
*Generated from a full read of the checked-out source at commit `d3ed573`. If a path has moved, `git grep` for the type name — the engine is small enough to find anything in seconds.*