pub struct SystemBuilder<Q = (), R = ()> { /* private fields */ }
Expand description
A low level builder for constructing systems.
#[derive(Copy, Clone, Debug, PartialEq)]
struct Static;
#[derive(Debug)]
struct TestResource {}
let mut system_one = SystemBuilder::new("TestSystem")
.read_resource::<TestResource>()
.with_query(
<(Entity, Read<Position>, Read<Model>)>::query()
.filter(!component::<Static>() | maybe_changed::<Position>()),
)
.build(
move |commands, world, resource, queries| {
for (entity, pos, model) in queries.iter_mut(world) {}
},
);
Implementations§
Source§impl SystemBuilder
impl SystemBuilder
Sourcepub fn new<T>(name: T) -> SystemBuilder
pub fn new<T>(name: T) -> SystemBuilder
Create a new system builder to construct a new system.
Please note, the name
argument for this method is just for debugging and visualization
purposes and is not logically used anywhere.
Source§impl<Q, R> SystemBuilder<Q, R>
impl<Q, R> SystemBuilder<Q, R>
Sourcepub fn with_name(self, name: SystemId) -> SystemBuilder<Q, R>
pub fn with_name(self, name: SystemId) -> SystemBuilder<Q, R>
Provides a name to the system being built.
Sourcepub fn with_query<V, F>(
self,
query: Query<V, F>,
) -> SystemBuilder<<Q as ConsAppend<Query<V, F>>>::Output, R>
pub fn with_query<V, F>( self, query: Query<V, F>, ) -> SystemBuilder<<Q as ConsAppend<Query<V, F>>>::Output, R>
Defines a query to provide this system for its execution. Multiple queries can be provided, and queries are cached internally for efficiency for filtering and archetype ID handling.
It is best practice to define your queries here, to allow for the caching to take place. These queries are then provided to the executing closure as a tuple of queries.
Sourcepub fn read_resource<T>(
self,
) -> SystemBuilder<Q, <R as ConsAppend<Read<T>>>::Output>where
T: 'static + Resource,
R: ConsAppend<Read<T>>,
<R as ConsAppend<Read<T>>>::Output: ConsFlatten,
pub fn read_resource<T>(
self,
) -> SystemBuilder<Q, <R as ConsAppend<Read<T>>>::Output>where
T: 'static + Resource,
R: ConsAppend<Read<T>>,
<R as ConsAppend<Read<T>>>::Output: ConsFlatten,
Flag this resource type as being read by this system.
This will inform the dispatcher to not allow any writes access to this resource while this system is running. Parralel reads still occur during execution.
Sourcepub fn write_resource<T>(
self,
) -> SystemBuilder<Q, <R as ConsAppend<Write<T>>>::Output>where
T: 'static + Resource,
R: ConsAppend<Write<T>>,
<R as ConsAppend<Write<T>>>::Output: ConsFlatten,
pub fn write_resource<T>(
self,
) -> SystemBuilder<Q, <R as ConsAppend<Write<T>>>::Output>where
T: 'static + Resource,
R: ConsAppend<Write<T>>,
<R as ConsAppend<Write<T>>>::Output: ConsFlatten,
Flag this resource type as being written by this system.
This will inform the dispatcher to not allow any parallel access to this resource while this system is running.
Sourcepub fn read_component<T>(self) -> SystemBuilder<Q, R>where
T: Component,
pub fn read_component<T>(self) -> SystemBuilder<Q, R>where
T: Component,
This performs a soft resource block on the component for writing. The dispatcher will generally handle dispatching read and writes on components based on archetype, allowing for more granular access and more parallelization of systems.
Using this method will mark the entire component as read by this system, blocking writing systems from accessing any archetypes which contain this component for the duration of its execution.
This type of access with SubWorld
is provided for cases where sparse component access
is required and searching entire query spaces for entities is inefficient.
Sourcepub fn write_component<T>(self) -> SystemBuilder<Q, R>where
T: Component,
pub fn write_component<T>(self) -> SystemBuilder<Q, R>where
T: Component,
This performs a exclusive resource block on the component for writing. The dispatcher will generally handle dispatching read and writes on components based on archetype, allowing for more granular access and more parallelization of systems.
Using this method will mark the entire component as written by this system, blocking other systems from accessing any archetypes which contain this component for the duration of its execution.
This type of access with SubWorld
is provided for cases where sparse component access
is required and searching entire query spaces for entities is inefficient.
Sourcepub fn build<F>(
self,
run_fn: F,
) -> System<<R as ConsFlatten>::Output, <Q as ConsFlatten>::Output, F>where
<R as ConsFlatten>::Output: for<'a> ResourceSet<'a>,
<Q as ConsFlatten>::Output: QuerySet,
F: FnMut(&mut CommandBuffer, &mut SubWorld<'_>, &mut <<R as ConsFlatten>::Output as ResourceSet<'static>>::Result, &mut <Q as ConsFlatten>::Output),
pub fn build<F>(
self,
run_fn: F,
) -> System<<R as ConsFlatten>::Output, <Q as ConsFlatten>::Output, F>where
<R as ConsFlatten>::Output: for<'a> ResourceSet<'a>,
<Q as ConsFlatten>::Output: QuerySet,
F: FnMut(&mut CommandBuffer, &mut SubWorld<'_>, &mut <<R as ConsFlatten>::Output as ResourceSet<'static>>::Result, &mut <Q as ConsFlatten>::Output),
Builds a system which is not Schedulable
, as it is not thread safe (!Send and !Sync),
but still implements all the calling infrastructure of the Runnable
trait. This provides
a way for legion consumers to leverage the System
construction and type-handling of
this build for thread local systems which cannot leave the main initializing thread.
Trait Implementations§
Source§impl Default for SystemBuilder
impl Default for SystemBuilder
Source§fn default() -> SystemBuilder
fn default() -> SystemBuilder
Auto Trait Implementations§
impl<Q, R> Freeze for SystemBuilder<Q, R>
impl<Q, R> RefUnwindSafe for SystemBuilder<Q, R>where
Q: RefUnwindSafe,
R: RefUnwindSafe,
impl<Q, R> Send for SystemBuilder<Q, R>
impl<Q, R> Sync for SystemBuilder<Q, R>
impl<Q, R> Unpin for SystemBuilder<Q, R>
impl<Q, R> UnwindSafe for SystemBuilder<Q, R>where
Q: UnwindSafe,
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Component for T
impl<T> Component for T
Source§type Storage = PackedStorage<T>
type Storage = PackedStorage<T>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more