mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
send Update events, fixing animation
This commit is contained in:
parent
46c07dc57a
commit
d2f0cd91ee
@ -68,6 +68,8 @@
|
|||||||
- speed
|
- speed
|
||||||
- make polygon store points and indices efficiently
|
- make polygon store points and indices efficiently
|
||||||
- change ezgui API to allow uploading geometry once
|
- change ezgui API to allow uploading geometry once
|
||||||
|
- event loop feels sticky
|
||||||
|
- first make UserInput borrow state and not need to consume
|
||||||
- experiment with batching and not passing colors
|
- experiment with batching and not passing colors
|
||||||
- measure performance of huge maps
|
- measure performance of huge maps
|
||||||
- quality
|
- quality
|
||||||
|
@ -302,21 +302,15 @@ pub fn run<T, G: GUI<T>>(mut gui: G, window_title: &str) {
|
|||||||
|
|
||||||
let mut accumulator = Duration::new(0, 0);
|
let mut accumulator = Duration::new(0, 0);
|
||||||
let mut previous_clock = Instant::now();
|
let mut previous_clock = Instant::now();
|
||||||
let mut lazy_events = true;
|
let mut wait_for_events = false;
|
||||||
let mut redraw = false;
|
|
||||||
loop {
|
loop {
|
||||||
if redraw {
|
|
||||||
state.draw(&display, &program);
|
|
||||||
state.after_render();
|
|
||||||
redraw = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut new_events: Vec<glutin::WindowEvent> = Vec::new();
|
let mut new_events: Vec<glutin::WindowEvent> = Vec::new();
|
||||||
events_loop.poll_events(|event| {
|
events_loop.poll_events(|event| {
|
||||||
if let glutin::Event::WindowEvent { event, .. } = event {
|
if let glutin::Event::WindowEvent { event, .. } = event {
|
||||||
new_events.push(event);
|
new_events.push(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
let any_new_events = !new_events.is_empty();
|
||||||
for event in new_events {
|
for event in new_events {
|
||||||
if event == glutin::WindowEvent::CloseRequested {
|
if event == glutin::WindowEvent::CloseRequested {
|
||||||
state.gui.before_quit();
|
state.gui.before_quit();
|
||||||
@ -326,25 +320,32 @@ pub fn run<T, G: GUI<T>>(mut gui: G, window_title: &str) {
|
|||||||
if let Some(ev) = Event::from_glutin_event(event) {
|
if let Some(ev) = Event::from_glutin_event(event) {
|
||||||
let (new_state, mode) = state.event(ev);
|
let (new_state, mode) = state.event(ev);
|
||||||
state = new_state;
|
state = new_state;
|
||||||
lazy_events = mode == EventLoopMode::InputOnly;
|
wait_for_events = mode == EventLoopMode::InputOnly;
|
||||||
redraw = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let now = Instant::now();
|
if any_new_events || !wait_for_events {
|
||||||
accumulator += now - previous_clock;
|
state.draw(&display, &program);
|
||||||
previous_clock = now;
|
state.after_render();
|
||||||
|
|
||||||
let fixed_time_stamp = Duration::new(0, 16_666_667);
|
|
||||||
while accumulator >= fixed_time_stamp {
|
|
||||||
accumulator -= fixed_time_stamp;
|
|
||||||
// TODO send off an update event
|
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(fixed_time_stamp - accumulator);
|
if !wait_for_events {
|
||||||
if !redraw && !lazy_events {
|
let (new_state, mode) = state.event(Event::Update);
|
||||||
redraw = true;
|
state = new_state;
|
||||||
|
wait_for_events = mode == EventLoopMode::InputOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO This isn't right at all... sleep only if nothing happened.
|
||||||
|
if !any_new_events && wait_for_events {
|
||||||
|
let now = Instant::now();
|
||||||
|
accumulator += now - previous_clock;
|
||||||
|
previous_clock = now;
|
||||||
|
let fixed_time_stamp = Duration::new(0, 16_666_667);
|
||||||
|
while accumulator >= fixed_time_stamp {
|
||||||
|
accumulator -= fixed_time_stamp;
|
||||||
|
}
|
||||||
|
thread::sleep(fixed_time_stamp - accumulator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user