-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add EntityRef/EntityMut based options to ReflectComponent #6856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Have you profiled the alternative of using let reflect_component = type_register.data<ReflectComponent>();
reflect_component.get(entity)vs let reflect_from_ptr = type_registry.data::<ReflectFromPtr>();
let ptr = entity_ref.get_by_id(component_id);
reflect_from_ptr.as_reflect(ptr)? I'd like to get rid of |
|
I have not, though my gut feeling like it's going to be slower due to not having any of the compile time optimizations we've been adding to the generic path. The use of |
This could be fixed by having wrappers at a safe boundary, like (TypeId, &TypeRegistry) -> &dyn Reflect |
This would still lose the |
|
Why did you keep the |
The primary one is that the lifetime of a |
|
Closing this as it's already been implemented by #7206. |
Objective
ReflectComponent::getand friends internally useWorld::getand similar APIs which spend time looking up theEntityLocationon each call. This can add significant overhead when fetching multiple components from the same entity, such as when animating multiple components via reflection.Solution
Extend the functions of
ReflectComponentto fetch references to components usingEntityRefandEntityMutinstead of a World/Entity. This allows users to fetch a singleEnttiyRef/EntityMutand query for any or all of it's components without refetching the entity's location for each one.Ideally, a World-specific version of
ReflectComponentwould cache theComponentIdso we could cut out theTypeId->ComponentIdlookup as well. However this requires a&mut WorldonReflectComponentinitialization and would only be valid for that specific World.Changelog
Added:
ReflectComponent::reflect_refAdded:
ReflectComponent::reflect_mut_refAdded:
ReflectComponent::reflect_unchecked_mut_ref