Skip to main content

euv_core/game/particles/
struct.rs

1use super::*;
2
3/// Individual pooled particle simulated without heap allocations.
4#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
5pub struct Particle {
6    /// Whether this pool slot is currently alive.
7    #[get(type(copy))]
8    pub(crate) active: bool,
9    /// Current world-space position.
10    #[get(type(copy))]
11    pub(crate) position: Point,
12    /// Current linear velocity in world units per second.
13    #[get(type(copy))]
14    pub(crate) velocity: Point,
15    /// Elapsed particle age in seconds.
16    #[get(type(copy))]
17    pub(crate) age: f32,
18    /// Total lifetime in seconds.
19    #[get(type(copy))]
20    pub(crate) lifetime: f32,
21    /// Initial radius in world units.
22    #[get(type(copy))]
23    pub(crate) start_size: f32,
24    /// Final radius at end of life.
25    #[get(type(copy))]
26    pub(crate) end_size: f32,
27    /// Initial RGBA color.
28    #[get(type(copy))]
29    pub(crate) start_color: Color,
30    /// Final RGBA color interpolated over lifetime.
31    #[get(type(copy))]
32    pub(crate) end_color: Color,
33    /// Linear drag per second.
34    #[get(type(copy))]
35    pub(crate) drag: f32,
36}
37
38/// Declarative burst/stream emitter configuration for `ParticleSystem`.
39#[derive(Clone, Copy, Data, Debug, PartialEq)]
40pub struct ParticleEmitterConfig {
41    /// Center direction angle in radians.
42    #[get(type(copy))]
43    pub(crate) base_angle: f32,
44    /// Angular cone spread in radians (`TAU` for full radial explosion).
45    #[get(type(copy))]
46    pub(crate) spread_rad: f32,
47    /// Minimum initial launch speed.
48    #[get(type(copy))]
49    pub(crate) min_speed: f32,
50    /// Maximum initial launch speed.
51    #[get(type(copy))]
52    pub(crate) max_speed: f32,
53    /// Minimum lifetime in seconds.
54    #[get(type(copy))]
55    pub(crate) min_life: f32,
56    /// Maximum lifetime in seconds.
57    #[get(type(copy))]
58    pub(crate) max_life: f32,
59    /// Starting particle radius.
60    #[get(type(copy))]
61    pub(crate) start_size: f32,
62    /// Ending particle radius.
63    #[get(type(copy))]
64    pub(crate) end_size: f32,
65    /// Starting particle color.
66    #[get(type(copy))]
67    pub(crate) start_color: Color,
68    /// Ending particle color.
69    #[get(type(copy))]
70    pub(crate) end_color: Color,
71    /// Linear drag per second.
72    #[get(type(copy))]
73    pub(crate) drag: f32,
74}
75
76/// Zero-allocation fixed-capacity 2D particle simulation engine using active-prefix SoA hot kinematics.
77#[derive(Clone, Data, Debug)]
78pub struct ParticleSystem {
79    /// Maximum concurrent particle slots pre-allocated in every SoA lane.
80    #[get(type(copy))]
81    #[get_mut(skip)]
82    #[set(skip)]
83    pub(crate) capacity: usize,
84    /// Hot SoA world-space X coordinates compacted in `[0..active_count)`.
85    #[get(skip)]
86    #[get_mut(skip)]
87    #[set(skip)]
88    pub(crate) pos_x: Vec<f32>,
89    /// Hot SoA world-space Y coordinates compacted in `[0..active_count)`.
90    #[get(skip)]
91    #[get_mut(skip)]
92    #[set(skip)]
93    pub(crate) pos_y: Vec<f32>,
94    /// Hot SoA X velocities compacted in `[0..active_count)`.
95    #[get(skip)]
96    #[get_mut(skip)]
97    #[set(skip)]
98    pub(crate) vel_x: Vec<f32>,
99    /// Hot SoA Y velocities compacted in `[0..active_count)`.
100    #[get(skip)]
101    #[get_mut(skip)]
102    #[set(skip)]
103    pub(crate) vel_y: Vec<f32>,
104    /// Hot SoA elapsed particle ages in seconds compacted in `[0..active_count)`.
105    #[get(skip)]
106    #[get_mut(skip)]
107    #[set(skip)]
108    pub(crate) age: Vec<f32>,
109    /// Hot SoA total particle lifetimes in seconds compacted in `[0..active_count)`.
110    #[get(skip)]
111    #[get_mut(skip)]
112    #[set(skip)]
113    pub(crate) lifetime: Vec<f32>,
114    /// Hot SoA linear drag coefficients compacted in `[0..active_count)`.
115    #[get(skip)]
116    #[get_mut(skip)]
117    #[set(skip)]
118    pub(crate) drag: Vec<f32>,
119    /// Cold SoA starting particle radii aligned 1:1 with `[0..active_count)`.
120    #[get(skip)]
121    #[get_mut(skip)]
122    #[set(skip)]
123    pub(crate) start_size: Vec<f32>,
124    /// Cold SoA ending particle radii aligned 1:1 with `[0..active_count)`.
125    #[get(skip)]
126    #[get_mut(skip)]
127    #[set(skip)]
128    pub(crate) end_size: Vec<f32>,
129    /// Cold SoA starting RGBA colors aligned 1:1 with `[0..active_count)`.
130    #[get(skip)]
131    #[get_mut(skip)]
132    #[set(skip)]
133    pub(crate) start_color: Vec<Color>,
134    /// Cold SoA ending RGBA colors aligned 1:1 with `[0..active_count)`.
135    #[get(skip)]
136    #[get_mut(skip)]
137    #[set(skip)]
138    pub(crate) end_color: Vec<Color>,
139    /// Conservative lower bound on remaining lifetime across active particles enabling branchless updates.
140    #[get(skip)]
141    #[get_mut(skip)]
142    #[set(skip)]
143    pub(crate) min_remaining_life: f32,
144    /// Next circular overwrite cursor used when `active_count == capacity`.
145    #[get(pub(crate), type(copy))]
146    #[set(pub(crate))]
147    pub(crate) cursor: usize,
148    /// Deterministic PRNG state for cross-platform bit-identical particle bursts.
149    #[get(pub(crate), type(copy))]
150    #[set(pub(crate))]
151    pub(crate) rng_state: u64,
152    /// Gravity applied to active particles.
153    #[get(type(copy))]
154    pub(crate) gravity: Point,
155    /// Live active particle count occupying `[0..active_count)`.
156    #[get(type(copy))]
157    pub(crate) active_count: usize,
158}