pub struct App { /* private fields */ }Expand description
The central application object.
App owns the ECS world, resources, plugins, and systems. The typical
lifecycle is:
- Create with
App::new. - Register plugins with
add_plugin. - Call
buildto run all plugin registrations and sort systems. - Call
runto hand control to the runner.
Implementations§
Source§impl App
impl App
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new App with an empty world and a default infinite-loop runner.
Builds in TimePlugin — Res<Time> works
without registering anything yourself — along with
AudioPlugin (Res<AudioOutput>), and,
on every target except wasm32,
GamepadPlugin (Res<Gamepads>).
Sourcepub fn add_plugin(&mut self, plugin: impl Plugin) -> &mut Self
pub fn add_plugin(&mut self, plugin: impl Plugin) -> &mut Self
Queue a plugin to be built during build.
Sourcepub fn set_ready_gate<F>(&mut self, gate: F) -> &mut Self
pub fn set_ready_gate<F>(&mut self, gate: F) -> &mut Self
Hold every stage idle until gate reports readiness.
gate is called once per update tick — instead of
running any SystemStage — for as long as it returns false. As
soon as it returns true, it is dropped and update goes back to
running stages normally, forever after; there is no re-checking, so
gate should only report true once its readiness condition can
never become false again (e.g. inserting a resource that is never
removed).
Only one gate can be active — a second call replaces the first — since
this is meant for a single startup precondition (e.g. an in-flight
async GPU backend init on wasm32, which can’t be waited on by
blocking the only thread the browser gives it), not general
scheduling.
Sourcepub fn add_resource(&mut self, res: impl Component) -> &mut Self
pub fn add_resource(&mut self, res: impl Component) -> &mut Self
Insert a resource into the world immediately.
Sourcepub fn get_resource<'a, T: Component>(&'a self) -> Ref<'a, T>
pub fn get_resource<'a, T: Component>(&'a self) -> Ref<'a, T>
Borrow resource T, panicking if it is absent.
Sourcepub fn get_resource_mut<'a, T: Component>(&'a self) -> RefMut<'a, T>
pub fn get_resource_mut<'a, T: Component>(&'a self) -> RefMut<'a, T>
Mutably borrow resource T, panicking if it is absent.
Sourcepub fn try_insert_resource<T: Component>(&mut self, res: T) -> bool
pub fn try_insert_resource<T: Component>(&mut self, res: T) -> bool
Insert resource T only if it is not already present.
Returns true if the resource was inserted.
Sourcepub fn add_event<T: Component>(&mut self) -> &mut Self
pub fn add_event<T: Component>(&mut self) -> &mut Self
Register event type T, making EventWriter<T>
and EventReader<T> usable as
system parameters.
Sourcepub fn add_async_event<T: Component>(&mut self) -> &mut Self
pub fn add_async_event<T: Component>(&mut self) -> &mut Self
Register event type T as in add_event, and
additionally make AsyncEventWriter<T>
usable as a system parameter.
Sourcepub fn add_system<Marker>(
&mut self,
stage: SystemStage,
system: impl IntoSystem<Marker> + 'static,
) -> &mut Self
pub fn add_system<Marker>( &mut self, stage: SystemStage, system: impl IntoSystem<Marker> + 'static, ) -> &mut Self
Register a single system to run at stage.
Sourcepub fn add_systems<Marker>(
&mut self,
stage: SystemStage,
systems: impl IntoSystemSet<Marker>,
) -> &mut Self
pub fn add_systems<Marker>( &mut self, stage: SystemStage, systems: impl IntoSystemSet<Marker>, ) -> &mut Self
Register multiple systems to run at stage.
Accepts a tuple of systems via IntoSystemSet.
Sourcepub fn build(&mut self) -> &mut Self
pub fn build(&mut self) -> &mut Self
Build all plugins and sort systems.
Plugins may register additional plugins during their build call; this
repeats until no new plugins are added, up to a hard limit of 64 passes
to catch accidental infinite registration cycles.
Sourcepub fn update(&mut self)
pub fn update(&mut self)
Run every stage once per tick, in [ALL_STAGES] order — unless a
ready_gate is still pending, in which case
this tick only checks the gate and returns.
Sourcepub fn set_runner<F>(&mut self, runner: F) -> &mut Self
pub fn set_runner<F>(&mut self, runner: F) -> &mut Self
Replace the default runner with a custom one.
The runner receives ownership of the App and is responsible for
calling update at the appropriate cadence (e.g. driven
by a window event loop).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for App
impl !RefUnwindSafe for App
impl !Send for App
impl !Sync for App
impl !UnwindSafe for App
impl Unpin for App
impl UnsafeUnpin for App
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().