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
impl Trail
pub fn new(config: TrailConfig) -> Result<Trail, TrailError>
pub fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn config(&self) -> TrailConfig
pub fn stats(&self) -> TrailStats
Sourcepub fn clear(&mut self)
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);pub fn reset_stats(&mut self)
Sourcepub fn break_segment(&mut self) -> TrailStats
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);Sourcepub fn teleport(
&mut self,
sample: TrailSample,
) -> Result<TrailStats, TrailError>
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);Sourcepub fn update(
&mut self,
dt: f32,
sample: Option<TrailSample>,
) -> Result<TrailStats, TrailError>
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.