Skip to content

Commit b45d83e

Browse files
Rename Add to Queue for methods with deferred semantics (#15234)
# Objective - Fixes #15106 ## Solution - Trivial refactor to rename the method. The duplicate method `push` was removed as well. This will simpify the API and make the semantics more clear. `Add` implies that the action happens immediately, whereas in reality, the command is queued to be run eventually. - `ChildBuilder::add_command` has similarly been renamed to `queue_command`. ## Testing Unit tests should suffice for this simple refactor. --- ## Migration Guide - `Commands::add` and `Commands::push` have been replaced with `Commnads::queue`. - `ChildBuilder::add_command` has been renamed to `ChildBuilder::queue_command`.
1 parent c2d54f5 commit b45d83e

File tree

14 files changed

+113
-118
lines changed

14 files changed

+113
-118
lines changed

benches/benches/bevy_ecs/world/commands.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ pub fn fake_commands(criterion: &mut Criterion) {
146146
let mut commands = Commands::new(&mut command_queue, &world);
147147
for i in 0..command_count {
148148
if black_box(i % 2 == 0) {
149-
commands.add(FakeCommandA);
149+
commands.queue(FakeCommandA);
150150
} else {
151-
commands.add(FakeCommandB(0));
151+
commands.queue(FakeCommandB(0));
152152
}
153153
}
154154
command_queue.apply(&mut world);
@@ -190,7 +190,7 @@ pub fn sized_commands_impl<T: Default + Command>(criterion: &mut Criterion) {
190190
bencher.iter(|| {
191191
let mut commands = Commands::new(&mut command_queue, &world);
192192
for _ in 0..command_count {
193-
commands.add(T::default());
193+
commands.queue(T::default());
194194
}
195195
command_queue.apply(&mut world);
196196
});

crates/bevy_ecs/src/event/writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use bevy_ecs::{
5151
/// //
5252
/// // NOTE: the event won't actually be sent until commands get applied during
5353
/// // apply_deferred.
54-
/// commands.add(|w: &mut World| {
54+
/// commands.queue(|w: &mut World| {
5555
/// w.send_event(MyEvent);
5656
/// });
5757
/// }

crates/bevy_ecs/src/observer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ mod tests {
830830
..Default::default()
831831
});
832832

833-
world.commands().add(
833+
world.commands().queue(
834834
// SAFETY: we registered `event_a` above and it matches the type of TriggerA
835835
unsafe { EmitDynamicTrigger::new_with_id(event_a, EventA, ()) },
836836
);

crates/bevy_ecs/src/observer/runner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Component for ObserverState {
6565

6666
fn register_component_hooks(hooks: &mut ComponentHooks) {
6767
hooks.on_add(|mut world, entity, _| {
68-
world.commands().add(move |world: &mut World| {
68+
world.commands().queue(move |world: &mut World| {
6969
world.register_observer(entity);
7070
});
7171
});
@@ -78,7 +78,7 @@ impl Component for ObserverState {
7878
.as_mut()
7979
.descriptor,
8080
);
81-
world.commands().add(move |world: &mut World| {
81+
world.commands().queue(move |world: &mut World| {
8282
world.unregister_observer(entity, descriptor);
8383
});
8484
});
@@ -398,7 +398,7 @@ fn hook_on_add<E: Event, B: Bundle, S: ObserverSystem<E, B>>(
398398
entity: Entity,
399399
_: ComponentId,
400400
) {
401-
world.commands().add(move |world: &mut World| {
401+
world.commands().queue(move |world: &mut World| {
402402
let event_type = world.init_component::<E>();
403403
let mut components = Vec::new();
404404
B::component_ids(&mut world.components, &mut world.storages, &mut |id| {

crates/bevy_ecs/src/reflect/entity_commands.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub trait ReflectCommandExt {
7979
///
8080
/// // Or even with BundleA
8181
/// prefab.data = boxed_reflect_bundle_a;
82-
///
82+
///
8383
/// // No matter which component or bundle is in the resource and without knowing the exact type, you can
8484
/// // use the insert_reflect entity command to insert that component/bundle into an entity.
8585
/// commands
@@ -174,7 +174,7 @@ pub trait ReflectCommandExt {
174174

175175
impl ReflectCommandExt for EntityCommands<'_> {
176176
fn insert_reflect(&mut self, component: Box<dyn PartialReflect>) -> &mut Self {
177-
self.commands.add(InsertReflect {
177+
self.commands.queue(InsertReflect {
178178
entity: self.entity,
179179
component,
180180
});
@@ -185,7 +185,7 @@ impl ReflectCommandExt for EntityCommands<'_> {
185185
&mut self,
186186
component: Box<dyn PartialReflect>,
187187
) -> &mut Self {
188-
self.commands.add(InsertReflectWithRegistry::<T> {
188+
self.commands.queue(InsertReflectWithRegistry::<T> {
189189
entity: self.entity,
190190
_t: PhantomData,
191191
component,
@@ -194,7 +194,7 @@ impl ReflectCommandExt for EntityCommands<'_> {
194194
}
195195

196196
fn remove_reflect(&mut self, component_type_path: impl Into<Cow<'static, str>>) -> &mut Self {
197-
self.commands.add(RemoveReflect {
197+
self.commands.queue(RemoveReflect {
198198
entity: self.entity,
199199
component_type_path: component_type_path.into(),
200200
});
@@ -205,7 +205,7 @@ impl ReflectCommandExt for EntityCommands<'_> {
205205
&mut self,
206206
component_type_name: impl Into<Cow<'static, str>>,
207207
) -> &mut Self {
208-
self.commands.add(RemoveReflectWithRegistry::<T> {
208+
self.commands.queue(RemoveReflectWithRegistry::<T> {
209209
entity: self.entity,
210210
_t: PhantomData,
211211
component_type_name: component_type_name.into(),

0 commit comments

Comments
 (0)