From 83352965b03bbac243f11c4f8f9d574d228e22d5 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 17 Nov 2019 12:44:24 -0800 Subject: [PATCH] woops, forgot about a block of commented stuff in apply_edits. prevent orphaning a bus stop --- game/src/edit/lanes.rs | 24 ++++++++--------- map_model/src/map.rs | 60 +++++++++++------------------------------- 2 files changed, 28 insertions(+), 56 deletions(-) diff --git a/game/src/edit/lanes.rs b/game/src/edit/lanes.rs index 3cdd578d46..78d077cecc 100644 --- a/game/src/edit/lanes.rs +++ b/game/src/edit/lanes.rs @@ -282,10 +282,10 @@ impl LaneEditor { fn can_change_lane_type(l: LaneID, new_lt: LaneType, map: &Map) -> Option { let r = map.get_parent(l); let (fwds, idx) = r.dir_and_offset(l); - let mut proposed_lts = if fwds { - r.get_lane_types().0 + let (mut proposed_lts, other_side) = if fwds { + (r.get_lane_types().0, r.get_lane_types().1) } else { - r.get_lane_types().1 + (r.get_lane_types().1, r.get_lane_types().0) }; proposed_lts[idx] = new_lt; @@ -308,22 +308,22 @@ fn can_change_lane_type(l: LaneID, new_lt: LaneType, map: &Map) -> Option = r - .all_lanes() - .iter() - .map(|l| map.get_l(*l).lane_type) - .collect(); - // Don't let players orphan a bus stop. if !r.all_bus_stops(map).is_empty() - && !types.contains(&LaneType::Driving) - && !types.contains(&LaneType::Bus) + && !proposed_lts + .iter() + .any(|lt| *lt == LaneType::Driving || *lt == LaneType::Bus) { return Some(format!("You need a driving or bus lane for the bus stop!")); } + let all_types: BTreeSet = other_side + .into_iter() + .chain(proposed_lts.iter().cloned()) + .collect(); + // A parking lane must have a driving lane somewhere on the road. - if types.contains(&LaneType::Parking) && !types.contains(&LaneType::Driving) { + if all_types.contains(&LaneType::Parking) && !all_types.contains(&LaneType::Driving) { return Some(format!( "A parking lane needs a driving lane somewhere on the same road" )); diff --git a/map_model/src/map.rs b/map_model/src/map.rs index 9783de7245..c4a7bd4219 100644 --- a/map_model/src/map.rs +++ b/map_model/src/map.rs @@ -8,7 +8,7 @@ use crate::{ }; use abstutil; use abstutil::{deserialize_btreemap, serialize_btreemap, Error, Timer}; -use geom::{Bounds, GPSBounds, Polygon, Pt2D}; +use geom::{Bounds, Distance, GPSBounds, Polygon, Pt2D}; use serde_derive::{Deserialize, Serialize}; use std::collections::{BTreeMap, BTreeSet, HashSet, VecDeque}; use std::io; @@ -681,6 +681,21 @@ impl Map { new_edits.commands.len() )); + // Might need to update bus stops. + for id in &effects.changed_roads { + let stops = self.get_r(*id).all_bus_stops(self); + for s in stops { + let sidewalk_pos = self.get_bs(s).sidewalk_pos; + // Must exist, because we aren't allowed to orphan a bus stop. + let driving_lane = self + .get_r(*id) + .find_closest_lane(sidewalk_pos.lane(), vec![LaneType::Driving, LaneType::Bus]) + .unwrap(); + let driving_pos = sidewalk_pos.equiv_pos(driving_lane, Distance::ZERO, self); + self.bus_stops.get_mut(&s).unwrap().driving_pos = driving_pos; + } + } + new_edits.update_derived(self, timer); self.edits = new_edits; self.pathfinder_dirty = true; @@ -696,49 +711,6 @@ impl Map { .filter(|t| self.turns.contains_key(t)) .collect(), ) - - /*for id in changed_roads { - let stops = self.get_r(id).all_bus_stops(self); - for s in stops { - let sidewalk_pos = self.get_bs(s).sidewalk_pos; - // Must exist, because we aren't allowed to orphan a bus stop. - let driving_lane = self - .get_r(id) - .find_closest_lane(sidewalk_pos.lane(), vec![LaneType::Driving, LaneType::Bus]) - .unwrap(); - let driving_pos = sidewalk_pos.equiv_pos(driving_lane, Distance::ZERO, self); - self.bus_stops.get_mut(&s).unwrap().driving_pos = driving_pos; - } - } - - // Make sure all of the turns of modified intersections are re-added in the pathfinder; - // they might've become banned. Lane markings may also change based on turn priorities. - for (id, ss) in all_stop_sign_edits { - self.stop_signs.insert(id, ss); - for t in &self.get_i(id).turns { - add_turns.insert(*t); - } - for l in &self.get_i(id).incoming_lanes { - changed_lanes.insert(*l); - } - } - for (id, ts) in all_traffic_signals { - self.traffic_signals.insert(id, ts); - for t in &self.get_i(id).turns { - add_turns.insert(*t); - } - for l in &self.get_i(id).incoming_lanes { - changed_lanes.insert(*l); - } - } - for id in all_closed_intersections { - let i = &mut self.intersections[id.0]; - i.intersection_type = IntersectionType::Construction; - for id in i.turns.drain(..) { - self.turns.remove(&id).unwrap(); - delete_turns.insert(id); - } - }*/ } pub fn recalculate_pathfinding_after_edits(&mut self, timer: &mut Timer) {