reorg time travel plugin. at last, teardown the old active_plugin cruft.

This commit is contained in:
Dustin Carlino 2018-12-24 17:59:21 -08:00
parent c83c4c4899
commit d56f2fad1c
5 changed files with 15 additions and 78 deletions

View File

@ -579,6 +579,7 @@ Plugin styles are blocking or ambient. And some can conflict...
- view mode... whew, one thing at a time.
- warp... exclusive blocking. apparently we used to still let ambient plugins draw and color stuff while it's active, but meh, doesnt seem important.
- search... argh, this is the one that's SOMETIMES exclusive blocking and sometimes stackable modal.
- finally, make time travel exclusive blocking, since lots of other stuff doesnt actually work with it.

View File

@ -1,7 +1,6 @@
pub mod debug;
pub mod edit;
pub mod sim;
pub mod time_travel;
pub mod view;
use crate::colors::ColorScheme;

View File

@ -2,3 +2,4 @@ pub mod controls;
pub mod diff_all;
pub mod diff_trip;
pub mod show_score;
pub mod time_travel;

View File

@ -1,4 +1,4 @@
use crate::plugins::{Plugin, PluginCtx};
use crate::plugins::PluginCtx;
use abstutil::MultiMap;
use map_model::{Map, Traversable};
use sim::{CarID, DrawCarInput, DrawPedestrianInput, GetDrawAgents, PedestrianID, Sim, Tick};
@ -63,10 +63,9 @@ impl TimeTravel {
fn get_current_state(&self) -> &StateAtTime {
&self.state_per_tick[self.current_tick.unwrap().as_usize() - self.first_tick.as_usize()]
}
}
impl Plugin for TimeTravel {
fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
// Don't really need to indicate activeness here.
pub fn event(&mut self, ctx: &mut PluginCtx) {
self.record_state(&ctx.primary.sim, &ctx.primary.map);
if let Some(tick) = self.current_tick {
@ -87,8 +86,6 @@ impl Plugin for TimeTravel {
} else if ctx.input.action_chosen("start time traveling") {
self.current_tick = Some(ctx.primary.sim.time);
}
self.is_active()
}
}

View File

@ -3,7 +3,6 @@ use crate::objects::{Ctx, RenderingHints, ID};
use crate::plugins;
use crate::plugins::debug;
use crate::plugins::edit;
use crate::plugins::time_travel::TimeTravel;
use crate::plugins::view;
use crate::plugins::{Plugin, PluginCtx};
use crate::render::{DrawMap, Renderable};
@ -53,8 +52,6 @@ pub struct DefaultUIState {
// Ambient plugins always exist, and they never block anything.
pub sim_controls: plugins::sim::controls::SimControls,
layers: debug::layers::ToggleableLayers,
active_plugin: Option<usize>,
}
impl DefaultUIState {
@ -72,48 +69,10 @@ impl DefaultUIState {
show_score: None,
sim_controls: plugins::sim::controls::SimControls::new(),
layers: debug::layers::ToggleableLayers::new(),
active_plugin: None,
};
state.layers.handle_zoom(-1.0, canvas.cam_zoom);
state
}
fn get_active_plugin(&self) -> Option<&Plugin> {
let idx = self.active_plugin?;
match idx {
x if x == 0 => Some(&self.primary_plugins.time_travel),
_ => {
panic!("Illegal active_plugin {}", idx);
}
}
}
fn run_plugin(
&mut self,
idx: usize,
input: &mut UserInput,
hints: &mut RenderingHints,
recalculate_current_selection: &mut bool,
cs: &mut ColorScheme,
canvas: &mut Canvas,
) -> bool {
let mut ctx = PluginCtx {
primary: &mut self.primary,
primary_plugins: None,
secondary: &mut self.secondary,
canvas,
cs,
input,
hints,
recalculate_current_selection,
};
match idx {
x if x == 0 => self.primary_plugins.time_travel.blocking_event(&mut ctx),
_ => {
panic!("Illegal active_plugin {}", idx);
}
}
}
}
impl UIState for DefaultUIState {
@ -150,7 +109,7 @@ impl UIState for DefaultUIState {
recalculate_current_selection,
};
// Special case!
// Special cases of weird blocking exclusive plugins!
if self
.primary_plugins
.search
@ -169,6 +128,11 @@ impl UIState for DefaultUIState {
}
return;
}
// Always run this here, to let it scrape sim state.
self.primary_plugins.time_travel.event(&mut ctx);
if self.primary_plugins.time_travel.is_active() {
return;
}
ctx.primary_plugins = Some(&mut self.primary_plugins);
if self.exclusive_blocking_plugin.is_some() {
@ -332,22 +296,6 @@ impl UIState for DefaultUIState {
self.sim_controls.ambient_event(&mut ctx);
}
self.layers.ambient_event(&mut ctx);
// TODO legacy stuff
// If there's an active plugin, just run it.
if let Some(idx) = self.active_plugin {
if !self.run_plugin(idx, input, hints, recalculate_current_selection, cs, canvas) {
self.active_plugin = None;
}
} else {
// Run each plugin, short-circuiting if the plugin claimed it was active.
for idx in 0..=0 {
if self.run_plugin(idx, input, hints, recalculate_current_selection, cs, canvas) {
self.active_plugin = Some(idx);
break;
}
}
}
}
fn get_objects_onscreen(
@ -403,11 +351,6 @@ impl UIState for DefaultUIState {
for p in &self.primary_plugins.ambient_plugins {
p.draw(g, ctx);
}
// TODO legacy
if let Some(p) = self.get_active_plugin() {
p.draw(g, ctx);
}
}
fn dump_before_abort(&self) {
@ -448,10 +391,6 @@ impl UIState for DefaultUIState {
}
}
// TODO legacy
if let Some(p) = self.get_active_plugin() {
return p.color_for(id, ctx);
}
None
}
@ -552,10 +491,10 @@ pub struct PluginsPerMap {
// When present, this either acts like exclusive blocking or like stackable modal. :\
search: Option<view::search::SearchState>,
ambient_plugins: Vec<Box<Plugin>>,
// This acts like exclusive blocking when active.
time_travel: plugins::sim::time_travel::TimeTravel,
// TODO legacy
time_travel: TimeTravel,
ambient_plugins: Vec<Box<Plugin>>,
}
impl PluginsPerMap {
@ -578,7 +517,7 @@ impl PluginsPerMap {
Box::new(view::show_route::ShowRouteState::new()),
Box::new(view::turn_cycler::TurnCyclerState::new()),
],
time_travel: TimeTravel::new(),
time_travel: plugins::sim::time_travel::TimeTravel::new(),
}
}
}