Skip to main content

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