Struct GraphPlayer

Source
pub struct GraphPlayer { /* private fields */ }
Expand description

Bounded state graph with deterministic authored transition priority. Examines transitions once before each nonzero, unpaused update; completion conditions become eligible on the next update after reaching the end. At most one edge wins per call, so unconditional graph cycles cannot spin inside one frame.

Implementations§

Source§

impl GraphPlayer

Source

pub fn new( graph: &AnimationGraph, state: usize, ) -> Result<GraphPlayer, AnimationError>

Source

pub fn reset(&mut self, state: usize) -> Result<(), AnimationError>

Restart an authored state for respawn/replay without rebuilding storage. Clears scalar parameters and pending triggers; preserves pause state.

Source

pub fn state(&self) -> usize

Source

pub fn animator(&self) -> &Animator

Source

pub fn animator_mut(&mut self) -> &mut Animator

Pose layers, seek and pause/speed controls are available on the player. Calling play/transition directly overrides presentation until the next graph transition; it does not change the graph’s state index.

Source

pub fn set_parameter( &mut self, parameter: usize, value: f32, ) -> Result<(), AnimationError>

Source

pub fn parameter(&self, parameter: usize) -> Option<f32>

Source

pub fn parameters(&self) -> &[f32]

Scalar values in stable parameter-index order, with exactly AnimationGraph::parameter_count entries. Borrows existing storage; trigger latches are independent and available via Self::pending_triggers.

use ferravex_play::{animation::*, scene::Transform};
let clip = AnimationClip::new(1, 1., LoopMode::Repeat, vec![], vec![])?;
let bank = AnimationBank::new(vec![Transform::default()], vec![clip])?;
let graph = AnimationGraph::new(
    &bank, vec![AnimationState { clip: 0, speed: 1. }], vec![], 2,
)?;
let mut player = GraphPlayer::new(&graph, 0)?;
player.set_parameter(1, 2.)?;
player.trigger(0)?;
assert_eq!(player.parameters(), &[0., 2.]);
assert_eq!(player.pending_triggers(), &[true, false]);
// Inspect both channels using the same stable parameter index.
for (index, (&value, &pending)) in player.parameters().iter()
    .zip(player.pending_triggers()).enumerate()
{
    assert_eq!(player.parameter(index), Some(value));
    assert_eq!(pending, index == 0);
}
Source

pub fn pending_triggers(&self) -> &[bool]

Pending trigger latches in the same stable index order and length as Self::parameters. Inspection never consumes a trigger or allocates. See that method’s example for inspecting both parameter channels.

Source

pub fn trigger(&mut self, parameter: usize) -> Result<(), AnimationError>

Source

pub fn clear_trigger(&mut self, parameter: usize) -> Result<(), AnimationError>

Source

pub fn transition_eligibility( &self, transition: usize, ) -> Option<AnimationTransitionEligibility>

Explain an edge using the current state, animator timeline and parameters, without advancing playback or consuming triggers. transition is a stable index into AnimationGraph::transitions; an invalid index returns None. Condition failure indices refer to that edge’s authored conditions.

This checks eligibility even when paused. It does not predict the timeline after an update: exit/completion checks use the current animator timeline, including any direct overrides through Self::animator_mut. Use Self::selected_transition to account for pause, delta and edge priority.

use ferravex_play::{animation::*, scene::Transform};
let clip = AnimationClip::new(1, 1., LoopMode::Clamp, vec![], vec![])?;
let bank = AnimationBank::new(vec![Transform::default()], vec![clip])?;
let graph = AnimationGraph::new(
    &bank,
    vec![AnimationState { clip: 0, speed: 1. }; 2],
    vec![AnimationTransition {
        from: 0, to: 1, seconds: 0., exit_time: 0.,
        conditions: vec![AnimationCondition::Trigger(0)],
    }],
    1,
)?;
let mut player = GraphPlayer::new(&graph, 0)?;
assert_eq!(player.transition_eligibility(0),
    Some(AnimationTransitionEligibility::ConditionNotMet { condition: 0 }));
player.trigger(0)?;
assert_eq!(player.transition_eligibility(0),
    Some(AnimationTransitionEligibility::Eligible));
assert_eq!(player.selected_transition(0.)?, None);
assert_eq!(player.selected_transition(0.125)?, Some(0));
assert_eq!(player.pending_triggers(), &[true]); // still latched
player.advance(0.125, &mut EventBuffer::<0>::default())?;
assert_eq!(player.state(), 1);
assert_eq!(player.pending_triggers(), &[false]);
assert_eq!(player.transition_eligibility(usize::MAX), None);
Source

pub fn selected_transition( &self, dt: f32, ) -> Result<Option<usize>, AnimationError>

Return the authored index of the edge that the next Self::advance with this dt would select, without changing any state or emitting events. See Self::transition_eligibility for a usage example.

Uses the same time validation as advance: non-finite, negative or greater-than-super::MAX_ANIMATION_DT input returns AnimationError::InvalidTime, even while paused. Zero delta or pause returns Ok(None); otherwise the first eligible edge wins. Zero playback speed does not prevent selection, matching advance. No future time is simulated, so reaching an exit/completion threshold during this update only makes the edge eligible for the following update.

Work is bounded by the authored transitions and conditions and does not allocate. This is a current-state query, not a reservation: subsequent player changes may alter the selected edge.

Source

pub fn advance<const N: usize>( &mut self, dt: f32, events: &mut EventBuffer<N>, ) -> Result<(), AnimationError>

Trait Implementations§

Source§

impl Clone for GraphPlayer

Source§

fn clone(&self) -> GraphPlayer

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 GraphPlayer

Source§

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

Formats the value using the given formatter. Read more

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.