Struct oxygengine_core::ecs::CommandBuffer
source · [−]pub struct CommandBuffer { /* private fields */ }
Expand description
Records operations for future application to a World
Useful when operations cannot be applied directly due to ordering concerns or borrow checking.
let mut world = World::new();
let entity = world.reserve_entity();
let mut cmd = CommandBuffer::new();
cmd.insert(entity, (true, 42));
cmd.run_on(&mut world); // cmd can now be reused
assert_eq!(*world.get::<&i32>(entity).unwrap(), 42);
Implementations
sourceimpl CommandBuffer
impl CommandBuffer
sourcepub fn new() -> CommandBuffer
pub fn new() -> CommandBuffer
Create an empty command buffer
sourcepub fn insert(&mut self, entity: Entity, components: impl DynamicBundle)
pub fn insert(&mut self, entity: Entity, components: impl DynamicBundle)
Add components from bundle
to entity
, if it exists
Pairs well with World::reserve_entity
to spawn entities with a known handle.
When inserting a single component, see insert_one
for convenience.
sourcepub fn insert_one(&mut self, entity: Entity, component: impl Component)
pub fn insert_one(&mut self, entity: Entity, component: impl Component)
Add component
to entity
, if the entity exists
See insert
.
sourcepub fn remove<T>(&mut self, ent: Entity)where
T: 'static + Bundle,
pub fn remove<T>(&mut self, ent: Entity)where
T: 'static + Bundle,
Remove components from entity
if they exist
When removing a single component, see remove_one
for convenience.
sourcepub fn remove_one<T>(&mut self, ent: Entity)where
T: Component,
pub fn remove_one<T>(&mut self, ent: Entity)where
T: Component,
Remove a component from entity
if it exists
See remove
.
sourcepub fn spawn(&mut self, components: impl DynamicBundle)
pub fn spawn(&mut self, components: impl DynamicBundle)
Spawn a new entity with components
If the Entity
is needed immediately, consider combining World::reserve_entity
with
insert
instead.
Trait Implementations
sourceimpl Default for CommandBuffer
impl Default for CommandBuffer
sourcefn default() -> CommandBuffer
fn default() -> CommandBuffer
Create an empty buffer
sourceimpl Drop for CommandBuffer
impl Drop for CommandBuffer
impl Send for CommandBuffer
impl Sync for CommandBuffer
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more