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: SceneMutable gameplay world and environment.
physics: PhysicsRapier simulation and ray queries, updated at the fixed cadence.
scripts: ScriptRuntimeScript instances and hot-reload host.
input: InputInput snapshot supplied by the hosting shell before each tick.
time: TimeScaled 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
impl Runtime
Sourcepub fn set_bindings<S: AsRef<str>>(&mut self, defs: &[(String, Vec<S>)])
pub fn set_bindings<S: AsRef<str>>(&mut self, defs: &[(String, Vec<S>)])
Applies the project’s input bindings (call right after new).
Sourcepub fn new(scene: Scene, host: Option<ScriptHost>) -> Self
pub fn new(scene: Scene, host: Option<ScriptHost>) -> Self
Creates a 60 Hz runtime, initializing world transforms before the first tick.
Sourcepub fn with_config(
scene: Scene,
host: Option<ScriptHost>,
config: RuntimeConfig,
) -> Result<Self, String>
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.
Sourcepub fn config(&self) -> &RuntimeConfig
pub fn config(&self) -> &RuntimeConfig
Active timing configuration. Construct a new runtime to change the fixed cadence.
Sourcepub fn set_paused(&mut self, paused: bool)
pub fn set_paused(&mut self, paused: bool)
Suspends or resumes ticks. Existing fractional fixed time is preserved.
Sourcepub fn time_scale(&self) -> f32
pub fn time_scale(&self) -> f32
Current simulation speed multiplier.
Sourcepub fn set_time_scale(&mut self, scale: f32) -> Result<(), String>
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.
Sourcepub fn frame_stats(&self) -> FrameStats
pub fn frame_stats(&self) -> FrameStats
Timing diagnostics from the most recent tick (zeroed on a skipped tick).
Sourcepub fn step_once(&mut self)
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§impl Runtime
impl Runtime
Sourcepub fn apply_scene_request(
&mut self,
reg: &Registry,
read: impl Fn(&str) -> Result<String, String>,
) -> Option<Result<String, String>>
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).
Sourcepub fn replace_scene(&mut self, scene: Scene)
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§
Auto Trait Implementations§
impl !Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl !UnwindSafe for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
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<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>, which can then be
downcast into Box<dyn 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>, which 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.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§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.