use crate::prelude::*;
use std::time::Duration;
#[derive(Clone)]
pub struct ClosureBehaviour<T, P, S>
where
T: Clone + Send + Sync,
P: Fn(&mut T, &mut RenderableParams, Duration, &Scene, Point<isize>) + Clone + Send + Sync,
S: Fn(&T, &Img, Point<f64>, Duration, Point<isize>) -> Rgba<u8> + Clone + Send + Sync,
{
pub data: T,
pub process: P,
pub shader: S,
}
impl<T, P, S> Behaviour for ClosureBehaviour<T, P, S>
where
T: Clone + Send + Sync,
P: Fn(&mut T, &mut RenderableParams, Duration, &Scene, Point<isize>) + Clone + Send + Sync,
S: Fn(&T, &Img, Point<f64>, Duration, Point<isize>) -> Rgba<u8> + Clone + Send + Sync,
{
fn process(
&mut self,
params: &mut RenderableParams,
time: Duration,
scene: &Scene,
abs_position: Point<isize>,
) {
(self.process)(&mut self.data, params, time, scene, abs_position);
}
fn get_pixel(
&self,
current_frame: &Img,
uv_coords: Point<f64>,
time: Duration,
abs_position: Point<isize>,
) -> Rgba<u8> {
(self.shader)(&self.data, current_frame, uv_coords, time, abs_position)
}
}