Skip to main content

App

Struct App 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_runner( &mut self, runner: impl FnOnce(App) -> Result<(), Box<dyn Error>> + 'static, ) -> &mut Self

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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§

Source§

impl Default for App

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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 T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more