mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 17:34:58 +03:00
debug_initialmap loads from raw_data. remove the complicated serialization stuff from InitialMap.
This commit is contained in:
parent
d9474494e7
commit
290c274661
@ -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<ID>,
|
||||
data: InitialMap,
|
||||
filename: String,
|
||||
// TODO Or, if these are common things, the World could also hold this state.
|
||||
selected: Option<ID>,
|
||||
hide: HashSet<ID>,
|
||||
@ -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<ID> {
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(id) = data.focus_on {
|
||||
ctx.canvas
|
||||
.center_on_map_pt(w.get_center(ID::Intersection(id)));
|
||||
}
|
||||
|
||||
w
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<StableRoadID, Road>,
|
||||
pub intersections: BTreeMap<StableIntersectionID, Intersection>,
|
||||
|
||||
pub name: String,
|
||||
pub bounds: Bounds,
|
||||
pub focus_on: Option<StableIntersectionID>,
|
||||
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<Pt2D>,
|
||||
@ -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<StableIntersectionID>) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user