Struct SpriteClip

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

Implementations§

Source§

impl SpriteClip

Source

pub fn new(frames: Vec<SpriteFrame>) -> Result<SpriteClip, AnimationError>

Source

pub fn validate_frames( frames: &[SpriteFrame], ) -> Result<f32, AnimationDiagnostic>

Check borrowed frames and return their accumulated duration, without allocating or consuming the authoring data.

Reports the first frame with a nonfinite/nonpositive duration or whose addition overflows or fails to advance the accumulated f32 end time. All such cases have category InvalidKey; empty input has category Empty and no index. Frame indices may repeat and need not be ordered. Work is O(frames.len()) with constant scratch space.

use ferravex_play::animation::{SpriteClip, SpriteFrame};
let frames = [
    SpriteFrame { index: 7, duration: 0.25 },
    SpriteFrame { index: 2, duration: 0.75 },
];
assert_eq!(SpriteClip::validate_frames(&frames), Ok(1.0));
let clip = SpriteClip::new(frames.to_vec()).unwrap();
assert_eq!(clip.frames(), &frames);
Source

pub fn frames(&self) -> &[SpriteFrame]

Borrow the original frame indices and durations in playback order. See Self::validate_frames for an inspection example.

Source

pub fn duration(&self) -> f32

Source

pub fn frame(&self, time: f32, mode: LoopMode) -> Result<u32, AnimationError>

Source

pub fn sample_into( &self, times: &[f32], mode: LoopMode, out: &mut [u32], ) -> Result<usize, AnimationError>

Sample sprite indices into a reusable output prefix without allocating.

Returns times.len(), leaving the output tail untouched. Empty input succeeds. A short output returns Capacity before nonfinite times are checked (InvalidTime); either error leaves output unchanged. Times may be negative or unsorted. Each result is identical to Self::frame, including exact frame/loop boundaries. Work is O(times.len() * log(frames.len())) with constant scratch space.

use ferravex_play::animation::{LoopMode, SpriteClip, SpriteFrame};
let clip = SpriteClip::new(vec![
    SpriteFrame { index: 4, duration: 0.25 },
    SpriteFrame { index: 7, duration: 0.75 },
]).unwrap();
let mut out = [99; 4];
assert_eq!(clip.sample_into(&[0.0, 0.25, 1.0], LoopMode::Repeat, &mut out), Ok(3));
assert_eq!(out, [4, 7, 4, 99]);

Trait Implementations§

Source§

impl Clone for SpriteClip

Source§

fn clone(&self) -> SpriteClip

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 SpriteClip

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.