Lane

Trait Lane 

Source
pub trait Lane: Send + Sync {
    // Required methods
    fn strategy_name(&self) -> &'static str;
    fn lane_kind(&self) -> LaneKind;
    fn as_any(&self) -> &dyn Any;
    fn as_any_mut(&mut self) -> &mut dyn Any;

    // Provided methods
    fn estimate_cost(&self, _ctx: &LaneContext) -> f32 { ... }
    fn on_initialize(&self, _ctx: &mut LaneContext) -> Result<(), LaneError> { ... }
    fn execute(&self, _ctx: &mut LaneContext) -> Result<(), LaneError> { ... }
    fn on_shutdown(&self, _ctx: &mut LaneContext) { ... }
}
Expand description

Base trait for ALL lane types in the KhoraEngine.

Every lane — regardless of domain — implements this trait, providing a common interface for identity, classification, lifecycle, and execution. This enables agents to reason about lanes generically during GORNA resource negotiation.

§Lifecycle

on_initialize(ctx)  →  [ execute(ctx) ]*  →  on_shutdown(ctx)
  • on_initialize is called once when the lane is registered with an agent or when the underlying device/context changes.
  • execute is the main entry point, called each frame/tick by the owning agent.
  • on_shutdown is called when the lane is unregistered or the agent shuts down.

§LaneContext

All lifecycle methods receive a LaneContext — a type-map where agents insert domain-specific data and lanes retrieve it by type. This decouples agents from domain-specific lane traits.

Required Methods§

Source

fn strategy_name(&self) -> &'static str

Human-readable name identifying this lane’s strategy.

Used for logging, debugging, and GORNA negotiation. Should be unique within a lane kind (e.g., "LitForward", "StandardPhysics").

Source

fn lane_kind(&self) -> LaneKind

The kind of processing this lane performs.

Used by agents to classify and route lanes to the appropriate execution context.

Source

fn as_any(&self) -> &dyn Any

Downcast to a concrete type for type-specific operations.

Source

fn as_any_mut(&mut self) -> &mut dyn Any

Downcast to a concrete type (mutable) for type-specific operations.

Provided Methods§

Source

fn estimate_cost(&self, _ctx: &LaneContext) -> f32

Estimated computational cost of running this lane.

Used by agents during GORNA resource negotiation to select lanes that fit within their allocated budget. Higher values indicate more expensive strategies.

Default returns 1.0 (medium cost). Override for more accurate estimation. The LaneContext may contain scene data needed for a more precise estimate.

Source

fn on_initialize(&self, _ctx: &mut LaneContext) -> Result<(), LaneError>

Called once when the lane is registered or the underlying context resets.

The LaneContext contains domain-specific resources. For example, render lanes expect an Arc<dyn GraphicsDevice> in the context.

Default is a no-op returning Ok(()).

Source

fn execute(&self, _ctx: &mut LaneContext) -> Result<(), LaneError>

Main execution entry point — called each frame/tick by the owning agent.

The LaneContext carries all the data the lane needs to do its work. Lanes extract typed values using ctx.get::<T>().

Default is a no-op returning Ok(()).

Source

fn on_shutdown(&self, _ctx: &mut LaneContext)

Called when the lane is being destroyed or the context is shutting down.

Default is a no-op.

Implementors§