1786004709
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
use std::thread::sleep;
|
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use self::input::InputState;
|
use self::input::InputState;
|
||||||
@@ -37,6 +36,7 @@ impl Trekstor {
|
|||||||
|
|
||||||
pub fn update(&mut self, update: UpdateFn) {
|
pub fn update(&mut self, update: UpdateFn) {
|
||||||
loop {
|
loop {
|
||||||
|
println!("Step");
|
||||||
self.input.handle_event();
|
self.input.handle_event();
|
||||||
self.last_time = self.current_time;
|
self.last_time = self.current_time;
|
||||||
self.current_time = Instant::now();
|
self.current_time = Instant::now();
|
||||||
@@ -47,17 +47,19 @@ impl Trekstor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while self.accumulator > self.update_timestep {
|
while self.accumulator > self.update_timestep {
|
||||||
|
println!("Frame");
|
||||||
|
|
||||||
if !update(&mut self.screen, &self.input) {
|
if !update(&mut self.screen, &self.input) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.screen.flush();
|
||||||
|
self.input.finish();
|
||||||
|
|
||||||
self.accumulator -= self.update_timestep;
|
self.accumulator -= self.update_timestep;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.screen.flush();
|
|
||||||
self.input.finish();
|
|
||||||
|
|
||||||
self.accumulator += dt;
|
self.accumulator += dt;
|
||||||
sleep(Duration::from_millis(1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ pub struct InputState {
|
|||||||
keys_down: HashSet<KeyCode>,
|
keys_down: HashSet<KeyCode>,
|
||||||
keys_pressed_this_update: HashSet<KeyCode>,
|
keys_pressed_this_update: HashSet<KeyCode>,
|
||||||
keys_released_this_update: HashSet<KeyCode>,
|
keys_released_this_update: HashSet<KeyCode>,
|
||||||
clear_before_next_event: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputState {
|
impl InputState {
|
||||||
@@ -32,7 +31,6 @@ impl InputState {
|
|||||||
keys_down: HashSet::new(),
|
keys_down: HashSet::new(),
|
||||||
keys_pressed_this_update: HashSet::new(),
|
keys_pressed_this_update: HashSet::new(),
|
||||||
keys_released_this_update: HashSet::new(),
|
keys_released_this_update: HashSet::new(),
|
||||||
clear_before_next_event: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,13 +44,6 @@ impl InputState {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// if self.clear_before_next_event {
|
|
||||||
// self.keys_pressed_this_update.clear();
|
|
||||||
// self.keys_released_this_update.clear();
|
|
||||||
// self.clear_before_next_event = false;
|
|
||||||
// println!("cleared");
|
|
||||||
// }
|
|
||||||
|
|
||||||
for event in events {
|
for event in events {
|
||||||
match event.destructure() {
|
match event.destructure() {
|
||||||
EventSummary::AbsoluteAxis(_, AbsoluteAxisCode::ABS_X, value) => {
|
EventSummary::AbsoluteAxis(_, AbsoluteAxisCode::ABS_X, value) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user