pub struct ActionTimeline { /* private fields */ }Implementations§
Source§impl ActionTimeline
impl ActionTimeline
pub fn new(spec: ActionSpec) -> Result<ActionTimeline, ActionError>
pub fn phase(&self) -> ActionPhase
pub fn serial(&self) -> u64
pub fn progress(&self) -> f32
Sourcepub fn phase_remaining(&self) -> f32
pub fn phase_remaining(&self) -> f32
Simulation seconds left in the current phase, or zero while idle.
This inspection neither advances time nor consumes input. Values are
rounded to f32; Self::step retains its existing boundary tolerance.
See Self::remaining for the time through the end of this action.
use ferravex_play::action::{ActionPhase, ActionSpec, ActionTimeline};
let mut action = ActionTimeline::new(ActionSpec {
windup: 0.125, active: 0.0625, recovery: 0.25,
cancel_before: 0.0625, buffer_seconds: 0.125,
}).unwrap();
assert_eq!(action.phase_remaining(), 0.0);
action.step(0.0625, true).unwrap();
assert_eq!(action.phase(), ActionPhase::Windup);
assert_eq!(action.phase_remaining(), 0.0625);
assert_eq!(action.remaining(), 0.375);Sourcepub fn remaining(&self) -> f32
pub fn remaining(&self) -> f32
Simulation seconds until the current action finishes, or zero while idle.
Includes the remainder of this phase and all subsequent phases of this
action. Excludes any buffered follow-up: finishing may immediately start
that next action instead of leaving the timeline idle. Values are rounded
to f32. For a usage example, see Self::phase_remaining.
Sourcepub fn check_cancel(&self, force: bool) -> Result<(), ActionCancelError>
pub fn check_cancel(&self, force: bool) -> Result<(), ActionCancelError>
Inspect whether cancellation would succeed at the current simulation time.
Ordinary cancellation is allowed only during windup, at or before
cancel_before. Forced cancellation accepts any non-idle phase. This
does not reserve a cancellation; Self::try_cancel checks again when
called, so advancing the timeline can change the answer.
use ferravex_play::action::{ActionCancelError, ActionSpec, ActionTimeline};
let mut action = ActionTimeline::new(ActionSpec {
windup: 0.125, active: 0.0625, recovery: 0.25,
cancel_before: 0.0625, buffer_seconds: 0.125,
}).unwrap();
assert_eq!(action.check_cancel(true), Err(ActionCancelError::Idle));
action.step(0.0625, true).unwrap();
assert_eq!(action.check_cancel(false), Ok(())); // Cutoff is inclusive.
action.step(0.03125, false).unwrap();
assert_eq!(action.check_cancel(false), Err(ActionCancelError::CutoffPassed));
assert_eq!(action.check_cancel(true), Ok(()));Sourcepub fn try_cancel(
&mut self,
force: bool,
) -> Result<ActionEvent, ActionCancelError>
pub fn try_cancel( &mut self, force: bool, ) -> Result<ActionEvent, ActionCancelError>
Cancel an action, returning its accepted ActionEdge::Cancelled event.
Uses the same policy as Self::check_cancel. Rejection changes nothing;
success enters idle and clears the buffered follow-up. The event carries
the cancelled action’s serial and offset zero (the time of this call).
Cancellation does not allocate a new serial, undo previously returned
events, or enqueue an event for the next Self::step. The host should
consume this result once and close any associated HitWindow itself.
use ferravex_play::action::{ActionEdge, ActionSpec, ActionTimeline, HitWindow};
let mut action = ActionTimeline::new(ActionSpec {
windup: 0.125, active: 0.0625, recovery: 0.25,
cancel_before: 0.0625, buffer_seconds: 0.125,
}).unwrap();
let mut hits = HitWindow::<4>::new().unwrap();
for event in action.step(0.125, true).unwrap().events() {
if event.edge == ActionEdge::Activated {
assert!(hits.begin(event.serial));
}
}
assert!(hits.accept(action.serial(), 7).unwrap());
let cancelled = action.try_cancel(true).unwrap();
assert_eq!(cancelled.edge, ActionEdge::Cancelled);
assert_eq!(cancelled.serial, action.serial());
assert_eq!(cancelled.offset, 0.0);
hits.close();
assert!(!hits.accept(cancelled.serial, 8).unwrap());
assert!(!hits.begin(cancelled.serial)); // Cannot reopen the old action.
assert_eq!(action.step(0.25, false).unwrap().events().count(), 0);Sourcepub fn cancel(&mut self, force: bool) -> bool
pub fn cancel(&mut self, force: bool) -> bool
External interruption can obey the authored windup cutoff or force cancellation
on death/stun. Successful cancellation clears queued follow-up actions.
Use Self::try_cancel for a rejection reason or accepted cancellation event.
Sourcepub fn step(
&mut self,
dt: f32,
trigger: bool,
) -> Result<ActionFrame, ActionError>
pub fn step( &mut self, dt: f32, trigger: bool, ) -> Result<ActionFrame, ActionError>
At most eight transition reports: an existing action and one buffered action. Offsets let an authoritative host schedule queries at the proper substep.
Trait Implementations§
Source§impl Clone for ActionTimeline
impl Clone for ActionTimeline
Source§fn clone(&self) -> ActionTimeline
fn clone(&self) -> ActionTimeline
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more