@@ -18,12 +18,12 @@ use bevy_reflect::{
18
18
/// [`bevy_reflect::TypeRegistration::data`].
19
19
#[ derive( Clone ) ]
20
20
pub 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 ) ,
27
27
}
28
28
29
29
impl ReflectComponent {
@@ -32,45 +32,37 @@ impl ReflectComponent {
32
32
/// # Panics
33
33
///
34
34
/// 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) ;
37
37
}
38
38
39
39
/// Uses reflection to set the value of this [`Component`] type in the entity to the given value.
40
40
///
41
41
/// # Panics
42
42
///
43
43
/// 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) ;
46
46
}
47
47
48
48
/// Removes this [`Component`] type from the entity. Does nothing if it doesn't exist.
49
49
///
50
50
/// # Panics
51
51
///
52
52
/// 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) ;
55
55
}
56
56
57
57
/// 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)
64
60
}
65
61
66
62
/// 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 > > {
72
64
// SAFETY: unique world access
73
- unsafe { ( self . reflect_component_mut ) ( world, entity) }
65
+ unsafe { ( self . reflect_mut ) ( world, entity) }
74
66
}
75
67
76
68
/// # Safety
@@ -79,27 +71,27 @@ impl ReflectComponent {
79
71
/// * Only call this method in an exclusive system to avoid sharing across threads (or use a
80
72
/// scheduler that enforces safe memory access).
81
73
/// * 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 > (
83
75
& self ,
84
76
world : & ' a World ,
85
77
entity : Entity ,
86
78
) -> Option < ReflectMut < ' a > > {
87
- ( self . reflect_component_mut ) ( world, entity)
79
+ ( self . reflect_mut ) ( world, entity)
88
80
}
89
81
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`.
91
83
///
92
84
/// # Panics
93
85
///
94
86
/// 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 (
96
88
& self ,
97
89
source_world : & World ,
98
90
destination_world : & mut World ,
99
91
source_entity : Entity ,
100
92
destination_entity : Entity ,
101
93
) {
102
- ( self . copy_component ) (
94
+ ( self . copy ) (
103
95
source_world,
104
96
destination_world,
105
97
source_entity,
@@ -111,35 +103,35 @@ impl ReflectComponent {
111
103
impl < C : Component + Reflect + FromWorld > FromType < C > for ReflectComponent {
112
104
fn from_type ( ) -> Self {
113
105
ReflectComponent {
114
- add_component : |world, entity, reflected_component| {
106
+ add : |world, entity, reflected_component| {
115
107
let mut component = C :: from_world ( world) ;
116
108
component. apply ( reflected_component) ;
117
109
world. entity_mut ( entity) . insert ( component) ;
118
110
} ,
119
- apply_component : |world, entity, reflected_component| {
111
+ apply : |world, entity, reflected_component| {
120
112
let mut component = world. get_mut :: < C > ( entity) . unwrap ( ) ;
121
113
component. apply ( reflected_component) ;
122
114
} ,
123
- remove_component : |world, entity| {
115
+ remove : |world, entity| {
124
116
world. entity_mut ( entity) . remove :: < C > ( ) ;
125
117
} ,
126
- copy_component : |source_world, destination_world, source_entity, destination_entity| {
118
+ copy : |source_world, destination_world, source_entity, destination_entity| {
127
119
let source_component = source_world. get :: < C > ( source_entity) . unwrap ( ) ;
128
120
let mut destination_component = C :: from_world ( destination_world) ;
129
121
destination_component. apply ( source_component) ;
130
122
destination_world
131
123
. entity_mut ( destination_entity)
132
124
. insert ( destination_component) ;
133
125
} ,
134
- reflect_component : |world, entity| {
126
+ reflect : |world, entity| {
135
127
world
136
128
. get_entity ( entity) ?
137
129
. get :: < C > ( )
138
130
. map ( |c| c as & dyn Reflect )
139
131
} ,
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
143
135
unsafe {
144
136
world
145
137
. get_entity ( entity) ?
@@ -160,43 +152,43 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
160
152
/// [`bevy_reflect::TypeRegistration::data`].
161
153
#[ derive( Clone ) ]
162
154
pub 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 ) ,
169
161
}
170
162
171
163
impl 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) ;
175
167
}
176
168
177
169
/// Uses reflection to set the value of this [`Resource`] type in the world to the given value.
178
170
///
179
171
/// # Panics
180
172
///
181
173
/// 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) ;
184
176
}
185
177
186
178
/// 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) ;
189
181
}
190
182
191
183
/// 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)
194
186
}
195
187
196
188
/// 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 > > {
198
190
// SAFETY: unique world access
199
- unsafe { ( self . reflect_resource_unchecked_mut ) ( world) }
191
+ unsafe { ( self . reflect_unchecked_mut ) ( world) }
200
192
}
201
193
202
194
/// # Safety
@@ -205,42 +197,39 @@ impl ReflectResource {
205
197
/// * Only call this method in an exclusive system to avoid sharing across threads (or use a
206
198
/// scheduler that enforces safe memory access).
207
199
/// * 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 > > {
212
201
// SAFETY: caller promises to uphold uniqueness guarantees
213
- ( self . reflect_resource_unchecked_mut ) ( world)
202
+ ( self . reflect_unchecked_mut ) ( world)
214
203
}
215
204
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`.
217
206
///
218
207
/// # Panics
219
208
///
220
209
/// 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) ;
223
212
}
224
213
}
225
214
226
215
impl < C : Resource + Reflect + FromWorld > FromType < C > for ReflectResource {
227
216
fn from_type ( ) -> Self {
228
217
ReflectResource {
229
- insert_resource : |world, reflected_resource| {
218
+ insert : |world, reflected_resource| {
230
219
let mut resource = C :: from_world ( world) ;
231
220
resource. apply ( reflected_resource) ;
232
221
world. insert_resource ( resource) ;
233
222
} ,
234
- apply_resource : |world, reflected_resource| {
223
+ apply : |world, reflected_resource| {
235
224
let mut resource = world. resource_mut :: < C > ( ) ;
236
225
resource. apply ( reflected_resource) ;
237
226
} ,
238
- remove_resource : |world| {
227
+ remove : |world| {
239
228
world. remove_resource :: < C > ( ) ;
240
229
} ,
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
244
233
// reference or multiple immutable ones alive at any given point
245
234
unsafe {
246
235
world
@@ -251,7 +240,7 @@ impl<C: Resource + Reflect + FromWorld> FromType<C> for ReflectResource {
251
240
} )
252
241
}
253
242
} ,
254
- copy_resource : |source_world, destination_world| {
243
+ copy : |source_world, destination_world| {
255
244
let source_resource = source_world. resource :: < C > ( ) ;
256
245
let mut destination_resource = C :: from_world ( destination_world) ;
257
246
destination_resource. apply ( source_resource) ;
0 commit comments