Skip to main content

App

Struct App 

Source
pub struct App {
    pub world: World,
    pub render_world: World,
    pub extract_fns: Vec<ExtractFn>,
    pub desired_threads: usize,
    pub installed_plugins: HashMap<&'static str, Box<dyn PluginMetadata>>,
    /* private fields */
}
Expand description

Lumen application holding the main world, render world, their schedules, and the extract-fn list.

Fields§

§world: World

Main world carrying app/UI state, layout, and scripts.

§render_world: World

Render world carrying per-frame extracted draw data and GPU resources.

§extract_fns: Vec<ExtractFn>

Extract fns invoked in registration order each tick, after the main schedule and before the render schedule. App::new seeds the list with the built-in extractors and App::add_extract_fn appends to it. The list is public so a plugin can also replace or reorder an entry; nothing in the workspace does that today.

§desired_threads: usize

Worker-thread budget for the bevy_ecs multithreaded executor.

  • Defaults to LUMEN_DEFAULT_THREADS (4).
  • Plugins raise it monotonically via Self::request_threads_at_least.
  • The LUMEN_THREADS environment variable overrides any plugin request.
  • Read at the first Self::tick; the task pool is initialised once via ComputeTaskPool::get_or_init and subsequent updates have no effect.
§installed_plugins: HashMap<&'static str, Box<dyn PluginMetadata>>

Plugin name -> metadata. Populated by Self::add_plugin in installation order.

Implementations§

Source§

impl App

Source

pub fn new() -> Self

Constructs a fresh app with both worlds, both schedules, the command queue, and the default extract fns.

Source

pub fn add_message<M: Message>(&mut self) -> &mut Self

Registers a message type with [MessageRegistry] so bevy_ecs::message::MessageWriter and bevy_ecs::message::MessageReader can be used for M.

Source

pub fn add_plugin<P: Plugin + 'static>(&mut self, plugin: P) -> &mut Self

Calls plugin.build(self), consuming the plugin.

Records the plugin’s metadata in Self::installed_plugins so Self::is_plugin_added and other queries can answer without re-running the build closure. Logs (but does not panic) when a declared depends_on entry has not been installed yet - wave 1 wires the topological sort that would defer the build instead.

Source

pub fn is_plugin_added<P: Plugin + 'static>(&self) -> bool

Returns true when a plugin of type P has been installed via Self::add_plugin.

Source

pub fn plugin_added(&self, name: &str) -> bool

Returns true when a plugin with the supplied Plugin::name has been installed.

Source

pub fn register_command<T, F>(&mut self, handler: F) -> &mut Self
where T: Any + Send, F: Fn(&mut World, Box<T>) + Send + Sync + 'static,

Registers a strongly-typed handler invoked when a Command::Typed payload of type T is drained.

Replaces the legacy blind Command::Custom(Box<dyn Any>) downcast pattern: producers build Command::Typed { type_id: TypeId::of::<T>(), payload: Box::new(value) }, the drain looks up the handler by type id and invokes it with the typed payload.

Source

pub fn add_systems<M>( &mut self, stage: TickStage, systems: impl IntoScheduleConfigs<ScheduleSystem, M>, ) -> &mut Self

Adds main-world systems into the Tick schedule under the given TickStage set.

Source

pub fn add_render_systems<M>( &mut self, stage: RenderStage, systems: impl IntoScheduleConfigs<ScheduleSystem, M>, ) -> &mut Self

Adds render-world systems into the Render schedule under the given RenderStage set.

Source

pub fn add_extract_systems<M>( &mut self, set: ExtractSet, systems: impl IntoScheduleConfigs<ScheduleSystem, M>, ) -> &mut Self

Adds render-world systems into the dedicated ExtractSchedule under the given ExtractSet.

Foundation only installs the schedule; the legacy Self::extract_fns list keeps providing cross-world data. Wave 2 migrates the existing extractors onto this schedule.

Source

pub fn add_extract_fn(&mut self, f: ExtractFn) -> &mut Self

Appends an extract fn to Self::extract_fns.

Source

pub fn request_threads_at_least(&mut self, n: usize) -> &mut Self

Raises Self::desired_threads to n if it is currently lower (monotonic max across plugins). Takes effect at the first Self::tick; the LUMEN_THREADS env var overrides the value.

Source

pub fn tick(&mut self)

Runs one tick: advance the crate::tick::Tick resource, run the main schedule, then (when FrameDirty is set) clear_extracted, every extract fn, the extract schedule, and the render schedule. When FrameDirty is unset, returns after the main schedule; the previous frame’s extracted entities remain in the render world for the backend’s next RedrawRequested.

Source

pub fn commands(&mut self) -> Mut<'_, CommandReceiver>

Borrows the CommandReceiver resource mutably from the main world.

Source

pub fn property<T>(&self, name: impl Into<Arc<str>>) -> Property<T>

Constructs a typed crate::property_store::Property handle bound to the global namespace. The cell is created lazily on the first set - this helper only mints the typed key wrapper, no allocations besides the shared Arc<str> for the name.

Equivalent to Property::<T>::new(name); lives on App so app-init code can read more like let count = app.property::<i64>("count"); without a separate use for the prelude.

Trait Implementations§

Source§

impl Default for App

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !Freeze for App

§

impl !RefUnwindSafe for App

§

impl Send for App

§

impl Sync for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

§

impl !UnwindSafe 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_world(_world: &mut World) -> T

Creates Self using default().

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.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
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.
§

impl<T> ConditionalSend for T
where T: Send,