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: EntityThe 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: EntityThe 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: SnapshotThe 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: EntityThe frame-rate measurement the windowed shell’s readout displays.
Unused by the snapshot tests, which have no display to report a rate on.
frame: u32The 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: EntityThe scene-selector’s switch component, read once per frame.
fullscreen: EntityThe fullscreen button’s request component, read once per frame.
fullscreen_active: EntityThe 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
impl Scene
Sourcepub fn new(
device: Device,
queue: Queue,
capabilities: DeviceCapabilities,
size: (u32, u32),
options: SceneOptions,
def: &'static SceneDef,
panels: PanelRects,
) -> (World, Self)
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.
Sourcepub(crate) fn resize(
&mut self,
target: (u32, u32),
baseline: Option<(u32, u32)>,
)
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.
Sourcepub fn advance(&mut self, world: &mut World, delta_time: f32)
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.
Sourcepub(crate) fn selector_rect(&self, world: &World) -> Option<Rect>
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.
Sourcepub(crate) fn gpu_info_rect(&self, world: &World) -> Option<Rect>
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.
Sourcepub(crate) fn panel_rect(&self, world: &World, id: &str) -> Option<Rect>
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.
Sourcepub(crate) fn fullscreen_request(&mut self, world: &World, active: bool) -> bool
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.
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> 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
impl<T> Component for Twhere
T: 'static,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more