From 26a7277f500cd4de47aef98c9e77a0d9d2cd4c64 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 22 Nov 2020 19:05:08 -0800 Subject: [PATCH] Reorganize zorder_range out of PerMap and into DrawMap. --- game/src/app.rs | 10 +++------- game/src/common/minimap.rs | 8 ++++++-- game/src/render/map.rs | 20 +++++++++----------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/game/src/app.rs b/game/src/app.rs index f1a6e1a1fa..30fdd02d2e 100644 --- a/game/src/app.rs +++ b/game/src/app.rs @@ -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>, 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), diff --git a/game/src/common/minimap.rs b/game/src/common/minimap.rs index d760079f23..3ae83ff0bf 100644 --- a/game/src/common/minimap.rs +++ b/game/src/common/minimap.rs @@ -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 { diff --git a/game/src/render/map.rs b/game/src/render/map.rs index 691451d067..fccfe12d5f 100644 --- a/game/src/render/map.rs +++ b/game/src/render/map.rs @@ -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, } 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 = 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 = 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(