Actor runtime: actors, parts, behaviors #43

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

Why

Editor scenes are made of actors: things with a tree of parts and some logic. They sit on top of the ECS so mass gameplay can still use plain entities.

Decided

  • Our own names: Actor, Behavior (per-object logic), Part (a piece with a transform), Prefab; Entity stays the ECS handle.
  • Every part owns one entity (actor::ActorOwner); the part tree is the entity hierarchy; the first part is the root. Objects cache no component data.
  • Behaviors belong to the actor and reach parts through PartRef fields; ActorRef/PartRef convert from pointers implicitly.
  • spawn() is immediate between frames and at the sync point, queued inside a frame; destroy()/remove_part() only between frames; queue_add_*() inside a frame.
  • Tick order: each actor, then its behaviors, in spawn order, after game scripts; only classes that override update() tick. late_update() after all updates.
  • Never remove an actor's entity with game_entity::remove() (asserts).

Read first

  • Actors, sections 1-8, 16 and 18.

Steps

  • 1. Write UnitTests/ActorTests.cpp: spawn, parts as children, behaviors begin play before the actor, destroy order, queued spawn inside a frame.
  • 2. Write Engine/EngineAPI/Actor.h and Engine/Actors/ until they pass.
  • 3. Add destroy_all() at shutdown; test it with 10,000 actors (the fork's was quadratic).

Done when

  • ActorTests pass under ASan and TSan; 0 warnings; tidy 0.

Claude can help with

  • Lifetime edge cases (destroying an actor from its own behavior).

Learn

  • Why the objects hold no copies of component data.
## Why Editor scenes are made of actors: things with a tree of parts and some logic. They sit on top of the ECS so mass gameplay can still use plain entities. ## Decided - Our own names: Actor, Behavior (per-object logic), Part (a piece with a transform), Prefab; Entity stays the ECS handle. - Every part owns one entity (`actor::ActorOwner`); the part tree is the entity hierarchy; the first part is the root. Objects cache no component data. - Behaviors belong to the actor and reach parts through `PartRef` fields; `ActorRef`/`PartRef` convert from pointers implicitly. - `spawn()` is immediate between frames and at the sync point, queued inside a frame; `destroy()`/`remove_part()` only between frames; `queue_add_*()` inside a frame. - Tick order: each actor, then its behaviors, in spawn order, after game scripts; only classes that override `update()` tick. `late_update()` after all updates. - Never remove an actor's entity with `game_entity::remove()` (asserts). ## Read first - [Actors](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Actors), sections 1-8, 16 and 18. ## Steps - [ ] 1. Write `UnitTests/ActorTests.cpp`: spawn, parts as children, behaviors begin play before the actor, destroy order, queued spawn inside a frame. - [ ] 2. Write `Engine/EngineAPI/Actor.h` and `Engine/Actors/` until they pass. - [ ] 3. Add `destroy_all()` at shutdown; test it with 10,000 actors (the fork's was quadratic). ## Done when - [ ] ActorTests pass under ASan and TSan; 0 warnings; tidy 0. ## Claude can help with - Lifetime edge cases (destroying an actor from its own behavior). ## Learn - Why the objects hold no copies of component data.
Sign in to join this conversation.
No assignees
No project
Blocks
#44 The engine's parts: mesh, lights, camera
UnflavoredMeson/Primal_Plus_Plus
#45 Actor reflection and spawning by name
UnflavoredMeson/Primal_Plus_Plus
#50 Actor messaging: mailboxes and events
UnflavoredMeson/Primal_Plus_Plus
Depends on
#20 Transforms as components with a hierarchy
UnflavoredMeson/Primal_Plus_Plus
#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#43
No description provided.