pub struct GhostTrack { /* private fields */ }Implementations§
Source§impl GhostTrack
impl GhostTrack
pub fn new( context: u64, tick_hz: u16, capacity: usize, ) -> Result<GhostTrack, ReplayError>
pub fn context(&self) -> u64
pub fn tick_hz(&self) -> u16
pub fn samples(&self) -> &[Sample]
Sourcepub fn push(&mut self, sample: Sample) -> Result<(), ReplayError>
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]);Sourcepub fn sample(&self, tick: u64, alpha: f32) -> Option<Sample>
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.
Sourcepub fn sample_checked(
&self,
tick: u64,
alpha: f32,
) -> Result<SampleState, ReplayError>
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
impl Clone for GhostTrack
Source§fn clone(&self) -> GhostTrack
fn clone(&self) -> GhostTrack
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more