Allow queries to work without mutable world access #84
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.
Objective
Bevy is considering not allowing mutable world access in
WorldQuery::init_state.See here.
This PR explores how this crate might migrate if those changes go through.
Solution
Don't initialize the registry resource in
init_state.Use atomics to seal the registry.
There is one caveat.
Before this pr, if a component was registered for a trait after the query was made, it would panic.
After this pr, that panic will only happen if, when the query was made, there were already components registered for that trait.
Since both the warning and panic serve the same purpose (to remind users to actually register their components), I don't think this is a concern, but I wanted to be transparent about it.