From 4d438b9b16fd98d61d3a9c42b7527de955e991df Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Wed, 31 May 2023 11:31:06 -0400 Subject: [PATCH 1/4] remove `GetOrSpawn` --- crates/bevy_ecs/src/system/commands/mod.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index e5db31f50b8a0..3abe394a68a3f 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -200,7 +200,9 @@ impl<'w, 's> Commands<'w, 's> { /// apps, and only when they have a scheme worked out to share an ID space (which doesn't happen /// by default). pub fn get_or_spawn<'a>(&'a mut self, entity: Entity) -> EntityCommands<'w, 's, 'a> { - self.add(GetOrSpawn { entity }); + self.add(move |world: &mut World| { + world.get_or_spawn(entity); + }); EntityCommands { entity, commands: self, @@ -853,16 +855,6 @@ where } } -pub struct GetOrSpawn { - entity: Entity, -} - -impl Command for GetOrSpawn { - fn write(self, world: &mut World) { - world.get_or_spawn(self.entity); - } -} - pub struct SpawnBatch where I: IntoIterator, From baabefca3b47f77645205a246e5ce99365a27e36 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Wed, 31 May 2023 11:36:51 -0400 Subject: [PATCH 2/4] hide `PhantomData` fields --- crates/bevy_ecs/src/system/commands/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 3abe394a68a3f..58e40b468d90e 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -931,7 +931,7 @@ where #[derive(Debug)] pub struct Remove { pub entity: Entity, - pub phantom: PhantomData, + _marker: PhantomData, } impl Command for Remove @@ -950,13 +950,13 @@ impl Remove { pub const fn new(entity: Entity) -> Self { Self { entity, - phantom: PhantomData::, + _marker: PhantomData::, } } } pub struct InitResource { - _phantom: PhantomData, + _marker: PhantomData, } impl Command for InitResource { @@ -969,7 +969,7 @@ impl InitResource { /// Creates a [`Command`] which will insert a default created [`Resource`] into the [`World`] pub const fn new() -> Self { Self { - _phantom: PhantomData::, + _marker: PhantomData::, } } } @@ -985,7 +985,7 @@ impl Command for InsertResource { } pub struct RemoveResource { - pub phantom: PhantomData, + _marker: PhantomData, } impl Command for RemoveResource { @@ -998,7 +998,7 @@ impl RemoveResource { /// Creates a [`Command`] which will remove a [`Resource`] from the [`World`] pub const fn new() -> Self { Self { - phantom: PhantomData::, + _marker: PhantomData::, } } } From 395ae228718e657bf159dfe8f39410e4ba4a5028 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Wed, 31 May 2023 11:41:32 -0400 Subject: [PATCH 3/4] add documentation to miscellaneous command types --- crates/bevy_ecs/src/system/commands/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 58e40b468d90e..64c7be13527aa 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -841,8 +841,10 @@ where } } +/// A [`Command`] that spawns a new entity and adds the components in a [`Bundle`] to it. #[derive(Debug)] pub struct Spawn { + /// The [`Bundle`] of components that will be added to the newly-spawned entity. pub bundle: T, } @@ -899,6 +901,7 @@ where } } +/// A [`Command`] that despawns a specific entity. #[derive(Debug)] pub struct Despawn { pub entity: Entity, @@ -910,8 +913,11 @@ impl Command for Despawn { } } +/// A [`Command`] that adds the components in a [`Bundle`] to an entity. pub struct Insert { + /// The entity to which the components will be added. pub entity: Entity, + /// The [`Bundle`] containing the components that will be added to the entity. pub bundle: T, } @@ -928,6 +934,9 @@ where } } +/// A [`Command`] that removes components from an entity. +/// For a [`Bundle`] type `T`, this will remove any components in the bundle. +/// Any components in the bundle that aren't found on the entity will be ignored. #[derive(Debug)] pub struct Remove { pub entity: Entity, @@ -946,7 +955,7 @@ where } impl Remove { - /// Creates a [`Command`] which will remove the specified [`Entity`] when flushed + /// Creates a [`Command`] which will remove the specified [`Entity`] when applied. pub const fn new(entity: Entity) -> Self { Self { entity, @@ -955,6 +964,8 @@ impl Remove { } } +/// A [`Command`] that inserts a [`Resource`] into the world using a value +/// created with the [`FromWorld`] trait. pub struct InitResource { _marker: PhantomData, } @@ -974,6 +985,7 @@ impl InitResource { } } +/// A [`Command`] that inserts a [`Resource`] into the world. pub struct InsertResource { pub resource: R, } @@ -984,6 +996,7 @@ impl Command for InsertResource { } } +/// A [`Command`] that removes the [resource](Resource) `R` from the world. pub struct RemoveResource { _marker: PhantomData, } From e60a91d3c86635444a478fa1ac3fa85cc9b67016 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Wed, 31 May 2023 11:51:27 -0400 Subject: [PATCH 4/4] simplify phantomdata constructors --- crates/bevy_ecs/src/system/commands/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 64c7be13527aa..e0c84dbcaa819 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -959,7 +959,7 @@ impl Remove { pub const fn new(entity: Entity) -> Self { Self { entity, - _marker: PhantomData::, + _marker: PhantomData, } } } @@ -980,7 +980,7 @@ impl InitResource { /// Creates a [`Command`] which will insert a default created [`Resource`] into the [`World`] pub const fn new() -> Self { Self { - _marker: PhantomData::, + _marker: PhantomData, } } } @@ -1011,7 +1011,7 @@ impl RemoveResource { /// Creates a [`Command`] which will remove a [`Resource`] from the [`World`] pub const fn new() -> Self { Self { - _marker: PhantomData::, + _marker: PhantomData, } } }