mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Cars in the process of parking were being double-counted for deletion in
live edits! #312
This commit is contained in:
parent
22ae06c3a4
commit
058103b84f
@ -33,13 +33,13 @@ pub trait ParkingSim {
|
||||
fn get_draw_cars(&self, id: LaneID, map: &Map) -> Vec<DrawCarInput>;
|
||||
fn get_draw_cars_in_lots(&self, id: LaneID, map: &Map) -> Vec<DrawCarInput>;
|
||||
fn get_draw_car(&self, id: CarID, map: &Map) -> Option<DrawCarInput>;
|
||||
// There's no DrawCarInput for cars parked offstreet, so we need this.
|
||||
/// There's no DrawCarInput for cars parked offstreet, so we need this.
|
||||
fn canonical_pt(&self, id: CarID, map: &Map) -> Option<Pt2D>;
|
||||
fn get_all_draw_cars(&self, map: &Map) -> Vec<DrawCarInput>;
|
||||
fn is_free(&self, spot: ParkingSpot) -> bool;
|
||||
fn get_car_at_spot(&self, spot: ParkingSpot) -> Option<&ParkedCar>;
|
||||
// The vehicle's front is currently at the given driving_pos. Returns all valid spots and their
|
||||
// driving position.
|
||||
/// The vehicle's front is currently at the given driving_pos. Returns all valid spots and their
|
||||
/// driving position.
|
||||
fn get_all_free_spots(
|
||||
&self,
|
||||
driving_pos: Position,
|
||||
@ -53,12 +53,12 @@ pub trait ParkingSim {
|
||||
fn spot_to_sidewalk_pos(&self, spot: ParkingSpot, map: &Map) -> Position;
|
||||
fn get_owner_of_car(&self, id: CarID) -> Option<PersonID>;
|
||||
fn lookup_parked_car(&self, id: CarID) -> Option<&ParkedCar>;
|
||||
// (Filled, available)
|
||||
/// (Filled, available)
|
||||
fn get_all_parking_spots(&self) -> (Vec<ParkingSpot>, Vec<ParkingSpot>);
|
||||
// Unrealistically assumes the driver has knowledge of currently free parking spots, even if
|
||||
// they're far away. Since they don't reserve the spot in advance, somebody else can still beat
|
||||
// them there, producing some nice, realistic churn if there's too much contention.
|
||||
// The first PathStep is the turn after start, NOT PathStep::Lane(start).
|
||||
/// Unrealistically assumes the driver has knowledge of currently free parking spots, even if
|
||||
/// they're far away. Since they don't reserve the spot in advance, somebody else can still beat
|
||||
/// them there, producing some nice, realistic churn if there's too much contention.
|
||||
/// The first PathStep is the turn after start, NOT PathStep::Lane(start).
|
||||
fn path_to_free_parking_spot(
|
||||
&self,
|
||||
start: LaneID,
|
||||
@ -209,8 +209,11 @@ impl ParkingSim for NormalParkingSimState {
|
||||
let mut evicted = Vec::new();
|
||||
for spot in filled_before {
|
||||
if !avail_after.contains(&spot) {
|
||||
let car = self.occupants.remove(&spot).unwrap();
|
||||
evicted.push(self.parked_cars.remove(&car).unwrap());
|
||||
// If the spot isn't occupied, it must be reserved; a car is in the process of
|
||||
// parking in it. That'll be handled below.
|
||||
if let Some(car) = self.occupants.remove(&spot) {
|
||||
evicted.push(self.parked_cars.remove(&car).unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -934,8 +934,11 @@ impl Sim {
|
||||
}
|
||||
|
||||
/// Returns (trips affected, number of parked cars displaced)
|
||||
fn find_trips_affected_by_live_edits(&mut self, map: &Map) -> (Vec<(AgentID, TripID)>, usize) {
|
||||
let mut affected: Vec<(AgentID, TripID)> = Vec::new();
|
||||
fn find_trips_affected_by_live_edits(
|
||||
&mut self,
|
||||
map: &Map,
|
||||
) -> (BTreeSet<(AgentID, TripID)>, usize) {
|
||||
let mut affected: BTreeSet<(AgentID, TripID)> = BTreeSet::new();
|
||||
|
||||
// TODO Handle changes to access restrictions
|
||||
|
||||
@ -958,7 +961,7 @@ impl Sim {
|
||||
Traversable::Turn(t) => closed_intersections.contains(&t.parent),
|
||||
})
|
||||
{
|
||||
affected.push((*a, *trip));
|
||||
affected.insert((*a, *trip));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -971,7 +974,7 @@ impl Sim {
|
||||
affected.extend(self.walking.find_trips_to_parking(evicted_cars));
|
||||
for car in cars_parking_in_the_void {
|
||||
let a = AgentID::Car(car);
|
||||
affected.push((a, self.agent_to_trip(a).unwrap()));
|
||||
affected.insert((a, self.agent_to_trip(a).unwrap()));
|
||||
}
|
||||
|
||||
if !self.parking.is_infinite() {
|
||||
|
Loading…
Reference in New Issue
Block a user