Layers, the game API boundary and the error-handling rules #13

Open
UnflavoredMeson/Primal_Plus_Plus
opened 2026-11-24 20:15:50 +00:00 by UnflavoredMeson · 0 comments
Owner

Why

Without a dependency table, the engine's folders grow into each other (the fork found Content and Graphics tangled). Fixing the game API's public set now keeps game projects compiling against a small surface.

Decided

  • The engine's folders are layers with an allowed dependency table in Tools/check_layers.py (--graph prints it). A new dependency fails the check: change the code, or add it with the reason.
  • The application glue (Core/Engine.cpp, Core/Main*.cpp, Core/Frame.*) is the top layer App; Core/Log and Core/Jobs are the bottom.
  • Three APIs: Engine/EngineAPI/ is the game API (game projects see only that folder; its headers include only EngineAPI/ and a public set: ids, primitive types, math, utl::vector, Log); the editor links the engine directly (S7); everything else is internal.
  • enum class for enums, std::to_underlying() for their values; bitmasks and array-slot enums stay plain wrappers on purpose.
  • std::expected<T, E> for fallible functions, E an enum class of reasons a caller acts on; [[nodiscard]]; never .value().

Read first

  • Preferences, "Layers and the game API" and "Error handling".
  • UnflavoredMeson/Primal#4 (group A and C: what was converted and what stayed on purpose).

Steps

  • 1. Write check_layers.py and draw today's graph. Decide each existing edge: allowed, or a tangle to fix.
  • 2. Write the public-set check for EngineAPI/ headers.
  • 3. Convert the enums the API exposes to enum class.
  • 4. Convert one fallible function to std::expected (content loading is a good first one) and its callers.

Done when

  • check_layers.py passes and is in ci.sh checks; 0 warnings both OSes; tidy 0; UnitTests pass.

Claude can help with

  • Producing the dependency graph and listing edges for you to judge.

Learn

  • Why a layer table is cheaper than CMake targets per layer at this size.
## Why Without a dependency table, the engine's folders grow into each other (the fork found `Content` and `Graphics` tangled). Fixing the game API's public set now keeps game projects compiling against a small surface. ## Decided - The engine's folders are layers with an allowed dependency table in `Tools/check_layers.py` (`--graph` prints it). A new dependency fails the check: change the code, or add it with the reason. - The application glue (`Core/Engine.cpp`, `Core/Main*.cpp`, `Core/Frame.*`) is the top layer `App`; `Core/Log` and `Core/Jobs` are the bottom. - Three APIs: `Engine/EngineAPI/` is the game API (game projects see only that folder; its headers include only `EngineAPI/` and a public set: ids, primitive types, math, `utl::vector`, Log); the editor links the engine directly (S7); everything else is internal. - `enum class` for enums, `std::to_underlying()` for their values; bitmasks and array-slot enums stay plain wrappers on purpose. - `std::expected<T, E>` for fallible functions, `E` an `enum class` of reasons a caller acts on; `[[nodiscard]]`; never `.value()`. ## Read first - [Preferences](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Preferences), "Layers and the game API" and "Error handling". - `UnflavoredMeson/Primal#4` (group A and C: what was converted and what stayed on purpose). ## Steps - [ ] 1. Write `check_layers.py` and draw today's graph. Decide each existing edge: allowed, or a tangle to fix. - [ ] 2. Write the public-set check for `EngineAPI/` headers. - [ ] 3. Convert the enums the API exposes to `enum class`. - [ ] 4. Convert one fallible function to `std::expected` (content loading is a good first one) and its callers. ## Done when - [ ] `check_layers.py` passes and is in `ci.sh checks`; 0 warnings both OSes; tidy 0; UnitTests pass. ## Claude can help with - Producing the dependency graph and listing edges for you to judge. ## Learn - Why a layer table is cheaper than CMake targets per layer at this size.
Sign in to join this conversation.
No assignees
No project
Depends on
#4 Self-contained headers and no include cycles
UnflavoredMeson/Primal_Plus_Plus
#11 The engine as one shared library
UnflavoredMeson/Primal_Plus_Plus
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
UnflavoredMeson/Primal_Plus_Plus#13
No description provided.