Skip to main content

euv_core/game/snapshot/
impl.rs

1use super::*;
2
3/// Construction, zero-allocation in-place capture, discontinuity handling, and interpolation sampling for `DoubleBufferedSnapshot`.
4impl<S> DoubleBufferedSnapshot<S>
5where
6    S: Clone,
7{
8    /// Initializes a three-slot double-buffered snapshot store with `initial` across all persistent slots.
9    ///
10    /// # Arguments
11    ///
12    /// - `S` - Initial simulation state snapshot.
13    ///
14    /// # Returns
15    ///
16    /// - `Self` - Initialized three-slot snapshot buffer.
17    #[must_use]
18    pub fn new(initial: S) -> Self {
19        Self {
20            prev_state: initial.clone(),
21            interp_scratch: initial.clone(),
22            curr_state: initial,
23            tick: 0,
24            discontinuity_tick: 0,
25            has_prev: false,
26        }
27    }
28
29    /// Commits a continuous fixed-step snapshot, promoting the prior `curr_state` into `prev_state`.
30    ///
31    /// # Arguments
32    ///
33    /// - `&Self` - Mutable snapshot buffer.
34    /// - `S` - New immutable simulation state snapshot.
35    pub fn commit(&mut self, next: S) {
36        let mut incoming: S = next;
37        swap(self.get_mut_curr_state(), &mut incoming);
38        self.set_prev_state(incoming);
39        let next_tick: u64 = self.get_tick().wrapping_add(1);
40        self.set_tick(next_tick);
41        self.set_has_prev(true);
42    }
43
44    /// Rotates `curr_state` into `prev_state` and populates the recycled `curr_state` slot in place via `capture_fn` with zero heap allocations.
45    ///
46    /// # Arguments
47    ///
48    /// - `&Self` - Mutable snapshot buffer.
49    /// - `F` - Closure overwriting the recycled `&mut S` slot in place.
50    pub fn capture_into<F>(&mut self, capture_fn: F)
51    where
52        F: FnOnce(&mut S),
53    {
54        let Self {
55            prev_state,
56            curr_state,
57            ..
58        } = self;
59        swap(prev_state, curr_state);
60        capture_fn(curr_state);
61        let next_tick: u64 = self.get_tick().wrapping_add(1);
62        self.set_tick(next_tick);
63        self.set_has_prev(true);
64    }
65
66    /// Captures a discontinuous snapshot in place via `capture_fn`, preventing interpolation across the boundary without reallocating backing vectors.
67    ///
68    /// # Arguments
69    ///
70    /// - `&Self` - Mutable snapshot buffer.
71    /// - `F` - Closure overwriting `curr_state` in place.
72    pub fn capture_discontinuous_into<F>(&mut self, capture_fn: F)
73    where
74        F: FnOnce(&mut S),
75    {
76        let Self { curr_state, .. } = self;
77        capture_fn(curr_state);
78        let next_tick: u64 = self.get_tick().wrapping_add(1);
79        self.set_tick(next_tick);
80        self.set_discontinuity_tick(next_tick);
81        self.set_has_prev(false);
82    }
83
84    /// Commits a discontinuous snapshot (teleport, scene reset, or hard camera cut), preventing interpolation across the boundary.
85    ///
86    /// # Arguments
87    ///
88    /// - `&Self` - Mutable snapshot buffer.
89    /// - `S` - New immutable simulation state snapshot.
90    pub fn commit_discontinuous(&mut self, next: S) {
91        let next_tick: u64 = self.get_tick().wrapping_add(1);
92        self.set_prev_state(next.clone());
93        self.set_curr_state(next);
94        self.set_tick(next_tick);
95        self.set_discontinuity_tick(next_tick);
96        self.set_has_prev(false);
97    }
98
99    /// Samples the render-time state at normalized `alpha` in `[0.0, 1.0]` directly into pre-allocated `out` with zero heap allocations.
100    ///
101    /// # Arguments
102    ///
103    /// - `&Self` - Snapshot buffer reference.
104    /// - `f32` - Normalized interpolation factor between previous and current fixed steps.
105    /// - `&mut S` - Persistent destination snapshot overwritten in place.
106    pub fn sample_into(&self, alpha: f32, out: &mut S)
107    where
108        S: InterpolatableState,
109    {
110        let clamped: f32 = if alpha.is_finite() {
111            alpha.clamp(0.0, 1.0)
112        } else {
113            1.0
114        };
115        if !self.get_has_prev()
116            || self.get_discontinuity_tick() == self.get_tick()
117            || clamped >= 1.0
118        {
119            out.copy_from_snapshot(self.get_curr_state());
120            return;
121        }
122        if clamped <= 0.0 {
123            out.copy_from_snapshot(self.get_prev_state());
124            return;
125        }
126        self.get_prev_state()
127            .interpolate_into(self.get_curr_state(), clamped, out);
128    }
129
130    /// Samples the render-time state at `alpha` into the internal third persistent `interp_scratch` slot and borrows it with zero allocations.
131    ///
132    /// # Arguments
133    ///
134    /// - `&Self` - Mutable snapshot buffer.
135    /// - `f32` - Normalized interpolation factor in `[0.0, 1.0]`.
136    ///
137    /// # Returns
138    ///
139    /// - `&S` - Borrowed interpolated snapshot stored in the persistent scratch slot.
140    #[must_use]
141    pub fn sample_cached(&mut self, alpha: f32) -> &S
142    where
143        S: InterpolatableState,
144    {
145        let clamped: f32 = if alpha.is_finite() {
146            alpha.clamp(0.0, 1.0)
147        } else {
148            1.0
149        };
150        let use_curr: bool = !self.get_has_prev()
151            || self.get_discontinuity_tick() == self.get_tick()
152            || clamped >= 1.0;
153        let Self {
154            prev_state,
155            curr_state,
156            interp_scratch,
157            ..
158        } = self;
159        if use_curr {
160            interp_scratch.copy_from_snapshot(curr_state);
161        } else if clamped <= 0.0 {
162            interp_scratch.copy_from_snapshot(prev_state);
163        } else {
164            prev_state.interpolate_into(curr_state, clamped, interp_scratch);
165        }
166        interp_scratch
167    }
168
169    /// Samples the render-time state at normalized `alpha` in `[0.0, 1.0]`.
170    ///
171    /// # Arguments
172    ///
173    /// - `&Self` - Snapshot buffer reference.
174    /// - `f32` - Normalized interpolation factor between previous and current fixed steps.
175    ///
176    /// # Returns
177    ///
178    /// - `S` - Interpolated snapshot or exact `curr_state` on discontinuities.
179    #[must_use]
180    pub fn sample(&self, alpha: f32) -> S
181    where
182        S: InterpolatableState,
183    {
184        let clamped: f32 = if alpha.is_finite() {
185            alpha.clamp(0.0, 1.0)
186        } else {
187            1.0
188        };
189        if !self.get_has_prev()
190            || self.get_discontinuity_tick() == self.get_tick()
191            || clamped >= 1.0
192        {
193            return self.get_curr_state().clone();
194        }
195        if clamped <= 0.0 {
196            return self.get_prev_state().clone();
197        }
198        self.get_prev_state()
199            .interpolate(self.get_curr_state(), clamped)
200    }
201}
202
203/// Snapshot builders and zero-allocation in-place capture helpers for `World2DSnapshot`.
204impl World2DSnapshot {
205    /// Captures `world` and `camera` into `self` reusing existing `entities` and `discrete_events` capacities with zero steady-state allocations.
206    ///
207    /// # Arguments
208    ///
209    /// - `&Self` - Mutable destination 2D snapshot.
210    /// - `&GameWorld` - Authoritative 2D ECS world.
211    /// - `Camera2D` - Active 2D camera state.
212    /// - `bool` - Whether a hard camera cut occurred on this tick.
213    /// - `&[DiscreteGameEvent]` - Discrete un-interpolated gameplay events emitted on this tick.
214    pub fn capture_into(
215        &mut self,
216        world: &GameWorld,
217        camera: Camera2D,
218        camera_cut: bool,
219        discrete_events: &[DiscreteGameEvent],
220    ) {
221        self.set_tick(world.get_tick());
222        self.set_camera(camera);
223        self.set_camera_cut(camera_cut);
224        let entities: &mut Vec<EntityPose2D> = self.get_mut_entities();
225        entities.clear();
226        let records: &[EntityRecord] = world.get_entities().as_slice();
227        if entities.capacity() < records.len() {
228            entities.reserve(records.len() - entities.capacity());
229        }
230        for ent in records.iter() {
231            entities.push(EntityPose2D::new(
232                ent.get_id(),
233                ent.get_transform(),
234                ent.get_teleport_epoch(),
235                ent.get_spawn_tick(),
236                ent.get_alive(),
237            ));
238        }
239        let events_buf: &mut Vec<DiscreteGameEvent> = self.get_mut_discrete_events();
240        events_buf.clear();
241        events_buf.extend_from_slice(discrete_events);
242    }
243
244    /// Captures an immutable `World2DSnapshot` from `world` and `camera`.
245    ///
246    /// # Arguments
247    ///
248    /// - `&GameWorld` - Authoritative 2D ECS world.
249    /// - `Camera2D` - Active 2D camera state.
250    /// - `bool` - Whether a hard camera cut occurred on this tick.
251    /// - `Vec<DiscreteGameEvent>` - Discrete un-interpolated gameplay events emitted on this tick.
252    ///
253    /// # Returns
254    ///
255    /// - `Self` - Captured immutable 2D world snapshot.
256    #[must_use]
257    pub fn capture(
258        world: &GameWorld,
259        camera: Camera2D,
260        camera_cut: bool,
261        discrete_events: Vec<DiscreteGameEvent>,
262    ) -> Self {
263        let mut snap: Self = Self::default();
264        snap.capture_into(world, camera, camera_cut, &[]);
265        snap.set_discrete_events(discrete_events);
266        snap
267    }
268}
269
270/// Discontinuity-safe render-time interpolation for `World2DSnapshot`.
271impl InterpolatableState for World2DSnapshot {
272    /// Copies `src` into `self` reusing backing vector allocations.
273    ///
274    /// # Arguments
275    ///
276    /// - `&Self` - Mutable destination snapshot.
277    /// - `&Self` - Source snapshot.
278    fn copy_from_snapshot(&mut self, src: &Self) {
279        self.set_tick(src.get_tick());
280        self.set_camera(src.get_camera());
281        self.set_camera_cut(src.get_camera_cut());
282        let ents: &mut Vec<EntityPose2D> = self.get_mut_entities();
283        ents.clear();
284        ents.extend_from_slice(src.get_entities().as_slice());
285        let evs: &mut Vec<DiscreteGameEvent> = self.get_mut_discrete_events();
286        evs.clear();
287        evs.extend_from_slice(src.get_discrete_events().as_slice());
288    }
289
290    /// Interpolates camera and continuous entity poses into `out` with zero steady-state heap allocations.
291    ///
292    /// # Arguments
293    ///
294    /// - `&Self` - Previous fixed-step 2D snapshot.
295    /// - `&Self` - Current fixed-step 2D snapshot.
296    /// - `f32` - Normalized interpolation factor in `[0.0, 1.0]`.
297    /// - `&mut Self` - Pre-allocated destination 2D snapshot overwritten in place.
298    fn interpolate_into(&self, next: &Self, alpha: f32, out: &mut Self) {
299        let k: f32 = alpha.clamp(0.0, 1.0);
300        let camera: Camera2D = if next.get_camera_cut() {
301            next.get_camera()
302        } else {
303            self.get_camera().lerp(next.get_camera(), k)
304        };
305        out.set_tick(next.get_tick());
306        out.set_camera(camera);
307        out.set_camera_cut(next.get_camera_cut());
308        let prev_entities: &[EntityPose2D] = self.get_entities().as_slice();
309        let next_entities: &[EntityPose2D] = next.get_entities().as_slice();
310        let out_entities: &mut Vec<EntityPose2D> = out.get_mut_entities();
311        out_entities.clear();
312        if out_entities.capacity() < next_entities.len() {
313            out_entities.reserve(next_entities.len() - out_entities.capacity());
314        }
315        let prev_tick: u64 = self.get_tick();
316        for (idx, curr) in next_entities.iter().copied().enumerate() {
317            let mut blended: EntityPose2D = curr;
318            if curr.get_alive()
319                && let Some(prev) = prev_entities.get(idx).copied()
320            {
321                let same_entity: bool = prev.get_alive() && prev.get_id() == curr.get_id();
322                let no_teleport: bool = prev.get_teleport_epoch() == curr.get_teleport_epoch();
323                let not_fresh_spawn: bool = curr.get_spawn_tick() <= prev_tick;
324                if same_entity && no_teleport && not_fresh_spawn {
325                    let interp_tr: EntityTransform =
326                        prev.get_transform().lerp(curr.get_transform(), k);
327                    blended.set_transform(interp_tr);
328                }
329            }
330            out_entities.push(blended);
331        }
332        let out_events: &mut Vec<DiscreteGameEvent> = out.get_mut_discrete_events();
333        out_events.clear();
334        out_events.extend_from_slice(next.get_discrete_events().as_slice());
335    }
336
337    /// Interpolates camera and continuous entity poses while snapping spawns, despawns, teleports, camera cuts, and discrete events.
338    ///
339    /// # Arguments
340    ///
341    /// - `&Self` - Previous fixed-step 2D snapshot.
342    /// - `&Self` - Current fixed-step 2D snapshot.
343    /// - `f32` - Normalized interpolation factor in `[0.0, 1.0]`.
344    ///
345    /// # Returns
346    ///
347    /// - `Self` - Render-time interpolated 2D world snapshot.
348    fn interpolate(&self, next: &Self, alpha: f32) -> Self {
349        let mut out: Self = Self::default();
350        self.interpolate_into(next, alpha, &mut out);
351        out
352    }
353}
354
355/// Discontinuity-safe skeletal joint interpolation for `SkeletonPoseSnapshot`.
356impl InterpolatableState for SkeletonPoseSnapshot {
357    /// Copies `src` into `self` reusing backing joint transform storage.
358    ///
359    /// # Arguments
360    ///
361    /// - `&Self` - Mutable destination skeletal pose snapshot.
362    /// - `&Self` - Source skeletal pose snapshot.
363    fn copy_from_snapshot(&mut self, src: &Self) {
364        self.set_cut(src.get_cut());
365        let dst: &mut Vec<Transform3D> = self.get_mut_joint_transforms();
366        dst.clear();
367        dst.extend_from_slice(src.get_joint_transforms().as_slice());
368    }
369
370    /// Interpolates joint transforms between `self` and `next` into `out` without heap reallocation.
371    ///
372    /// # Arguments
373    ///
374    /// - `&Self` - Previous skeletal pose snapshot.
375    /// - `&Self` - Current skeletal pose snapshot.
376    /// - `f32` - Normalized interpolation factor in `[0.0, 1.0]`.
377    /// - `&mut Self` - Pre-allocated destination skeletal pose snapshot.
378    fn interpolate_into(&self, next: &Self, alpha: f32, out: &mut Self) {
379        let prev_joints: &[Transform3D] = self.get_joint_transforms().as_slice();
380        let next_joints: &[Transform3D] = next.get_joint_transforms().as_slice();
381        if next.get_cut() || prev_joints.len() != next_joints.len() {
382            out.copy_from_snapshot(next);
383            return;
384        }
385        let k: f32 = alpha.clamp(0.0, 1.0);
386        out.set_cut(false);
387        let dst: &mut Vec<Transform3D> = out.get_mut_joint_transforms();
388        dst.clear();
389        if dst.capacity() < next_joints.len() {
390            dst.reserve(next_joints.len() - dst.capacity());
391        }
392        for (a, b) in prev_joints.iter().copied().zip(next_joints.iter().copied()) {
393            dst.push(a.lerp_shortest_angle(b, k));
394        }
395    }
396
397    /// Interpolates joint transforms between `self` and `next` unless `next.cut` is set or joint counts differ.
398    ///
399    /// # Arguments
400    ///
401    /// - `&Self` - Previous skeletal pose snapshot.
402    /// - `&Self` - Current skeletal pose snapshot.
403    /// - `f32` - Normalized interpolation factor in `[0.0, 1.0]`.
404    ///
405    /// # Returns
406    ///
407    /// - `Self` - Interpolated skeletal pose snapshot.
408    fn interpolate(&self, next: &Self, alpha: f32) -> Self {
409        let mut out: Self = Self::default();
410        self.interpolate_into(next, alpha, &mut out);
411        out
412    }
413}
414
415/// Snapshot builders and zero-allocation in-place capture helpers for `World3DSnapshot`.
416impl World3DSnapshot {
417    /// Captures all 3D object poses from `world` into `self` reusing backing buffers with zero steady-state allocations.
418    ///
419    /// # Arguments
420    ///
421    /// - `&Self` - Mutable destination 3D snapshot.
422    /// - `&World3D` - Authoritative 3D world state.
423    /// - `u64` - Fixed simulation tick number.
424    /// - `bool` - Whether an instant camera cut occurred on this tick.
425    /// - `&[SkeletonPoseSnapshot]` - Skeletal pose snapshots sampled on this tick.
426    /// - `&[DiscreteGameEvent]` - Un-interpolated discrete events emitted on this tick.
427    pub fn capture_into(
428        &mut self,
429        world: &World3D,
430        tick: u64,
431        camera_cut: bool,
432        skeletons: &[SkeletonPoseSnapshot],
433        discrete_events: &[DiscreteGameEvent],
434    ) {
435        self.set_tick(tick);
436        self.set_camera(world.get_camera());
437        self.set_camera_cut(camera_cut);
438        let objs: &[SceneObject3D] = world.get_objects().as_slice();
439        let poses: &mut Vec<ObjectPose3D> = self.get_mut_objects();
440        poses.clear();
441        if poses.capacity() < objs.len() {
442            poses.reserve(objs.len() - poses.capacity());
443        }
444        for (idx, obj) in objs.iter().enumerate() {
445            poses.push(ObjectPose3D::new(
446                idx,
447                obj.get_transform(),
448                obj.get_teleport_epoch(),
449                true,
450            ));
451        }
452        let skels: &mut Vec<SkeletonPoseSnapshot> = self.get_mut_skeletons();
453        skels.resize_with(skeletons.len(), SkeletonPoseSnapshot::default);
454        for (dst, src) in skels.iter_mut().zip(skeletons.iter()) {
455            dst.copy_from_snapshot(src);
456        }
457        let evs: &mut Vec<DiscreteGameEvent> = self.get_mut_discrete_events();
458        evs.clear();
459        evs.extend_from_slice(discrete_events);
460    }
461
462    /// Captures only dynamic 3D objects from `world` into `self` (skipping static buildings/roads) with zero steady-state allocations.
463    ///
464    /// # Arguments
465    ///
466    /// - `&Self` - Mutable destination 3D snapshot.
467    /// - `&World3D` - Authoritative 3D world state.
468    /// - `u64` - Fixed simulation tick number.
469    /// - `bool` - Whether an instant camera cut occurred on this tick.
470    /// - `&[SkeletonPoseSnapshot]` - Skeletal pose snapshots sampled on this tick.
471    /// - `&[DiscreteGameEvent]` - Un-interpolated discrete events emitted on this tick.
472    pub fn capture_dynamic_into(
473        &mut self,
474        world: &World3D,
475        tick: u64,
476        camera_cut: bool,
477        skeletons: &[SkeletonPoseSnapshot],
478        discrete_events: &[DiscreteGameEvent],
479    ) {
480        self.set_tick(tick);
481        self.set_camera(world.get_camera());
482        self.set_camera_cut(camera_cut);
483        let objs: &[SceneObject3D] = world.get_objects().as_slice();
484        let poses: &mut Vec<ObjectPose3D> = self.get_mut_objects();
485        poses.clear();
486        for (idx, obj) in objs.iter().enumerate() {
487            if obj.get_is_dynamic() {
488                poses.push(ObjectPose3D::new(
489                    idx,
490                    obj.get_transform(),
491                    obj.get_teleport_epoch(),
492                    true,
493                ));
494            }
495        }
496        let skels: &mut Vec<SkeletonPoseSnapshot> = self.get_mut_skeletons();
497        skels.resize_with(skeletons.len(), SkeletonPoseSnapshot::default);
498        for (dst, src) in skels.iter_mut().zip(skeletons.iter()) {
499            dst.copy_from_snapshot(src);
500        }
501        let evs: &mut Vec<DiscreteGameEvent> = self.get_mut_discrete_events();
502        evs.clear();
503        evs.extend_from_slice(discrete_events);
504    }
505
506    /// Captures an immutable `World3DSnapshot` from `world` with optional skeletal poses and discrete events.
507    ///
508    /// # Arguments
509    ///
510    /// - `&World3D` - Authoritative 3D world state.
511    /// - `u64` - Fixed simulation tick number.
512    /// - `bool` - Whether an instant camera cut occurred on this tick.
513    /// - `Vec<SkeletonPoseSnapshot>` - Skeletal pose snapshots sampled on this tick.
514    /// - `Vec<DiscreteGameEvent>` - Un-interpolated discrete events emitted on this tick.
515    ///
516    /// # Returns
517    ///
518    /// - `Self` - Captured immutable 3D world snapshot.
519    #[must_use]
520    pub fn capture(
521        world: &World3D,
522        tick: u64,
523        camera_cut: bool,
524        skeletons: Vec<SkeletonPoseSnapshot>,
525        discrete_events: Vec<DiscreteGameEvent>,
526    ) -> Self {
527        let mut snap: Self = Self::default();
528        snap.capture_into(world, tick, camera_cut, &[], &[]);
529        snap.set_skeletons(skeletons);
530        snap.set_discrete_events(discrete_events);
531        snap
532    }
533}
534
535/// Discontinuity-safe render-time interpolation for `World3DSnapshot`.
536impl InterpolatableState for World3DSnapshot {
537    /// Copies `src` into `self` reusing existing vector allocations.
538    ///
539    /// # Arguments
540    ///
541    /// - `&Self` - Mutable destination 3D snapshot.
542    /// - `&Self` - Source 3D snapshot.
543    fn copy_from_snapshot(&mut self, src: &Self) {
544        self.set_tick(src.get_tick());
545        self.set_camera(src.get_camera());
546        self.set_camera_cut(src.get_camera_cut());
547        let objs: &mut Vec<ObjectPose3D> = self.get_mut_objects();
548        objs.clear();
549        objs.extend_from_slice(src.get_objects().as_slice());
550        let src_skels: &[SkeletonPoseSnapshot] = src.get_skeletons().as_slice();
551        let dst_skels: &mut Vec<SkeletonPoseSnapshot> = self.get_mut_skeletons();
552        dst_skels.resize_with(src_skels.len(), SkeletonPoseSnapshot::default);
553        for (dst, s) in dst_skels.iter_mut().zip(src_skels.iter()) {
554            dst.copy_from_snapshot(s);
555        }
556        let evs: &mut Vec<DiscreteGameEvent> = self.get_mut_discrete_events();
557        evs.clear();
558        evs.extend_from_slice(src.get_discrete_events().as_slice());
559    }
560
561    /// Interpolates 3D camera, object transforms, and skeletal poses into `out` without heap allocation.
562    ///
563    /// # Arguments
564    ///
565    /// - `&Self` - Previous fixed-step 3D snapshot.
566    /// - `&Self` - Current fixed-step 3D snapshot.
567    /// - `f32` - Normalized interpolation factor in `[0.0, 1.0]`.
568    /// - `&mut Self` - Pre-allocated destination 3D snapshot overwritten in place.
569    fn interpolate_into(&self, next: &Self, alpha: f32, out: &mut Self) {
570        let k: f32 = alpha.clamp(0.0, 1.0);
571        let camera: Camera3D = if next.get_camera_cut() {
572            next.get_camera()
573        } else {
574            self.get_camera().lerp(next.get_camera(), k)
575        };
576        out.set_tick(next.get_tick());
577        out.set_camera(camera);
578        out.set_camera_cut(next.get_camera_cut());
579        let prev_objs: &[ObjectPose3D] = self.get_objects().as_slice();
580        let next_objs: &[ObjectPose3D] = next.get_objects().as_slice();
581        let out_objs: &mut Vec<ObjectPose3D> = out.get_mut_objects();
582        out_objs.clear();
583        if out_objs.capacity() < next_objs.len() {
584            out_objs.reserve(next_objs.len() - out_objs.capacity());
585        }
586        for (idx, curr) in next_objs.iter().copied().enumerate() {
587            let mut blended: ObjectPose3D = curr;
588            if curr.get_visible()
589                && let Some(prev) = prev_objs.get(idx).copied()
590            {
591                let continuous: bool = prev.get_visible()
592                    && prev.get_object_index() == curr.get_object_index()
593                    && prev.get_teleport_epoch() == curr.get_teleport_epoch();
594                if continuous {
595                    blended.set_transform(
596                        prev.get_transform()
597                            .lerp_shortest_angle(curr.get_transform(), k),
598                    );
599                }
600            }
601            out_objs.push(blended);
602        }
603        let prev_skels: &[SkeletonPoseSnapshot] = self.get_skeletons().as_slice();
604        let next_skels: &[SkeletonPoseSnapshot] = next.get_skeletons().as_slice();
605        let out_skels: &mut Vec<SkeletonPoseSnapshot> = out.get_mut_skeletons();
606        out_skels.resize_with(next_skels.len(), SkeletonPoseSnapshot::default);
607        for (idx, curr_sk) in next_skels.iter().enumerate() {
608            if let Some(prev_sk) = prev_skels.get(idx) {
609                prev_sk.interpolate_into(curr_sk, k, &mut out_skels[idx]);
610            } else {
611                out_skels[idx].copy_from_snapshot(curr_sk);
612            }
613        }
614        let out_evs: &mut Vec<DiscreteGameEvent> = out.get_mut_discrete_events();
615        out_evs.clear();
616        out_evs.extend_from_slice(next.get_discrete_events().as_slice());
617    }
618
619    /// Interpolates 3D camera, continuous object transforms, and skeletal poses while snapping cuts, teleports, and discrete events.
620    ///
621    /// # Arguments
622    ///
623    /// - `&Self` - Previous fixed-step 3D snapshot.
624    /// - `&Self` - Current fixed-step 3D snapshot.
625    /// - `f32` - Normalized interpolation factor in `[0.0, 1.0]`.
626    ///
627    /// # Returns
628    ///
629    /// - `Self` - Render-time interpolated 3D world snapshot.
630    fn interpolate(&self, next: &Self, alpha: f32) -> Self {
631        let mut out: Self = Self::default();
632        self.interpolate_into(next, alpha, &mut out);
633        out
634    }
635}