Skip to content

Multiple concurrent world support - #42

Open
bryanjeal wants to merge 4 commits into
zig-gamedev:mainfrom
bryanjeal:multi-world
Open

Multiple concurrent world support#42
bryanjeal wants to merge 4 commits into
zig-gamedev:mainfrom
bryanjeal:multi-world

Conversation

@bryanjeal

@bryanjeal bryanjeal commented Jul 14, 2026

Copy link
Copy Markdown

Remove the single-world restriction. Alternative to PR #31: component IDs are shared globally and assigned deterministically via use_low_id. Both COMPONENT and TAG call into the C library in every world, updating the shared global.

Tradeoffs vs per-world maps:

  • No API changes. id(T) unchanged. No world_id().
  • No hash map lookup in hot path. set/get/add deref a global pointer.
  • Smaller diff: only COMPONENT, TAG, init, fini touched.
  • Requires identical registration order across worlds. Asserted when num_worlds > 1.
  • Capped at ~230 component types (FLECS_HI_COMPONENT_ID range).

Adds deinit() for explicit process-lifetime cleanup. Guard assertions for low-ID exhaustion and registration order mismatch. 7 multi-world tests.

Remove single-world assertions from init/fini. Always register
components via ecs_component_init even when global already set,
updating the global to the latest ID. Add shutdown() for explicit
process-exit cleanup of the global component ID map and allocator.

Add multi_world_test.zig with 8 test cases covering concurrent
world lifecycle and component ID isolation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant