diff --git a/examples/example00.rs b/examples/example00.rs index 0ef28ce..3fc68e3 100644 --- a/examples/example00.rs +++ b/examples/example00.rs @@ -11,6 +11,9 @@ impl Callbacks for Example { fn update(&mut self) {} fn draw(&self, graphics: &mut Graphics) {} fn clean_up(self) {} + fn do_next_step(&self) -> bool { + true + } } pub fn main() { diff --git a/src/lib.rs b/src/lib.rs index 8b9fbdc..42f9b23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,7 @@ pub trait Callbacks { fn update(&mut self); fn draw(&self, graphics: &mut Graphics); fn clean_up(self); + fn do_next_step(&self) -> bool; } pub fn run(config: Config) { @@ -30,7 +31,7 @@ pub fn run(config: Config) { let mut state = C::load_state(); state.pre_loop(); - loop { + while state.do_next_step() { state.update(); for ev in graphics.get_events() { state.handle_event(ev); @@ -46,22 +47,28 @@ mod tests { use crate::run; struct TestCallbacks { + stepper: u32, } impl Callbacks for TestCallbacks { fn load_state() -> Self { TestCallbacks{ + stepper: 0, } } //fn preLoop(&mut self){} fn handle_event(&mut self, ev: Event){ } fn update(&mut self){ + self.stepper = self.stepper + 1; } fn draw(&self, graphics: &mut Graphics){ } fn clean_up(self){ } + fn do_next_step(&self) -> bool{ + self.stepper < 999999 + } } #[test]