Struct Trail

Source
pub struct Trail { /* private fields */ }
Expand description

Fixed ring, distance resampling and a current head. Capacity bounds the visible point count (including that head); one extra head value is stored separately. Stops and teleports create breaks; old segments fade naturally without bridges. Use Self::break_segment or Self::teleport for explicit discontinuities, including short respawn jumps, and Self::clear to reset all trail history.

Implementations§

Source§

impl Trail

Source

pub fn new(config: TrailConfig) -> Result<Trail, TrailError>

Source

pub fn capacity(&self) -> usize

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn config(&self) -> TrailConfig

Source

pub fn stats(&self) -> TrailStats

Source

pub fn clear(&mut self)

Removes all points and resets sampling history, retaining configuration, backing storage and cumulative statistics. The next sample starts a new segment with no residual spacing or connection to the old position. Call Self::reset_stats as well to reset the statistics for a new run.

use ferravex_play::particles::{Trail, TrailConfig, TrailSample, TrailStats};

let mut trail = Trail::new(TrailConfig::default()).unwrap();
trail.update(0.0, Some(TrailSample::default())).unwrap();
trail.clear();
assert!(trail.is_empty());
assert_eq!(trail.stats().sampled, 1);
trail.reset_stats();
assert_eq!(trail.stats(), TrailStats::default());
trail.update(0.0, Some(TrailSample::default())).unwrap();
assert!(trail.iter().next().unwrap().break_before);
Source

pub fn reset_stats(&mut self)

Source

pub fn break_segment(&mut self) -> TrailStats

Ends the current segment without advancing time or clearing old points. The current head is retained in the ring at age zero, subject to capacity; existing points keep their ages. The next accepted sample starts a new segment regardless of its distance from the old head. Spacing carry is discarded. Repeating this call without new samples is a no-op.

Returns the operation’s statistics, also added to Self::stats. A break does not count as a teleport. Equivalent to update(0.0, None), without delta validation or aging work.

use ferravex_play::particles::{Trail, TrailConfig, TrailSample, TrailStats};

let mut trail = Trail::new(TrailConfig::default()).unwrap();
let sample = TrailSample { color: [1.0; 4], width: 0.2, ..Default::default() };
trail.update(0.0, Some(sample)).unwrap();
trail.break_segment();
assert_eq!(trail.break_segment(), TrailStats::default());
// Even a respawn at the same position starts a disconnected segment.
trail.update(0.0, Some(sample)).unwrap();
assert!(trail.iter().last().unwrap().break_before);
Source

pub fn teleport( &mut self, sample: TrailSample, ) -> Result<TrailStats, TrailError>

Ends the current segment and starts a new one at sample, even at the same position or below the automatic teleport distance. Retains the old head and starts the new sample at age zero, subject to ring capacity. Existing points keep their ages and spacing carry is discarded. This does not advance time; use Self::update to age points normally.

Invalid samples leave all state unchanged. An accepted call counts one teleport, including on an empty trail. Returns the operation’s statistics, also added to Self::stats. Use Self::clear to discard old segments.

use ferravex_play::particles::{Trail, TrailConfig, TrailSample};

let mut trail = Trail::new(TrailConfig::default()).unwrap();
let sample = TrailSample { color: [1.0; 4], width: 0.2, ..Default::default() };
trail.update(0.0, Some(sample)).unwrap();
let respawn = TrailSample { position: [0.01, 0.0, 0.0], ..sample };
assert_eq!(trail.teleport(respawn).unwrap().teleports, 1);
assert_eq!(trail.len(), 2);
assert!(trail.iter().last().unwrap().break_before);
Source

pub fn update( &mut self, dt: f32, sample: Option<TrailSample>, ) -> Result<TrailStats, TrailError>

None stops emission while aging existing points. Invalid input leaves the trail unchanged. New samples receive their within-frame birth ages. Automatic teleports retain the previous head aged by dt and begin a disconnected segment at the new sample. Use Self::teleport for smaller jumps that must also break the trail.

Source

pub fn iter(&self) -> impl ExactSizeIterator

Trait Implementations§

Auto Trait Implementations§

§

impl Freeze for Trail

§

impl RefUnwindSafe for Trail

§

impl Send for Trail

§

impl Sync for Trail

§

impl Unpin for Trail

§

impl UnwindSafe for Trail

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> 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, 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.