pub trait System: 'static + Send + Sync {
type In;
type Out;
fn name(&self) -> Cow<'static, str>;
fn component_access(&self) -> &Access<ComponentId>;
fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>;
fn is_send(&self) -> bool;
unsafe fn run_unsafe(&mut self, input: Self::In, world: &World) -> Self::Out;
fn apply_buffers(&mut self, world: &mut World);
fn initialize(&mut self, _world: &mut World);
fn update_archetype_component_access(&mut self, world: &World);
fn check_change_tick(&mut self, change_tick: u32);
fn run(&mut self, input: Self::In, world: &mut World) -> Self::Out { ... }
fn default_labels(&self) -> Vec<SystemLabelId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
{ ... }
}
Expand description
An ECS system that can be added to a Schedule
Systems are functions with all arguments implementing
SystemParam
.
Systems are added to an application using App::add_system(my_system)
or similar methods, and will generally run once per pass of the main loop.
Systems are executed in parallel, in opportunistic order; data access is managed automatically.
It’s possible to specify explicit execution order between specific systems,
see SystemDescriptor
.
Required Associated Types
type In
type In
The system’s input. See In
for
FunctionSystem
s.
type Out
type Out
The system’s output.
Required Methods
fn component_access(&self) -> &Access<ComponentId>
fn component_access(&self) -> &Access<ComponentId>
Returns the system’s component Access
.
fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>
fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>
Returns the system’s archetype component Access
.
unsafe fn run_unsafe(&mut self, input: Self::In, world: &World) -> Self::Out
unsafe fn run_unsafe(&mut self, input: Self::In, world: &World) -> Self::Out
Runs the system with the given input in the world. Unlike System::run
, this function
takes a shared reference to World
and may therefore break Rust’s aliasing rules, making
it unsafe to call.
Safety
This might access world and resources in an unsafe manner. This should only be called in one
of the following contexts:
1. This system is the only system running on the given world across all threads.
2. This system only runs in parallel with other systems that do not conflict with the
System::archetype_component_access()
.
fn apply_buffers(&mut self, world: &mut World)
fn initialize(&mut self, _world: &mut World)
fn initialize(&mut self, _world: &mut World)
Initialize the system.
fn update_archetype_component_access(&mut self, world: &World)
fn update_archetype_component_access(&mut self, world: &World)
Update the system’s archetype component Access
.
fn check_change_tick(&mut self, change_tick: u32)
Provided Methods
Runs the system with the given input in the world.
fn default_labels(&self) -> Vec<SystemLabelId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn default_labels(&self) -> Vec<SystemLabelId, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
The default labels for the system
Trait Implementations
impl IntoRunCriteria<Box<dyn System<In = (), Out = ShouldRun> + 'static, Global>> for Box<dyn System<In = (), Out = ShouldRun> + 'static, Global>
impl IntoRunCriteria<Box<dyn System<In = (), Out = ShouldRun> + 'static, Global>> for Box<dyn System<In = (), Out = ShouldRun> + 'static, Global>
fn into(self) -> RunCriteriaDescriptorOrLabel
impl IntoSystemDescriptor<()> for Box<dyn System<In = (), Out = ()> + 'static, Global>
impl IntoSystemDescriptor<()> for Box<dyn System<In = (), Out = ()> + 'static, Global>
fn into_descriptor(self) -> SystemDescriptor
impl ParallelSystemDescriptorCoercion<()> for Box<dyn System<In = (), Out = ()> + 'static, Global>
impl ParallelSystemDescriptorCoercion<()> for Box<dyn System<In = (), Out = ()> + 'static, Global>
fn with_run_criteria<Marker>(
self,
run_criteria: impl IntoRunCriteria<Marker>
) -> ParallelSystemDescriptor
fn with_run_criteria<Marker>(
self,
run_criteria: impl IntoRunCriteria<Marker>
) -> ParallelSystemDescriptor
Assigns a run criteria to the system. Can be a new descriptor or a label of a run criteria defined elsewhere. Read more
fn label(self, label: impl SystemLabel) -> ParallelSystemDescriptor
fn label(self, label: impl SystemLabel) -> ParallelSystemDescriptor
Assigns a label to the system; there can be more than one, and it doesn’t have to be unique.
fn before<Marker>(
self,
label: impl AsSystemLabel<Marker>
) -> ParallelSystemDescriptor
fn before<Marker>(
self,
label: impl AsSystemLabel<Marker>
) -> ParallelSystemDescriptor
Specifies that the system should run before systems with the given label.
fn after<Marker>(
self,
label: impl AsSystemLabel<Marker>
) -> ParallelSystemDescriptor
fn after<Marker>(
self,
label: impl AsSystemLabel<Marker>
) -> ParallelSystemDescriptor
Specifies that the system should run after systems with the given label.
fn in_ambiguity_set(
self,
set: impl AmbiguitySetLabel
) -> ParallelSystemDescriptor
fn in_ambiguity_set(
self,
set: impl AmbiguitySetLabel
) -> ParallelSystemDescriptor
Specifies that the system is exempt from execution order ambiguity detection with other systems in this set. Read more
impl RunCriteriaDescriptorCoercion<()> for Box<dyn System<In = (), Out = ShouldRun> + 'static, Global>
impl RunCriteriaDescriptorCoercion<()> for Box<dyn System<In = (), Out = ShouldRun> + 'static, Global>
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor
fn label(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor
Assigns a label to the criteria. Must be unique.
fn label_discard_if_duplicate(
self,
label: impl RunCriteriaLabel
) -> RunCriteriaDescriptor
fn label_discard_if_duplicate(
self,
label: impl RunCriteriaLabel
) -> RunCriteriaDescriptor
Assigns a label to the criteria. If the given label is already in use, this criteria will be discarded before initialization. Read more
fn before(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor
fn before(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor
Specifies that this criteria must be evaluated before a criteria with the given label.
fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor
fn after(self, label: impl RunCriteriaLabel) -> RunCriteriaDescriptor
Specifies that this criteria must be evaluated after a criteria with the given label.