Struct GhostTrack

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

Implementations§

Source§

impl GhostTrack

Source

pub fn new( context: u64, tick_hz: u16, capacity: usize, ) -> Result<GhostTrack, ReplayError>

Source

pub fn context(&self) -> u64

Source

pub fn tick_hz(&self) -> u16

Source

pub fn samples(&self) -> &[Sample]

Source

pub fn push(&mut self, sample: Sample) -> Result<(), ReplayError>

Append a pose at a strictly newer tick, normalizing its rotation.

Duplicate, decreasing and wrapped ticks return ReplayError::TickOrder while space remains; a full track returns ReplayError::Capacity first. Rejections leave all recorded poses unchanged, including teleport flags. A teleport must use its own newer tick, never replace an existing key.

use ferravex_play::replay::{ReplayError, ghost::{GhostTrack, Sample}};
use ferravex_math::{Quat, Vec3};

let mut track = GhostTrack::new(7, 60, 2)?;
let pose = Sample {
    tick: 10, position: Vec3::ZERO, rotation: Quat::IDENTITY, teleport: false,
};
track.push(pose)?;
assert_eq!(track.push(Sample { teleport: true, ..pose }), Err(ReplayError::TickOrder));
assert_eq!(track.samples(), &[pose]);
Source

pub fn sample(&self, tick: u64, alpha: f32) -> Option<Sample>

Integer ticks retain precision even after long sessions. Alpha is the fractional simulation tick, not a fraction between sparse samples.

This compatibility API retains its original synthesized teleport flags. Use Self::sample_checked for exact stored keys and explicit states.

Source

pub fn sample_checked( &self, tick: u64, alpha: f32, ) -> Result<SampleState, ReplayError>

Sample tick + alpha with explicit range and discontinuity states.

Alpha is a fractional simulation tick in [0, 1), not a fraction of the gap between recorded keys. Invalid alpha (including NaN, infinity or 1) returns ReplayError::InvalidData, even for an empty track. No input is clamped. A positive alpha at the final tick is AfterEnd, including at u64::MAX; ticks never wrap or convert wholesale to floats.

Exact queries return stored keys unchanged, including teleport flags and quaternion signs. Between keys, an upcoming teleport holds both position and rotation until its exact tick. Interpolation resumes from that key unless the next key is also marked. Only exact keys retain teleport flags; a hold is reported as Held, not a repeated teleport.

Duplicate/decreasing keys are rejected by Self::push, so every interpolation interval has positive length. Queries allocate nothing, take O(log(samples.len())) time and may repeat or seek in either direction. Interpolation uses relative f64 tick differences, then f32 poses; rounding can produce an endpoint pose for a strictly interior query.

use ferravex_play::replay::{ReplayError, ghost::{GhostTrack, Sample, SampleState}};
use ferravex_math::{Quat, Vec3};

let mut track = GhostTrack::new(7, 60, 3)?;
for (tick, x, teleport) in [(10, 0.0, false), (20, 100.0, true), (30, 110.0, false)] {
    track.push(Sample {
        tick, position: Vec3::X * x, rotation: Quat::IDENTITY, teleport,
    })?;
}
assert!(matches!(track.sample_checked(9, 0.5)?, SampleState::BeforeStart { .. }));
assert!(matches!(track.sample_checked(19, 0.5)?, SampleState::Held {
    from_tick: 10, teleport_tick: 20, ..
}));
assert_eq!(track.sample_checked(19, 0.5)?.sample().unwrap().position.x, 0.0);
assert_eq!(track.sample_checked(20, 0.0)?, SampleState::Exact(track.samples()[1]));
let moving = track.sample_checked(20, 0.5)?;
assert!(matches!(moving, SampleState::Interpolated { from_tick: 20, to_tick: 30, .. }));
assert_eq!(moving.sample().unwrap().position.x, 100.5);
assert!(matches!(track.sample_checked(30, 0.5)?, SampleState::AfterEnd { .. }));
assert_eq!(track.sample_checked(20, f32::NAN), Err(ReplayError::InvalidData));

Trait Implementations§

Source§

impl Clone for GhostTrack

Source§

fn clone(&self) -> GhostTrack

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 GhostTrack

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.