pub struct App {
pub world: World,
pub startup: Schedule<World>,
pub stages: Stages<World>,
/* private fields */
}Expand description
The plugin-composed application: the world, a startup schedule that
runs once, and per-frame Stages that plugins push systems into.
The stages run in Stage declaration order each frame. The game
stages (Stage::First, Stage::Update, Stage::LateUpdate) run
first, then the engine’s own per-frame stages (Stage::FrameStart
through Stage::Last: physics, animation, transforms, retained UI,
render sync), exactly where the frame schedule ran historically. Game
logic belongs in Stage::Update; Stage::LateUpdate is for
systems that must observe every update system’s writes.
Fields§
§world: World§startup: Schedule<World>§stages: Stages<World>Implementations§
Source§impl App
impl App
pub fn new() -> Self
Sourcepub fn add_plugin<P: Plugin + 'static>(self, plugin: P) -> Self
pub fn add_plugin<P: Plugin + 'static>(self, plugin: P) -> Self
Adds a plugin. Panics if a plugin of the same type was already added, since building twice would double every system and hook the plugin registers.
Sourcepub fn add_plugin_if_absent<P: Plugin + 'static>(&mut self, plugin: P)
pub fn add_plugin_if_absent<P: Plugin + 'static>(&mut self, plugin: P)
Adds a plugin from inside another plugin’s build, and
only if a plugin of that type is not already present. A capability
plugin uses this to pull in a plugin it depends on: the window,
renderer, and worker hosts all require the engine’s default frame
systems, so each composes CorePlugin
this way. Because more than one may ask, the add is idempotent rather
than the once-per-type panic of add_plugin.
Sourcepub fn add_plugins(self, group: impl PluginGroup) -> Self
pub fn add_plugins(self, group: impl PluginGroup) -> Self
Adds a PluginGroup’s members in group order, skipping disabled
ones. Members count toward the same once-per-type rule as
add_plugin.
Sourcepub fn add_system<Marker>(
&mut self,
stage: Stage,
systems: impl SystemCollection<Marker>,
) -> &mut Self
pub fn add_system<Marker>( &mut self, stage: Stage, systems: impl SystemCollection<Marker>, ) -> &mut Self
Registers systems onto a Stage, in registration order. The one
registration method: it takes a plain fn(&mut World) system, a
state-and-world fn(&mut T, &mut World) game system (game_scope
applied at registration, state type inferred from the function, the
state inserted with App::insert_resource), or a tuple mixing
both. Stage::Startup routes to the startup schedule, which runs
once. Gate a system on an app state by wrapping it in
while_in.
Sourcepub fn add_systems<Marker>(
&mut self,
stage: Stage,
systems: impl SystemCollection<Marker>,
) -> &mut Self
pub fn add_systems<Marker>( &mut self, stage: Stage, systems: impl SystemCollection<Marker>, ) -> &mut Self
Registers a tuple of systems onto a Stage in one call, in tuple
order, so app.add_systems(Stage::Update, (input, movement, render))
stands in for one add_system per system. Each
tuple member is any shape add_system accepts, and
the members may mix shapes freely.
Sourcepub fn remove_frame_system<F>(&mut self, system: F) -> bool
pub fn remove_frame_system<F>(&mut self, system: F) -> bool
Removes an engine frame system by passing the same function value it was registered with, returning whether anything was removed. Drops one of the default frame systems (the input reset, say) that a custom runner would rather drive itself.
Sourcepub fn insert_resource<T: Send + Sync + 'static>(
&mut self,
value: T,
) -> &mut Self
pub fn insert_resource<T: Send + Sync + 'static>( &mut self, value: T, ) -> &mut Self
Inserts a group-level resource, readable from any system through
game_scope or world.ecs.resource/resource_mut.
Sourcepub fn add_render_graph_config(
&mut self,
hook: impl FnMut(&mut RenderGraph<RenderInputs>, &Device, TextureFormat, RenderResources) + 'static,
) -> &mut Self
pub fn add_render_graph_config( &mut self, hook: impl FnMut(&mut RenderGraph<RenderInputs>, &Device, TextureFormat, RenderResources) + 'static, ) -> &mut Self
Adds a render graph configuration hook, called once when the renderer is created. Hooks from every plugin run in the order they were added.
Sourcepub fn on_pre_render(
&mut self,
hook: impl FnMut(&mut WgpuRenderer, &mut World) + 'static,
) -> &mut Self
pub fn on_pre_render( &mut self, hook: impl FnMut(&mut WgpuRenderer, &mut World) + 'static, ) -> &mut Self
Adds a pre-render hook, called each frame before the render graph executes. Hooks from every plugin run in the order they were added.
Sourcepub fn on_update_render_graph(
&mut self,
hook: impl FnMut(&mut RenderGraph<RenderInputs>, &World) + 'static,
) -> &mut Self
pub fn on_update_render_graph( &mut self, hook: impl FnMut(&mut RenderGraph<RenderInputs>, &World) + 'static, ) -> &mut Self
Adds a per-frame render graph update hook. Hooks from every plugin run in the order they were added.
Sourcepub fn set_runner_if_unset(
&mut self,
runner: impl FnOnce(App) -> Result<(), Box<dyn Error>> + 'static,
)
pub fn set_runner_if_unset( &mut self, runner: impl FnOnce(App) -> Result<(), Box<dyn Error>> + 'static, )
Hands the whole app to a custom runner in place of the built-in
loops: the runner owns the world, the schedules, the render hooks
(through App::into_parts), and the log guards, and drives them
however its host requires. This is how a plugin claims the main
loop itself, the way WorkerHostPlugin hosts the engine inside a
web worker.
Installs runner only if no runner has been set yet. Capability
plugins that own the main loop (window, renderer) use this so the
first one composed wins and an explicit set_runner
still overrides them.
pub fn set_runner( &mut self, runner: impl FnOnce(App) -> Result<(), Box<dyn Error>> + 'static, ) -> &mut Self
Sourcepub fn run(self) -> Result<(), Box<dyn Error>>
pub fn run(self) -> Result<(), Box<dyn Error>>
Runs the app. A runner installed with App::set_runner takes the
whole app and owns the loop. Otherwise, with neither
[WindowPlugin] nor [RenderPlugin],
the startup schedule and one pass of the stages run against the
world and the program returns: the do-nothing composition. With
either, the winit event
loop drives the startup schedule once and then the stages every
frame; without [WindowPlugin] the window stays hidden, and
without [RenderPlugin] no renderer is created.
Sourcepub fn take_log_guards(&mut self) -> Vec<Box<dyn Any>>
pub fn take_log_guards(&mut self) -> Vec<Box<dyn Any>>
Takes the log appender guards out of the app. A custom runner calls
this before App::into_parts and keeps the guards alive for the
life of the program so buffered log lines flush.
Sourcepub fn into_parts(self) -> (World, impl State + 'static)
pub fn into_parts(self) -> (World, impl State + 'static)
Splits the composed app into its world and a State that drives
the startup schedule at initialize and the stages every frame, for
custom runners like offscreen workers that own their own loop.
Source§impl App
impl App
Sourcepub fn insert_state<S: Copy + PartialEq + Send + Sync + 'static>(
&mut self,
initial: S,
) -> &mut Self
pub fn insert_state<S: Copy + PartialEq + Send + Sync + 'static>( &mut self, initial: S, ) -> &mut Self
Inserts the State and
NextState resources for S at initial
and registers the transition-apply step onto Stage::First, so a
transition requested during a frame lands at the start of the next and
no frame observes a mid-frame flip. Enter hooks for initial run on the
first frame. Panics if a state of type S was already inserted.
Sourcepub fn on_enter<S: Copy + PartialEq + Send + Sync + 'static, Marker>(
&mut self,
state: S,
systems: impl IntoGroupRunner<World, Marker>,
) -> &mut Self
pub fn on_enter<S: Copy + PartialEq + Send + Sync + 'static, Marker>( &mut self, state: S, systems: impl IntoGroupRunner<World, Marker>, ) -> &mut Self
Runs systems once each time S enters state, after the transition
step, reading the emitted
StateTransition through its own
cursor so each entry fires exactly once. Takes a single system or a
tuple. Requires insert_state first.
Sourcepub fn on_exit<S: Copy + PartialEq + Send + Sync + 'static, Marker>(
&mut self,
state: S,
systems: impl IntoGroupRunner<World, Marker>,
) -> &mut Self
pub fn on_exit<S: Copy + PartialEq + Send + Sync + 'static, Marker>( &mut self, state: S, systems: impl IntoGroupRunner<World, Marker>, ) -> &mut Self
Runs systems once each time S leaves state, after the transition
step. Takes a single system or a tuple. Requires
insert_state first.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for App
impl !Send for App
impl !Sync for App
impl !UnwindSafe for App
impl Freeze 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.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>, which can then be
downcast into Box<dyn 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>, which 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> 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<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.