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
impl Emitter
pub fn new(desc: EmitterDesc, seed: u64) -> Result<Emitter, ParticleError>
pub fn config(&self) -> EmitterDesc
pub fn set_config(&mut self, desc: EmitterDesc) -> Result<(), ParticleError>
pub fn set_rate(&mut self, rate: f32) -> Result<(), ParticleError>
pub fn stats(&self) -> EmissionStats
pub fn sequence(&self) -> u64
pub fn reset(&mut self, seed: u64)
pub fn teleport( &mut self, transform: EmitterTransform, ) -> Result<(), ParticleError>
Sourcepub fn update(
&mut self,
dt: f32,
transform: EmitterTransform,
pool: &mut ParticlePool,
) -> Result<EmissionStats, ParticleError>
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.
Sourcepub fn burst(
&mut self,
count: u32,
transform: EmitterTransform,
pool: &mut ParticlePool,
) -> Result<EmissionStats, ParticleError>
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.
Sourcepub fn burst_admission(
&self,
count: u32,
budget: u16,
pool: &ParticlePool,
) -> BurstAdmission
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());Sourcepub fn burst_with_budget(
&mut self,
count: u32,
budget: u16,
transform: EmitterTransform,
pool: &mut ParticlePool,
) -> Result<EmissionStats, ParticleError>
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);