# Seele × MeshShadingDemo — Cross-Repository Orientation > **Read this first** if you are an agent working in the *MeshShadingDemo* test > repository and need to reach into the **Seele engine** at `external/Seele`, or > vice-versa. This is the "how does the test game plug into the engine" doc. > For engine-internal navigation (per-subsystem deep dives) see > [`docs/README.md`](README.md) and [`AGENTS.md`](../AGENTS.md). The **MeshShadingDemo** repo is *not* a standalone app. It is a **test game / integration harness** built *against* the Seele engine. It exists to exercise the engine (mesh shading, lighting, culling, the render pipeline) with real content. The engine itself lives in the `external/Seele` **git submodule** and is the only place engine code should be modified. --- ## 1. Repository relationship (the two repos) | | **Seele (the engine)** | **MeshShadingDemo (the test game)** | |---|---|---| | Role | Game engine (C++23, Vulkan/Metal) | Test / integration harness | | Location | `external/Seele/` (git submodule → `Dynamitos/Seele`) | repo root | | Default branch | `master` | `main` | | Build target | `Engine` (SHARED lib) + `Editor`, `Benchmark`, `AssetViewer`, tests | `MeshShadingDemo` (SHARED lib, a **plugin DLL**) | | Where you change | engine code, render passes, materials, components | scene content, demo actors, demo systems, camera rigs | **The rule that keeps the two from bleeding together:** - To change *engine* behaviour (rendering, components, systems, assets) → edit files under `external/Seele/`. That is a **separate repository**; a commit there must be made *inside the submodule* and then the parent repo must re-record the new submodule pointer. - To change the *demo* (which meshes, lights, camera moves, what the test asserts) → edit files in the demo repo (`src/`, `res/`, `CMakeLists.txt`). These files never touch the engine. Both repos are consumed by the same CMake build: the demo's top-level `CMakeLists.txt` does `add_subdirectory(external/Seele)` and links the engine's `Engine` target. There is one build tree, two source trees, two git identities. --- ## 2. The plugin contract: how a "game" plugs into the engine The engine is backend-agnostic about *games*. A "game" is just a **shared library that exports two C symbols** and provides a `Seele::Game` subclass. The engine (or any host) loads the DLL, calls `createInstance()`, and the engine drives the game. This is the *entire* contract — it is deliberately tiny. ### 2.1 The engine side (`Seele::Game`) `src/Engine/Game.h` (12 lines total — the whole interface): ```cpp namespace Seele { class Game { public: Game() {} virtual ~Game() {} virtual void setupScene(PScene scene, PSystemGraph graph) = 0; // the only hook }; } ``` That single pure-virtual, `setupScene(PScene, PSystemGraph)`, is the **only** entry point the engine gives a game. The engine hands you: - a **`PScene`** — the scene to populate (entities, components, actors), and - a **`PSystemGraph`** — the per-frame system graph to register your update systems into. You do *not* own the main loop, the window, the render loop, or the `Graphics` instance. The engine (specifically the `WindowManager` + `GameView`) owns all of that. Your job in `setupScene` is to **declare content and per-frame work**; the engine runs the frame loop and calls your systems. > This is why there is no "main" in a Seele game and no `app.run()` call — the > host (the editor, a benchmark harness, or the game's own `main.cpp`) is what > owns `WindowManager` and pumps frames. ### 2.2 The demo side (what MeshShadingDemo actually ships) `src/MeshShadingDemoGame.h` + `.cpp` implement the contract: - `class MeshShadingDemoGame : public Game` with the override `setupScene(PScene, PSystemGraph)`. - `extern "C" MESHSHADINGDEMO_API Game* createInstance();` — constructs and returns the game (host calls this to load the plugin). - `extern "C" MESHSHADINGDEMO_API void destroyInstance(Game* game);` — the matching teardown (host calls this to unload it). `MESHSHADINGDEMO_API` is the DLL export macro in `src/Define.h` (`__declspec(dllexport)` when building the DLL, `dllimport` otherwise, empty on non-Windows). `Define.h` also does `using namespace Seele;` so demo code can write `Scene`, `Component::Camera`, etc. without the namespace. **When you add demo content, the flow is:** 1. In `setupScene`, create actors via the engine factories (`scene->createActor<...>()` / `O<...Actor>`) — e.g. `OStaticMeshActor`, `ODirectionalLightActor`, `OPointLightActor`, `OFlyCam`, `OPathFollowCam`. 2. Attach components (`scene->attachComponent(...)`, `.Transform`, `.Camera`, etc.) to those actors. 3. Register any **demo-specific per-frame systems** with `graph->addSystem(...)`. See §3. 4. Load assets through the engine's `AssetRegistry` (`assetRegistry->findMesh<...>(path)`, `findMaterial`, `findTexture`) — the demo never parses asset files itself; the engine's importers (§ in the asset docs) do that. The demo's `MeshShadingDemoGame::setupScene` is the canonical example of all four steps; it is the single best "how a game is composed" reference in the whole monorepo. **Read it before touching demo code.** --- ## 3. The demo-side system pattern (per-frame logic lives here) The demo is not just a scene — it carries its **own per-frame systems** (camera rigs). These are *demo* `System`s: they live in the demo repo, are registered into the engine's `SystemGraph` from `setupScene`, and operate on **demo components** (`Component::Path`, `Component::PathFollow`, plus the engine's own `Camera`/`Transform`/`KeyboardInput`). This is the "game logic" half of the cross-repo contract. ### 3.1 The `ComponentSystem<...>` pattern (the only pattern you need) The demo's systems all derive from the engine's **`System::ComponentSystem`** (`src/Engine/System/ComponentSystem.h` in the engine). A `ComponentSystem<...>` is a `System` whose `update` is invoked **per entity that carries every one of the template parameter components**. The engine's ECS (entt) does the entity selection for you; you just write the per-entity body. **The canonical example** (`src/System/FlyCamSystem.h` in the demo): ```cpp class FlyCamSystem : public System::ComponentSystem< Component::KeyboardInput, // <- entity must have all of these Component::Camera, Component::Transform, Component::PointLight> { public: FlyCamSystem(PScene scene); virtual ~FlyCamSystem(); // one call per matching entity, with the components passed in already: virtual void update(Seele::Component::KeyboardInput& input, Seele::Component::Camera& camera, Seele::Component::Transform& transform, Seele::Component::PointLight& pointLight) override; private: float lastMouseX; // per-system state (NOT per-entity — see gotchas) float lastMouseY; }; DEFINE_REF(FlyCamSystem) ``` Key facts about this pattern: - **Template params = the entity query.** Add/remove a component in the `ComponentSystem<...>` list and the set of entities your `update` runs on changes. This is how the "I want to run on every fly-cam entity" selection is expressed — there is no manual query writing. - **The `update` signature mirrors the template list, in order.** The engine binds each of your `update`'s parameters to the corresponding component on the matched entity. Get the order or the type wrong and it won't compile. - **`DEFINE_REF(YourSystem)`** is required at the bottom — the demo's systems are `RefPtr`/`OwningPtr`-managed like engine systems. - **Constructor takes a `PScene`** — you get the scene for creating/attaching things; you do *not* own the graph. ### 3.2 The two demo systems that exist (and the rig they serve) The demo ships **two** systems, both camera rigs (`src/System/`): | System | Components (the query) | What it does | |---|---|---| | `FlyCamSystem` | `KeyboardInput`, `Camera`, `Transform`, `PointLight` | WASD/mouse fly camera; drives a `PointLight` (the "light follows the cam" test rig). | | `SplineCamSystem` | `Camera`, `Transform`, `Path`, `PathFollow` | moves a `Camera` along a demo `Path` (a control-point spline) via `PathFollow` progress — the cinematic path camera. | The **path machinery is demo-side**: `Component::Path` (`src/Component/Path.h`) holds a control-point spline; `Component::PathFollow` holds a progress parameter; `SplineCamSystem` samples the spline and writes the camera `Transform`. The engine has no knowledge of "spline cameras" — that's demo logic built on the engine's generic `Transform`/`Camera` components. ### 3.3 The demo's actors (the "game objects") Demo content actors live in `src/Actor/` (`FlyCam`, `PathFollowCam`). The `FlyCam`/`PathFollowCam` *actors* are thin wrappers that *attach* the relevant components; the actual per-frame behavior is in the systems above. The `setupScene` in `src/MeshShadingDemoGame.cpp` is where actors are created and components attached. **When you add a new camera rig or content type, the pattern is exactly what the two existing ones do:** an actor that attaches components + a `ComponentSystem` that reads them. ### 3.4 Gotchas (demo systems) - **Per-system state vs per-entity state.** A `ComponentSystem` `update` runs *per entity*. Any member field on the system (like `FlyCamSystem::lastMouseX`) is **shared across every matched entity** — it is per-*system*, not per-*entity*. If you need per-entity state, put it in a **component**, not in a system field. This is the most common demo-system bug (stale state leaking between entities that happen to match the same query). - **Do not add GPU work in `update`.** Same rule as the engine: `update` is the CPU tick; anything that touches the render graph / GPU belongs in the engine's render-side systems (or you're in the wrong layer). Demo systems only write transforms and component state. - **`ComponentSystem` order = binding order.** The template list order and the `update` parameter order must line up 1:1. The compiler is your friend here. - **Demo components** like `Path`/`PathFollow` are plain data structs stored *by value* in the entt registry — no `REF` needed. (See [scene-ecs-components-actors.md](subsystems/scene-ecs-components-actors.md) for the component model.) --- ## 4. The CMake contract (how the two builds are stitched) There are **two ways** to consume the engine, and the demo uses the first: ### 4.1 In-tree (what the demo actually does) The demo's top-level `CMakeLists.txt` (`main/CMakeLists.txt` in the demo repo) does: ```cmake set(CMAKE_TOOLCHAIN_FILE .../external/Seele/external/vcpkg/scripts/buildsystems/vcpkg.cmake) project(MeshShadingDemo) add_subdirectory(external/Seele) # <- builds the Engine target in-tree add_library(MeshShadingDemo SHARED "") target_link_libraries(MeshShadingDemo PUBLIC Engine) # <- link the engine target_compile_definitions(MeshShadingDemo PRIVATE BUILD_DLL) # -> __declspec(dllexport) add_subdirectory(src/) ``` Key facts: - **One build tree, two source trees, two git identities.** `add_subdirectory` compiles the *entire engine* as part of the demo's build. There is no separate engine install step in this flow. - **`BUILD_DLL` is the demo's export switch.** It is a *demo* compile definition (see `src/Define.h`): it flips `MESHSHADINGDEMO_API` to `__declspec(dllexport)`, which is what makes `createInstance`/`destroyInstance` visible to the engine's `GameInterface` `GetProcAddress`/`dlsym`. **If a symbol isn't exported, the engine's loader can't see it** — this is the most common "game won't load" bug. - **vcpkg is the single dependency provider** for *both* repos (the toolchain file is pointed at `external/Seele/external/vcpkg`). The engine's `find_package` calls (Vulkan, EnTT, assimp, slang, etc.) all resolve through it. You do not manage dependencies per-repo. - **Outputs are written to the demo's `bin/`** (`CMAKE_BINARY_DIR` is set to `main/bin` in the demo's CMake). The demo's `.so`/`.dll` and the engine's `Engine` shared lib both land there; the engine's `GameInterface` is given a path to that `.so`. ### 4.2 Out-of-tree (the engine's install/export path) The engine *also* ships a proper install/export so it can be consumed as a **package** (not used by this demo, but it's how a real consumer would link against a prebuilt engine). In `external/Seele/CMakeLists.txt`: ```cmake install(TARGETS AssetViewer Editor Engine crcpp metal EXPORT EngineTargets FILE_SET HEADERS DESTINATION include/Seele) export(EXPORT EngineTargets FILE "${CMAKE_BINARY_DIR}/EngineTargets.cmake" NAMESPACE Seele::) configure_package_config_file(cmake/EngineConfig.cmake.in "SeeleConfig.cmake" ...) install(EXPORT EngineTargets FILE EngineTargets.cmake ...) ``` - `FILE_SET HEADERS` (CMake ≥ 3.23) is what installs the public headers under `include/Seele` — this is the "clean install" story. - The `Seele::` namespace prefix means an out-of-tree consumer would `find_package(Seele)` and link `Seele::Engine`. - **This demo does NOT use this path.** It builds the engine in-tree. If you ever need a "link against a prebuilt Seele" flow, *this* is the export to consume — but today, in this repo, `add_subdirectory` is the only path. ### 4.3 Gotchas (CMake) - **Two CMake versions matter.** The demo's CMake is `3.7...3.23` (range) and the engine's `FILE_SET HEADERS` needs `≥3.23`. If you downgrade your CMake below 3.23, the *install* path breaks (the in-tree build may still work). - **Don't `find_package(Seele)` in the demo** — it isn't installed; it's `add_subdirectory`'d. Conversely, don't `add_subdirectory` the demo *into* the engine (wrong direction). - **`BUILD_DLL` is demo-side, not engine-side.** The engine never defines it. If you move the demo's `CMakeLists` or restructure, the `target_compile_definitions (BUILD_DLL)` must travel with the demo library target or exports vanish. - **vcpkg toolchain file is a single global switch.** Changing vcpkg manifests or the toolchain affects *both* repos at once. --- ## 5. Practical "where do I look" map A quick index by task. For full detail, each link is a per-subsystem deep dive. | You want to… | Start at | |---|---| | Compose a scene (actors + components) in the demo | `main/src/MeshShadingDemoGame.cpp` (`setupScene`) + [scene-ecs](subsystems/scene-ecs-components-actors.md) | | Add a new demo per-frame system (camera, etc.) | `main/src/System/FlyCamSystem.{h,cpp}` as the template + §3 above | | Add a new component (engine or demo) | [scene-ecs](subsystems/scene-ecs-components-actors.md) (component model) + `src/Engine/Component/` | | Add a new render pass / change a shader | [render-graph](subsystems/render-graph-and-passes.md) + [graphics-backend](subsystems/graphics-abstract-backend.md) + `src/Engine/Rendering/` | | Add/modify a material or shader graph | [materials](subsystems/materials-shader-graphs.md) + `src/Engine/Materials/` (slang) | | Add a mesh / change meshlet layout | [render-graph](subsystems/render-graph-and-passes.md) (meshlet layout + render pipeline) + `src/Engine/Rendering/` + the `Culling.md` note in the engine root | | Work on ray tracing | [render-graph](subsystems/render-graph-and-passes.md) + [graphics-backend](subsystems/graphics-abstract-backend.md) + the RT sections in [vulkan](subsystems/vulkan-backend.md) / [metal](subsystems/metal-backend.md) | | Add UI (HUD, menus, panels) | [ui](subsystems/ui.md) + `src/Engine/UI/` (flexbox, theming, the font INVARAIT) | | Add physics (rigid bodies, collisions) | [physics](subsystems/physics.md) + `AGENTS.md` § "Physics (Jolt)" | | Touch the window / frame loop / input | [window](subsystems/window.md) + `src/Engine/Window/` | | Fix "game won't load" / cross-repo symbol issues | [platform](subsystems/platform.md) + `src/Engine/Platform//GameInterface.cpp` + §2 (the two-symbol contract) | | Load/create/serialize assets | [assets](subsystems/asset-pipeline.md) + [core-utils](subsystems/core-utilities.md) (serialization) + `src/Engine/Asset/` | | Vulkan backend specifics | [vulkan](subsystems/vulkan-backend.md) + `src/Engine/Graphics/Vulkan/` | | Metal backend specifics | [metal](subsystems/metal-backend.md) + `src/Engine/Graphics/Metal/` | | Understand the frame (what runs when) | [systems](subsystems/systems-update-loop.md) + [window](subsystems/window.md) (the render/update protocol) | | The engine↔demo ABI (the two C symbols) | §2 above + [game-interface](subsystems/game-interface.md) + [platform](subsystems/platform.md) | ### 5.1 The three invariants that save hours 1. **Engine changes go in the submodule.** Edit `external/Seele/...`, commit *inside the submodule*, then re-record the submodule pointer in the parent. Never edit engine files from the demo repo's perspective. 2. **`update` is CPU; `prepare`/`render`/`commitUpdate` are GPU.** Put work in the right phase of the [render/update protocol](subsystems/window.md) or you will get tearing, stale resources, or the render graph's auto-invalidation fighting you. 3. **The ABI is exactly two C symbols** (`createInstance`/`destroyInstance`). Everything else crosses the boundary as virtual methods on `Game`. Don't add a third export; route new functionality through `Game`'s virtuals. ### 5.2 The two "read these first" documents - **`AGENTS.md`** (engine root) — the map + the rules (memory model, the `update`/GPU split, the Jolt ground rules, the culling note). **It is the single best first read.** This `docs/` tree is the *per-subsystem* layer that it points you into. - **`src/MeshShadingDemoGame.cpp`** (demo) — the one file that shows the whole "how a game is composed" flow against the real engine. Read it before writing demo code. **That is the whole orientation.** Every other detail is a per-subsystem doc, linked from the table above.