start tutorial with sim playing

This commit is contained in:
Dustin Carlino 2018-12-18 09:46:18 -08:00
parent 7621f6a999
commit ac961f2016
3 changed files with 20 additions and 6 deletions

View File

@ -31,6 +31,14 @@ impl SimControls {
primary_events: None, primary_events: None,
} }
} }
pub fn run_sim(&mut self, primary_sim: &mut Sim) {
self.state = State::Running {
last_step: Instant::now(),
benchmark: primary_sim.start_benchmark(),
speed: "running".to_string(),
};
}
} }
impl Plugin for SimControls { impl Plugin for SimControls {
@ -118,11 +126,7 @@ impl Plugin for SimControls {
} }
if ctx.input.action_chosen("run/pause sim") { if ctx.input.action_chosen("run/pause sim") {
self.state = State::Running { self.run_sim(&mut ctx.primary.sim);
last_step: Instant::now(),
benchmark: ctx.primary.sim.start_benchmark(),
speed: "running".to_string(),
};
} else if ctx.input.action_chosen("run one step of sim") { } else if ctx.input.action_chosen("run one step of sim") {
let tick = ctx.primary.sim.time; let tick = ctx.primary.sim.time;
let events = ctx.primary.sim.step(&ctx.primary.map); let events = ctx.primary.sim.step(&ctx.primary.map);

View File

@ -6,7 +6,7 @@ mod show_score;
use crate::objects::Ctx; use crate::objects::Ctx;
use crate::plugins::{Plugin, PluginCtx}; use crate::plugins::{Plugin, PluginCtx};
use ezgui::GfxCtx; use ezgui::GfxCtx;
use sim::{Event, Tick}; use sim::{Event, Sim, Tick};
// TODO This is per UI, so it's never reloaded. Make sure to detect new loads, even when the // TODO This is per UI, so it's never reloaded. Make sure to detect new loads, even when the
// initial time is 0? But we probably have no state then, so... // initial time is 0? But we probably have no state then, so...
@ -44,6 +44,13 @@ impl SimMode {
None None
} }
} }
pub fn run_sim(&mut self, primary_sim: &mut Sim) {
self.ambient_plugins[1]
.downcast_mut::<controls::SimControls>()
.unwrap()
.run_sim(primary_sim);
}
} }
impl Plugin for SimMode { impl Plugin for SimMode {

View File

@ -62,6 +62,9 @@ impl UIState for TutorialState {
State::GiveInstructions(ref mut scroller) => { State::GiveInstructions(ref mut scroller) => {
if scroller.event(input) { if scroller.event(input) {
setup_scenario(&mut self.main.primary); setup_scenario(&mut self.main.primary);
// TODO Levels of indirection now feel bad. I almost want dependency injection
// -- just give me the SimControls.
self.main.sim_mode.run_sim(&mut self.main.primary.sim);
self.state = State::Play { self.state = State::Play {
last_tick_observed: None, last_tick_observed: None,
spawned_from_north: 0, spawned_from_north: 0,