From 290c274661db1329016891b72f31f99e5d828a51 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 11 Jun 2019 17:15:17 -0700 Subject: [PATCH] debug_initialmap loads from raw_data. remove the complicated serialization stuff from InitialMap. --- debug_initialmap/src/main.rs | 45 +++++++++-------------------- map_model/src/make/initial/merge.rs | 6 ---- map_model/src/make/initial/mod.rs | 24 +-------------- 3 files changed, 14 insertions(+), 61 deletions(-) diff --git a/debug_initialmap/src/main.rs b/debug_initialmap/src/main.rs index 1bc928945b..bbbb00fe55 100644 --- a/debug_initialmap/src/main.rs +++ b/debug_initialmap/src/main.rs @@ -1,7 +1,7 @@ -use abstutil::{find_next_file, find_prev_file, read_binary, Timer}; +use abstutil::Timer; use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI}; use geom::{Distance, Polygon}; -use map_model::raw_data::{StableIntersectionID, StableRoadID, InitialMap}; +use map_model::raw_data::{InitialMap, StableIntersectionID, StableRoadID}; use std::collections::HashSet; use std::{env, process}; use viewer::World; @@ -12,7 +12,6 @@ const MIN_ROAD_LENGTH: Distance = Distance::const_meters(13.0); struct UI { world: World, data: InitialMap, - filename: String, // TODO Or, if these are common things, the World could also hold this state. selected: Option, hide: HashSet, @@ -21,27 +20,25 @@ struct UI { impl UI { fn new(filename: &str, ctx: &mut EventCtx) -> UI { - let data: InitialMap = - read_binary(filename, &mut Timer::new("load InitialMap")).unwrap(); + let mut timer = Timer::new(&format!("load {}", filename)); + let raw: map_model::raw_data::Map = abstutil::read_binary(filename, &mut timer).unwrap(); + let gps_bounds = raw.get_gps_bounds(); + let data = InitialMap::new( + filename.to_string(), + &raw, + &gps_bounds, + &gps_bounds.to_bounds(), + &mut timer, + ); let world = initial_map_to_world(&data, ctx); UI { world, data, - filename: filename.to_string(), selected: None, hide: HashSet::new(), osd: Text::new(), } } - - fn load_different(&mut self, filename: String, ctx: &mut EventCtx) { - let data: InitialMap = - read_binary(&filename, &mut Timer::new("load InitialMap")).unwrap(); - self.world = initial_map_to_world(&data, ctx); - self.selected = None; - self.filename = filename; - self.hide.clear(); - } } impl GUI for UI { @@ -56,17 +53,6 @@ impl GUI for UI { process::exit(0); } - if let Some(prev) = find_prev_file(self.filename.clone()) { - if ctx.input.key_pressed(Key::Comma, "load previous map") { - self.load_different(prev, ctx); - } - } - if let Some(next) = find_next_file(self.filename.clone()) { - if ctx.input.key_pressed(Key::Dot, "load next map") { - self.load_different(next, ctx); - } - } - if let Some(id) = self.selected { if ctx.input.key_pressed(Key::H, "hide this") { self.hide.insert(id); @@ -75,7 +61,7 @@ impl GUI for UI { } if let Some(ID::HalfRoad(r, _)) = self.selected { if ctx.input.key_pressed(Key::M, "merge") { - self.data.merge(r); + self.data.merge_road(r); self.world = initial_map_to_world(&self.data, ctx); self.selected = None; } @@ -177,10 +163,5 @@ fn initial_map_to_world(data: &InitialMap, ctx: &mut EventCtx) -> World { ); } - if let Some(id) = data.focus_on { - ctx.canvas - .center_on_map_pt(w.get_center(ID::Intersection(id))); - } - w } diff --git a/map_model/src/make/initial/merge.rs b/map_model/src/make/initial/merge.rs index 0ba559c052..6af4f56cde 100644 --- a/map_model/src/make/initial/merge.rs +++ b/map_model/src/make/initial/merge.rs @@ -73,8 +73,6 @@ pub fn merge( (r.src_i, r.dst_i) }; - // Show what we're about to delete - map.save(Some(delete_i)); map.roads.remove(&merge_road); map.intersections.remove(&delete_i); map.intersections @@ -140,13 +138,9 @@ pub fn merge( } } } - // Show the reset road geometry - map.save(None); let mut i = map.intersections.get_mut(&keep_i).unwrap(); i.polygon = geometry::intersection_polygon(i, &mut map.roads, timer); - // Show the final results of fixing this area - map.save(None); keep_i } diff --git a/map_model/src/make/initial/mod.rs b/map_model/src/make/initial/mod.rs index 7e55cb1db3..7101618f20 100644 --- a/map_model/src/make/initial/mod.rs +++ b/map_model/src/make/initial/mod.rs @@ -7,21 +7,16 @@ use crate::raw_data::{StableIntersectionID, StableRoadID}; use crate::{raw_data, LANE_THICKNESS}; use abstutil::Timer; use geom::{Bounds, Distance, GPSBounds, PolyLine, Pt2D}; -use serde_derive::{Deserialize, Serialize}; use std::collections::{BTreeMap, BTreeSet}; -#[derive(Serialize, Deserialize)] pub struct InitialMap { pub roads: BTreeMap, pub intersections: BTreeMap, pub name: String, pub bounds: Bounds, - pub focus_on: Option, - versions_saved: usize, } -#[derive(Serialize, Deserialize)] pub struct Road { pub id: StableRoadID, pub src_i: StableIntersectionID, @@ -45,7 +40,6 @@ impl Road { } } -#[derive(Serialize, Deserialize)] pub struct Intersection { pub id: StableIntersectionID, pub polygon: Vec, @@ -65,8 +59,6 @@ impl InitialMap { intersections: BTreeMap::new(), name, bounds: bounds.clone(), - focus_on: None, - versions_saved: 0, }; for stable_id in data.intersections.keys() { @@ -153,21 +145,7 @@ impl InitialMap { m } - pub fn save(&mut self, focus_on: Option) { - if true { - return; - } - let path = format!("../initial_maps/{:03}.bin", self.versions_saved); - self.focus_on = focus_on; - self.versions_saved += 1; - abstutil::write_binary(&path, self).expect(&format!("Saving {} failed", path)); - println!("Saved {}", path); - } - - pub fn merge( - &mut self, - r: StableRoadID, - ) { + pub fn merge_road(&mut self, r: StableRoadID) { merge::merge(self, r, &mut Timer::throwaway()); } }