move recalc_current_selection... it's this temporary bit of state

This commit is contained in:
Dustin Carlino 2018-12-13 11:19:10 -08:00
parent 8e715de098
commit f9016c6871
4 changed files with 25 additions and 19 deletions

View File

@ -44,7 +44,7 @@ impl Plugin for DebugMode {
if self.hider.event(ctx.input, ctx.primary.current_selection)
|| self.layers.event(ctx.input)
{
ctx.primary.recalculate_current_selection = true;
*ctx.recalculate_current_selection = true;
ctx.primary.current_selection = None;
}

View File

@ -47,6 +47,7 @@ pub struct PluginCtx<'a> {
pub cs: &'a mut ColorScheme,
pub input: &'a mut UserInput,
pub hints: &'a mut RenderingHints,
pub recalculate_current_selection: &'a mut bool,
}
// TODO Further refactoring should be done, but at least group these here to start.

View File

@ -61,7 +61,7 @@ impl Plugin for SimControls {
mem::swap(primary_plugins, &mut secondary_plugins);
ctx.primary_plugins = Some(primary_plugins);
*ctx.secondary = Some((secondary, secondary_plugins));
ctx.primary.recalculate_current_selection = true;
*ctx.recalculate_current_selection = true;
}
match self.state {
@ -89,7 +89,7 @@ impl Plugin for SimControls {
// TODO From the perspective of other SimMode plugins, does this just
// look like the simulation stepping forwards?
ctx.primary.sim = new_sim;
ctx.primary.recalculate_current_selection = true;
*ctx.recalculate_current_selection = true;
if let Some((s, _)) = ctx.secondary {
s.sim = Sim::load_savestate(
@ -114,7 +114,7 @@ impl Plugin for SimControls {
{
Ok(new_sim) => {
ctx.primary.sim = new_sim;
ctx.primary.recalculate_current_selection = true;
*ctx.recalculate_current_selection = true;
if let Some((s, _)) = ctx.secondary {
s.sim = Sim::load_savestate(
@ -135,7 +135,7 @@ impl Plugin for SimControls {
.unimportant_key_pressed(Key::S, SIM, "Seed the map with agents")
{
ctx.primary.sim.small_spawn(&ctx.primary.map);
ctx.primary.recalculate_current_selection = true;
*ctx.recalculate_current_selection = true;
}
if ctx
@ -152,7 +152,7 @@ impl Plugin for SimControls {
.unimportant_key_pressed(Key::M, SIM, "run one step")
{
ctx.primary.sim.step(&ctx.primary.map);
ctx.primary.recalculate_current_selection = true;
*ctx.recalculate_current_selection = true;
if let Some((s, _)) = ctx.secondary {
s.sim.step(&s.map);
}
@ -176,7 +176,7 @@ impl Plugin for SimControls {
let dt_s = elapsed_seconds(*last_step);
if dt_s >= TIMESTEP.value_unsafe / self.desired_speed {
ctx.primary.sim.step(&ctx.primary.map);
ctx.primary.recalculate_current_selection = true;
*ctx.recalculate_current_selection = true;
if let Some((s, _)) = ctx.secondary {
s.sim.step(&s.map);
}

View File

@ -62,14 +62,25 @@ impl GUI<RenderingHints> for UI {
}
// If there's an active plugin, just run it.
let mut recalculate_current_selection = false;
if let Some(idx) = self.active_plugin {
if !self.run_plugin(idx, &mut input, &mut hints) {
if !self.run_plugin(
idx,
&mut input,
&mut hints,
&mut recalculate_current_selection,
) {
self.active_plugin = None;
}
} else {
// Run each plugin, short-circuiting if the plugin claimed it was active.
for idx in 0..self.plugins.list.len() + self.primary_plugins.list.len() {
if self.run_plugin(idx, &mut input, &mut hints) {
if self.run_plugin(
idx,
&mut input,
&mut hints,
&mut recalculate_current_selection,
) {
self.active_plugin = Some(idx);
break;
}
@ -85,8 +96,7 @@ impl GUI<RenderingHints> for UI {
process::exit(0);
}
if self.primary.recalculate_current_selection {
self.primary.recalculate_current_selection = false;
if recalculate_current_selection {
self.primary.current_selection = self.mouseover_something();
}
@ -163,16 +173,11 @@ pub struct PerMapUI {
pub sim: Sim,
pub current_selection: Option<ID>,
pub recalculate_current_selection: bool,
pub current_flags: SimFlags,
}
impl PerMapUI {
pub fn new(
flags: SimFlags,
kml: Option<String>,
canvas: &Canvas,
) -> (PerMapUI, PluginsPerMap) {
pub fn new(flags: SimFlags, kml: Option<String>, canvas: &Canvas) -> (PerMapUI, PluginsPerMap) {
let mut timer = abstutil::Timer::new("setup PerMapUI");
let (map, sim) = sim::load(flags.clone(), Some(Tick::from_seconds(30)), &mut timer);
@ -198,9 +203,7 @@ impl PerMapUI {
map,
draw_map,
sim,
current_selection: None,
recalculate_current_selection: false,
current_flags: flags,
};
let plugins = PluginsPerMap::new(&state, canvas, &mut timer);
@ -309,6 +312,7 @@ impl UI {
idx: usize,
input: &mut UserInput,
hints: &mut RenderingHints,
recalculate_current_selection: &mut bool,
) -> bool {
let mut ctx = PluginCtx {
primary: &mut self.primary,
@ -318,6 +322,7 @@ impl UI {
cs: &mut self.cs,
input,
hints,
recalculate_current_selection,
};
let len = self.plugins.list.len();
if idx < len {