Skip to content

Commit a29d328

Browse files
authored
Rename map_entities and map_specific_entities (#7570)
# Objective After fixing dynamic scene to only map specific entities, we want map_entities to default to the less error prone behavior and have the previous behavior renamed to "map_all_entities." As this is a breaking change, it could not be pushed out with the bug fix. ## Solution Simple rename and refactor. ## Changelog ### Changed - `map_entities` now accepts a list of entities to apply to, with `map_all_entities` retaining previous behavior of applying to all entities in the map. ## Migration Guide - In `bevy_ecs`, `ReflectMapEntities::map_entites` now requires an additional `entities` parameter to specify which entities it applies to. To keep the old behavior, use the new `ReflectMapEntities::map_all_entities`, but consider if passing the entities in specifically might be better for your use case to avoid bugs.
1 parent 8070c29 commit a29d328

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

crates/bevy_ecs/src/reflect.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ impl_from_reflect_value!(Entity);
412412

413413
#[derive(Clone)]
414414
pub struct ReflectMapEntities {
415-
map_entities: fn(&mut World, &mut EntityMapper),
416-
map_specific_entities: fn(&mut World, &mut EntityMapper, &[Entity]),
415+
map_all_entities: fn(&mut World, &mut EntityMapper),
416+
map_entities: fn(&mut World, &mut EntityMapper, &[Entity]),
417417
}
418418

419419
impl ReflectMapEntities {
@@ -424,40 +424,36 @@ impl ReflectMapEntities {
424424
/// by the [`EntityMap`] might already contain valid entity references, you should use [`map_entities`](Self::map_entities).
425425
///
426426
/// An example of this: A scene can be loaded with `Parent` components, but then a `Parent` component can be added
427-
/// to these entities after they have been loaded. If you reload the scene using [`map_entities`](Self::map_entities), those `Parent`
427+
/// to these entities after they have been loaded. If you reload the scene using [`map_all_entities`](Self::map_all_entities), those `Parent`
428428
/// components with already valid entity references could be updated to point at something else entirely.
429-
pub fn map_entities(&self, world: &mut World, entity_map: &mut EntityMap) {
430-
entity_map.world_scope(world, self.map_entities);
429+
pub fn map_all_entities(&self, world: &mut World, entity_map: &mut EntityMap) {
430+
entity_map.world_scope(world, self.map_all_entities);
431431
}
432432

433-
/// This is like [`map_entities`](Self::map_entities), but only applied to specific entities, not all values
433+
/// A general method for applying [`MapEntities`] behavior to elements in an [`EntityMap`]. Unlike
434+
/// [`map_all_entities`](Self::map_all_entities), this is applied to specific entities, not all values
434435
/// in the [`EntityMap`].
435436
///
436437
/// This is useful mostly for when you need to be careful not to update components that already contain valid entity
437-
/// values. See [`map_entities`](Self::map_entities) for more details.
438-
pub fn map_specific_entities(
439-
&self,
440-
world: &mut World,
441-
entity_map: &mut EntityMap,
442-
entities: &[Entity],
443-
) {
438+
/// values. See [`map_all_entities`](Self::map_all_entities) for more details.
439+
pub fn map_entities(&self, world: &mut World, entity_map: &mut EntityMap, entities: &[Entity]) {
444440
entity_map.world_scope(world, |world, mapper| {
445-
(self.map_specific_entities)(world, mapper, entities);
441+
(self.map_entities)(world, mapper, entities);
446442
});
447443
}
448444
}
449445

450446
impl<C: Component + MapEntities> FromType<C> for ReflectMapEntities {
451447
fn from_type() -> Self {
452448
ReflectMapEntities {
453-
map_specific_entities: |world, entity_mapper, entities| {
449+
map_entities: |world, entity_mapper, entities| {
454450
for &entity in entities {
455451
if let Some(mut component) = world.get_mut::<C>(entity) {
456452
component.map_entities(entity_mapper);
457453
}
458454
}
459455
},
460-
map_entities: |world, entity_mapper| {
456+
map_all_entities: |world, entity_mapper| {
461457
let entities = entity_mapper.get_map().values().collect::<Vec<Entity>>();
462458
for entity in &entities {
463459
if let Some(mut component) = world.get_mut::<C>(*entity) {

crates/bevy_scene/src/dynamic_scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl DynamicScene {
142142
"we should be getting TypeId from this TypeRegistration in the first place",
143143
);
144144
if let Some(map_entities_reflect) = registration.data::<ReflectMapEntities>() {
145-
map_entities_reflect.map_specific_entities(world, entity_map, &entities);
145+
map_entities_reflect.map_entities(world, entity_map, &entities);
146146
}
147147
}
148148

crates/bevy_scene/src/scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Scene {
120120

121121
for registration in type_registry.iter() {
122122
if let Some(map_entities_reflect) = registration.data::<ReflectMapEntities>() {
123-
map_entities_reflect.map_entities(world, &mut instance_info.entity_map);
123+
map_entities_reflect.map_all_entities(world, &mut instance_info.entity_map);
124124
}
125125
}
126126

0 commit comments

Comments
 (0)