Skip to main content

BehaviorInterpreter

Trait BehaviorInterpreter 

Source
pub trait BehaviorInterpreter {
    // Required method
    fn tick(
        &mut self,
        ctx: &mut BehaviorContext<'_>,
    ) -> Result<BehaviorStatus, BehaviorError>;

    // Provided methods
    fn apply(&mut self, diff: GraphDiff) -> Result<(), BehaviorError> { ... }
    fn load(&mut self, graph: Graph) -> Result<(), BehaviorError> { ... }
}
Expand description

A behavior executor: something the Arora runtime ticks once per step to run an authored behavior.

Implemented by the behavior tree (arora-behavior-tree’s [BehaviorTreeInterpreter]) and by other interpreters such as a Vizij node-graph interpreter. The runtime holds one Box<dyn BehaviorInterpreter> and ticks it without knowing which is which.

Implement this to add a new kind of executor (a new authored-behavior representation the runtime can run), not to hand-code one particular behavior — authored behaviors come from the visual editors, run by an existing interpreter.

Not Send: the runtime is a single-owner, single-thread step loop.

Required Methods§

Source

fn tick( &mut self, ctx: &mut BehaviorContext<'_>, ) -> Result<BehaviorStatus, BehaviorError>

Advance one step. Return BehaviorStatus::Running to be ticked again, or BehaviorStatus::Done to be dropped.

Provided Methods§

Source

fn apply(&mut self, diff: GraphDiff) -> Result<(), BehaviorError>

Edit the running behavior by applying a GraphDiff: add/remove nodes and links, set/override predetermined keys. Loading a behavior is applying a diff onto an empty graph.

The default rejects edition — override it in interpreters that carry an editable graph::Graph (the behavior tree does). A hand-coded, non-graph interpreter (the corner case above) can leave this as-is.

apply validates and stores the edit; an implementation may defer re-lowering its runtime form to the next tick (which carries the store in its context), so a lowering problem can surface there rather than here. This keeps apply callable from anywhere a GraphDiff arrives — notably the interpreter’s engine-registered edit function, which holds no store.

Source

fn load(&mut self, graph: Graph) -> Result<(), BehaviorError>

Replace the running behavior with graph, whole. Like apply it is store-less — an implementation may defer lowering to the next tick — so it is callable from the interpreter’s engine-registered load function. The default rejects loading, for hand-coded interpreters that carry no graph.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§