Added display callback, restoring full functionality
This commit is contained in:
parent
1801cb9d80
commit
4faaf7d2c1
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4,4 +4,4 @@ version = 3
|
||||
|
||||
[[package]]
|
||||
name = "hypoloop"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user