Struct ActionTimeline

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

Implementations§

Source§

impl ActionTimeline

Source

pub fn new(spec: ActionSpec) -> Result<ActionTimeline, ActionError>

Source

pub fn phase(&self) -> ActionPhase

Source

pub fn serial(&self) -> u64

Source

pub fn progress(&self) -> f32

Source

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);
Source

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.

Source

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(()));
Source

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);
Source

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.

Source

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

Source§

fn clone(&self) -> ActionTimeline

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 ActionTimeline

Source§

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

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

impl Copy for ActionTimeline

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.