Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime {
    pub scene: Scene,
    pub physics: Physics,
    pub scripts: ScriptRuntime,
    pub input: Input,
    pub time: Time,
    pub log: Vec<String>,
    /* private fields */
}
Expand description

Owned gameplay state shared by editor Play mode and the standalone player. Dropping the runtime destroys script instances before unloading their library.

Fields§

§scene: Scene

Mutable gameplay world and environment.

§physics: Physics

Rapier simulation and ray queries, updated at the fixed cadence.

§scripts: ScriptRuntime

Script instances and hot-reload host.

§input: Input

Input snapshot supplied by the hosting shell before each tick.

§time: Time

Scaled simulation time visible to scripts.

§log: Vec<String>

Script messages and runtime diagnostics. The host may drain these at any time.

Implementations§

Source§

impl Runtime

Source

pub fn set_bindings<S: AsRef<str>>(&mut self, defs: &[(String, Vec<S>)])

Applies the project’s input bindings (call right after new).

Source

pub fn new(scene: Scene, host: Option<ScriptHost>) -> Self

Creates a 60 Hz runtime, initializing world transforms before the first tick.

Source

pub fn with_config( scene: Scene, host: Option<ScriptHost>, config: RuntimeConfig, ) -> Result<Self, String>

Creates a runtime with a validated timing policy. Returns an error for non-finite/non-positive intervals or a zero step limit.

Source

pub fn config(&self) -> &RuntimeConfig

Active timing configuration. Construct a new runtime to change the fixed cadence.

Source

pub fn is_paused(&self) -> bool

Whether regular ticks are suspended.

Source

pub fn set_paused(&mut self, paused: bool)

Suspends or resumes ticks. Existing fractional fixed time is preserved.

Source

pub fn time_scale(&self) -> f32

Current simulation speed multiplier.

Source

pub fn set_time_scale(&mut self, scale: f32) -> Result<(), String>

Sets speed in [0, 100]; rejects invalid values without changing state. Zero freezes simulation time like pause. Wall-frame clamping occurs before scaling.

Source

pub fn frame_stats(&self) -> FrameStats

Timing diagnostics from the most recent tick (zeroed on a skipped tick).

Source

pub fn step_once(&mut self)

Advances one fixed-size simulation frame even when paused or time scale is zero. Useful for editor single-step controls. It does not consume shell input.

Source

pub fn drain_log(&mut self) -> Drain<'_, String> ⓘ

Drains pending script/runtime log messages, preserving their order.

Source

pub fn tick(&mut self, dt: f32)

Advances a wall-clock frame. Negative/non-finite intervals and paused frames are skipped. Large intervals are clamped before applying time scale.

Source§

impl Runtime

Source

pub fn apply_scene_request( &mut self, reg: &Registry, read: impl Fn(&str) -> Result<String, String>, ) -> Option<Result<String, String>>

Applies a scene change a script asked for during the last tick: read returns the text of a scene asset. Returns None when nothing was asked, else the outcome (the running scene stays as it was on error).

Source

pub fn replace_scene(&mut self, scene: Scene)

Swaps the running scene for another: script instances and the physics world start over, time, input bindings and the cursor state carry on.

Trait Implementations§

Source§

impl Drop for Runtime

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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<T> Downcast for T
where T: Any,

§

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

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

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

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, 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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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.