From 0f8fc38bd9a5e6dd3e832b48fb84c2014fa09b1d Mon Sep 17 00:00:00 2001 From: Shaen Date: Sat, 27 Feb 2021 14:07:54 -0800 Subject: [PATCH 1/6] set PreviousParent when it exists remove some duplicate child insertion code fix duplicates this way --- bevy.iml | 47 +++++++++++++++++++ .../src/hierarchy/child_builder.rs | 6 ++- .../hierarchy/hierarchy_maintenance_system.rs | 34 +++++++------- 3 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 bevy.iml diff --git a/bevy.iml b/bevy.iml new file mode 100644 index 0000000000000..cdf49bae67042 --- /dev/null +++ b/bevy.iml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/crates/bevy_transform/src/hierarchy/child_builder.rs b/crates/bevy_transform/src/hierarchy/child_builder.rs index ab1ce6216de35..ca50352fff804 100644 --- a/crates/bevy_transform/src/hierarchy/child_builder.rs +++ b/crates/bevy_transform/src/hierarchy/child_builder.rs @@ -47,8 +47,12 @@ pub struct ChildBuilder<'a> { impl Command for PushChildren { fn write(self: Box, world: &mut World, _resources: &mut Resources) { for child in self.children.iter() { + let previous = match world.get::(*child) { + Ok(Parent(previous)) => *previous, + Err(_) => self.parent, + }; world - .insert(*child, (Parent(self.parent), PreviousParent(self.parent))) + .insert(*child, (Parent(self.parent), PreviousParent(previous))) .unwrap(); } { diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index 468e624046bad..08b21a79c8a68 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -42,22 +42,24 @@ pub fn parent_update_system( commands.insert_one(entity, PreviousParent(parent.0)); }; - // Add to the parent's `Children` (either the real component, or - // `children_additions`). - if let Ok(mut new_parent_children) = children_query.get_mut(parent.0) { - // This is the parent - debug_assert!( - !(*new_parent_children).0.contains(&entity), - "children already added" - ); - (*new_parent_children).0.push(entity); - } else { - // The parent doesn't have a children entity, lets add it - children_additions - .entry(parent.0) - .or_insert_with(Default::default) - .push(entity); - } + #[cfg(feature = "trace")] + log::warn!(?entity, "would add as child here") + // // Add to the parent's `Children` (either the real component, or + // // `children_additions`). + // if let Ok(mut new_parent_children) = children_query.get_mut(parent.0) { + // // This is the parent + // debug_assert!( + // !(*new_parent_children).0.contains(&entity), + // "children already added" + // ); + // (*new_parent_children).0.push(entity); + // } else { + // // The parent doesn't have a children entity, lets add it + // children_additions + // .entry(parent.0) + // .or_insert_with(Default::default) + // .push(entity); + // } } // Flush the `children_additions` to the command buffer. It is stored separate to From 1a6f9b8417348c979ba89c3037ddb52023928a9b Mon Sep 17 00:00:00 2001 From: Shaen Date: Fri, 5 Mar 2021 10:29:54 -0800 Subject: [PATCH 2/6] remove some dead code --- .../hierarchy/hierarchy_maintenance_system.rs | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index e0021ccef5e85..562c4e90cce6b 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -45,33 +45,6 @@ pub fn parent_update_system( } else { commands.insert(entity, PreviousParent(parent.0)); }; - - #[cfg(feature = "trace")] - log::warn!(?entity, "would add as child here") - // // Add to the parent's `Children` (either the real component, or - // // `children_additions`). - // if let Ok(mut new_parent_children) = children_query.get_mut(parent.0) { - // // This is the parent - // debug_assert!( - // !(*new_parent_children).0.contains(&entity), - // "children already added" - // ); - // (*new_parent_children).0.push(entity); - // } else { - // // The parent doesn't have a children entity, lets add it - // children_additions - // .entry(parent.0) - // .or_insert_with(Default::default) - // .push(entity); - // } - } - - // Flush the `children_additions` to the command buffer. It is stored separate to - // collect multiple new children that point to the same parent into the same - // SmallVec, and to prevent redundant add+remove operations. - children_additions.iter().for_each(|(k, v)| { - commands.insert(*k, Children::with(v)); - }); } #[cfg(test)] mod test { From ffedfd769613ba08dcfa5e92c2258d81b21b7a6d Mon Sep 17 00:00:00 2001 From: Shaen Date: Fri, 5 Mar 2021 10:32:06 -0800 Subject: [PATCH 3/6] dropped a brace --- .../bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index 562c4e90cce6b..f48ee6000cf02 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -45,6 +45,7 @@ pub fn parent_update_system( } else { commands.insert(entity, PreviousParent(parent.0)); }; + } } #[cfg(test)] mod test { From 94bb58e16a4258e4295b159294b1eacca54df88f Mon Sep 17 00:00:00 2001 From: Shaen Date: Fri, 5 Mar 2021 10:36:47 -0800 Subject: [PATCH 4/6] remove vec --- .../src/hierarchy/hierarchy_maintenance_system.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index f48ee6000cf02..6e092096fde96 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -24,9 +24,6 @@ pub fn parent_update_system( } } - // Tracks all newly created `Children` Components this frame. - let mut children_additions = HashMap::>::default(); - // Entities with a changed Parent (that also have a PreviousParent, even if None) for (entity, parent, possible_previous_parent) in parent_query.iter_mut() { if let Some(mut previous_parent) = possible_previous_parent { From c0d44234ec82bcd1a69da9e4b565a7d285b065f2 Mon Sep 17 00:00:00 2001 From: Shaen Date: Wed, 3 Mar 2021 15:58:55 -0800 Subject: [PATCH 5/6] remove duplicate Parent update, properly set PreviousParent --- .../src/hierarchy/hierarchy_maintenance_system.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index 010e4c9db0bcf..783fb77b15241 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -4,8 +4,6 @@ use bevy_ecs::{ query::Without, system::{Commands, Query}, }; -use bevy_utils::HashMap; -use smallvec::SmallVec; pub fn parent_update_system( mut commands: Commands, @@ -97,9 +95,11 @@ mod test { ); // Parent `e1` to `e2`. - (*world.get_mut::(children[0]).unwrap()).0 = children[1]; + let mut commands = Commands::default(); + commands.push_children(children[1], &[children[0]]); - schedule.run(&mut world); + commands.apply(&mut world, &mut resources); + schedule.run(&mut world, &mut resources); assert_eq!( world From 6fced4993aa99bab1cea6b81a7138369a8f5413b Mon Sep 17 00:00:00 2001 From: Shaen Date: Thu, 18 Mar 2021 12:25:43 -0700 Subject: [PATCH 6/6] fix remaining ECSv2 changes --- .gitignore | 1 + bevy.iml | 47 ------------------- .../hierarchy/hierarchy_maintenance_system.rs | 6 +-- 3 files changed, 4 insertions(+), 50 deletions(-) delete mode 100644 bevy.iml diff --git a/.gitignore b/.gitignore index 48bbc7e0e1c91..aa82a29225742 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ Cargo.lock .cargo/config .cargo/config.toml /.idea +.iml /.vscode /benches/target diff --git a/bevy.iml b/bevy.iml deleted file mode 100644 index cdf49bae67042..0000000000000 --- a/bevy.iml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index 783fb77b15241..63bd6e384780f 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -95,11 +95,11 @@ mod test { ); // Parent `e1` to `e2`. - let mut commands = Commands::default(); + let mut commands = Commands::new(&mut command_queue, &world); commands.push_children(children[1], &[children[0]]); - commands.apply(&mut world, &mut resources); - schedule.run(&mut world, &mut resources); + command_queue.apply(&mut world); + schedule.run(&mut world); assert_eq!( world