diff --git a/Cargo.lock b/Cargo.lock index d51b4de..b1228b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "hypoloop" -version = "0.1.4" +version = "0.1.5" diff --git a/Cargo.toml b/Cargo.toml index 1859ea3..a556918 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hypoloop" description = "A low-level control loop for real-time and baked simulations." -version = "0.1.4" +version = "0.1.5" edition = "2018" license = "GPL-3.0" repository = "https://github.com/skyeterran/hypoloop" diff --git a/examples/basics.rs b/examples/basics.rs index 08148eb..0b489f5 100644 --- a/examples/basics.rs +++ b/examples/basics.rs @@ -1,20 +1,24 @@ -use hypoloop::core::Loop; +use hypoloop::core::{State, Loop}; // look into using closures for this fn main() { // create sim and configure it let mut sim = Loop::new(); - //sim.set_realtime(false); // test variable let mut x: f32 = 0.0; - // run the simulation using custom update logic - sim.run(|state| { - state.debug_tick(); - - x += 2.0 * state.get_timescale(); + let update_logic = |state: &mut State| { + x += state.get_timescale(); + print!("x: {} | ", x); - //println!("Delta time: {} | Timescale: {} | Sim time: {} | x: {}", state.get_delta_time(), state.get_timescale(), state.get_sim_time().as_millis(), x); - }); + state.debug_tick(); + }; + + let display_logic = |state: &State| { + // put all display logic here + }; + + // run the simulation using custom update and display logic + sim.run(update_logic, display_logic); } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5bcb58f..3051e46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,7 +100,7 @@ pub mod core { } /// Initializes and runs the simulation using a user-supplied callback as the update logic - pub fn run(&mut self, mut update_callback: impl FnMut(&mut State)) { + pub fn run(&mut self, mut update_callback: impl FnMut(&mut State), mut display_callback: impl FnMut(&State)) { // Make sure the simulation will run self.state.simulate = true; @@ -133,7 +133,7 @@ pub mod core { // display if self.realtime { - display(delta_time(self.state.last_tick), self.state.timescale, self.state.update_interval); + display_callback(&self.state); } } }