diff --git a/crates/bevy_ecs/src/removal_detection.rs b/crates/bevy_ecs/src/removal_detection.rs index 0118ab8ded..c645fe017a 100644 --- a/crates/bevy_ecs/src/removal_detection.rs +++ b/crates/bevy_ecs/src/removal_detection.rs @@ -200,7 +200,7 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> { /// Iterates over the events this [`RemovedComponents`] has not seen yet. This updates the /// [`RemovedComponents`]'s event counter, which means subsequent event reads will not include events /// that happened before now. - pub fn iter(&mut self) -> RemovedIter<'_> { + pub fn read(&mut self) -> RemovedIter<'_> { self.reader_mut_with_events() .map(|(reader, events)| reader.read(events).cloned()) .into_iter() @@ -208,8 +208,16 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> { .map(RemovedComponentEntity::into) } - /// Like [`iter`](Self::iter), except also returning the [`EventId`] of the events. - pub fn iter_with_id(&mut self) -> RemovedIterWithId<'_> { + /// Iterates over the events this [`RemovedComponents`] has not seen yet. This updates the + /// [`RemovedComponents`]'s event counter, which means subsequent event reads will not include events + /// that happened before now. + #[deprecated = "use `.read()` instead."] + pub fn iter(&mut self) -> RemovedIter<'_> { + self.read() + } + + /// Like [`read`](Self::read), except also returning the [`EventId`] of the events. + pub fn read_with_id(&mut self) -> RemovedIterWithId<'_> { self.reader_mut_with_events() .map(|(reader, events)| reader.read_with_id(events)) .into_iter() @@ -217,6 +225,12 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> { .map(map_id_events) } + /// Like [`iter`](Self::iter), except also returning the [`EventId`] of the events. + #[deprecated = "use `.read_with_id()` instead."] + pub fn iter_with_id(&mut self) -> RemovedIterWithId<'_> { + self.read_with_id() + } + /// Determines the number of removal events available to be read from this [`RemovedComponents`] without consuming any. pub fn len(&self) -> usize { self.events() @@ -233,8 +247,8 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> { /// Consumes all available events. /// - /// This means these events will not appear in calls to [`RemovedComponents::iter()`] or - /// [`RemovedComponents::iter_with_id()`] and [`RemovedComponents::is_empty()`] will return `true`. + /// This means these events will not appear in calls to [`RemovedComponents::read()`] or + /// [`RemovedComponents::read_with_id()`] and [`RemovedComponents::is_empty()`] will return `true`. pub fn clear(&mut self) { if let Some((reader, events)) = self.reader_mut_with_events() { reader.clear(events); @@ -242,17 +256,6 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> { } } -impl<'a, 'w, 's: 'a, T> IntoIterator for &'a mut RemovedComponents<'w, 's, T> -where - T: Component, -{ - type Item = Entity; - type IntoIter = RemovedIter<'a>; - fn into_iter(self) -> Self::IntoIter { - self.iter() - } -} - // SAFETY: Only reads World removed component events unsafe impl<'a> ReadOnlySystemParam for &'a RemovedComponentEvents {} diff --git a/crates/bevy_ecs/src/schedule/condition.rs b/crates/bevy_ecs/src/schedule/condition.rs index 6c3b8e80fe..021964311e 100644 --- a/crates/bevy_ecs/src/schedule/condition.rs +++ b/crates/bevy_ecs/src/schedule/condition.rs @@ -943,7 +943,7 @@ pub mod common_conditions { // Simply checking `is_empty` would not be enough. // PERF: note that `count` is efficient (not actually looping/iterating), // due to Bevy having a specialized implementation for events. - move |mut removals: RemovedComponents| removals.iter().count() != 0 + move |mut removals: RemovedComponents| removals.read().count() != 0 } /// Generates a [`Condition`](super::Condition) that inverses the result of passed one. diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 527864d298..e07445aa65 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -1172,7 +1172,7 @@ mod tests { mut n_systems: ResMut, ) { assert_eq!( - removed_i32.iter().collect::>(), + removed_i32.read().collect::>(), &[despawned.0], "despawning causes the correct entity to show up in the 'RemovedComponent' system parameter." ); @@ -1200,7 +1200,7 @@ mod tests { // The despawned entity from the previous frame was // double buffered so we now have it in this system as well. assert_eq!( - removed_i32.iter().collect::>(), + removed_i32.read().collect::>(), &[despawned.0, removed.0], "removing a component causes the correct entity to show up in the 'RemovedComponent' system parameter." ); diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index 76ba509f67..b25784c388 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -34,7 +34,7 @@ pub fn sync_simple_transforms( }); // Update orphaned entities. let mut query = query.p1(); - let mut iter = query.iter_many_mut(orphaned.iter()); + let mut iter = query.iter_many_mut(orphaned.read()); while let Some((transform, mut global_transform)) = iter.fetch_next() { if !transform.is_changed() && !global_transform.is_added() { *global_transform = GlobalTransform::from(*transform); @@ -57,7 +57,7 @@ pub fn propagate_transforms( mut orphaned_entities: Local>, ) { orphaned_entities.clear(); - orphaned_entities.extend(orphaned.iter()); + orphaned_entities.extend(orphaned.read()); orphaned_entities.sort_unstable(); root_query.par_iter_mut().for_each( |(entity, children, transform, mut global_transform)| { diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index 41db367209..a8ea44f664 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -281,10 +281,10 @@ pub fn ui_layout_system( } // clean up removed nodes - ui_surface.remove_entities(removed_nodes.iter()); + ui_surface.remove_entities(removed_nodes.read()); // When a `ContentSize` component is removed from an entity, we need to remove the measure from the corresponding taffy node. - for entity in removed_content_sizes.iter() { + for entity in removed_content_sizes.read() { ui_surface.try_remove_measure(entity); } @@ -292,7 +292,7 @@ pub fn ui_layout_system( ui_surface.set_window_children(primary_window_entity, root_node_query.iter()); // update and remove children - for entity in removed_children.iter() { + for entity in removed_children.read() { ui_surface.try_remove_children(entity); } for (entity, children) in &children_query { diff --git a/crates/bevy_winit/src/system.rs b/crates/bevy_winit/src/system.rs index 0cd89c429c..896466f3c7 100644 --- a/crates/bevy_winit/src/system.rs +++ b/crates/bevy_winit/src/system.rs @@ -110,7 +110,7 @@ pub(crate) fn despawn_windows( mut close_events: EventWriter, mut winit_windows: NonSendMut, ) { - for window in closed.iter() { + for window in closed.read() { info!("Closing window {:?}", window); // Guard to verify that the window is in fact actually gone, // rather than having the component added and removed in the same frame. diff --git a/examples/ecs/removal_detection.rs b/examples/ecs/removal_detection.rs index 2a5d641ea0..096d22472a 100644 --- a/examples/ecs/removal_detection.rs +++ b/examples/ecs/removal_detection.rs @@ -51,9 +51,9 @@ fn remove_component( } fn react_on_removal(mut removed: RemovedComponents, mut query: Query<&mut Sprite>) { - // `RemovedComponents::iter()` returns an iterator with the `Entity`s that had their + // `RemovedComponents::read()` returns an iterator with the `Entity`s that had their // `Component` `T` (in this case `MyComponent`) removed at some point earlier during the frame. - for entity in &mut removed { + for entity in removed.read() { if let Ok(mut sprite) = query.get_mut(entity) { sprite.color.set_r(0.0); }