pub struct ParticlePool<const N: usize> { /* private fields */ }Expand description
Fixed-capacity pool of N particles.
Uses a linear search for free slots on spawn. N up to ~128
is comfortably fast on a 33 MHz MIPS – if you’re routinely
saturating a 256+ pool you want a proper object pool with a
free-list, which lives at the engine layer.
Implementations§
Source§impl<const N: usize> ParticlePool<N>
impl<const N: usize> ParticlePool<N>
Sourcepub fn spawn_burst(
&mut self,
rng: &mut LcgRng,
centre: (i16, i16),
color: (u8, u8, u8),
count: usize,
velocity_range: i16,
ttl: u8,
)
pub fn spawn_burst( &mut self, rng: &mut LcgRng, centre: (i16, i16), color: (u8, u8, u8), count: usize, velocity_range: i16, ttl: u8, )
Spawn count particles at centre with velocities
scattered within [-velocity_range, +velocity_range] on
each axis (Q4.4). Colour and TTL are uniform across the
burst.
Finds free slots via linear scan; if the pool is full the
burst is truncated silently. Callers that care about
guaranteed-spawns should size the pool to
max_concurrent_bursts * count_per_burst.
rng is stepped for each spawned particle, seeding two
signed values per axis.
Sourcepub fn update(&mut self, gravity: i16)
pub fn update(&mut self, gravity: i16)
One simulation step for every live particle:
- Position += velocity (Q4.4: whole pixels move
x, the remainder carries inx_fracto the next frame). vy += gravity(Q4.4, so 1 = 0.0625 px/frame² falling).ttl -= 1– particle expires when it hits zero.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear every slot. Use when resetting between levels so leftover particles don’t float in from the previous scene.
Sourcepub fn render_into_frame<'f, const OT_N: usize>(
&self,
frame: &mut OtFrame<'f, OT_N>,
rects: &mut PrimitiveArena<'f, RectFlat>,
z: u8,
shake: (i16, i16),
) -> usize
pub fn render_into_frame<'f, const OT_N: usize>( &self, frame: &mut OtFrame<'f, OT_N>, rects: &mut PrimitiveArena<'f, RectFlat>, z: u8, shake: (i16, i16), ) -> usize
Render every live particle as a RectFlat from rects into
frame at slot z, stopping when the arena runs out. Returns the
number of rects written.
Colour fades with ttl / spawn_ttl and size tapers from 3 px to
2 px.
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
How many slots currently hold live particles. O(N) scan – useful for debugging budgets + tests, not hot-path code.