2021-08-12 11:52:21 -06:00
|
|
|
use hypoloop::core::{State, Loop};
|
2021-08-11 14:21:12 -06:00
|
|
|
|
2021-08-11 13:52:44 -06:00
|
|
|
fn main() {
|
2021-08-12 16:53:36 -06:00
|
|
|
// create a new sim loop
|
2021-08-12 00:34:13 -06:00
|
|
|
let mut sim = Loop::new();
|
2021-08-12 16:53:36 -06:00
|
|
|
sim.set_update_interval(20);
|
2021-08-11 14:21:12 -06:00
|
|
|
|
2021-08-12 00:34:13 -06:00
|
|
|
// test variable
|
|
|
|
let mut x: f32 = 0.0;
|
2021-08-11 20:20:26 -06:00
|
|
|
|
2021-08-12 12:01:34 -06:00
|
|
|
// create a closure containing your update logic
|
2021-08-13 02:46:56 -06:00
|
|
|
let mut tick = move |state: &mut State| {
|
2021-08-12 12:01:34 -06:00
|
|
|
// access loop metadata via the State object
|
2021-08-12 16:53:36 -06:00
|
|
|
x += state.get_timestep();
|
2021-08-12 11:52:21 -06:00
|
|
|
print!("x: {} | ", x);
|
|
|
|
|
2021-08-12 12:01:34 -06:00
|
|
|
// print information about the current tick's timings
|
2021-08-12 14:11:46 -06:00
|
|
|
state.debug_time();
|
2021-08-12 11:52:21 -06:00
|
|
|
};
|
2021-08-12 14:11:46 -06:00
|
|
|
|
2021-08-12 12:01:34 -06:00
|
|
|
// create a closure containing your display logic
|
2021-08-13 02:46:56 -06:00
|
|
|
let mut display = move |state: &mut State| {
|
2021-08-12 12:01:34 -06:00
|
|
|
//
|
2021-08-12 11:52:21 -06:00
|
|
|
};
|
2021-08-12 00:34:13 -06:00
|
|
|
|
2021-08-12 12:01:34 -06:00
|
|
|
// run the simulation with your user-defined update and display logic
|
2021-08-12 14:11:46 -06:00
|
|
|
// initialize the sim (cleans internal clocks, etc.)
|
|
|
|
sim.init();
|
|
|
|
loop {
|
|
|
|
// "step" the sim forward
|
2021-08-13 02:46:56 -06:00
|
|
|
sim.step(&mut tick, &mut display);
|
2021-08-12 14:11:46 -06:00
|
|
|
}
|
2021-08-11 20:20:26 -06:00
|
|
|
}
|