pub trait RuntimePlugin: Send + 'static {
// Required methods
fn priority(&self) -> i32;
fn step(&mut self, ctx: &mut RuntimeStepContext<'_>);
// Provided methods
fn submit(&mut self, _ctx: &RuntimeStepContext<'_>) { ... }
fn collect(&mut self, _ctx: &mut RuntimeStepContext<'_>) { ... }
fn on_event(
&mut self,
_event: &RuntimeEvent,
_ctx: &mut RuntimeStepContext<'_>,
) { ... }
}Expand description
A plugin that executes during the scene step.
Register plugins with super::ViewportRuntime::with_plugin. Each frame
the runtime calls submit, then step (once or more for simulate phases),
then collect.
§Example
use viewport_lib::runtime::{RuntimePlugin, RuntimeStepContext};
use viewport_lib::runtime::plugin::phase;
struct GravityPlugin {
gravity: glam::Vec3,
}
impl RuntimePlugin for GravityPlugin {
fn priority(&self) -> i32 {
phase::SIMULATE
}
fn step(&mut self, ctx: &mut RuntimeStepContext) {
// Apply gravity to tracked bodies via ctx.writeback.set(id, new_transform).
}
}Required Methods§
Sourcefn priority(&self) -> i32
fn priority(&self) -> i32
Numeric execution priority. Lower values run first. Use the constants
in phase as base values and offset within a band if needed.
Sourcefn step(&mut self, ctx: &mut RuntimeStepContext<'_>)
fn step(&mut self, ctx: &mut RuntimeStepContext<'_>)
Called once per phase execution.
For plugins in the [SIMULATE, POST_SIM) range with a fixed timestep,
ctx.dt is the fixed step size and this is called once per step. For
all other priorities, ctx.dt is the wall-clock frame delta and this
is called once per frame.
Provided Methods§
Sourcefn submit(&mut self, _ctx: &RuntimeStepContext<'_>)
fn submit(&mut self, _ctx: &RuntimeStepContext<'_>)
Called once per frame before the step loop, in priority order.
Use this to kick off background work (e.g. async physics) that will
be read in collect on the next frame.
Sourcefn collect(&mut self, _ctx: &mut RuntimeStepContext<'_>)
fn collect(&mut self, _ctx: &mut RuntimeStepContext<'_>)
Called once per frame after the step loop, in priority order.
Use this to read results from background work started in submit.
Sourcefn on_event(&mut self, _event: &RuntimeEvent, _ctx: &mut RuntimeStepContext<'_>)
fn on_event(&mut self, _event: &RuntimeEvent, _ctx: &mut RuntimeStepContext<'_>)
Called for each lifecycle event before the step loop.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".