Support multiple worlds#31
Open
dudeax wants to merge 3 commits into
Open
Conversation
Member
|
This looks fine to me. I would perhaps even add a comptime config bool that allows the user to mark it as a single-world application to reduce the world-lookup to just instantly resolve to the first world. But that could easily be its own PR. I can't test this myself unfortunately due to being behind on zflecs and Zig so will see if anyone else have any comments before I merge it. (feel free to ping me if I forget) |
|
I tested the PR, and the core multiple-world functionality works well. However, there's a bug in script_vars_define return script_vars_define_id(vars, name, id(vars.world, T));
This causes a compile error when anyone tries to use script_vars_define. |
|
world_id(world, T) - works with multiple worlds |
Member
Member
|
Ping @dudeax :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.