bevy/crates
Patrick Walton 05288ffa32
Generalize component reflection to operate on FilteredEntityRef and FilteredEntityMut, not EntityRef and EntityMut. (#13549)
Currently, either an `EntityRef` or `EntityMut` is required in order to
reflect a component on an entity. This can, however, be generalized to
`FilteredEntityRef` and `FilteredEntityMut`, which are versions of
`EntityRef` and `EntityMut` that restrict the components that can be
accessed. This is useful because dynamic queries yield
`FilteredEntityRef` and `FilteredEntityMut` rows when iterated over.

This commit changes `ReflectComponent::contains()`,
`ReflectComponent::reflect()`, and `ReflectComponent::reflect_mut()` to
take an `Into<FilteredEntityRef>` (in the case of `contains()` and
`reflect()`) and `Into<FilteredEntityMut>` (in the case of
`reflect_mut()`). Fortunately, `EntityRef` and `EntityMut` already
implement the corresponding trait, so nothing else has to be done to the
public API. Note that in order to implement
`ReflectComponent::reflect_mut()` properly, an additional method
`FilteredEntityMut::into_mut()` was required, to match the one on
`EntityMut`.

I ran into this when attempting to implement `QUERY` in the Bevy Remote
Protocol when trying to iterate over rows of dynamic queries and fetch
the associated components without unsafe code. There were other
potential ways to work around this problem, but they required either
reimplementing the query logic myself instead of using regular Bevy
queries or storing entity IDs and then issuing another query to fetch
the associated `EntityRef`. Both of these seemed worse than just
improving the `reflect()` function.

## Migration Guide

* `ReflectComponent::contains`, `ReflectComponent::reflect`, and
`ReflectComponent::reflect_mut` now take `FilteredEntityRef` (in the
case of `contains()` and `reflect()`) and `FilteredEntityMut` (in the
case of `reflect_mut()`) parameters. `FilteredEntityRef` and
`FilteredEntityMut` have very similar APIs to `EntityRef` and
`EntityMut` respectively, but optionally restrict the components that
can be accessed.
2024-05-28 14:02:09 +00:00
..
bevy_a11y Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_animation Remove ClampColor (#13307) 2024-05-10 13:15:56 +00:00
bevy_app Fix bevy_app not compiling without default features (#13532) 2024-05-27 21:22:03 +00:00
bevy_asset Allow AssetServer::load to acquire a guard item. (#13051) 2024-05-23 13:28:29 +00:00
bevy_audio Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_color Added a Grey trait, and implementations on baked-in colors. Fixes #13206 (#13237) 2024-05-26 12:53:50 +00:00
bevy_core Determine msrv for every standalone bevy_* crate. (#13211) 2024-05-13 18:26:41 +00:00
bevy_core_pipeline add tonemapping LUT bindings for sprite and mesh2d pipelines (#13262) 2024-05-28 12:09:26 +00:00
bevy_derive Deprecate dynamic plugins (#13080) 2024-05-20 20:01:28 +00:00
bevy_dev_tools Refactor ci_testing and separate it from DevToolsPlugin (#13513) 2024-05-26 22:32:36 +00:00
bevy_diagnostic Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_dylib Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_dynamic_plugin Deprecate dynamic plugins (#13080) 2024-05-20 20:01:28 +00:00
bevy_ecs Generalize component reflection to operate on FilteredEntityRef and FilteredEntityMut, not EntityRef and EntityMut. (#13549) 2024-05-28 14:02:09 +00:00
bevy_encase_derive Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_gilrs Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_gizmos Make gizmos take primitives by ref (#13534) 2024-05-27 13:48:47 +00:00
bevy_gltf Emissive is now LinearRgba on StandardMaterial (#13352) 2024-05-24 17:23:35 +00:00
bevy_hierarchy Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_input Separate state crate (#13216) 2024-05-09 18:06:05 +00:00
bevy_internal Refactor ci_testing and separate it from DevToolsPlugin (#13513) 2024-05-26 22:32:36 +00:00
bevy_log Improve tracing layer customization (#13159) 2024-05-12 21:16:56 +00:00
bevy_macro_utils Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_math Implemented Reflect for (almost) all bevy_math types (#13537) 2024-05-27 18:18:10 +00:00
bevy_mikktspace Determine msrv for every standalone bevy_* crate. (#13211) 2024-05-13 18:26:41 +00:00
bevy_pbr add tonemapping LUT bindings for sprite and mesh2d pipelines (#13262) 2024-05-28 12:09:26 +00:00
bevy_ptr add Debug for ptr types (#13498) 2024-05-24 21:25:11 +00:00
bevy_reflect Move bevy_math Reflect impls (#13520) 2024-05-27 14:15:22 +00:00
bevy_render add tonemapping LUT bindings for sprite and mesh2d pipelines (#13262) 2024-05-28 12:09:26 +00:00
bevy_scene Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_sprite add tonemapping LUT bindings for sprite and mesh2d pipelines (#13262) 2024-05-28 12:09:26 +00:00
bevy_state Revert "Add on_unimplemented Diagnostics to Most Public Traits" (#13413) 2024-05-17 17:00:43 +00:00
bevy_tasks multi_threaded feature rename (#12997) 2024-05-06 20:49:32 +00:00
bevy_text Add doc comments explaining the different behaviours of alignment and Anchor with text_2d (#8022) 2024-05-12 21:42:04 +00:00
bevy_time Adds doc note that Timer and Stopwatch must be progressed manually (#13441) 2024-05-20 19:46:25 +00:00
bevy_transform Use Dir3 for local axis methods in GlobalTransform (#13264) 2024-05-06 20:52:05 +00:00
bevy_ui fix rounded borders on buttons (#13541) 2024-05-27 21:46:56 +00:00
bevy_utils Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00
bevy_window Ensure clean exit (#13236) 2024-05-12 15:56:01 +00:00
bevy_winit Ensure clean exit (#13236) 2024-05-12 15:56:01 +00:00