Struct Emitter

Source
pub struct Emitter { /* private fields */ }
Expand description

Particle position/velocity and spawn shapes are emitter-local; acceleration remains world-space so rotating a nozzle does not rotate gravity. Counter-seeded emission: dropped work still advances the sequence without iterating it, so pool capacity/quality cannot perturb a gameplay RNG or the random values assigned to later requested particles. No per-frame allocation.

Implementations§

Source§

impl Emitter

Source

pub fn new(desc: EmitterDesc, seed: u64) -> Result<Emitter, ParticleError>

Source

pub fn config(&self) -> EmitterDesc

Source

pub fn set_config(&mut self, desc: EmitterDesc) -> Result<(), ParticleError>

Source

pub fn set_rate(&mut self, rate: f32) -> Result<(), ParticleError>

Source

pub fn stats(&self) -> EmissionStats

Source

pub fn sequence(&self) -> u64

Source

pub fn reset(&mut self, seed: u64)

Source

pub fn teleport( &mut self, transform: EmitterTransform, ) -> Result<(), ParticleError>

Source

pub fn update( &mut self, dt: f32, transform: EmitterTransform, pool: &mut ParticlePool, ) -> Result<EmissionStats, ParticleError>

Update the existing pool first, then emit along previous->current motion. New particles catch up from their actual within-frame birth times. Large demand retains newest bounded samples; skipped demand never catches up later.

Source

pub fn burst( &mut self, count: u32, transform: EmitterTransform, pool: &mut ParticlePool, ) -> Result<EmissionStats, ParticleError>

Burst samples share a birth time. Continuous rate phase is unchanged. Uses the configured per-call maximum; see Self::burst_with_budget for a caller-supplied lower budget and detailed admission semantics.

Source

pub fn burst_admission( &self, count: u32, budget: u16, pool: &ParticlePool, ) -> BurstAdmission

Preview a burst’s work and capacity limits without allocating, consuming sequence numbers, changing statistics or reserving pool slots.

budget is a per-call limit, capped by EmitterDesc::max_per_update. Zero suppresses all samples. Budget drops are counted before capacity drops, so every requested particle belongs to exactly one category. This query does not validate a transform or sample any particles.

use ferravex_play::particles::{BurstAdmission, Emitter, EmitterDesc, ParticlePool};
let emitter = Emitter::new(EmitterDesc::default(), 42)?;
let pool = ParticlePool::new(3);
let plan: BurstAdmission = emitter.burst_admission(10, 4, &pool);
assert_eq!((plan.admitted, plan.dropped_budget, plan.dropped_capacity), (3, 6, 1));
assert_eq!(emitter.sequence(), 0);
assert!(pool.is_empty());
Source

pub fn burst_with_budget( &mut self, count: u32, budget: u16, transform: EmitterTransform, pool: &mut ParticlePool, ) -> Result<EmissionStats, ParticleError>

Emit an immediate burst with an additional per-call work limit.

At most min(count, budget, config.max_per_update, pool.available()) samples are attempted. Excess demand is dropped without iteration or deferred catch-up; zero budget is valid. Budgets above the configured maximum are clamped. Multiple calls have independent budgets: callers enforcing a shared frame budget must pass its remaining allowance.

As with Self::burst, the newest admitted sequence numbers are sampled and all requested particles advance the wrapping seeded sequence, including dropped or invalid samples. The result accounts for each request in spawned, dropped_budget, dropped_capacity, expired or invalid. Admitted samples that fail validation are not replaced.

A non-finite or degenerate transform returns ParticleError::InvalidParticle without mutating the emitter or pool, even with zero count or budget. Bursts never age existing particles, change the continuous rate phase or motion history, or allocate storage. New particles have age zero and no inherited emitter velocity. Use Self::burst_admission to inspect the limits beforehand; it is a snapshot, not a reservation.

use ferravex_play::particles::{Emitter, EmitterDesc, EmitterTransform, ParticlePool};
let mut emitter = Emitter::new(EmitterDesc::default(), 42)?;
let mut pool = ParticlePool::new(2);
let result = emitter.burst_with_budget(8, 3, EmitterTransform::default(), &mut pool)?;
assert_eq!((result.spawned, result.dropped_budget, result.dropped_capacity), (2, 5, 1));
assert_eq!(emitter.sequence(), 8);
let muted = emitter.burst_with_budget(5, 0, EmitterTransform::default(), &mut pool)?;
assert_eq!(muted.dropped_budget, 5);
assert_eq!(emitter.sequence(), 13);

Trait Implementations§

Source§

impl Clone for Emitter

Source§

fn clone(&self) -> Emitter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Emitter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.