Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Nek0 - | 795243d14e | |
Nek0 - | 13c86a98d7 |
|
@ -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() {
|
||||
|
|
34
src/lib.rs
34
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<C: Callbacks>(config: Config) {
|
||||
|
@ -30,7 +31,7 @@ pub fn run<C: Callbacks>(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);
|
||||
|
@ -42,10 +43,37 @@ pub fn run<C: Callbacks>(config: Config) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Config;
|
||||
use super::{Config, Callbacks, Event, Graphics};
|
||||
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]
|
||||
fn it_works() {
|
||||
let _config = Config::default();
|
||||
let config = Config::default();
|
||||
run::<TestCallbacks>(config);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue