Game scripts and the game library ABI #22

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

Why

Game code is a separate library. It has to register its types in the engine's registry and run game-level logic without exporting anything the engine must know by name.

Decided

  • PRIMAL_GAME_SCRIPT() + class X : public script::GameScript for game-level logic (game mode, managers). Created and begin_play() at the first sync point, update(dt) before actors, end_play() at script::end_game_scripts().
  • Per-object logic is actor behaviors (S8). There are no entity scripts; plain entities get ECS systems.
  • The game library links PrimalEngine and exports nothing: its types register while the host loads it, between reflect::begin_library_load() and end_library_load(); release_library_types() before unloading. Types registered that way are copied so they outlive the library.
  • ScriptBase has the name and log helpers (log_info("fmt", ...), category script).

Read first

  • Ecs, section 10; Actors, section 17.
  • Engine/Components/Script.cpp and EngineTest/Scripts.cpp on master.

Steps

  • 1. Write tests with a test game library (CMake target, loaded with dlopen/LoadLibrary): its script registers, runs, and its type is gone after release.
  • 2. Write GameScript and the load bracket until they pass.
  • 3. Remove REGISTER_SCRIPT and the per-entity script component.

Done when

  • Tests pass on both OSes (also the library load on Windows); 0 warnings; tidy 0.

Claude can help with

  • Debugging a library that loads on one OS and not the other.

Learn

  • How static initializers in a loaded library run, and why the load bracket is needed.
## Why Game code is a separate library. It has to register its types in the engine's registry and run game-level logic without exporting anything the engine must know by name. ## Decided - `PRIMAL_GAME_SCRIPT()` + `class X : public script::GameScript` for game-level logic (game mode, managers). Created and `begin_play()` at the first sync point, `update(dt)` before actors, `end_play()` at `script::end_game_scripts()`. - Per-object logic is actor behaviors (S8). There are no entity scripts; plain entities get ECS systems. - The game library links `PrimalEngine` and exports nothing: its types register while the host loads it, between `reflect::begin_library_load()` and `end_library_load()`; `release_library_types()` before unloading. Types registered that way are copied so they outlive the library. - `ScriptBase` has the name and log helpers (`log_info("fmt", ...)`, category `script`). ## Read first - [Ecs](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Ecs), section 10; [Actors](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Actors), section 17. - `Engine/Components/Script.cpp` and `EngineTest/Scripts.cpp` on `master`. ## Steps - [ ] 1. Write tests with a test game library (CMake target, loaded with `dlopen`/`LoadLibrary`): its script registers, runs, and its type is gone after release. - [ ] 2. Write `GameScript` and the load bracket until they pass. - [ ] 3. Remove `REGISTER_SCRIPT` and the per-entity script component. ## Done when - [ ] Tests pass on both OSes (also the library load on Windows); 0 warnings; tidy 0. ## Claude can help with - Debugging a library that loads on one OS and not the other. ## Learn - How static initializers in a loaded library run, and why the load bracket is needed.
Sign in to join this conversation.
No assignees
No project
Blocks
#56 Loading the game library in the editor
UnflavoredMeson/Primal_Plus_Plus
Depends on
#21 Reflection generator PrimalReflectGen
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#22
No description provided.