@@ -18,12 +18,12 @@ use bevy_reflect::{
1818/// [`bevy_reflect::TypeRegistration::data`].
1919#[ derive( Clone ) ]
2020pub struct ReflectComponent {
21- add_component : fn ( & mut World , Entity , & dyn Reflect ) ,
22- apply_component : fn ( & mut World , Entity , & dyn Reflect ) ,
23- remove_component : fn ( & mut World , Entity ) ,
24- reflect_component : fn ( & World , Entity ) -> Option < & dyn Reflect > ,
25- reflect_component_mut : unsafe fn ( & World , Entity ) -> Option < ReflectMut > ,
26- copy_component : fn ( & World , & mut World , Entity , Entity ) ,
21+ add : fn ( & mut World , Entity , & dyn Reflect ) ,
22+ apply : fn ( & mut World , Entity , & dyn Reflect ) ,
23+ remove : fn ( & mut World , Entity ) ,
24+ reflect : fn ( & World , Entity ) -> Option < & dyn Reflect > ,
25+ reflect_mut : unsafe fn ( & World , Entity ) -> Option < ReflectMut > ,
26+ copy : fn ( & World , & mut World , Entity , Entity ) ,
2727}
2828
2929impl ReflectComponent {
@@ -32,45 +32,37 @@ impl ReflectComponent {
3232 /// # Panics
3333 ///
3434 /// Panics if there is no such entity.
35- pub fn add_component ( & self , world : & mut World , entity : Entity , component : & dyn Reflect ) {
36- ( self . add_component ) ( world, entity, component) ;
35+ pub fn add ( & self , world : & mut World , entity : Entity , component : & dyn Reflect ) {
36+ ( self . add ) ( world, entity, component) ;
3737 }
3838
3939 /// Uses reflection to set the value of this [`Component`] type in the entity to the given value.
4040 ///
4141 /// # Panics
4242 ///
4343 /// Panics if there is no [`Component`] of the given type or the `entity` does not exist.
44- pub fn apply_component ( & self , world : & mut World , entity : Entity , component : & dyn Reflect ) {
45- ( self . apply_component ) ( world, entity, component) ;
44+ pub fn apply ( & self , world : & mut World , entity : Entity , component : & dyn Reflect ) {
45+ ( self . apply ) ( world, entity, component) ;
4646 }
4747
4848 /// Removes this [`Component`] type from the entity. Does nothing if it doesn't exist.
4949 ///
5050 /// # Panics
5151 ///
5252 /// Panics if there is no [`Component`] of the given type or the `entity` does not exist.
53- pub fn remove_component ( & self , world : & mut World , entity : Entity ) {
54- ( self . remove_component ) ( world, entity) ;
53+ pub fn remove ( & self , world : & mut World , entity : Entity ) {
54+ ( self . remove ) ( world, entity) ;
5555 }
5656
5757 /// Gets the value of this [`Component`] type from the entity as a reflected reference.
58- pub fn reflect_component < ' a > (
59- & self ,
60- world : & ' a World ,
61- entity : Entity ,
62- ) -> Option < & ' a dyn Reflect > {
63- ( self . reflect_component ) ( world, entity)
58+ pub fn reflect < ' a > ( & self , world : & ' a World , entity : Entity ) -> Option < & ' a dyn Reflect > {
59+ ( self . reflect ) ( world, entity)
6460 }
6561
6662 /// Gets the value of this [`Component`] type from the entity as a mutable reflected reference.
67- pub fn reflect_component_mut < ' a > (
68- & self ,
69- world : & ' a mut World ,
70- entity : Entity ,
71- ) -> Option < ReflectMut < ' a > > {
63+ pub fn reflect_mut < ' a > ( & self , world : & ' a mut World , entity : Entity ) -> Option < ReflectMut < ' a > > {
7264 // SAFETY: unique world access
73- unsafe { ( self . reflect_component_mut ) ( world, entity) }
65+ unsafe { ( self . reflect_mut ) ( world, entity) }
7466 }
7567
7668 /// # Safety
@@ -79,27 +71,27 @@ impl ReflectComponent {
7971 /// * Only call this method in an exclusive system to avoid sharing across threads (or use a
8072 /// scheduler that enforces safe memory access).
8173 /// * Don't call this method more than once in the same scope for a given [`Component`].
82- pub unsafe fn reflect_component_unchecked_mut < ' a > (
74+ pub unsafe fn reflect_unchecked_mut < ' a > (
8375 & self ,
8476 world : & ' a World ,
8577 entity : Entity ,
8678 ) -> Option < ReflectMut < ' a > > {
87- ( self . reflect_component_mut ) ( world, entity)
79+ ( self . reflect_mut ) ( world, entity)
8880 }
8981
90- /// Gets the value of this [`Component`] type from entity from `source_world` and [applies](Self::apply_component ()) it to the value of this [`Component`] type in entity in `destination_world`.
82+ /// Gets the value of this [`Component`] type from entity from `source_world` and [applies](Self::apply ()) it to the value of this [`Component`] type in entity in `destination_world`.
9183 ///
9284 /// # Panics
9385 ///
9486 /// Panics if there is no [`Component`] of the given type or either entity does not exist.
95- pub fn copy_component (
87+ pub fn copy (
9688 & self ,
9789 source_world : & World ,
9890 destination_world : & mut World ,
9991 source_entity : Entity ,
10092 destination_entity : Entity ,
10193 ) {
102- ( self . copy_component ) (
94+ ( self . copy ) (
10395 source_world,
10496 destination_world,
10597 source_entity,
@@ -111,35 +103,35 @@ impl ReflectComponent {
111103impl < C : Component + Reflect + FromWorld > FromType < C > for ReflectComponent {
112104 fn from_type ( ) -> Self {
113105 ReflectComponent {
114- add_component : |world, entity, reflected_component| {
106+ add : |world, entity, reflected_component| {
115107 let mut component = C :: from_world ( world) ;
116108 component. apply ( reflected_component) ;
117109 world. entity_mut ( entity) . insert ( component) ;
118110 } ,
119- apply_component : |world, entity, reflected_component| {
111+ apply : |world, entity, reflected_component| {
120112 let mut component = world. get_mut :: < C > ( entity) . unwrap ( ) ;
121113 component. apply ( reflected_component) ;
122114 } ,
123- remove_component : |world, entity| {
115+ remove : |world, entity| {
124116 world. entity_mut ( entity) . remove :: < C > ( ) ;
125117 } ,
126- copy_component : |source_world, destination_world, source_entity, destination_entity| {
118+ copy : |source_world, destination_world, source_entity, destination_entity| {
127119 let source_component = source_world. get :: < C > ( source_entity) . unwrap ( ) ;
128120 let mut destination_component = C :: from_world ( destination_world) ;
129121 destination_component. apply ( source_component) ;
130122 destination_world
131123 . entity_mut ( destination_entity)
132124 . insert ( destination_component) ;
133125 } ,
134- reflect_component : |world, entity| {
126+ reflect : |world, entity| {
135127 world
136128 . get_entity ( entity) ?
137129 . get :: < C > ( )
138130 . map ( |c| c as & dyn Reflect )
139131 } ,
140- reflect_component_mut : |world, entity| {
141- // SAFETY: reflect_component_mut is an unsafe function pointer used by `reflect_component_unchecked_mut ` which promises to never
142- // produce aliasing mutable references, and reflect_component_mut , which has mutable world access
132+ reflect_mut : |world, entity| {
133+ // SAFETY: reflect_mut is an unsafe function pointer used by `reflect_unchecked_mut ` which promises to never
134+ // produce aliasing mutable references, and reflect_mut , which has mutable world access
143135 unsafe {
144136 world
145137 . get_entity ( entity) ?
@@ -160,43 +152,43 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
160152/// [`bevy_reflect::TypeRegistration::data`].
161153#[ derive( Clone ) ]
162154pub struct ReflectResource {
163- insert_resource : fn ( & mut World , & dyn Reflect ) ,
164- apply_resource : fn ( & mut World , & dyn Reflect ) ,
165- remove_resource : fn ( & mut World ) ,
166- reflect_resource : fn ( & World ) -> Option < & dyn Reflect > ,
167- reflect_resource_unchecked_mut : unsafe fn ( & World ) -> Option < ReflectMut > ,
168- copy_resource : fn ( & World , & mut World ) ,
155+ insert : fn ( & mut World , & dyn Reflect ) ,
156+ apply : fn ( & mut World , & dyn Reflect ) ,
157+ remove : fn ( & mut World ) ,
158+ reflect : fn ( & World ) -> Option < & dyn Reflect > ,
159+ reflect_unchecked_mut : unsafe fn ( & World ) -> Option < ReflectMut > ,
160+ copy : fn ( & World , & mut World ) ,
169161}
170162
171163impl ReflectResource {
172- /// Insert a reflected [`Resource`] into the world like [`insert_resource ()`](World::insert_resource).
173- pub fn insert_resource ( & self , world : & mut World , resource : & dyn Reflect ) {
174- ( self . insert_resource ) ( world, resource) ;
164+ /// Insert a reflected [`Resource`] into the world like [`insert ()`](World::insert_resource).
165+ pub fn insert ( & self , world : & mut World , resource : & dyn Reflect ) {
166+ ( self . insert ) ( world, resource) ;
175167 }
176168
177169 /// Uses reflection to set the value of this [`Resource`] type in the world to the given value.
178170 ///
179171 /// # Panics
180172 ///
181173 /// Panics if there is no [`Resource`] of the given type.
182- pub fn apply_resource ( & self , world : & mut World , resource : & dyn Reflect ) {
183- ( self . apply_resource ) ( world, resource) ;
174+ pub fn apply ( & self , world : & mut World , resource : & dyn Reflect ) {
175+ ( self . apply ) ( world, resource) ;
184176 }
185177
186178 /// Removes this [`Resource`] type from the world. Does nothing if it doesn't exist.
187- pub fn remove_resource ( & self , world : & mut World ) {
188- ( self . remove_resource ) ( world) ;
179+ pub fn remove ( & self , world : & mut World ) {
180+ ( self . remove ) ( world) ;
189181 }
190182
191183 /// Gets the value of this [`Resource`] type from the world as a reflected reference.
192- pub fn reflect_resource < ' a > ( & self , world : & ' a World ) -> Option < & ' a dyn Reflect > {
193- ( self . reflect_resource ) ( world)
184+ pub fn reflect < ' a > ( & self , world : & ' a World ) -> Option < & ' a dyn Reflect > {
185+ ( self . reflect ) ( world)
194186 }
195187
196188 /// Gets the value of this [`Resource`] type from the world as a mutable reflected reference.
197- pub fn reflect_resource_mut < ' a > ( & self , world : & ' a mut World ) -> Option < ReflectMut < ' a > > {
189+ pub fn reflect_mut < ' a > ( & self , world : & ' a mut World ) -> Option < ReflectMut < ' a > > {
198190 // SAFETY: unique world access
199- unsafe { ( self . reflect_resource_unchecked_mut ) ( world) }
191+ unsafe { ( self . reflect_unchecked_mut ) ( world) }
200192 }
201193
202194 /// # Safety
@@ -205,42 +197,39 @@ impl ReflectResource {
205197 /// * Only call this method in an exclusive system to avoid sharing across threads (or use a
206198 /// scheduler that enforces safe memory access).
207199 /// * Don't call this method more than once in the same scope for a given [`Resource`].
208- pub unsafe fn reflect_resource_unckecked_mut < ' a > (
209- & self ,
210- world : & ' a World ,
211- ) -> Option < ReflectMut < ' a > > {
200+ pub unsafe fn reflect_unchecked_mut < ' a > ( & self , world : & ' a World ) -> Option < ReflectMut < ' a > > {
212201 // SAFETY: caller promises to uphold uniqueness guarantees
213- ( self . reflect_resource_unchecked_mut ) ( world)
202+ ( self . reflect_unchecked_mut ) ( world)
214203 }
215204
216- /// Gets the value of this [`Resource`] type from `source_world` and [applies](Self::apply_resource ()) it to the value of this [`Resource`] type in `destination_world`.
205+ /// Gets the value of this [`Resource`] type from `source_world` and [applies](Self::apply ()) it to the value of this [`Resource`] type in `destination_world`.
217206 ///
218207 /// # Panics
219208 ///
220209 /// Panics if there is no [`Resource`] of the given type.
221- pub fn copy_resource ( & self , source_world : & World , destination_world : & mut World ) {
222- ( self . copy_resource ) ( source_world, destination_world) ;
210+ pub fn copy ( & self , source_world : & World , destination_world : & mut World ) {
211+ ( self . copy ) ( source_world, destination_world) ;
223212 }
224213}
225214
226215impl < C : Resource + Reflect + FromWorld > FromType < C > for ReflectResource {
227216 fn from_type ( ) -> Self {
228217 ReflectResource {
229- insert_resource : |world, reflected_resource| {
218+ insert : |world, reflected_resource| {
230219 let mut resource = C :: from_world ( world) ;
231220 resource. apply ( reflected_resource) ;
232221 world. insert_resource ( resource) ;
233222 } ,
234- apply_resource : |world, reflected_resource| {
223+ apply : |world, reflected_resource| {
235224 let mut resource = world. resource_mut :: < C > ( ) ;
236225 resource. apply ( reflected_resource) ;
237226 } ,
238- remove_resource : |world| {
227+ remove : |world| {
239228 world. remove_resource :: < C > ( ) ;
240229 } ,
241- reflect_resource : |world| world. get_resource :: < C > ( ) . map ( |res| res as & dyn Reflect ) ,
242- reflect_resource_unchecked_mut : |world| {
243- // SAFETY: all usages of `reflect_resource_unchecked_mut ` guarantee that there is either a single mutable
230+ reflect : |world| world. get_resource :: < C > ( ) . map ( |res| res as & dyn Reflect ) ,
231+ reflect_unchecked_mut : |world| {
232+ // SAFETY: all usages of `reflect_unchecked_mut ` guarantee that there is either a single mutable
244233 // reference or multiple immutable ones alive at any given point
245234 unsafe {
246235 world
@@ -251,7 +240,7 @@ impl<C: Resource + Reflect + FromWorld> FromType<C> for ReflectResource {
251240 } )
252241 }
253242 } ,
254- copy_resource : |source_world, destination_world| {
243+ copy : |source_world, destination_world| {
255244 let source_resource = source_world. resource :: < C > ( ) ;
256245 let mut destination_resource = C :: from_world ( destination_world) ;
257246 destination_resource. apply ( source_resource) ;
0 commit comments