pub struct BeamPool { /* private fields */ }Implementations§
Source§impl BeamPool
impl BeamPool
pub fn new(capacity: usize, policy: OverflowPolicy) -> BeamPool
pub fn try_new( capacity: usize, policy: OverflowPolicy, ) -> Result<BeamPool, BeamError>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
pub fn dropped(&self) -> u64
pub fn replaced(&self) -> u64
pub fn clear(&mut self)
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clears beams, overflow counters and admission ordering while retaining
the allocated storage, capacity and overflow policy. Self::clear
preserves the counters instead.
use ferravex_play::particles::{BeamDesc, BeamError, BeamPool, OverflowPolicy};
let mut pool = BeamPool::new(1, OverflowPolicy::DropNewest);
pool.spawn(BeamDesc::default()).unwrap();
assert_eq!(pool.spawn(BeamDesc::default()), Err(BeamError::Full));
pool.reset();
assert!(pool.is_empty());
assert_eq!((pool.capacity(), pool.dropped(), pool.replaced()), (1, 0, 0));
pool.spawn(BeamDesc::default()).unwrap();Sourcepub fn set_endpoints(
&mut self,
index: usize,
start: [f32; 3],
end: [f32; 3],
) -> Result<bool, BeamError>
pub fn set_endpoints( &mut self, index: usize, start: [f32; 3], end: [f32; 3], ) -> Result<bool, BeamError>
Moves the beam at the current Self::iter index without changing its
age, lifetime, colors, width or replacement priority. Both endpoints must
be finite; coincident endpoints are allowed. Invalid input leaves the
entire pool unchanged. Valid input with no beam at index returns false.
Indices are temporary positions, not identities: aging can compact the pool and spawning can replace a beam. Reacquire indices after those calls.
use ferravex_play::particles::{BeamDesc, BeamPool, OverflowPolicy};
let mut pool = BeamPool::new(1, OverflowPolicy::DropNewest);
pool.spawn(BeamDesc { lifetime: 1.0, ..BeamDesc::default() }).unwrap();
pool.update(0.25).unwrap();
assert!(pool.set_endpoints(0, [1.0, 0.0, 0.0], [3.0, 0.0, 0.0]).unwrap());
assert_eq!(pool.iter().next().unwrap().normalized_age, 0.25);
assert!(!pool.set_endpoints(1, [0.0; 3], [0.0; 3]).unwrap());Sourcepub fn reset_beam(
&mut self,
index: usize,
desc: BeamDesc,
) -> Result<bool, BeamError>
pub fn reset_beam( &mut self, index: usize, desc: BeamDesc, ) -> Result<bool, BeamError>
Reconfigures a beam at the current Self::iter index and restarts its
lifetime/fade at age zero. It becomes newest for equal-age replacement
ties. This does not spawn, change length or increment overflow counters.
Validation precedes lookup: invalid descriptors return
BeamError::InvalidBeam without mutation, and valid descriptors with
no beam at index return false. Indices have the same temporary meaning
as in Self::set_endpoints.
use ferravex_play::particles::{BeamDesc, BeamPool, OverflowPolicy};
let mut pool = BeamPool::new(1, OverflowPolicy::ReplaceOldest);
pool.spawn(BeamDesc { lifetime: 1.0, ..BeamDesc::default() }).unwrap();
pool.update(0.5).unwrap();
assert!(pool.reset_beam(0, BeamDesc::default()).unwrap());
assert_eq!(pool.iter().next().unwrap().normalized_age, 0.0);
assert_eq!(pool.replaced(), 0);