Transforms as components with a hierarchy #20

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

Why

Actors attach parts to each other, and the editor reparents things. Transforms need parents from the start, and the renderer needs world matrices computed once per frame in parallel.

Decided

  • Six components (transform::Position, ... in Components/Transform.h) plus Parent/HierarchyDepth on children.
  • position() and set_position() are world space; local_* is relative to the parent (Unity's and Unreal's convention).
  • Reparenting keeps the world transform unless told otherwise; removing an entity removes its children.
  • Update order: roots, then children level by level (depth-sorted), then frames and inverses, on jobs (transform::update_matrices()).
  • Game code writes transforms directly; it runs one object at a time on the frame thread, which keeps that safe.

Read first

  • Ecs, sections 8 and 9.
  • UnflavoredMeson/Primal#57 (an O(n) set_position() that became O(n²) per frame).

Steps

  • 1. Write tests: a child follows its parent; reparenting keeps the world position; removing a parent removes the child; three levels update in order.
  • 2. Write the components and update_matrices() until they pass.
  • 3. Write a benchmark with 10,000 moving entities and check set_position() is O(1).

Done when

  • Tests pass under TSan; the benchmark is in this issue; 0 warnings; tidy 0.

Claude can help with

  • Test cases for the world/local conversions with rotation and non-uniform scale.

Learn

  • Why non-uniform scale under rotation can't be represented exactly in a child's TRS.
## Why Actors attach parts to each other, and the editor reparents things. Transforms need parents from the start, and the renderer needs world matrices computed once per frame in parallel. ## Decided - Six components (`transform::Position`, ... in `Components/Transform.h`) plus `Parent`/`HierarchyDepth` on children. - `position()` and `set_position()` are world space; `local_*` is relative to the parent (Unity's and Unreal's convention). - Reparenting keeps the world transform unless told otherwise; removing an entity removes its children. - Update order: roots, then children level by level (depth-sorted), then frames and inverses, on jobs (`transform::update_matrices()`). - Game code writes transforms directly; it runs one object at a time on the frame thread, which keeps that safe. ## Read first - [Ecs](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Ecs), sections 8 and 9. - `UnflavoredMeson/Primal#57` (an O(n) `set_position()` that became O(n²) per frame). ## Steps - [ ] 1. Write tests: a child follows its parent; reparenting keeps the world position; removing a parent removes the child; three levels update in order. - [ ] 2. Write the components and `update_matrices()` until they pass. - [ ] 3. Write a benchmark with 10,000 moving entities and check `set_position()` is O(1). ## Done when - [ ] Tests pass under TSan; the benchmark is in this issue; 0 warnings; tidy 0. ## Claude can help with - Test cases for the world/local conversions with rotation and non-uniform scale. ## Learn - Why non-uniform scale under rotation can't be represented exactly in a child's TRS.
Sign in to join this conversation.
No assignees
No project
Blocks
#43 Actor runtime: actors, parts, behaviors
UnflavoredMeson/Primal_Plus_Plus
Depends on
#19 Archetype ECS
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#20
No description provided.