euv_core/game/snapshot/struct.rs
1use super::*;
2
3/// Timestamped discrete gameplay event carried without interpolation on a simulation snapshot.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
5pub struct DiscreteGameEvent {
6 /// Semantic discrete event category.
7 #[get(type(copy))]
8 pub(crate) kind: DiscreteGameEventKind,
9 /// Simulation tick on which this event occurred.
10 #[get(type(copy))]
11 pub(crate) tick: u64,
12 /// Associated entity or object slot identifier (`u32::MAX` when global).
13 #[get(type(copy))]
14 pub(crate) subject_id: u32,
15}
16
17/// Three-slot double-buffered snapshot store decoupling fixed-step simulation commits from zero-allocation high-refresh render interpolation.
18#[derive(Clone, Data, Debug, PartialEq)]
19pub struct DoubleBufferedSnapshot<S> {
20 /// Persistent snapshot slot captured at the previous fixed simulation step.
21 pub(crate) prev_state: S,
22 /// Persistent snapshot slot captured at the latest fixed simulation step.
23 pub(crate) curr_state: S,
24 /// Third persistent scratch slot overwritten in place during zero-allocation `sample_cached` calls.
25 #[get(skip)]
26 #[get_mut(skip)]
27 #[set(skip)]
28 pub(crate) interp_scratch: S,
29 /// Monotonic simulation tick counter incremented on every commit.
30 #[get(type(copy))]
31 pub(crate) tick: u64,
32 /// Tick at which the last global discontinuity occurred (camera cut or world reset).
33 #[get(type(copy))]
34 pub(crate) discontinuity_tick: u64,
35 /// Whether `prev_state` represents a valid prior simulation step distinct from `curr_state`.
36 #[get(type(copy))]
37 pub(crate) has_prev: bool,
38}
39
40/// Immutable 2D entity pose captured for render-time interpolation with teleport and spawn guards.
41#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
42pub struct EntityPose2D {
43 /// Generational entity handle identifying continuity across ticks.
44 #[get(type(copy))]
45 pub(crate) id: EntityId,
46 /// Entity transform at snapshot time.
47 #[get(type(copy))]
48 pub(crate) transform: EntityTransform,
49 /// Teleport discontinuity counter incremented whenever the entity snaps instantaneously.
50 #[get(type(copy))]
51 pub(crate) teleport_epoch: u32,
52 /// Simulation tick on which this entity was spawned.
53 #[get(type(copy))]
54 pub(crate) spawn_tick: u64,
55 /// Whether the entity slot is alive in this snapshot.
56 #[get(type(copy))]
57 pub(crate) alive: bool,
58}
59
60/// Immutable 2D simulation snapshot pairing camera state, continuous entity poses, and discrete events.
61#[derive(Clone, Data, Debug, Default, PartialEq)]
62pub struct World2DSnapshot {
63 /// Simulation tick corresponding to this snapshot.
64 #[get(type(copy))]
65 pub(crate) tick: u64,
66 /// 2D camera state at this simulation step.
67 #[get(type(copy))]
68 pub(crate) camera: Camera2D,
69 /// When `true`, camera motion snapped via an instant cut and must not interpolate.
70 #[get(type(copy))]
71 pub(crate) camera_cut: bool,
72 /// Dense entity poses indexed identically to `GameWorld::entities`.
73 pub(crate) entities: Vec<EntityPose2D>,
74 /// Un-interpolated discrete events emitted during this simulation tick.
75 pub(crate) discrete_events: Vec<DiscreteGameEvent>,
76}
77
78/// Immutable 3D object pose captured for render-time interpolation with teleport guards.
79#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
80pub struct ObjectPose3D {
81 /// Index of the object inside `World3D::objects`.
82 #[get(type(copy))]
83 pub(crate) object_index: usize,
84 /// World-space 3D transform at snapshot time.
85 #[get(type(copy))]
86 pub(crate) transform: Transform3D,
87 /// Teleport epoch preventing continuous interpolation across instant relocations.
88 #[get(type(copy))]
89 pub(crate) teleport_epoch: u32,
90 /// Whether the object is visible in this snapshot.
91 #[get(type(copy))]
92 pub(crate) visible: bool,
93}
94
95/// Immutable skeletal joint pose snapshot supporting continuous interpolation unless a cut occurs.
96#[derive(Clone, Data, Debug, Default, PartialEq)]
97pub struct SkeletonPoseSnapshot {
98 /// Local joint transforms ordered identically to `SkeletonRig3D::joints`.
99 pub(crate) joint_transforms: Vec<Transform3D>,
100 /// When `true`, skeletal pose snapped cleanly (e.g. animation cut or respawn).
101 #[get(type(copy))]
102 pub(crate) cut: bool,
103}
104
105/// Immutable 3D world snapshot pairing camera state, object transforms, skeletal poses, and discrete events.
106#[derive(Clone, Data, Debug, Default, PartialEq)]
107pub struct World3DSnapshot {
108 /// Simulation tick corresponding to this snapshot.
109 #[get(type(copy))]
110 pub(crate) tick: u64,
111 /// 3D perspective camera state at this simulation step.
112 #[get(type(copy))]
113 pub(crate) camera: Camera3D,
114 /// When `true`, camera perspective cut instantaneously and must not interpolate.
115 #[get(type(copy))]
116 pub(crate) camera_cut: bool,
117 /// Continuous object poses indexed identically to `World3D::objects`.
118 pub(crate) objects: Vec<ObjectPose3D>,
119 /// Optional skeletal pose snapshots interpolated alongside world transforms.
120 pub(crate) skeletons: Vec<SkeletonPoseSnapshot>,
121 /// Un-interpolated discrete events emitted during this simulation tick.
122 pub(crate) discrete_events: Vec<DiscreteGameEvent>,
123}