pub struct CommandBuffer { /* private fields */ }
Expand description
A command buffer used to queue mutable changes to the world from a system. This buffer is automatically
flushed and refreshed at the beginning of every frame by Schedule
. If Schedule
is not used,
then the user needs to manually flush it by performing CommandBuffer::flush
.
§Examples
Inserting an entity using the CommandBuffer
:
let mut command_buffer = CommandBuffer::new(&world);
let entity = command_buffer.push(());
command_buffer.add_component(entity, Position(123.0));
command_buffer.remove(entity);
command_buffer.flush(&mut world, &mut resources);
Implementations§
Source§impl CommandBuffer
impl CommandBuffer
Sourcepub fn new(world: &World) -> CommandBuffer
pub fn new(world: &World) -> CommandBuffer
Constructs an empty command buffer.
Sourcepub fn flush(&mut self, world: &mut World, resources: &mut Resources)
pub fn flush(&mut self, world: &mut World, resources: &mut Resources)
Flushes this command buffer, draining all stored commands and writing them to the world.
Command flushes are performed in a FIFO manner, allowing for reliable, linear commands being executed in the order they were provided.
Sourcepub fn exec_mut<F>(&mut self, f: F)
pub fn exec_mut<F>(&mut self, f: F)
Executes an arbitrary closure against the mutable world, allowing for queued exclusive access to the world.
Sourcepub fn push<T>(&mut self, components: T) -> Entitywhere
Option<T>: 'static + IntoComponentSource,
<Option<T> as IntoComponentSource>::Source: KnownLength + Send + Sync,
pub fn push<T>(&mut self, components: T) -> Entitywhere
Option<T>: 'static + IntoComponentSource,
<Option<T> as IntoComponentSource>::Source: KnownLength + Send + Sync,
Queues the insertion of a single entity into the world.
Sourcepub fn extend<T>(&mut self, components: T) -> &[Entity]where
T: 'static + IntoComponentSource,
<T as IntoComponentSource>::Source: KnownLength + Send + Sync,
pub fn extend<T>(&mut self, components: T) -> &[Entity]where
T: 'static + IntoComponentSource,
<T as IntoComponentSource>::Source: KnownLength + Send + Sync,
Queues the insertion of new entities into the world.
Sourcepub fn remove(&mut self, entity: Entity)
pub fn remove(&mut self, entity: Entity)
Queues the deletion of an entity in the command buffer.
Sourcepub fn add_component<C>(&mut self, entity: Entity, component: C)where
C: Component,
pub fn add_component<C>(&mut self, entity: Entity, component: C)where
C: Component,
Queues the addition of a component from an entity in the command buffer.
Sourcepub fn remove_component<C>(&mut self, entity: Entity)where
C: Component,
pub fn remove_component<C>(&mut self, entity: Entity)where
C: Component,
Queues the removal of a component from an entity in the command buffer.
Auto Trait Implementations§
impl Freeze for CommandBuffer
impl !RefUnwindSafe for CommandBuffer
impl Send for CommandBuffer
impl Sync for CommandBuffer
impl Unpin for CommandBuffer
impl !UnwindSafe for CommandBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Component for T
impl<T> Component for T
Source§type Storage = PackedStorage<T>
type Storage = PackedStorage<T>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more