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, execute startup systems, and validate required resources. - Call
runto hand control to the runner.
Implementations§
Source§impl App
impl App
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 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 provides<T: 'static>(&mut self) -> &mut Self
pub fn provides<T: 'static>(&mut self) -> &mut Self
Declare that resource type T is expected to be inserted later —
possibly asynchronously (a background thread’s result, a hand-rolled
lazy resource) rather than up front. A system elsewhere with a hard
Res<T>/ResMut<T> requirement on T will then wait quietly for it
instead of App treating the absence as a configuration mistake and
panicking.
GraphicsPlugin
and LazyResourcePlugin
already call this for the backend and lazy resource types they
manage — reach for this directly only for your own resource types
that arrive outside of those.
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, run startup systems, and validate required resources.
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 [TICK_STAGES] order. Before every
tick, and again after every stage, reconverge
drains Startup/AssetSync/AssetSyncDeps — so newly-queued asset
or resource work (and any Startup system it unblocks) is handled
immediately rather than waiting for the next tick’s front pass.
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).