pub struct Timeline { /* private fields */ }Expand description
A looping sequence of labelled phases (CORE-R38).
Storage is one Box<[Phase]> built in Timeline::new — the only allocation.
Taking &'static slices instead would forbid durations computed at runtime (from
the canvas size or ctx.rng), and precomputing start offsets means a query is a
rem_euclid plus an O(log n) binary search, with no summing and no allocation.
Implementations§
Source§impl Timeline
impl Timeline
Sourcepub fn new(phases: &[(&'static str, f64)]) -> Self
pub fn new(phases: &[(&'static str, f64)]) -> Self
Build a timeline from (label, seconds) pairs (CORE-R38).
Phases whose duration is not a finite positive number (zero, negative, NaN, ∞)
are zero-length and never reported by Timeline::at. An infinite phase would
make the loop never wrap, which a scene can express by simply not using a
timeline, so it is treated as invalid rather than special-cased.
Sourcepub fn total(&self) -> f64
pub fn total(&self) -> f64
Length of one cycle in seconds; 0 for an empty or all-zero timeline (CORE-R38).
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true when no phase has positive length, so every query reports phase 0.
Sourcepub fn at(&self, t: f64) -> Beat
pub fn at(&self, t: f64) -> Beat
The phase active at sim time t, looping every Timeline::total seconds
(CORE-R38).
Any finite t, including negative, maps into the cycle; non-finite t behaves
like t = 0. An empty timeline yields index 0 (labelled with the first phase
given, or "") with local = progress = 0.