2019-04-30 00:40:48 +03:00
|
|
|
use crate::helpers::{ColorScheme, ID};
|
2019-02-17 01:26:29 +03:00
|
|
|
use crate::render::{
|
2019-08-14 23:11:45 +03:00
|
|
|
draw_vehicle, AgentCache, DrawCtx, DrawMap, DrawOptions, DrawPedCrowd, DrawPedestrian,
|
|
|
|
Renderable, MIN_ZOOM_FOR_DETAIL,
|
2019-02-17 01:26:29 +03:00
|
|
|
};
|
2019-02-15 00:01:26 +03:00
|
|
|
use abstutil;
|
2019-06-07 20:59:13 +03:00
|
|
|
use abstutil::{MeasureMemory, Timer};
|
2019-08-15 00:32:02 +03:00
|
|
|
use ezgui::{Canvas, Color, EventCtx, GfxCtx, Prerender, Text};
|
2019-08-10 02:16:36 +03:00
|
|
|
use geom::{Bounds, Circle, Distance};
|
2019-05-11 02:21:21 +03:00
|
|
|
use map_model::{Map, Traversable};
|
2019-06-21 01:15:14 +03:00
|
|
|
use rand::seq::SliceRandom;
|
2018-12-06 22:05:11 +03:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2019-08-16 20:35:47 +03:00
|
|
|
use sim::{GetDrawAgents, Sim, SimFlags, SimOptions};
|
2019-04-29 19:27:43 +03:00
|
|
|
use structopt::StructOpt;
|
2018-03-13 18:04:21 +03:00
|
|
|
|
2019-04-22 03:30:04 +03:00
|
|
|
pub struct UI {
|
2019-04-29 19:27:43 +03:00
|
|
|
pub primary: PerMapUI,
|
2019-06-24 02:45:58 +03:00
|
|
|
// Invariant: This is Some(...) iff we're in A/B test mode or a sub-state.
|
|
|
|
pub secondary: Option<PerMapUI>,
|
2019-04-29 19:27:43 +03:00
|
|
|
pub cs: ColorScheme,
|
2018-09-13 08:43:58 +03:00
|
|
|
}
|
2018-03-13 18:04:21 +03:00
|
|
|
|
2019-04-22 03:30:04 +03:00
|
|
|
impl UI {
|
2019-06-21 01:15:14 +03:00
|
|
|
pub fn new(flags: Flags, ctx: &mut EventCtx, splash: bool) -> UI {
|
2019-04-29 19:27:43 +03:00
|
|
|
let cs = ColorScheme::load().unwrap();
|
2019-06-07 20:59:13 +03:00
|
|
|
let primary = ctx.loading_screen("load map", |ctx, mut timer| {
|
|
|
|
PerMapUI::new(flags, &cs, ctx, &mut timer)
|
|
|
|
});
|
2019-06-21 01:15:14 +03:00
|
|
|
|
|
|
|
let mut rng = primary.current_flags.sim_flags.make_rng();
|
|
|
|
let rand_focus_pt = primary
|
|
|
|
.map
|
|
|
|
.all_buildings()
|
|
|
|
.choose(&mut rng)
|
|
|
|
.and_then(|b| ID::Building(b.id).canonical_point(&primary))
|
|
|
|
.or_else(|| {
|
|
|
|
primary
|
|
|
|
.map
|
|
|
|
.all_lanes()
|
|
|
|
.choose(&mut rng)
|
|
|
|
.and_then(|l| ID::Lane(l.id).canonical_point(&primary))
|
|
|
|
})
|
|
|
|
.expect("Can't get canonical_point of a random building or lane");
|
|
|
|
|
|
|
|
if splash {
|
|
|
|
ctx.canvas.center_on_map_pt(rand_focus_pt);
|
|
|
|
} else {
|
2019-08-05 21:36:49 +03:00
|
|
|
let path = abstutil::path_editor_state(primary.map.get_name());
|
|
|
|
match abstutil::read_json::<EditorState>(&path) {
|
|
|
|
Ok(ref loaded) => {
|
|
|
|
println!("Loaded {}", path);
|
2019-06-21 01:15:14 +03:00
|
|
|
ctx.canvas.cam_x = loaded.cam_x;
|
|
|
|
ctx.canvas.cam_y = loaded.cam_y;
|
|
|
|
ctx.canvas.cam_zoom = loaded.cam_zoom;
|
|
|
|
}
|
|
|
|
_ => {
|
2019-08-05 21:36:49 +03:00
|
|
|
println!(
|
|
|
|
"Couldn't load {}, so just focusing on an arbitrary building",
|
|
|
|
path
|
|
|
|
);
|
2019-06-21 01:15:14 +03:00
|
|
|
ctx.canvas.center_on_map_pt(rand_focus_pt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-24 02:45:58 +03:00
|
|
|
UI {
|
|
|
|
primary,
|
|
|
|
cs,
|
|
|
|
secondary: None,
|
|
|
|
}
|
2018-10-22 05:23:47 +03:00
|
|
|
}
|
2018-10-21 22:18:25 +03:00
|
|
|
|
2019-04-29 23:55:59 +03:00
|
|
|
pub fn draw(
|
2019-04-24 21:16:50 +03:00
|
|
|
&self,
|
|
|
|
g: &mut GfxCtx,
|
2019-04-29 23:55:59 +03:00
|
|
|
opts: DrawOptions,
|
2019-04-26 01:23:45 +03:00
|
|
|
source: &GetDrawAgents,
|
2019-04-26 02:56:38 +03:00
|
|
|
show_objs: &ShowObject,
|
2019-04-24 21:16:50 +03:00
|
|
|
) {
|
|
|
|
let ctx = DrawCtx {
|
2019-04-29 19:27:43 +03:00
|
|
|
cs: &self.cs,
|
|
|
|
map: &self.primary.map,
|
|
|
|
draw_map: &self.primary.draw_map,
|
|
|
|
sim: &self.primary.sim,
|
2019-04-24 21:16:50 +03:00
|
|
|
};
|
|
|
|
let mut sample_intersection: Option<String> = None;
|
|
|
|
|
2019-04-29 19:27:43 +03:00
|
|
|
g.clear(self.cs.get_def("true background", Color::BLACK));
|
|
|
|
g.redraw(&self.primary.draw_map.boundary_polygon);
|
2019-04-24 21:16:50 +03:00
|
|
|
|
|
|
|
if g.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL && !g.is_screencap() {
|
|
|
|
// Unzoomed mode
|
2019-04-26 08:19:54 +03:00
|
|
|
let layers = show_objs.layers();
|
|
|
|
if layers.show_areas {
|
2019-04-29 19:27:43 +03:00
|
|
|
g.redraw(&self.primary.draw_map.draw_all_areas);
|
2019-04-24 21:16:50 +03:00
|
|
|
}
|
2019-04-26 08:19:54 +03:00
|
|
|
if layers.show_lanes {
|
2019-04-29 19:27:43 +03:00
|
|
|
g.redraw(&self.primary.draw_map.draw_all_thick_roads);
|
2019-04-24 21:16:50 +03:00
|
|
|
}
|
2019-04-26 08:19:54 +03:00
|
|
|
if layers.show_intersections {
|
2019-04-29 19:27:43 +03:00
|
|
|
g.redraw(&self.primary.draw_map.draw_all_unzoomed_intersections);
|
2019-04-24 21:16:50 +03:00
|
|
|
}
|
2019-04-26 08:19:54 +03:00
|
|
|
if layers.show_buildings {
|
2019-04-29 19:27:43 +03:00
|
|
|
g.redraw(&self.primary.draw_map.draw_all_buildings);
|
2019-04-24 21:16:50 +03:00
|
|
|
}
|
|
|
|
|
2019-05-10 00:00:07 +03:00
|
|
|
if layers.show_extra_shapes {
|
|
|
|
for es in &self.primary.draw_map.extra_shapes {
|
2019-08-15 01:09:54 +03:00
|
|
|
if show_objs.show(&es.get_id()) {
|
2019-05-10 00:00:07 +03:00
|
|
|
es.draw(g, &opts, &ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still show area/extra shape selection when zoomed out.
|
2019-04-29 19:27:43 +03:00
|
|
|
if let Some(ID::Area(id)) = self.primary.current_selection {
|
2019-04-27 22:02:32 +03:00
|
|
|
g.draw_polygon(
|
2019-04-29 19:27:43 +03:00
|
|
|
self.cs.get("selected"),
|
2019-05-12 01:00:46 +03:00
|
|
|
&ctx.draw_map.get_a(id).get_outline(&ctx.map),
|
2019-04-27 22:02:32 +03:00
|
|
|
);
|
2019-05-10 00:00:07 +03:00
|
|
|
} else if let Some(ID::ExtraShape(id)) = self.primary.current_selection {
|
|
|
|
g.draw_polygon(
|
|
|
|
self.cs.get("selected"),
|
2019-05-12 01:00:46 +03:00
|
|
|
&ctx.draw_map.get_es(id).get_outline(&ctx.map),
|
2019-05-10 00:00:07 +03:00
|
|
|
);
|
2019-04-24 21:16:50 +03:00
|
|
|
}
|
|
|
|
|
2019-08-07 19:41:40 +03:00
|
|
|
if !opts.suppress_unzoomed_agents {
|
2019-08-15 00:32:02 +03:00
|
|
|
let mut cache = self.primary.draw_map.agents.borrow_mut();
|
|
|
|
cache.draw_unzoomed_agents(&self.primary, &self.cs, g);
|
2019-06-01 19:28:28 +03:00
|
|
|
}
|
2019-04-24 21:16:50 +03:00
|
|
|
} else {
|
2019-04-29 19:27:43 +03:00
|
|
|
let mut cache = self.primary.draw_map.agents.borrow_mut();
|
2019-04-24 21:16:50 +03:00
|
|
|
let objects = self.get_renderables_back_to_front(
|
|
|
|
g.get_screen_bounds(),
|
|
|
|
&g.prerender,
|
|
|
|
&mut cache,
|
2019-04-26 01:23:45 +03:00
|
|
|
source,
|
2019-04-26 02:56:38 +03:00
|
|
|
show_objs,
|
2019-04-24 21:16:50 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
let mut drawn_all_buildings = false;
|
|
|
|
let mut drawn_all_areas = false;
|
|
|
|
|
|
|
|
for obj in objects {
|
|
|
|
match obj.get_id() {
|
2019-08-13 21:26:18 +03:00
|
|
|
ID::Building(b) => {
|
2019-04-24 21:16:50 +03:00
|
|
|
if !drawn_all_buildings {
|
2019-04-29 19:27:43 +03:00
|
|
|
g.redraw(&self.primary.draw_map.draw_all_buildings);
|
2019-04-24 21:16:50 +03:00
|
|
|
drawn_all_buildings = true;
|
|
|
|
}
|
2019-08-13 21:26:18 +03:00
|
|
|
// TODO Cache the Sections in DrawBldg
|
|
|
|
if opts.label_buildings {
|
|
|
|
let bldg = ctx.map.get_b(b);
|
|
|
|
if let Some(num) = bldg.osm_tags.get("addr:housenumber") {
|
|
|
|
let mut txt = Text::with_bg_color(None);
|
|
|
|
txt.add_styled_line(
|
|
|
|
num.to_string(),
|
|
|
|
Some(Color::BLACK),
|
|
|
|
None,
|
|
|
|
Some(50),
|
|
|
|
);
|
|
|
|
g.draw_text_at_mapspace(&txt, bldg.polygon.center());
|
|
|
|
}
|
|
|
|
}
|
2019-04-24 21:16:50 +03:00
|
|
|
}
|
|
|
|
ID::Area(_) => {
|
|
|
|
if !drawn_all_areas {
|
2019-04-29 19:27:43 +03:00
|
|
|
g.redraw(&self.primary.draw_map.draw_all_areas);
|
2019-04-24 21:16:50 +03:00
|
|
|
drawn_all_areas = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
};
|
2019-04-30 00:31:12 +03:00
|
|
|
obj.draw(g, &opts, &ctx);
|
2019-04-24 21:16:50 +03:00
|
|
|
|
2019-04-29 19:27:43 +03:00
|
|
|
if self.primary.current_selection == Some(obj.get_id()) {
|
2019-04-24 21:16:50 +03:00
|
|
|
g.draw_polygon(
|
2019-05-12 01:15:03 +03:00
|
|
|
self.cs.get_def("selected", Color::RED.alpha(0.7)),
|
2019-05-12 01:00:46 +03:00
|
|
|
&obj.get_outline(&ctx.map),
|
2019-04-24 21:16:50 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if g.is_screencap() && sample_intersection.is_none() {
|
|
|
|
if let ID::Intersection(id) = obj.get_id() {
|
|
|
|
sample_intersection = Some(format!("_i{}", id.0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(i) = sample_intersection {
|
|
|
|
g.set_screencap_naming_hint(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-24 23:26:00 +03:00
|
|
|
// Assumes some defaults.
|
|
|
|
pub fn recalculate_current_selection(&mut self, ctx: &EventCtx) {
|
|
|
|
self.primary.current_selection =
|
|
|
|
self.calculate_current_selection(ctx, &self.primary.sim, &ShowEverything::new(), false);
|
|
|
|
}
|
|
|
|
|
2019-04-26 01:23:45 +03:00
|
|
|
// Because we have to sometimes borrow part of self for GetDrawAgents, this just returns the
|
|
|
|
// Option<ID> that the caller should assign. When this monolithic UI nonsense is dismantled,
|
|
|
|
// this weirdness goes away.
|
2019-06-24 23:26:00 +03:00
|
|
|
pub fn calculate_current_selection(
|
2019-04-26 01:23:45 +03:00
|
|
|
&self,
|
2019-06-06 22:12:03 +03:00
|
|
|
ctx: &EventCtx,
|
2019-04-26 01:23:45 +03:00
|
|
|
source: &GetDrawAgents,
|
2019-04-26 02:56:38 +03:00
|
|
|
show_objs: &ShowObject,
|
2019-05-20 01:01:40 +03:00
|
|
|
debug_mode: bool,
|
2019-04-26 01:23:45 +03:00
|
|
|
) -> Option<ID> {
|
2019-06-06 22:12:03 +03:00
|
|
|
// Unzoomed mode. Ignore when debugging areas and extra shapes.
|
|
|
|
if ctx.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL && !debug_mode {
|
|
|
|
return None;
|
|
|
|
}
|
2019-04-30 00:44:43 +03:00
|
|
|
|
2019-06-06 22:12:03 +03:00
|
|
|
let pt = ctx.canvas.get_cursor_in_map_space()?;
|
|
|
|
|
|
|
|
let mut cache = self.primary.draw_map.agents.borrow_mut();
|
|
|
|
let mut objects = self.get_renderables_back_to_front(
|
|
|
|
Circle::new(pt, Distance::meters(3.0)).get_bounds(),
|
|
|
|
ctx.prerender,
|
|
|
|
&mut cache,
|
|
|
|
source,
|
|
|
|
show_objs,
|
|
|
|
);
|
|
|
|
objects.reverse();
|
|
|
|
|
|
|
|
for obj in objects {
|
|
|
|
// In unzoomed mode, can only mouseover areas
|
|
|
|
match obj.get_id() {
|
|
|
|
ID::Area(_) | ID::ExtraShape(_) => {
|
|
|
|
if !debug_mode {
|
2019-05-16 00:27:44 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 22:12:03 +03:00
|
|
|
// Never mouseover these
|
|
|
|
ID::Road(_) => {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
if ctx.canvas.cam_zoom < MIN_ZOOM_FOR_DETAIL {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-16 00:27:44 +03:00
|
|
|
}
|
2019-04-30 00:44:43 +03:00
|
|
|
}
|
2019-06-06 22:12:03 +03:00
|
|
|
if obj.contains_pt(pt, &self.primary.map) {
|
|
|
|
return Some(obj.get_id());
|
|
|
|
}
|
2019-04-24 03:26:10 +03:00
|
|
|
}
|
2019-06-06 22:12:03 +03:00
|
|
|
None
|
2019-04-24 03:26:10 +03:00
|
|
|
}
|
|
|
|
|
2019-02-02 23:49:17 +03:00
|
|
|
// TODO This could probably belong to DrawMap again, but it's annoying to plumb things that
|
|
|
|
// State does, like show_icons_for() and show().
|
2019-02-02 23:35:50 +03:00
|
|
|
fn get_renderables_back_to_front<'a>(
|
|
|
|
&'a self,
|
2019-02-02 09:41:32 +03:00
|
|
|
bounds: Bounds,
|
|
|
|
prerender: &Prerender,
|
2019-02-02 23:35:50 +03:00
|
|
|
agents: &'a mut AgentCache,
|
2019-04-26 01:23:45 +03:00
|
|
|
source: &GetDrawAgents,
|
2019-04-26 02:56:38 +03:00
|
|
|
show_objs: &ShowObject,
|
2019-06-12 19:42:34 +03:00
|
|
|
) -> Vec<&'a (dyn Renderable + 'a)> {
|
2019-04-29 19:27:43 +03:00
|
|
|
let map = &self.primary.map;
|
|
|
|
let draw_map = &self.primary.draw_map;
|
2019-02-02 09:41:32 +03:00
|
|
|
|
2019-06-12 19:42:34 +03:00
|
|
|
let mut areas: Vec<&dyn Renderable> = Vec::new();
|
|
|
|
let mut lanes: Vec<&dyn Renderable> = Vec::new();
|
|
|
|
let mut roads: Vec<&dyn Renderable> = Vec::new();
|
|
|
|
let mut intersections: Vec<&dyn Renderable> = Vec::new();
|
|
|
|
let mut buildings: Vec<&dyn Renderable> = Vec::new();
|
|
|
|
let mut extra_shapes: Vec<&dyn Renderable> = Vec::new();
|
|
|
|
let mut bus_stops: Vec<&dyn Renderable> = Vec::new();
|
2019-02-02 09:41:32 +03:00
|
|
|
let mut agents_on: Vec<Traversable> = Vec::new();
|
|
|
|
|
|
|
|
for id in draw_map.get_matching_objects(bounds) {
|
2019-08-15 01:09:54 +03:00
|
|
|
if !show_objs.show(&id) {
|
2019-02-02 09:41:32 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
match id {
|
2019-06-12 19:42:34 +03:00
|
|
|
ID::Area(id) => areas.push(draw_map.get_a(id)),
|
2019-02-02 09:41:32 +03:00
|
|
|
ID::Lane(id) => {
|
2019-06-12 19:42:34 +03:00
|
|
|
lanes.push(draw_map.get_l(id));
|
2019-05-11 02:21:21 +03:00
|
|
|
agents_on.push(Traversable::Lane(id));
|
|
|
|
for bs in &map.get_l(id).bus_stops {
|
2019-06-12 19:42:34 +03:00
|
|
|
bus_stops.push(draw_map.get_bs(*bs));
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
|
|
|
}
|
2019-02-12 19:26:23 +03:00
|
|
|
ID::Road(id) => {
|
2019-06-12 19:42:34 +03:00
|
|
|
roads.push(draw_map.get_r(id));
|
2019-02-12 19:26:23 +03:00
|
|
|
}
|
2019-02-02 09:41:32 +03:00
|
|
|
ID::Intersection(id) => {
|
2019-06-12 19:42:34 +03:00
|
|
|
intersections.push(draw_map.get_i(id));
|
2019-05-12 02:14:21 +03:00
|
|
|
for t in &map.get_i(id).turns {
|
|
|
|
agents_on.push(Traversable::Turn(*t));
|
|
|
|
}
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
|
|
|
// TODO front paths will get drawn over buildings, depending on quadtree order.
|
|
|
|
// probably just need to make them go around other buildings instead of having
|
|
|
|
// two passes through buildings.
|
2019-06-12 19:42:34 +03:00
|
|
|
ID::Building(id) => buildings.push(draw_map.get_b(id)),
|
|
|
|
ID::ExtraShape(id) => extra_shapes.push(draw_map.get_es(id)),
|
2019-02-02 09:41:32 +03:00
|
|
|
|
2019-08-15 01:29:02 +03:00
|
|
|
ID::BusStop(_)
|
|
|
|
| ID::Turn(_)
|
|
|
|
| ID::Car(_)
|
|
|
|
| ID::Pedestrian(_)
|
|
|
|
| ID::PedCrowd(_)
|
|
|
|
| ID::Trip(_) => panic!("{:?} shouldn't be in the quadtree", id),
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// From background to foreground Z-order
|
2019-06-12 19:42:34 +03:00
|
|
|
let mut borrows: Vec<&dyn Renderable> = Vec::new();
|
2019-02-10 06:28:26 +03:00
|
|
|
borrows.extend(areas);
|
2019-02-02 09:41:32 +03:00
|
|
|
borrows.extend(lanes);
|
2019-02-12 19:26:23 +03:00
|
|
|
borrows.extend(roads);
|
2019-02-02 09:41:32 +03:00
|
|
|
borrows.extend(intersections);
|
|
|
|
borrows.extend(buildings);
|
|
|
|
borrows.extend(extra_shapes);
|
|
|
|
borrows.extend(bus_stops);
|
|
|
|
|
2019-02-02 23:35:50 +03:00
|
|
|
// Expand all of the Traversables into agents, populating the cache if needed.
|
2019-02-02 09:41:32 +03:00
|
|
|
{
|
2019-02-26 23:50:43 +03:00
|
|
|
let time = source.time();
|
2019-05-09 04:24:57 +03:00
|
|
|
let step_count = source.step_count();
|
2019-02-02 09:41:32 +03:00
|
|
|
|
|
|
|
for on in &agents_on {
|
2019-02-26 23:50:43 +03:00
|
|
|
if !agents.has(time, *on) {
|
2019-02-02 09:41:32 +03:00
|
|
|
let mut list: Vec<Box<Renderable>> = Vec::new();
|
2019-02-10 00:07:00 +03:00
|
|
|
for c in source.get_draw_cars(*on, map).into_iter() {
|
2019-04-29 19:27:43 +03:00
|
|
|
list.push(draw_vehicle(c, map, prerender, &self.cs));
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
2019-08-14 23:11:45 +03:00
|
|
|
let (loners, crowds) =
|
|
|
|
DrawPedestrian::aggregate_peds(source.get_draw_peds(*on, map));
|
|
|
|
for p in loners {
|
2019-05-06 22:12:31 +03:00
|
|
|
list.push(Box::new(DrawPedestrian::new(
|
2019-05-09 04:24:57 +03:00
|
|
|
p, step_count, map, prerender, &self.cs,
|
2019-05-06 22:12:31 +03:00
|
|
|
)));
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
2019-08-14 23:11:45 +03:00
|
|
|
for c in crowds {
|
|
|
|
list.push(Box::new(DrawPedCrowd::new(c, map, prerender, &self.cs)));
|
|
|
|
}
|
2019-02-26 23:50:43 +03:00
|
|
|
agents.put(time, *on, list);
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 23:35:50 +03:00
|
|
|
for on in agents_on {
|
|
|
|
for obj in agents.get(on) {
|
|
|
|
borrows.push(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a stable sort.
|
|
|
|
borrows.sort_by_key(|r| r.get_zorder());
|
|
|
|
|
|
|
|
borrows
|
2019-02-02 09:41:32 +03:00
|
|
|
}
|
2019-08-05 21:36:49 +03:00
|
|
|
|
|
|
|
pub fn save_editor_state(&self, canvas: &Canvas) {
|
|
|
|
let state = EditorState {
|
|
|
|
map_name: self.primary.map.get_name().clone(),
|
|
|
|
cam_x: canvas.cam_x,
|
|
|
|
cam_y: canvas.cam_y,
|
|
|
|
cam_zoom: canvas.cam_zoom,
|
|
|
|
};
|
|
|
|
let path = abstutil::path_editor_state(&state.map_name);
|
|
|
|
abstutil::write_json(&path, &state).unwrap();
|
|
|
|
println!("Saved {}", path);
|
|
|
|
}
|
2018-03-13 18:04:21 +03:00
|
|
|
}
|
2018-06-22 21:01:44 +03:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2019-08-05 21:36:49 +03:00
|
|
|
struct EditorState {
|
2018-09-09 23:21:53 +03:00
|
|
|
pub map_name: String,
|
2018-06-22 21:01:44 +03:00
|
|
|
pub cam_x: f64,
|
|
|
|
pub cam_y: f64,
|
|
|
|
pub cam_zoom: f64,
|
|
|
|
}
|
2019-03-28 06:54:04 +03:00
|
|
|
|
2019-04-26 08:19:54 +03:00
|
|
|
pub struct ShowLayers {
|
|
|
|
pub show_buildings: bool,
|
|
|
|
pub show_intersections: bool,
|
|
|
|
pub show_lanes: bool,
|
|
|
|
pub show_areas: bool,
|
|
|
|
pub show_extra_shapes: bool,
|
|
|
|
pub geom_debug_mode: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShowLayers {
|
|
|
|
pub fn new() -> ShowLayers {
|
|
|
|
ShowLayers {
|
|
|
|
show_buildings: true,
|
|
|
|
show_intersections: true,
|
|
|
|
show_lanes: true,
|
|
|
|
show_areas: true,
|
|
|
|
show_extra_shapes: true,
|
|
|
|
geom_debug_mode: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 02:56:38 +03:00
|
|
|
pub trait ShowObject {
|
2019-08-15 01:09:54 +03:00
|
|
|
fn show(&self, obj: &ID) -> bool;
|
2019-04-26 08:19:54 +03:00
|
|
|
fn layers(&self) -> &ShowLayers;
|
2019-04-26 02:56:38 +03:00
|
|
|
}
|
|
|
|
|
2019-04-26 08:19:54 +03:00
|
|
|
pub struct ShowEverything {
|
|
|
|
layers: ShowLayers,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShowEverything {
|
|
|
|
pub fn new() -> ShowEverything {
|
|
|
|
ShowEverything {
|
|
|
|
layers: ShowLayers::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 02:56:38 +03:00
|
|
|
|
|
|
|
impl ShowObject for ShowEverything {
|
2019-08-15 01:09:54 +03:00
|
|
|
fn show(&self, _: &ID) -> bool {
|
2019-04-26 02:56:38 +03:00
|
|
|
true
|
|
|
|
}
|
2019-04-26 08:19:54 +03:00
|
|
|
|
|
|
|
fn layers(&self) -> &ShowLayers {
|
|
|
|
&self.layers
|
|
|
|
}
|
2019-04-26 02:56:38 +03:00
|
|
|
}
|
2019-04-29 19:27:43 +03:00
|
|
|
|
|
|
|
#[derive(StructOpt, Debug, Clone)]
|
|
|
|
#[structopt(name = "editor")]
|
|
|
|
pub struct Flags {
|
|
|
|
#[structopt(flatten)]
|
|
|
|
pub sim_flags: SimFlags,
|
|
|
|
|
|
|
|
/// Extra KML or ExtraShapes to display
|
|
|
|
#[structopt(long = "kml")]
|
|
|
|
pub kml: Option<String>,
|
|
|
|
|
|
|
|
// TODO Ideally these'd be phrased positively, but can't easily make them default to true.
|
|
|
|
/// Should lane markings be drawn? Sometimes they eat too much GPU memory.
|
|
|
|
#[structopt(long = "dont_draw_lane_markings")]
|
|
|
|
pub dont_draw_lane_markings: bool,
|
|
|
|
|
|
|
|
/// Enable cpuprofiler?
|
|
|
|
#[structopt(long = "enable_profiler")]
|
|
|
|
pub enable_profiler: bool,
|
|
|
|
|
2019-05-09 20:45:45 +03:00
|
|
|
/// Number of agents to generate when requested. If unspecified, trips to/from borders will be
|
|
|
|
/// included.
|
|
|
|
#[structopt(long = "num_agents")]
|
|
|
|
pub num_agents: Option<usize>,
|
2019-04-29 19:27:43 +03:00
|
|
|
|
|
|
|
/// Don't start with the splash screen and menu
|
|
|
|
#[structopt(long = "no_splash")]
|
|
|
|
pub no_splash: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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: Flags,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PerMapUI {
|
2019-06-07 20:59:13 +03:00
|
|
|
pub fn new(flags: Flags, cs: &ColorScheme, ctx: &mut EventCtx, timer: &mut Timer) -> PerMapUI {
|
|
|
|
let mut mem = MeasureMemory::new();
|
2019-08-10 02:16:36 +03:00
|
|
|
let (map, sim, _) = flags.sim_flags.load(None, timer);
|
2019-06-07 20:59:13 +03:00
|
|
|
mem.reset("Map and Sim", timer);
|
|
|
|
|
|
|
|
timer.start("draw_map");
|
|
|
|
let draw_map = DrawMap::new(&map, &flags, cs, ctx.prerender, timer);
|
|
|
|
timer.stop("draw_map");
|
|
|
|
mem.reset("DrawMap", timer);
|
2019-04-29 19:27:43 +03:00
|
|
|
|
|
|
|
PerMapUI {
|
|
|
|
map,
|
|
|
|
draw_map,
|
|
|
|
sim,
|
|
|
|
current_selection: None,
|
|
|
|
current_flags: flags.clone(),
|
|
|
|
}
|
|
|
|
}
|
2019-05-04 19:38:42 +03:00
|
|
|
|
|
|
|
pub fn reset_sim(&mut self) {
|
2019-08-16 20:35:47 +03:00
|
|
|
let flags = &self.current_flags.sim_flags;
|
|
|
|
|
2019-05-04 19:38:42 +03:00
|
|
|
// TODO savestate_every gets lost
|
|
|
|
self.sim = Sim::new(
|
|
|
|
&self.map,
|
2019-08-16 20:35:47 +03:00
|
|
|
SimOptions {
|
|
|
|
run_name: flags
|
|
|
|
.run_name
|
|
|
|
.clone()
|
|
|
|
.unwrap_or_else(|| "unnamed".to_string()),
|
|
|
|
savestate_every: None,
|
|
|
|
use_freeform_policy_everywhere: flags.freeform_policy,
|
|
|
|
},
|
2019-05-04 19:38:42 +03:00
|
|
|
);
|
|
|
|
}
|
2019-04-29 19:27:43 +03:00
|
|
|
}
|