Struct DecisionState

Source
pub struct DecisionState { /* private fields */ }

Implementations§

Source§

impl DecisionState

Source

pub fn state(&self) -> u16

Source

pub fn elapsed(&self) -> f64

Source

pub fn reset(&mut self, graph: &DecisionGraph)

Source

pub fn explain<'a>( &self, graph: &'a DecisionGraph, flags: u64, dt: f32, ) -> Result<DecisionExplanation<'a>, AiError>

Preview one update without advancing the state or timer. Shares the evaluator with Self::update, including first-match priority, wildcard holds, the elapsed-time cap and discarded transition overshoot. Use dt = 0 to inspect current guards. Work is bounded by the graph’s edge count and does not allocate.

Returns AiError::InvalidState if the current state is outside this graph, then AiError::InvalidInput for a nonfinite delta or one outside 0..=60 seconds. As with update, graphs are interchangeable when the state index fits; no graph identity is tracked.

use ferravex_play::ai::{DecisionEdge, DecisionEdgeOutcome, DecisionGraph};
let graph = DecisionGraph::new(2, 0, &[
    DecisionEdge { from: Some(0), to: 1, all: 1, none: 2, after: 0.5 },
    DecisionEdge { from: None, to: 0, all: 0, none: 0, after: 0. },
]).unwrap();
let mut state = graph.initial();
let waiting = state.explain(&graph, 1, 0.25).unwrap();
assert_eq!(waiting.elapsed(), 0.25);
assert_eq!(waiting.selected_edge(), Some(1)); // Wildcard hold.
assert_eq!(waiting.change(), None);
let edge = waiting.edges().next().unwrap();
assert!(edge.source_matches);
assert_eq!((edge.missing_flags, edge.forbidden_flags), (0, 0));
assert_eq!(edge.remaining_seconds, 0.25);
assert_eq!(edge.outcome, DecisionEdgeOutcome::Rejected);
assert_eq!(state.elapsed(), 0.); // Preview never advances simulation.
let ready = state.explain(&graph, 1, 0.5).unwrap();
assert_eq!(ready.selected_edge(), Some(0));
assert_eq!(ready.edges().next().unwrap().outcome, DecisionEdgeOutcome::Transition);
assert_eq!(ready.edges().nth(1).unwrap().outcome, DecisionEdgeOutcome::Shadowed { by: 0 });
assert_eq!(state.update(&graph, 1, 0.5).unwrap(), ready.change());
assert_eq!(state.elapsed(), 0.); // Transition discards overshoot.
assert_eq!(waiting.edges().nth(1).unwrap().outcome, DecisionEdgeOutcome::Hold);
Source

pub fn update( &mut self, graph: &DecisionGraph, flags: u64, dt: f32, ) -> Result<Option<DecisionChange>, AiError>

At most one transition per call, including dt=0. Timers stop at 3600s; transition overshoot is not applied to the destination state.

Trait Implementations§

Source§

impl Clone for DecisionState

Source§

fn clone(&self) -> DecisionState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DecisionState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DecisionState

Source§

fn eq(&self, other: &DecisionState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for DecisionState

Source§

impl StructuralPartialEq for DecisionState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.