Skip to main content

ParticleSystem

Trait ParticleSystem 

Source
pub trait ParticleSystem {
    type ParticleType: Particle;
    type EmitterType: ParticleEmitter<ParticleType = Self::ParticleType>;

    // Required methods
    fn iter_particles(&self) -> impl Iterator<Item = &Self::ParticleType>;
    fn iter_particles_mut(
        &mut self,
    ) -> impl Iterator<Item = &mut Self::ParticleType>;
    fn iter_emitters(&self) -> impl Iterator<Item = &Self::EmitterType>;
    fn iter_emitters_mut(
        &mut self,
    ) -> impl Iterator<Item = &mut Self::EmitterType>;
    fn add_particle(&mut self, particle: Self::ParticleType);
    fn add_emitter(&mut self, emitter: Self::EmitterType);
    fn clean_particles(&mut self);
    fn clean_emitters(&mut self);

    // Provided methods
    fn update_particles(&mut self, dt: f64) { ... }
    fn update_emitters(&mut self, dt: f64) -> Vec<Self::ParticleType> { ... }
    fn update(&mut self, dt: f64) { ... }
}
Expand description

A collection of particles and emitters

Required Associated Types§

Source

type ParticleType: Particle

The type of particle that this system will contain

Source

type EmitterType: ParticleEmitter<ParticleType = Self::ParticleType>

The type of emitter that this system will contain

Required Methods§

Source

fn iter_particles(&self) -> impl Iterator<Item = &Self::ParticleType>

Returns an iterator over all currently alive particles in the system

Source

fn iter_particles_mut( &mut self, ) -> impl Iterator<Item = &mut Self::ParticleType>

Returns a mutable iterator over all currently alive particles in the system

Source

fn iter_emitters(&self) -> impl Iterator<Item = &Self::EmitterType>

Returns an iterator over all currently alive particle emitters in the system

Source

fn iter_emitters_mut(&mut self) -> impl Iterator<Item = &mut Self::EmitterType>

Returns a mutable iterator over all currently alive particle emitters in the system

Source

fn add_particle(&mut self, particle: Self::ParticleType)

Adds a particle to the system

Source

fn add_emitter(&mut self, emitter: Self::EmitterType)

Adds an emitter to the system

Source

fn clean_particles(&mut self)

Removes dead particles from the system

Source

fn clean_emitters(&mut self)

Removes dead emitters from the system

Provided Methods§

Source

fn update_particles(&mut self, dt: f64)

Iterates over all currently alive particles in the system and calls their update method

Source

fn update_emitters(&mut self, dt: f64) -> Vec<Self::ParticleType>

Iterates over all currently alive particle emitters in the system and calls their update method, returning the vector of new particles to add to the system

Source

fn update(&mut self, dt: f64)

Updates the particle system

This method is comprised of 3 steps:

  1. Update emitters and add the new particles to the system
  2. Update all particles in the system
  3. Remove dead particles and emitters from the system

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§