Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

ParticlePool

Struct ParticlePool 

Source
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>

Source

pub const fn new() -> Self

A brand-new empty pool. Const-safe for static-array init.

Source

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.

Source

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 in x_frac to the next frame).
  • vy += gravity (Q4.4, so 1 = 0.0625 px/frame² falling).
  • ttl -= 1 – particle expires when it hits zero.
Source

pub fn clear(&mut self)

Clear every slot. Use when resetting between levels so leftover particles don’t float in from the previous scene.

Source

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.

Source

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.

Source

pub fn particles(&self) -> &[Particle; N]

Immutable view of the raw particle array. Debugging helper; most consumers don’t need this.

Trait Implementations§

Source§

impl<const N: usize> Default for ParticlePool<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for ParticlePool<N>

§

impl<const N: usize> RefUnwindSafe for ParticlePool<N>

§

impl<const N: usize> Send for ParticlePool<N>

§

impl<const N: usize> Sync for ParticlePool<N>

§

impl<const N: usize> Unpin for ParticlePool<N>

§

impl<const N: usize> UnsafeUnpin for ParticlePool<N>

§

impl<const N: usize> UnwindSafe for ParticlePool<N>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.