Skip to main content

Module runtime

Module runtime 

Source
Expand description

Scene runtime: per-frame orchestration, plugin system, and physics hooks. Scene runtime: per-frame orchestration layer between Scene and ViewportRenderer.

ViewportRuntime runs registered plugins in a defined priority order each frame, drives a fixed timestep accumulator for physics, and flushes accumulated transform writes back to the scene. It does not own the scene, selection, or GPU resources.

§Usage

use viewport_lib::runtime::{
    FixedTimestep, RuntimeFrameContext, RuntimePhase, RuntimePlugin,
    RuntimeStepContext, SceneRuntimeMode, ViewportRuntime,
};

// Build the runtime once at startup.
let mut runtime = ViewportRuntime::new()
    .with_mode(SceneRuntimeMode::Simulation)
    .with_fixed_timestep(FixedTimestep::new(60.0))
    .with_plugin(MyPhysicsPlugin::new());

// Each frame:
let mut frame_ctx = RuntimeFrameContext::default();
frame_ctx.dt = wall_dt;
frame_ctx.camera = camera.clone();
frame_ctx.viewport_size = glam::Vec2::new(width, height);
frame_ctx.input = action_frame.clone();
let output = runtime.step(&mut scene, &mut selection, &frame_ctx);

// Handle contact events in game logic:
for event in output.events.read::<viewport_lib::plugins::physics_lite::ContactEvent>() { /* ... */ }

// Render with interpolated transforms between fixed steps:
let alpha = runtime.alpha();
if let Some(t) = runtime.snapshots().interpolated(node_id, alpha) {
    // use t instead of the node's scene transform
}

Existing prepare / paint_to call sites need no changes. ViewportRuntime is purely additive and does not affect ViewportRenderer.

Re-exports§

pub use camera_follow::CameraFollow;
pub use context::RuntimeFrameContext;
pub use context::RuntimeStepContext;
pub use context::SimulationStepContext;
pub use debug_draw::DebugDraw;
pub use debug_draw::DebugLayer;
pub use debug_draw::DebugPrim;
pub use events::RuntimeEventBus;
pub use gpu_plugin::GpuFrameContext;
pub use gpu_plugin::GpuPlugin;
pub use gpu_plugin::PostPaintTargets;
pub use gpu_plugin::gpu_phase;
pub use jobs::JobPoll;
pub use jobs::JobSender;
pub use jobs::JobSlot;
pub use mode::SceneRuntimeMode;
pub use output::CameraCommand;
pub use output::CameraFollowTarget;
pub use output::NodeTransformOp;
pub use output::RuntimeOutput;
pub use output::SelectionOp;
pub use output::TransformWriteback;
pub use output::apply_camera_commands;
pub use plugin::RuntimeEvent;
pub use plugin::RuntimePhase;
pub use plugin::RuntimePlugin;
pub use plugin::phase;
pub use resources::RuntimeResources;
pub use snapshot::TransformSnapshot;
pub use snapshot::TransformSnapshotTable;
pub use systems::ManipulationSystem;
pub use systems::SelectionSystem;
pub use timestep::FixedStepIter;
pub use timestep::FixedTimestep;

Modules§

camera_follow
Camera tracking binding for follow-camera behavior.
context
Per-frame and per-step context types for runtime plugins.
debug_draw
Debug draw accumulator for runtime plugins. Debug draw accumulator for runtime plugins.
events
Generic typed event bus for runtime plugin communication.
gpu_plugin
GPU plugin trait and lifecycle hooks. GPU plugin trait and lifecycle hooks for runtime extensions.
guide
Plugin authoring guide. Plugin authoring guide.
jobs
Async job handoff types for runtime plugins. Async job handoff types for runtime plugins.
mode
Runtime mode enum for super::ViewportRuntime.
output
Runtime output types: transform ops, selection ops, contact events, and generic events.
plugin
Runtime plugin trait and phase ordering.
resources
Built-in animation, constraint, and physics plugins. Typed resource registry for sharing engine-owned state across runtime plugins.
snapshot
Transform snapshot table for smooth physics-driven rendering.
systems
Built-in interaction systems: SelectionSystem and ManipulationSystem.
timestep
Fixed timestep accumulator for physics and simulation.

Structs§

RuntimeStats
Per-plugin timing for one runtime cycle, in milliseconds.
ViewportRuntime
Per-frame scene orchestration layer.