From f2b2065fbe602825f2dfba3cfb49bd151cb52995 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 7 Apr 2020 13:29:11 -0700 Subject: [PATCH] make CommandBufferBuilder non-consuming --- bevy_core/src/transform/world_builder.rs | 21 ++++++++++----------- examples/startup_system.rs | 3 +-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/bevy_core/src/transform/world_builder.rs b/bevy_core/src/transform/world_builder.rs index 2c2ce96e6b..81d84bc28a 100644 --- a/bevy_core/src/transform/world_builder.rs +++ b/bevy_core/src/transform/world_builder.rs @@ -71,7 +71,7 @@ impl<'a> WorldBuilder<'a> { self } - pub fn add_children(&mut self, build_children: impl Fn(&mut WorldBuilder)) -> &mut Self { + pub fn add_children(&mut self, build_children: impl Fn(&mut Self)) -> &mut Self { self.parent_entity = self.current_entity; self.current_entity = None; @@ -116,16 +116,15 @@ pub struct CommandBufferBuilder<'a> { } impl<'a> CommandBufferBuilder<'a> { - pub fn build_entity(mut self) -> Self { + pub fn build_entity(&mut self) -> &mut Self { let entity = *self.command_buffer.insert((), vec![()]).first().unwrap(); self.current_entity = Some(entity); self.add_parent_to_current_entity(); self } - pub fn build(self) {} // note: this is slow and does a full entity copy - pub fn add(self, component: T) -> Self + pub fn add(&mut self, component: T) -> &mut Self where T: legion::storage::Component, { @@ -135,7 +134,7 @@ impl<'a> CommandBufferBuilder<'a> { self } - pub fn tag(self, tag: T) -> Self + pub fn tag(&mut self, tag: T) -> &mut Self where T: legion::storage::Tag, { @@ -145,7 +144,7 @@ impl<'a> CommandBufferBuilder<'a> { self } - pub fn add_entities(self, tags: T, components: C) -> Self + pub fn add_entities(&mut self, tags: T, components: C) -> &mut Self where T: TagSet + TagLayout + for<'b> Filter> + 'static, C: IntoComponentSource + 'static, @@ -154,7 +153,7 @@ impl<'a> CommandBufferBuilder<'a> { self } - pub fn add_entity(mut self, entity_archetype: impl EntityArchetype) -> Self { + pub fn add_entity(&mut self, entity_archetype: impl EntityArchetype) -> &mut Self { let current_entity = entity_archetype.insert_command_buffer(self.command_buffer); self.current_entity = Some(current_entity); self.add_parent_to_current_entity(); @@ -162,13 +161,13 @@ impl<'a> CommandBufferBuilder<'a> { } pub fn add_children( - mut self, - build_children: impl Fn(CommandBufferBuilder) -> CommandBufferBuilder, - ) -> Self { + &mut self, + build_children: impl Fn(&mut Self) -> &mut Self, + ) -> &mut Self { self.parent_entity = self.current_entity; self.current_entity = None; - self = build_children(self); + build_children(self); self.current_entity = self.parent_entity; self.parent_entity = None; diff --git a/examples/startup_system.rs b/examples/startup_system.rs index d666593985..a6327635fd 100644 --- a/examples/startup_system.rs +++ b/examples/startup_system.rs @@ -43,7 +43,6 @@ pub fn startup_system() -> Box { Vec3::new(0.0, 0.0, 1.0), )), ..Default::default() - }) - .build(); + }); }) }