Frame phases primal.frame and queued entity changes #17

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

Why

Once work runs on several threads, entities can't be created or removed at any moment. A frame with fixed phases and a sync point says when structural changes happen and when data may be read in parallel.

Decided

  • frame::run(dt, render) (module primal.frame, Engine/Core/Frame.ixx): sync point, game code, transforms, render.
  • Inside a frame, entities are created and removed only through game_entity::queue_create()/queue_remove(), applied at the next sync point; the immediate calls assert that they run between frames.
  • Lifetime: begin_play() at the sync point after creation; end_play() before removal (only after begin_play()).
  • After transform::update_matrices(), render preparation reads transforms from several threads, so nothing there may write a component.

Read first

Steps

  • 1. Write UnitTests/FrameTests.cpp: a queued entity exists from the next frame; begin_play() runs once; end_play() runs only after begin_play().
  • 2. Write the module until they pass.
  • 3. Move EngineTest's loop onto frame::run().
  • 4. Run transforms with parallel_for and measure 100,000 entities with and without jobs.

Done when

  • FrameTests pass, also under TSan; the numbers are in this issue as a comment.
  • 0 warnings both OSes; tidy 0.

Claude can help with

  • A benchmark case for the transform update.

Learn

  • Why a sync point makes structural changes cheap to reason about.
## Why Once work runs on several threads, entities can't be created or removed at any moment. A frame with fixed phases and a sync point says when structural changes happen and when data may be read in parallel. ## Decided - `frame::run(dt, render)` (module `primal.frame`, `Engine/Core/Frame.ixx`): sync point, game code, transforms, render. - Inside a frame, entities are created and removed only through `game_entity::queue_create()`/`queue_remove()`, applied at the next sync point; the immediate calls assert that they run between frames. - Lifetime: `begin_play()` at the sync point after creation; `end_play()` before removal (only after `begin_play()`). - After `transform::update_matrices()`, render preparation reads transforms from several threads, so nothing there may write a component. ## Read first - [Multithreading](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Multithreading), section 4 (data access rules) and section 9 step 6. ## Steps - [ ] 1. Write `UnitTests/FrameTests.cpp`: a queued entity exists from the next frame; `begin_play()` runs once; `end_play()` runs only after `begin_play()`. - [ ] 2. Write the module until they pass. - [ ] 3. Move EngineTest's loop onto `frame::run()`. - [ ] 4. Run transforms with `parallel_for` and measure 100,000 entities with and without jobs. ## Done when - [ ] FrameTests pass, also under TSan; the numbers are in this issue as a comment. - [ ] 0 warnings both OSes; tidy 0. ## Claude can help with - A benchmark case for the transform update. ## Learn - Why a sync point makes structural changes cheap to reason about.
Sign in to join this conversation.
No assignees
No project
No milestone
Blocks
#19 Archetype ECS
UnflavoredMeson/Primal_Plus_Plus
Depends on
#16 Job system module primal.jobs
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#17
No description provided.