Skip to main content

Scene

Struct Scene 

Source
pub struct Scene {
    pub renderer: Entity,
    pub(crate) size: (u32, u32),
    pub viewport: Option<ViewportRect>,
    pub pass: Entity,
    pub snapshot: Snapshot,
    pub(crate) frame_rate: Entity,
    pub(crate) frame: u32,
    pub(crate) switch: Entity,
    pub(crate) fullscreen: Entity,
    pub(crate) fullscreen_active: Entity,
    pub(crate) pending: Option<&'static SceneDef>,
}
Expand description

The scene’s world and the frame loop that drives it.

Deliberately knows nothing about how a frame reaches a display: it advances the scene’s behaviour and renders into whatever target is bound, so the windowed run and the snapshot tests differ only in what they bind and what with the result. The scene itself is a scenes::SceneDef whose build populated the world and returned the SceneControl this drives.

Public because the snapshot tests drive the same scenes offscreen: the web renders them and compares each frame against its snapshot, which is the comparison they make.

The world is not owned here: a scene is the driving state of a world the caller owns, and every frame method takes that world back as &mut World. A windowed run stores the world as a component of its host world and pulls it out per frame; the snapshot tests keep a local one. Either way one world has exactly one scene driving it, and the scene never reaches across to another.

Fields§

§renderer: Entity

The renderer resource entity: the handle every renderer access goes through.

§size: (u32, u32)

The size the scene’s content is drawn at, in pixels: the target’s own, or the letterboxed part of it when Self::viewport is set.

This is what the scene’s camera is built for and what its behaviour is handed, so the projection matches what the viewport scales into place.

§viewport: Option<ViewportRect>

The region of the target the 3D content is drawn into, or None to draw into the whole of it.

Set when the scene declares an aspect of its own — see scenes::SceneDef::baseline — so a target of any shape shows the same picture at a different scale rather than showing more of it.

§pass: Entity

The frame pass the scene’s own sources record into.

Everything a scene builds hangs under it, which is what puts the scene in the frame: a pass records the sources in its own scope, so the pass a source’s entity sits under is the pass its scene is drawn in.

§snapshot: Snapshot

The snapshot the scene’s test compares each frame against, if any.

The scene’s per-frame behaviour is not here: it was moved into the scene’s own world as a frame behaviour at build time, so a frame advances it without &mut Scene.

§frame_rate: Entity

The frame-rate measurement the windowed shell’s readout displays.

Unused by the snapshot tests, which have no display to report a rate on.

§frame: u32

The index of the next frame the scene’s behaviour advances from.

Carried across calls because Self::advance hands it to the frame behaviours through the frame’s context, and a fixed sequence may skip a frame without advancing it.

§switch: Entity

The scene-selector’s switch component, read once per frame.

§fullscreen: Entity

The fullscreen button’s request component, read once per frame.

§fullscreen_active: Entity

The window’s fullscreen state, written once per frame for the button to label itself from: a panel runs with no window to ask.

§pending: Option<&'static SceneDef>

A scene switch requested by the selector, consumed by the frame loop.

Implementations§

Source§

impl Scene

Source

pub fn new( device: Device, queue: Queue, capabilities: DeviceCapabilities, size: (u32, u32), options: SceneOptions, def: &'static SceneDef, panels: PanelRects, ) -> (World, Self)

Build the scene def into a fresh world.

Sync, and on the main thread: the ECS world is single-threaded, so it lives on the thread the event loop runs on. The world starts with the frame’s GPU context and the renderer resource entity; the scene’s build adds its sources, meshes, camera and entities, and returns the SceneControl that drives them.

Source

pub(crate) fn resize( &mut self, target: (u32, u32), baseline: Option<(u32, u32)>, )

Re-state the target’s size, re-letterboxing the content for its shape.

Called on every resize and on the first frame that knows the window’s size, so the projection and the size the scene’s behaviour is handed follow the target together. The region is the scene’s own state here and reaches the pass that draws it from restate_viewport, which is the one place holding both that pass and this scene.

Source

pub fn advance(&mut self, world: &mut World, delta_time: f32)

Advance the scene by delta_time seconds.

A frame is the dispatch of the scene world’s OnFrame behaviours. The input and the index state no order; the scene’s own behaviour states one after the index, since it advances by the frame the index names. The index and the content size travel in the frame’s context, so a behaviour reads them without a component of its own.

Source

pub(crate) fn selector_rect(&self, world: &World) -> Option<Rect>

The selector window’s rectangle the last time it was laid out, or None before it has been shown once.

The window’s rectangle is remembered by egui, in this scene’s context; the shell reads it from here so a scene switch — which rebuilds that context — can rebuild the window in the same place and at the same size.

Source

pub(crate) fn gpu_info_rect(&self, world: &World) -> Option<Rect>

The GPU-info panel’s rectangle the last time it was laid out, or None before it has been shown once.

Carried across a scene switch exactly like Self::selector_rect: the panel is a window the user may drag, and the switch rebuilds the context that remembers where it was left.

Source

pub(crate) fn panel_rect(&self, world: &World, id: &str) -> Option<Rect>

The rectangle egui remembers for the window with id.

Several sources share the world; only the UI one holds egui’s window memory, so skip every other source’s entity.

Source

pub(crate) fn fullscreen_request(&mut self, world: &World, active: bool) -> bool

Record whether the window is fullscreen and report whether the button asked for a change, clearing the request.

Both are read and written once per frame by the windowed loop, which is what owns the window; the scene keeps no opinion of its own about fullscreen.

Source

pub fn render(&mut self, world: &World)

Render one frame into whatever target the caller bound.

Only the snapshot tests draw through this: the windowed run acquires the swap chain’s image and renders between the acquire and the present, so it needs both under one borrow.

Source

pub fn end_frame(&mut self, world: &mut World) -> Result<(), EntityAccessError>

Finish the frame: apply whatever a behaviour component or panel queued.

Nothing is cleared: every consumer reads the events from its own subscription, and the dispatch that reads them takes them.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scene

§

impl !Send for Scene

§

impl !Sync for Scene

§

impl !UnwindSafe for Scene

§

impl Forget for Scene

§

impl Freeze for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

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
§

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

§

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

Source§

impl<T> Component for T
where T: 'static,

§

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

§

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.
§

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.
§

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.
§

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.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

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

§

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

§

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

§

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

§

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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