Struct BeamPool

Source
pub struct BeamPool { /* private fields */ }

Implementations§

Source§

impl BeamPool

Source

pub fn new(capacity: usize, policy: OverflowPolicy) -> BeamPool

Source

pub fn try_new( capacity: usize, policy: OverflowPolicy, ) -> Result<BeamPool, BeamError>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> usize

Source

pub fn dropped(&self) -> u64

Source

pub fn replaced(&self) -> u64

Source

pub fn clear(&mut self)

Source

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();
Source

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());
Source

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

pub fn spawn(&mut self, desc: BeamDesc) -> Result<(), BeamError>

Source

pub fn update(&mut self, dt: f32) -> Result<(), BeamError>

Source

pub fn iter(&self) -> impl ExactSizeIterator

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> 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, 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.