diff --git a/crates/bevy_ecs/examples/mutate_obsover.rs b/crates/bevy_ecs/examples/mutate_obsover.rs deleted file mode 100644 index 428646ee59d193..00000000000000 --- a/crates/bevy_ecs/examples/mutate_obsover.rs +++ /dev/null @@ -1,54 +0,0 @@ - - -//! In this example we add a counter resource and increase its value in one system, -//! while a different system prints the current count to the console. - -#![expect(clippy::std_instead_of_core)] - -use bevy_ecs::prelude::*; -use bevy_ecs::world::OnMutate; -use bevy_reflect::Reflect; - -fn main() { - let mut world = World::new(); - - world.add_observer(ob); - - let mut schedule = Schedule::default(); - - schedule - .add_systems( - ( - first, - second, - ) - .chain() - ); - - schedule.run(&mut world); - - println!("{:?}", world); -} - -#[derive(Reflect, Default, Component, Debug)] -struct Count(usize); - -fn first(mut commands: Commands) { - commands.spawn(Count(0)); -} - -fn second(mut counts: Query>) { - counts.iter_mut().for_each(|mut count| { - count.0 += 1; - }) -} - -fn ob( - trigger: Trigger, - counts: Query<&Count>, -) { - let Ok(count) = counts.get(trigger.entity()) else { - return; - }; - dbg!(count); -} \ No newline at end of file diff --git a/crates/bevy_ecs/src/storage/entity_change.rs b/crates/bevy_ecs/src/storage/entity_change.rs index e6a8cc9d762bbb..98efcba1d9cc7e 100644 --- a/crates/bevy_ecs/src/storage/entity_change.rs +++ b/crates/bevy_ecs/src/storage/entity_change.rs @@ -52,4 +52,29 @@ impl EntityChange { pub fn component(&self) -> ComponentId { self.component } +} + +mod tests { + #![allow(unused_imports)] + use crate::component::ComponentId; + use crate::entity::Entity; + use crate::storage::{Changes, EntityChange}; + + #[test] + fn changes() { + let mut storage = Changes::new(); + let entity = Entity::PLACEHOLDER; + let component = ComponentId::new(1); + storage.push(EntityChange::new(entity, component)); + storage.push(EntityChange::new(entity, component)); + + let changes = storage.take_all(); + assert_eq!(changes.len(), 2); + assert_eq!(storage.take_all().len(), 0); + + changes.iter().for_each(|change| { + assert_eq!(change.component, component); + assert_eq!(change.entity, entity); + }) + } } \ No newline at end of file diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 511610533ed9da..1f33b9a2773e34 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -63,7 +63,6 @@ use bevy_ptr::UnsafeCellDeref; use core::panic::Location; use unsafe_world_cell::{UnsafeEntityCell, UnsafeWorldCell}; -use crate::storage::Changes; /// A [`World`] mutation. /// @@ -136,14 +135,6 @@ pub struct World { pub(crate) command_queue: RawCommandQueue, } -impl World { - - /// Just For Test - pub fn test(&mut self) -> &mut Changes { - &mut self.storages.changes - } -} - impl Default for World { fn default() -> Self { let mut world = Self {