mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 01:13:53 +03:00
start tutorial with sim playing
This commit is contained in:
parent
7621f6a999
commit
ac961f2016
@ -31,6 +31,14 @@ impl SimControls {
|
||||
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 {
|
||||
@ -118,11 +126,7 @@ impl Plugin for SimControls {
|
||||
}
|
||||
|
||||
if ctx.input.action_chosen("run/pause sim") {
|
||||
self.state = State::Running {
|
||||
last_step: Instant::now(),
|
||||
benchmark: ctx.primary.sim.start_benchmark(),
|
||||
speed: "running".to_string(),
|
||||
};
|
||||
self.run_sim(&mut ctx.primary.sim);
|
||||
} else if ctx.input.action_chosen("run one step of sim") {
|
||||
let tick = ctx.primary.sim.time;
|
||||
let events = ctx.primary.sim.step(&ctx.primary.map);
|
||||
|
@ -6,7 +6,7 @@ mod show_score;
|
||||
use crate::objects::Ctx;
|
||||
use crate::plugins::{Plugin, PluginCtx};
|
||||
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
|
||||
// initial time is 0? But we probably have no state then, so...
|
||||
@ -44,6 +44,13 @@ impl SimMode {
|
||||
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 {
|
||||
|
@ -62,6 +62,9 @@ impl UIState for TutorialState {
|
||||
State::GiveInstructions(ref mut scroller) => {
|
||||
if scroller.event(input) {
|
||||
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 {
|
||||
last_tick_observed: None,
|
||||
spawned_from_north: 0,
|
||||
|
Loading…
Reference in New Issue
Block a user