Support multiple worlds #31
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously multiple world support was blocked by the clever implementation of zigs comptime to get type id look ups for free. This relied on single global static variables which obviously didn't play well once you had more than world with potentially different ids.
For my implementation I attempted to keep (most of) the benefits of this implementation while also allowing multiple worlds to exist.
Type -> flecsid mapping is done via a nested hash map ofworld -> type -> flecs id. This will have the same runtime complexity as the old version, but will take slightly longer to look up.pub fn world_id(world: *const world_t, comptime T: type) id_tfunction.pub inline fn id(comptime T: type) id_tis still supported so this PR will be a drop in replacement for all existing implementations, and shouldn't contain any breaking changes.first_world_pointers(formerlycomponent_ids_hm) andworld_component_lookupinto the init function and to use the EcsAllocator rather than the page allocator. If there are any concerns around this I would be happy to move them back to the page allocator, but this felt cleaner than the previous iteration.In general I think another option could be to fully deprecate any idea of a singleton look up for the first world, but this would be a breaking change, and technically slightly less performant for single world applications.