pub trait System {
type Filter;
type Views<'a>: Views<'a>;
type ResourceViews<'a>;
type EntryViews<'a>: Views<'a>;
// Required method
fn run<'a, R, S, I, E>(
&mut self,
query_result: Result<'a, R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
)
where R: ContainsViews<'a, Self::EntryViews<'a>, E>,
I: Iterator<Item = Self::Views<'a>>;
}Expand description
An executable type which operates over the entities within a World.
Systems can be passed to a World to be executed. When executed, the query specified by the
Filter and Views associated types is performed and the result is passed to the run
method.
It is advised to define a new struct for each System you wish to write. System structs can
contain internal state, which can be used after running the system to execute post-processing
logic.
§Example
use brood::{
query::{
filter,
filter::Filter,
result,
Result,
Views,
},
registry,
system::System,
};
// Define components.
struct Foo(usize);
struct Bar(bool);
// Define system to operate on those components.
struct MySystem;
impl System for MySystem {
type Views<'a> = Views!(&'a mut Foo, &'a Bar);
type Filter = filter::None;
type ResourceViews<'a> = Views!();
type EntryViews<'a> = Views!();
fn run<'a, R, S, I, E>(
&mut self,
query_results: Result<R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: registry::Registry,
I: Iterator<Item = Self::Views<'a>>,
{
for result!(foo, bar) in query_results.iter {
if bar.0 {
foo.0 += 1;
}
}
}
}Required Associated Types§
Sourcetype ResourceViews<'a>
type ResourceViews<'a>
Views on resources.
The system will have access to the resources requested here when run.
Sourcetype EntryViews<'a>: Views<'a>
type EntryViews<'a>: Views<'a>
Entry views.
These views specify which components are accessible in entry lookups.
The views here must be Disjoint with Self::Views
Required Methods§
Sourcefn run<'a, R, S, I, E>(
&mut self,
query_result: Result<'a, R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
)
fn run<'a, R, S, I, E>( &mut self, query_result: Result<'a, R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>, )
Logic to be run over the query result.
Any action performed using the query result should be performed here. If any modifications
to the World itself are desired based on the query result, they should be performed
after running the system.
§Example
use brood::{
query::{
filter,
filter::Filter,
result,
Result,
Views,
},
registry,
system::System,
};
// Define components.
struct Foo(usize);
struct Bar(bool);
// Define system to operate on those components.
struct MySystem;
impl System for MySystem {
type Views<'a> = Views!(&'a mut Foo, &'a Bar);
type Filter = filter::None;
type ResourceViews<'a> = Views!();
type EntryViews<'a> = Views!();
fn run<'a, R, S, I, E>(
&mut self,
query_results: Result<R, S, I, Self::ResourceViews<'a>, Self::EntryViews<'a>, E>,
) where
R: registry::Registry,
I: Iterator<Item = Self::Views<'a>>,
{
for result!(foo, bar) in query_results.iter {
if bar.0 {
foo.0 += 1;
}
}
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".