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]]
|
[[package]]
|
||||||
name = "hypoloop"
|
name = "hypoloop"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hypoloop"
|
name = "hypoloop"
|
||||||
description = "A low-level control loop for real-time and baked simulations."
|
description = "A low-level control loop for real-time and baked simulations."
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
repository = "https://github.com/skyeterran/hypoloop"
|
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
|
// look into using closures for this
|
||||||
fn main() {
|
fn main() {
|
||||||
// create sim and configure it
|
// create sim and configure it
|
||||||
let mut sim = Loop::new();
|
let mut sim = Loop::new();
|
||||||
//sim.set_realtime(false);
|
|
||||||
|
|
||||||
// test variable
|
// test variable
|
||||||
let mut x: f32 = 0.0;
|
let mut x: f32 = 0.0;
|
||||||
|
|
||||||
// run the simulation using custom update logic
|
let update_logic = |state: &mut State| {
|
||||||
sim.run(|state| {
|
x += state.get_timescale();
|
||||||
|
print!("x: {} | ", x);
|
||||||
|
|
||||||
state.debug_tick();
|
state.debug_tick();
|
||||||
|
};
|
||||||
|
|
||||||
x += 2.0 * state.get_timescale();
|
let display_logic = |state: &State| {
|
||||||
|
// put all display logic here
|
||||||
|
};
|
||||||
|
|
||||||
//println!("Delta time: {} | Timescale: {} | Sim time: {} | x: {}", state.get_delta_time(), state.get_timescale(), state.get_sim_time().as_millis(), x);
|
// 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
|
/// 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
|
// Make sure the simulation will run
|
||||||
self.state.simulate = true;
|
self.state.simulate = true;
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ pub mod core {
|
|||||||
|
|
||||||
// display
|
// display
|
||||||
if self.realtime {
|
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