use std::slice::{Iter, IterMut};
pub trait ParticleSys {
type T: ParticleSys;
fn is_active(&self) -> bool;
fn is_looping(&self) -> bool;
fn is_initialized(&mut self) -> bool;
fn reset_time(&mut self);
fn elapsed_time(&mut self) -> Option<f32>;
fn setup(&mut self, should_loop: bool, p: Option<f32>) -> Result<(), String>;
fn tear_down(&mut self);
fn next_frame(&mut self, time: Option<f32>) -> Result<bool, String>;
fn iter(&self) -> Option<Iter<'_, Self::T>>;
fn iter_mut(&mut self) -> Option<IterMut<'_, Self::T>>;
fn with_period(self, p: f32) -> Result<Self, String>
where
Self: Sized;
fn start_loop(&mut self) -> Result<(), String> {
self.tear_down();
self.setup(true, None)
}
fn start(&mut self) -> Result<(), String> {
self.tear_down();
self.setup(false, None)
}
fn stop(&mut self) {
self.tear_down();
}
fn run(&mut self) -> Result<bool, String> {
if !(self.is_active() && self.is_initialized()) {
return Err("object has not been setup yet for running".into());
}
let elapsed = self.elapsed_time();
if !self.next_frame(elapsed)? {
if self.is_looping() {
self.reset_time();
}
Ok(false)
} else {
Ok(true)
}
}
}