pub struct BehaviorExecutor { /* private fields */ }Expand description
Executor for behavior trees with tick-based execution.
This provides a simple interface for running behavior trees at a fixed rate.
§Example
use mecha10_behavior_runtime::prelude::*;
let mut executor = BehaviorExecutor::new(behavior, 30.0);
let (status, stats) = executor.run_until_complete(&ctx).await?;
println!("Behavior completed with status: {} in {} ticks", status, stats.tick_count);Implementations§
Source§impl BehaviorExecutor
impl BehaviorExecutor
Sourcepub fn new(
behavior: Box<dyn BehaviorNode>,
tick_rate_hz: f32,
) -> BehaviorExecutor
pub fn new( behavior: Box<dyn BehaviorNode>, tick_rate_hz: f32, ) -> BehaviorExecutor
Create a new behavior executor.
§Arguments
behavior- The behavior to executetick_rate_hz- Tick rate in Hz (e.g., 30.0 for 30 Hz)
Sourcepub fn with_max_ticks(self, max_ticks: usize) -> BehaviorExecutor
pub fn with_max_ticks(self, max_ticks: usize) -> BehaviorExecutor
Set the maximum number of ticks before timeout.
Sourcepub async fn run_until_complete(
&mut self,
ctx: &Context,
) -> Result<(NodeStatus, ExecutionStats), Error>
pub async fn run_until_complete( &mut self, ctx: &Context, ) -> Result<(NodeStatus, ExecutionStats), Error>
Run the behavior until it completes (Success or Failure).
This will tick the behavior at the configured rate until it returns a terminal status (Success or Failure).
§Returns
The final status and execution statistics.
Sourcepub async fn run_for_duration(
&mut self,
ctx: &Context,
duration: Duration,
) -> Result<(NodeStatus, ExecutionStats), Error>
pub async fn run_for_duration( &mut self, ctx: &Context, duration: Duration, ) -> Result<(NodeStatus, ExecutionStats), Error>
Run the behavior for a fixed duration.
This will tick the behavior at the configured rate for the specified duration, regardless of whether it completes.
Auto Trait Implementations§
impl Freeze for BehaviorExecutor
impl !RefUnwindSafe for BehaviorExecutor
impl Send for BehaviorExecutor
impl Sync for BehaviorExecutor
impl Unpin for BehaviorExecutor
impl !UnwindSafe for BehaviorExecutor
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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