use a loading screen when exiting a/b test mode, since it's so laggy

This commit is contained in:
Dustin Carlino 2019-06-24 14:43:59 -07:00
parent 36b3558db5
commit 66b21c81ec
4 changed files with 15 additions and 12 deletions

View File

@ -189,12 +189,15 @@ impl State for ABTestMode {
self.speed.pause();
}
fn on_destroy(&mut self, ui: &mut UI) {
// TODO Should we clear edits too?
ui.primary.reset_sim();
fn on_destroy(&mut self, ctx: &mut EventCtx, ui: &mut UI) {
ctx.loading_screen("exit A/B test mode", |_, timer| {
timer.start("destroy secondary sim");
// TODO Should we clear edits too?
ui.primary.reset_sim();
// Note destroying this has some noticeable delay.
ui.secondary = None;
ui.secondary = None;
timer.stop("destroy secondary sim");
});
}
}

View File

@ -279,7 +279,7 @@ impl State for EditMode {
self.menu.draw(g);
}
fn on_destroy(&mut self, ui: &mut UI) {
fn on_destroy(&mut self, _: &mut EventCtx, ui: &mut UI) {
// TODO Warn about unsaved edits
// TODO Maybe put a loading screen around these.
ui.primary

View File

@ -70,7 +70,7 @@ impl GUI for Game {
match transition {
Transition::KeepWithMode(evmode) => evmode,
Transition::PopWithMode(evmode) => {
self.states.pop().unwrap().on_destroy(&mut self.ui);
self.states.pop().unwrap().on_destroy(ctx, &mut self.ui);
if self.states.is_empty() {
self.before_quit(ctx.canvas);
std::process::exit(0);
@ -81,7 +81,7 @@ impl GUI for Game {
evmode
}
Transition::PopWithData(cb) => {
self.states.pop().unwrap().on_destroy(&mut self.ui);
self.states.pop().unwrap().on_destroy(ctx, &mut self.ui);
cb(self.states.last_mut().unwrap());
if self.idx_draw_base == Some(self.states.len()) {
self.idx_draw_base = None;
@ -101,7 +101,7 @@ impl GUI for Game {
evmode
}
Transition::ReplaceWithMode(state, evmode) => {
self.states.pop().unwrap().on_destroy(&mut self.ui);
self.states.pop().unwrap().on_destroy(ctx, &mut self.ui);
if self.idx_draw_base == Some(self.states.len()) {
self.idx_draw_base = None;
}
@ -182,7 +182,7 @@ pub trait State: downcast_rs::Downcast {
// Before we push a new state on top of this one, call this.
fn on_suspend(&mut self, _: &mut UI) {}
// Before this state is popped or replaced, call this.
fn on_destroy(&mut self, _: &mut UI) {}
fn on_destroy(&mut self, _: &mut EventCtx, _: &mut UI) {}
// We don't need an on_enter -- the constructor for the state can just do it.
}

View File

@ -50,7 +50,7 @@ impl State for TutorialMode {
self.menu.draw(g);
}
fn on_destroy(&mut self, ui: &mut UI) {
fn on_destroy(&mut self, _: &mut EventCtx, ui: &mut UI) {
ui.primary.reset_sim();
}
}
@ -86,7 +86,7 @@ impl State for Part2 {
self.menu.draw(g);
}
fn on_destroy(&mut self, ui: &mut UI) {
fn on_destroy(&mut self, _: &mut EventCtx, ui: &mut UI) {
ui.primary.reset_sim();
}
}