Skip to main content

euv_core/game/snapshot/
trait.rs

1/// Trait for simulation snapshots supporting discontinuity-safe render interpolation and zero-allocation in-place reuse.
2pub trait InterpolatableState: Clone {
3    /// Interpolates between `self` (previous fixed-step snapshot) and `next` (current fixed-step snapshot) at `alpha` in `[0.0, 1.0]`.
4    ///
5    /// # Arguments
6    ///
7    /// - `&Self` - Previous immutable simulation snapshot (`t - dt`).
8    /// - `&Self` - Current immutable simulation snapshot (`t`).
9    /// - `f32` - Render interpolation factor clamped to `[0.0, 1.0]`.
10    ///
11    /// # Returns
12    ///
13    /// - `Self` - Smoothly interpolated state for rendering without interpolating discontinuous events.
14    #[must_use]
15    fn interpolate(&self, next: &Self, alpha: f32) -> Self;
16
17    /// Copies `src` into `self` reusing existing internal buffer capacities without heap allocation whenever possible.
18    ///
19    /// # Arguments
20    ///
21    /// - `&Self` - Mutable destination snapshot.
22    /// - `&Self` - Source snapshot to copy from.
23    fn copy_from_snapshot(&mut self, src: &Self) {
24        *self = src.clone();
25    }
26
27    /// Interpolates between `self` and `next` at `alpha` directly into pre-allocated `out` with zero steady-state allocations.
28    ///
29    /// # Arguments
30    ///
31    /// - `&Self` - Previous fixed-step snapshot (`t - dt`).
32    /// - `&Self` - Current fixed-step snapshot (`t`).
33    /// - `f32` - Render interpolation factor clamped to `[0.0, 1.0]`.
34    /// - `&mut Self` - Persistent destination snapshot overwritten in place.
35    fn interpolate_into(&self, next: &Self, alpha: f32, out: &mut Self) {
36        *out = self.interpolate(next, alpha);
37    }
38}