mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 16:02:23 +03:00
dont redraw on ignored Update events either
This commit is contained in:
parent
0c26e3e127
commit
cab95e91e2
@ -181,7 +181,7 @@ impl AmbientPluginWithPrimaryPlugins for SimControls {
|
||||
} else {
|
||||
ctx.hints.mode = EventLoopMode::Animation;
|
||||
|
||||
if ctx.input.is_update_event() {
|
||||
if ctx.input.nonblocking_is_update_event() {
|
||||
// TODO https://gafferongames.com/post/fix_your_timestep/
|
||||
// TODO This doesn't interact correctly with the fixed 30 Update events
|
||||
// sent per second. Even Benchmark is kind of wrong. I think we want to
|
||||
@ -189,6 +189,7 @@ impl AmbientPluginWithPrimaryPlugins for SimControls {
|
||||
// the speed says we should.
|
||||
let dt_s = elapsed_seconds(*last_step);
|
||||
if dt_s >= TIMESTEP.inner_seconds() / self.desired_speed {
|
||||
ctx.input.use_update_event();
|
||||
let time = ctx.primary.sim.time();
|
||||
let events = ctx.primary.sim.step(&ctx.primary.map);
|
||||
self.primary_events = Some((time, events));
|
||||
@ -198,12 +199,12 @@ impl AmbientPluginWithPrimaryPlugins for SimControls {
|
||||
s.sim.step(&s.map);
|
||||
}
|
||||
*last_step = Instant::now();
|
||||
}
|
||||
|
||||
if benchmark.has_real_time_passed(Duration::seconds(1.0)) {
|
||||
// I think the benchmark should naturally account for the delay of the
|
||||
// secondary sim.
|
||||
*speed = ctx.primary.sim.measure_speed(benchmark);
|
||||
if benchmark.has_real_time_passed(Duration::seconds(1.0)) {
|
||||
// I think the benchmark should naturally account for the delay of
|
||||
// the secondary sim.
|
||||
*speed = ctx.primary.sim.measure_speed(benchmark);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ impl UserInput {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn is_update_event(&mut self) -> bool {
|
||||
pub fn nonblocking_is_update_event(&mut self) -> bool {
|
||||
if self.context_menu_active() {
|
||||
return false;
|
||||
}
|
||||
@ -403,12 +403,11 @@ impl UserInput {
|
||||
return false;
|
||||
}
|
||||
|
||||
if self.event == Event::Update {
|
||||
self.consume_event();
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
self.event == Event::Update
|
||||
}
|
||||
pub fn use_update_event(&mut self) {
|
||||
self.consume_event();
|
||||
assert!(self.event == Event::Update)
|
||||
}
|
||||
|
||||
// TODO I'm not sure this is even useful anymore
|
||||
|
@ -91,10 +91,10 @@ impl<T, G: GUI<T>> State<T, G> {
|
||||
self.canvas = canvas;
|
||||
self.last_data = Some(data);
|
||||
// TODO We should always do has_been_consumed, but various hacks prevent this from being
|
||||
// true. For now, just avoid the specific annoying redraw case when a KeyRelease event is
|
||||
// unused.
|
||||
// true. For now, just avoid the specific annoying redraw case when a KeyRelease or Update
|
||||
// event is unused.
|
||||
let input_used = match ev {
|
||||
Event::KeyRelease(_) => input.has_been_consumed(),
|
||||
Event::KeyRelease(_) | Event::Update => input.has_been_consumed(),
|
||||
_ => true,
|
||||
};
|
||||
self.context_menu = input.context_menu.maybe_build(&self.canvas);
|
||||
|
Loading…
Reference in New Issue
Block a user