Tree context injection #17409
darthLeviN
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a very useful feature. It exists in react native (via
useContext
). however it doesn't exist in the game engines that i have seen so far (for example godot).It is not a good idea to implement such system by plugins as it's susceptible to data races.
My proposals is that app/world would have a method called
register_context
where you pass a specific component type. and then any entity will be able to useget_context<C>
in commands, world.and also it would be available in queries using
&Option<Context<C>>
or&mut Option<Context<C>>
for now i have implemented some traits to search in the tree whenever i need them, but that's not good for performance for heavy usages. Example usages :
Implementation of context should be optimized in
World
with specific map for each context.If memory usage is a concern we can go with a more process intensive kind of map that only tracks the entities that have the
ContextUser<C>
component. every time such component is spawned, the entity will be tracked for such context uses. Insert/Remove will become less efficient but it's going to have less memory usage.Beta Was this translation helpful? Give feedback.
All reactions