Reorganize zorder_range out of PerMap and into DrawMap.

This commit is contained in:
Dustin Carlino 2020-11-22 19:05:08 -08:00
parent abf3dbc859
commit 26a7277f50
3 changed files with 18 additions and 20 deletions

View File

@ -439,10 +439,8 @@ impl App {
ctx.set_style(self.cs.gui_style.clone());
ctx.loading_screen("rerendering map colors", |ctx, timer| {
let (draw_map, zorder_range) =
self.primary.draw_map =
DrawMap::new(&self.primary.map, &self.opts, &self.cs, ctx, timer);
self.primary.draw_map = draw_map;
self.primary.zorder_range = zorder_range;
});
true
@ -530,7 +528,6 @@ pub struct PerMap {
pub last_warped_from: Option<(Pt2D, f64)>,
pub sim_cb: Option<Box<dyn SimCallback>>,
pub show_zorder: isize,
pub zorder_range: (isize, isize),
/// If we ever left edit mode and resumed without restarting from midnight, this is true.
pub dirty_from_edits: bool,
/// Any ScenarioModifiers in effect?
@ -566,19 +563,18 @@ impl PerMap {
timer: &mut Timer,
) -> PerMap {
timer.start("draw_map");
let (draw_map, zorder_range) = DrawMap::new(&map, opts, cs, ctx, timer);
let draw_map = DrawMap::new(&map, opts, cs, ctx, timer);
timer.stop("draw_map");
let per_map = PerMap {
map,
show_zorder: draw_map.zorder_range.1,
draw_map,
sim,
current_selection: None,
current_flags: flags,
last_warped_from: None,
sim_cb: None,
zorder_range,
show_zorder: zorder_range.1,
dirty_from_edits: false,
has_modified_trips: false,
unedited_map: RefCell::new(None),

View File

@ -111,8 +111,12 @@ impl Minimap {
if app.opts.dev || !self.extra_controls {
Widget::col(vec![
Line("Z-order:").small().draw(ctx),
Spinner::new(ctx, app.primary.zorder_range, app.primary.show_zorder)
.named("zorder"),
Spinner::new(
ctx,
app.primary.draw_map.zorder_range,
app.primary.show_zorder,
)
.named("zorder"),
])
.margin_above(10)
} else {

View File

@ -46,23 +46,28 @@ pub struct DrawMap {
pub draw_all_unzoomed_parking_lots: Drawable,
pub draw_all_areas: Drawable,
pub zorder_range: (isize, isize),
quadtree: QuadTree<ID>,
}
impl DrawMap {
/// Returns the DrawMap and also the zorder_range (low, high)
pub fn new(
map: &Map,
opts: &Options,
cs: &ColorScheme,
ctx: &EventCtx,
timer: &mut Timer,
) -> (DrawMap, (isize, isize)) {
) -> DrawMap {
let mut roads: Vec<DrawRoad> = Vec::new();
let mut low_z = 0;
let mut high_z = 0;
timer.start_iter("make DrawRoads", map.all_roads().len());
for r in map.all_roads() {
timer.next();
roads.push(DrawRoad::new(r));
low_z = low_z.min(r.zorder);
high_z = high_z.max(r.zorder);
}
let mut lanes: Vec<DrawLane> = Vec::new();
@ -172,7 +177,7 @@ impl DrawMap {
abstutil::prettyprint_usize(ctx.prerender.get_total_bytes_uploaded() / 1024 / 1024)
));
let draw_map = DrawMap {
DrawMap {
roads,
lanes,
intersections,
@ -195,16 +200,9 @@ impl DrawMap {
}),
quadtree,
};
let mut low_z = 0;
let mut high_z = 0;
for r in map.all_roads() {
low_z = low_z.min(r.zorder);
high_z = high_z.max(r.zorder);
zorder_range: (low_z, high_z),
}
(draw_map, (low_z, high_z))
}
pub fn regenerate_unzoomed_layer(