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
impl GraphPlayer
pub fn new( graph: &AnimationGraph, state: usize, ) -> Result<GraphPlayer, AnimationError>
Sourcepub fn reset(&mut self, state: usize) -> Result<(), AnimationError>
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.
pub fn state(&self) -> usize
pub fn animator(&self) -> &Animator
Sourcepub fn animator_mut(&mut self) -> &mut Animator
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.
pub fn set_parameter( &mut self, parameter: usize, value: f32, ) -> Result<(), AnimationError>
pub fn parameter(&self, parameter: usize) -> Option<f32>
Sourcepub fn parameters(&self) -> &[f32]
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);
}Sourcepub fn pending_triggers(&self) -> &[bool]
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.
pub fn trigger(&mut self, parameter: usize) -> Result<(), AnimationError>
pub fn clear_trigger(&mut self, parameter: usize) -> Result<(), AnimationError>
Sourcepub fn transition_eligibility(
&self,
transition: usize,
) -> Option<AnimationTransitionEligibility>
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);Sourcepub fn selected_transition(
&self,
dt: f32,
) -> Result<Option<usize>, AnimationError>
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.
pub fn advance<const N: usize>( &mut self, dt: f32, events: &mut EventBuffer<N>, ) -> Result<(), AnimationError>
Trait Implementations§
Source§impl Clone for GraphPlayer
impl Clone for GraphPlayer
Source§fn clone(&self) -> GraphPlayer
fn clone(&self) -> GraphPlayer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more