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.
77#[derive(Clone, Data, Debug)]
78pub struct ParticleSystem {
79    /// Pre-allocated contiguous particle pool.
80    pub(crate) pool: Vec<Particle>,
81    /// Next circular allocation cursor.
82    #[get(pub(crate), type(copy))]
83    #[set(pub(crate))]
84    pub(crate) cursor: usize,
85    /// Deterministic PRNG state for cross-platform bit-identical particle bursts.
86    #[get(pub(crate), type(copy))]
87    #[set(pub(crate))]
88    pub(crate) rng_state: u64,
89    /// Gravity applied to active particles.
90    #[get(type(copy))]
91    pub(crate) gravity: Point,
92    /// Live active particle count updated during `update`.
93    #[get(type(copy))]
94    pub(crate) active_count: usize,
95}