-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add EntityRef/EntityMut based options to ReflectComponent #6856
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::get
and friends internally useWorld::get
and similar APIs which spend time looking up theEntityLocation
on 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
ReflectComponent
to fetch references to components usingEntityRef
andEntityMut
instead of a World/Entity. This allows users to fetch a singleEnttiyRef
/EntityMut
and query for any or all of it's components without refetching the entity's location for each one.Ideally, a World-specific version of
ReflectComponent
would cache theComponentId
so we could cut out theTypeId
->ComponentId
lookup as well. However this requires a&mut World
onReflectComponent
initialization and would only be valid for that specific World.Changelog
Added:
ReflectComponent::reflect_ref
Added:
ReflectComponent::reflect_mut_ref
Added:
ReflectComponent::reflect_unchecked_mut_ref