td

pool.rs at trunk
Login

pool.rs at trunk

File src/behavior/pool.rs artifact d636833568 on branch trunk


//! The `PoolBehavior` trait and its dispatch runner. Concrete pool behaviors (acid, slow)
//! live in `crate::pools`; the `GroundPool` entity lives in `crate::pool`.

use crate::{
    behavior::{dyn_clone_trait, projectile::BehaviorPriority},
    context::TickContext,
    pool::GroundPool,
};

pub trait PoolBehavior: PoolClone + Send + Sync {
    fn on_tick(&mut self, _pool: &mut GroundPool, _c: &mut TickContext) {}
    fn priority(&self) -> i32 {
        BehaviorPriority::DEFAULT
    }
}

dyn_clone_trait!(PoolClone, PoolBehavior);

pub fn dispatch_pool_tick(g: &mut GroundPool, c: &mut TickContext) {
    let mut behaviors = std::mem::take(&mut g.behaviors);
    for b in behaviors.iter_mut() {
        b.on_tick(g, c);
    }
    g.behaviors = behaviors;
}