Struct EcsCommandBuffer
pub struct EcsCommandBuffer { /* private fields */ }Expand description
Typed, bounded structural changes for one ECS world at a tick boundary. See the module recipe for preparation, query lifetimes and accepted feedback.
Implementations§
§impl EcsCommandBuffer
impl EcsCommandBuffer
pub fn new(command_capacity: usize, spawn_capacity: usize) -> EcsCommandBuffer
pub fn new(command_capacity: usize, spawn_capacity: usize) -> EcsCommandBuffer
Reserves bounded queue/report/map storage. Zero capacities are valid. Construction uses the ordinary allocator and can panic/abort.
pub fn is_empty(&self) -> bool
pub fn remaining_capacity(&self) -> usize
pub fn spawn_capacity(&self) -> usize
pub fn spawn_capacity(&self) -> usize
Total accepted-spawn limit per epoch; claiming does not release slots.
pub fn remaining_spawn_capacity(&self) -> usize
pub fn spawn<B>(
&mut self,
id: u64,
bundle: B,
) -> Result<SpawnToken, RejectedBundle<B>>where
B: Bundle + 'static,
pub fn spawn<B>(
&mut self,
id: u64,
bundle: B,
) -> Result<SpawnToken, RejectedBundle<B>>where
B: Bundle + 'static,
Authors a prepared single spawn; full queue takes precedence over map full. Returns a token only after accepting the command and its mapping slot.
pub fn insert<B>(
&mut self,
id: u64,
target: impl Into<EntityTarget>,
bundle: B,
) -> Result<(), RejectedBundle<B>>where
B: Bundle + 'static,
pub fn insert<B>(
&mut self,
id: u64,
target: impl Into<EntityTarget>,
bundle: B,
) -> Result<(), RejectedBundle<B>>where
B: Bundle + 'static,
Appends a checked insert. Queue capacity is checked before token validity. Ordinary entity liveness is checked at apply by the existing ECS API.
pub fn remove<T>(
&mut self,
id: u64,
target: impl Into<EntityTarget>,
) -> Result<(), EnqueueError>where
T: 'static,
pub fn remove<T>(
&mut self,
id: u64,
target: impl Into<EntityTarget>,
) -> Result<(), EnqueueError>where
T: 'static,
Removes and drops T at apply; absence is an ECS error, not a no-op.
pub fn despawn(
&mut self,
id: u64,
target: impl Into<EntityTarget>,
) -> Result<(), EnqueueError>
pub fn despawn( &mut self, id: u64, target: impl Into<EntityTarget>, ) -> Result<(), EnqueueError>
Despawns at apply; stale entities are errors, not silently ignored.
pub fn apply_report(
&mut self,
world: &mut World,
limit: usize,
policy: CommandFailurePolicy,
on_error: impl FnMut(CommandFailure<EcsCommandError>),
) -> Result<EcsApplyReport<'_>, BufferError>
pub fn apply_report( &mut self, world: &mut World, limit: usize, policy: CommandFailurePolicy, on_error: impl FnMut(CommandFailure<EcsCommandError>), ) -> Result<EcsApplyReport<'_>, BufferError>
Executes at most limit operations; errors consume budget and commands.
Stop/continue and untouched-tail behavior match the shared fallible queue.
Each failure is moved synchronously to on_error; no error list is built.
Successes are logged before any later command/callback can panic. Both
command and callback panics propagate. A spawn is marked failed before
invocation, then mapped only on success. No spawn is automatically retried.
Only incomplete reset returns Err before doing work.
pub fn last_accepted(&self) -> &[AppliedEntityCommand]
pub fn last_accepted(&self) -> &[AppliedEntityCommand]
Last flush’s successes, also inspectable after an unwind. A later apply replaces this log. Hosts must avoid emitting the same inspected log twice.
pub fn take_spawn(&mut self, token: &SpawnToken) -> Result<Entity, TokenError>
pub fn take_spawn(&mut self, token: &SpawnToken) -> Result<Entity, TokenError>
Claims an accepted spawn even after the report drops or a later unwind. Does not check entity liveness; a subsequent command may have despawned it.
pub fn reset(&mut self) -> Result<(), BufferError>
pub fn reset(&mut self) -> Result<(), BufferError>
Cancels pending work, invalidates every token and clears mappings/logs. Does not despawn accepted entities. Retains all storage and buffer identity. Epoch advancement is checked before mutation and never wraps. Tokens keep the reference-counted identity alive, so buffer drop/recreation cannot revive them. Before dropping payloads the buffer enters reset-incomplete state; if a destructor panics, the untouched tail is disabled until another reset completes. No cancellation callback runs; owned payloads are dropped.