pub struct DecisionState { /* private fields */ }Implementations§
Source§impl DecisionState
impl DecisionState
pub fn state(&self) -> u16
pub fn elapsed(&self) -> f64
pub fn reset(&mut self, graph: &DecisionGraph)
Sourcepub fn explain<'a>(
&self,
graph: &'a DecisionGraph,
flags: u64,
dt: f32,
) -> Result<DecisionExplanation<'a>, AiError>
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);Sourcepub fn update(
&mut self,
graph: &DecisionGraph,
flags: u64,
dt: f32,
) -> Result<Option<DecisionChange>, AiError>
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
impl Clone for DecisionState
Source§fn clone(&self) -> DecisionState
fn clone(&self) -> DecisionState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DecisionState
impl Debug for DecisionState
Source§impl PartialEq for DecisionState
impl PartialEq for DecisionState
impl Copy for DecisionState
impl StructuralPartialEq for DecisionState
Auto Trait Implementations§
impl Freeze for DecisionState
impl RefUnwindSafe for DecisionState
impl Send for DecisionState
impl Sync for DecisionState
impl Unpin for DecisionState
impl UnwindSafe for DecisionState
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