mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
move PerMapUI to state module
This commit is contained in:
parent
b8ca1728e2
commit
a3a41ed186
@ -1,7 +1,6 @@
|
||||
use crate::objects::{Ctx, SIM_SETUP};
|
||||
use crate::plugins::{choose_edits, choose_scenario, load_ab_test, Plugin, PluginCtx};
|
||||
use crate::state::PluginsPerMap;
|
||||
use crate::ui::PerMapUI;
|
||||
use crate::state::{PerMapUI, PluginsPerMap};
|
||||
use ezgui::{Canvas, GfxCtx, LogScroller, Wizard, WrappedWizard};
|
||||
use map_model::Map;
|
||||
use piston::input::Key;
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::objects::{Ctx, SIM_SETUP};
|
||||
use crate::plugins::{choose_edits, Plugin, PluginCtx};
|
||||
use crate::state::PluginsPerMap;
|
||||
use crate::ui::PerMapUI;
|
||||
use crate::state::{PerMapUI, PluginsPerMap};
|
||||
use ezgui::{Canvas, GfxCtx, Wizard, WrappedWizard};
|
||||
use map_model::Map;
|
||||
use piston::input::Key;
|
||||
|
@ -7,8 +7,7 @@ pub mod view;
|
||||
|
||||
use crate::colors::ColorScheme;
|
||||
use crate::objects::{Ctx, RenderingHints, ID};
|
||||
use crate::state::PluginsPerMap;
|
||||
use crate::ui::PerMapUI;
|
||||
use crate::state::{PerMapUI, PluginsPerMap};
|
||||
use ::sim::{ABTest, Neighborhood, NeighborhoodBuilder, OriginDestination, Scenario, Tick};
|
||||
use abstutil;
|
||||
use abstutil::WeightedUsizeChoice;
|
||||
|
@ -7,12 +7,11 @@ use crate::plugins::sim::SimMode;
|
||||
use crate::plugins::time_travel::TimeTravel;
|
||||
use crate::plugins::view::ViewMode;
|
||||
use crate::plugins::{Plugin, PluginCtx};
|
||||
use crate::render::Renderable;
|
||||
use crate::ui::PerMapUI;
|
||||
use crate::render::{DrawMap, Renderable};
|
||||
use abstutil::Timer;
|
||||
use ezgui::{Canvas, Color, GfxCtx, UserInput};
|
||||
use map_model::IntersectionID;
|
||||
use sim::{GetDrawAgents, SimFlags};
|
||||
use map_model::{IntersectionID, Map};
|
||||
use sim::{GetDrawAgents, Sim, SimFlags, Tick};
|
||||
|
||||
pub trait UIState {
|
||||
fn handle_zoom(&mut self, old_zoom: f64, new_zoom: f64);
|
||||
@ -247,6 +246,52 @@ impl ShowTurnIcons for DefaultUIState {
|
||||
}
|
||||
}
|
||||
|
||||
// All of the state that's bound to a specific map+edit has to live here.
|
||||
pub struct PerMapUI {
|
||||
pub map: Map,
|
||||
pub draw_map: DrawMap,
|
||||
pub sim: Sim,
|
||||
|
||||
pub current_selection: Option<ID>,
|
||||
pub current_flags: SimFlags,
|
||||
}
|
||||
|
||||
impl PerMapUI {
|
||||
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);
|
||||
let extra_shapes: Vec<kml::ExtraShape> = if let Some(path) = kml {
|
||||
if path.ends_with(".kml") {
|
||||
kml::load(&path, &map.get_gps_bounds(), &mut timer)
|
||||
.expect("Couldn't load extra KML shapes")
|
||||
.shapes
|
||||
} else {
|
||||
let shapes: kml::ExtraShapes =
|
||||
abstutil::read_binary(&path, &mut timer).expect("Couldn't load ExtraShapes");
|
||||
shapes.shapes
|
||||
}
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
timer.start("draw_map");
|
||||
let draw_map = DrawMap::new(&map, extra_shapes, &mut timer);
|
||||
timer.stop("draw_map");
|
||||
|
||||
let state = PerMapUI {
|
||||
map,
|
||||
draw_map,
|
||||
sim,
|
||||
current_selection: None,
|
||||
current_flags: flags,
|
||||
};
|
||||
let plugins = PluginsPerMap::new(&state, canvas, &mut timer);
|
||||
timer.done();
|
||||
(state, plugins)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PluginsPerMap {
|
||||
// Anything that holds onto any kind of ID has to live here!
|
||||
debug_mode: DebugMode,
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::colors::ColorScheme;
|
||||
use crate::objects::{Ctx, RenderingHints, ID};
|
||||
use crate::render::Renderable;
|
||||
use crate::state::{DefaultUIState, UIState};
|
||||
use crate::ui::PerMapUI;
|
||||
use crate::state::{DefaultUIState, PerMapUI, UIState};
|
||||
use ezgui::{Canvas, Color, GfxCtx, LogScroller, UserInput};
|
||||
use sim::SimFlags;
|
||||
|
||||
|
@ -2,15 +2,13 @@ use crate::colors::ColorScheme;
|
||||
use abstutil;
|
||||
//use cpuprofiler;
|
||||
use crate::objects::{Ctx, RenderingHints, ID, ROOT_MENU};
|
||||
use crate::render::{DrawMap, RenderOptions};
|
||||
use crate::state::{PluginsPerMap, UIState};
|
||||
use crate::render::RenderOptions;
|
||||
use crate::state::UIState;
|
||||
use ezgui::{Canvas, Color, EventLoopMode, GfxCtx, Text, UserInput, BOTTOM_LEFT, GUI};
|
||||
use kml;
|
||||
use map_model::{BuildingID, LaneID, Map};
|
||||
use map_model::{BuildingID, LaneID};
|
||||
use piston::input::Key;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use sim;
|
||||
use sim::{Sim, SimFlags, Tick};
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::process;
|
||||
@ -117,54 +115,6 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
}
|
||||
}
|
||||
|
||||
// All of the state that's bound to a specific map+edit has to live here.
|
||||
// TODO How can we arrange the code so that we statically know that we don't pass anything from UI
|
||||
// to something in PerMapUI?
|
||||
pub struct PerMapUI {
|
||||
pub map: Map,
|
||||
pub draw_map: DrawMap,
|
||||
pub sim: Sim,
|
||||
|
||||
pub current_selection: Option<ID>,
|
||||
pub current_flags: SimFlags,
|
||||
}
|
||||
|
||||
impl PerMapUI {
|
||||
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);
|
||||
let extra_shapes: Vec<kml::ExtraShape> = if let Some(path) = kml {
|
||||
if path.ends_with(".kml") {
|
||||
kml::load(&path, &map.get_gps_bounds(), &mut timer)
|
||||
.expect("Couldn't load extra KML shapes")
|
||||
.shapes
|
||||
} else {
|
||||
let shapes: kml::ExtraShapes =
|
||||
abstutil::read_binary(&path, &mut timer).expect("Couldn't load ExtraShapes");
|
||||
shapes.shapes
|
||||
}
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
timer.start("draw_map");
|
||||
let draw_map = DrawMap::new(&map, extra_shapes, &mut timer);
|
||||
timer.stop("draw_map");
|
||||
|
||||
let state = PerMapUI {
|
||||
map,
|
||||
draw_map,
|
||||
sim,
|
||||
current_selection: None,
|
||||
current_flags: flags,
|
||||
};
|
||||
let plugins = PluginsPerMap::new(&state, canvas, &mut timer);
|
||||
timer.done();
|
||||
(state, plugins)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: UIState> UI<S> {
|
||||
pub fn new(state: S, canvas: Canvas) -> UI<S> {
|
||||
let mut ui = UI {
|
||||
|
Loading…
Reference in New Issue
Block a user