Skip to main content

SystemContext

Trait SystemContext 

Source
pub trait SystemContext: WorldHandle {
    // Required methods
    fn spawn(&mut self) -> EntityId;
    fn despawn(&mut self, entity: EntityId);
    fn set_component(
        &mut self,
        entity: EntityId,
        type_id: TypeId,
        component: Box<dyn Any + Send + Sync>,
    );
    fn entities_with(&self, type_id: TypeId) -> Vec<EntityId> ;
    fn get_component(
        &self,
        entity: EntityId,
        type_id: TypeId,
    ) -> Option<&dyn Any>;
    fn get_component_mut(
        &mut self,
        entity: EntityId,
        type_id: TypeId,
    ) -> Option<&mut dyn Any>;
    fn budget(&self) -> &TickBudget;
}
Expand description

Abstract interface for system runners.

Extends WorldHandle with ECS storage methods (spawn, despawn, component access). System closures receive this trait object instead of a raw &mut Ecs, keeping the ECS as an implementation detail.

Pure world ops (get_block, set_block, check_overlap, …) come from WorldHandle and are not redeclared here. ECS methods use TypeId + dyn Any internally; typed access is provided via SystemContextExt.

Required Methods§

Source

fn spawn(&mut self) -> EntityId

Spawns a new entity and returns its unique ID.

Source

fn despawn(&mut self, entity: EntityId)

Removes an entity and all its components.

Source

fn set_component( &mut self, entity: EntityId, type_id: TypeId, component: Box<dyn Any + Send + Sync>, )

Sets a component value for an entity (type-erased).

Source

fn entities_with(&self, type_id: TypeId) -> Vec<EntityId>

Returns all entity IDs that have a component of the given type.

Source

fn get_component(&self, entity: EntityId, type_id: TypeId) -> Option<&dyn Any>

Returns a reference to a component as dyn Any.

Source

fn get_component_mut( &mut self, entity: EntityId, type_id: TypeId, ) -> Option<&mut dyn Any>

Returns a mutable reference to a component as dyn Any.

Source

fn budget(&self) -> &TickBudget

Returns the CPU budget for the current system invocation.

Budget-aware systems call this to check remaining time and yield early when expired. Systems that ignore the budget run to completion.

Implementors§