1786004955
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::thread::sleep;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use self::input::InputState;
|
||||
@@ -36,30 +37,23 @@ impl Trekstor {
|
||||
|
||||
pub fn update(&mut self, update: UpdateFn) {
|
||||
loop {
|
||||
println!("Step");
|
||||
self.input.handle_event();
|
||||
self.last_time = self.current_time;
|
||||
self.current_time = Instant::now();
|
||||
let mut dt = self.current_time - self.last_time;
|
||||
let dt = self.current_time - self.last_time;
|
||||
|
||||
if dt > Duration::from_millis(100) {
|
||||
dt = Duration::from_millis(100);
|
||||
println!("Frame");
|
||||
|
||||
if !update(&mut self.screen, &self.input) {
|
||||
return;
|
||||
}
|
||||
|
||||
while self.accumulator > self.update_timestep {
|
||||
println!("Frame");
|
||||
self.screen.flush();
|
||||
self.input.finish();
|
||||
|
||||
if !update(&mut self.screen, &self.input) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.screen.flush();
|
||||
self.input.finish();
|
||||
|
||||
self.accumulator -= self.update_timestep;
|
||||
}
|
||||
|
||||
self.accumulator += dt;
|
||||
let wait_time = self.update_timestep - dt;
|
||||
dbg!(wait_time);
|
||||
sleep(wait_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user