From dba7ced0948f5affb52be2e96d9749ee41468435 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 17 Oct 2019 14:54:30 -0700 Subject: [PATCH] distinguish parked cars that have a trip scheduled or not --- game/src/render/map.rs | 9 +++++++-- sim/src/mechanics/car.rs | 6 +++--- sim/src/mechanics/parking.rs | 32 +++++++++++++++++++++++--------- sim/src/render.rs | 3 ++- sim/src/sim.rs | 6 +++--- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/game/src/render/map.rs b/game/src/render/map.rs index 40f903231a..8f2b2d66a7 100644 --- a/game/src/render/map.rs +++ b/game/src/render/map.rs @@ -457,7 +457,12 @@ impl AgentColorScheme { CarStatus::Debug => cs.get_def("debug car", Color::BLUE.alpha(0.8)), CarStatus::Moving => cs.get_def("moving car", Color::CYAN), CarStatus::Stuck => cs.get_def("stuck car", Color::rgb(222, 184, 135)), - CarStatus::Parked => cs.get_def("parked car", Color::rgb(180, 233, 76)), + CarStatus::ParkedWithoutTrip => { + cs.get_def("parked car without trip", Color::rgb(200, 233, 176)) + } + CarStatus::ParkedWithTrip => { + cs.get_def("parked car with trip", Color::rgb(180, 233, 76)) + } } } } @@ -472,7 +477,7 @@ impl AgentColorScheme { // TODO Hard to see on the greenish bike lanes? :P CarStatus::Moving => cs.get_def("moving bike", Color::GREEN), CarStatus::Stuck => cs.get_def("stuck bike", Color::RED), - CarStatus::Parked => panic!("Can't have a parked bike {}", input.id), + CarStatus::ParkedWithoutTrip | CarStatus::ParkedWithTrip => unreachable!(), }, _ => self.by_metadata(&input.metadata), } diff --git a/sim/src/mechanics/car.rs b/sim/src/mechanics/car.rs index fdb97be4f1..58ea037d62 100644 --- a/sim/src/mechanics/car.rs +++ b/sim/src/mechanics/car.rs @@ -154,10 +154,10 @@ impl Car { CarState::WaitingToAdvance => CarStatus::Stuck, CarState::Crossing(_, _) => CarStatus::Moving, // Eh they're technically moving, but this is a bit easier to spot - CarState::Unparking(_, _, _) => CarStatus::Parked, - CarState::Parking(_, _, _) => CarStatus::Parked, + CarState::Unparking(_, _, _) => CarStatus::ParkedWithTrip, + CarState::Parking(_, _, _) => CarStatus::ParkedWithTrip, // Changing color for idling buses is helpful - CarState::Idling(_, _) => CarStatus::Parked, + CarState::Idling(_, _) => CarStatus::ParkedWithTrip, }, on: self.router.head(), label: if self.vehicle.vehicle_type == VehicleType::Bus { diff --git a/sim/src/mechanics/parking.rs b/sim/src/mechanics/parking.rs index 918f52b45b..03a6e03a04 100644 --- a/sim/src/mechanics/parking.rs +++ b/sim/src/mechanics/parking.rs @@ -1,4 +1,6 @@ -use crate::{AgentMetadata, CarID, CarStatus, DrawCarInput, ParkedCar, ParkingSpot, Vehicle}; +use crate::{ + AgentMetadata, CarID, CarStatus, DrawCarInput, ParkedCar, ParkingSpot, TripManager, Vehicle, +}; use abstutil::{ deserialize_btreemap, deserialize_multimap, serialize_btreemap, serialize_multimap, MultiMap, }; @@ -142,27 +144,37 @@ impl ParkingSimState { self.dynamically_reserved_cars.remove(&p.vehicle.id); } - pub fn get_draw_cars(&self, id: LaneID, map: &Map) -> Vec { + pub fn get_draw_cars(&self, id: LaneID, map: &Map, trips: &TripManager) -> Vec { let mut cars = Vec::new(); if let Some(ref lane) = self.onstreet_lanes.get(&id) { for spot in lane.spots() { if let Some(car) = self.occupants.get(&spot) { - cars.push(self.get_draw_car(*car, map).unwrap()); + cars.push(self.get_draw_car(*car, map, trips).unwrap()); } } } cars } - pub fn get_draw_car(&self, id: CarID, map: &Map) -> Option { + pub fn get_draw_car(&self, id: CarID, map: &Map, trips: &TripManager) -> Option { let p = self.parked_cars.get(&id)?; match p.spot { ParkingSpot::Onstreet(lane, idx) => { let front_dist = self.onstreet_lanes[&lane].dist_along_for_car(idx, &p.vehicle); + // TODO Is this expensive to do constantly? + let status = if let Some(b) = p.vehicle.owner { + if trips.find_trip_using_car(id, b).is_some() { + CarStatus::ParkedWithTrip + } else { + CarStatus::ParkedWithoutTrip + } + } else { + CarStatus::ParkedWithoutTrip + }; Some(DrawCarInput { id: p.vehicle.id, waiting_for_turn: None, - status: CarStatus::Parked, + status, on: Traversable::Lane(lane), label: None, metadata: AgentMetadata { @@ -182,18 +194,20 @@ impl ParkingSimState { } // There's no DrawCarInput for cars parked offstreet, so we need this. - pub fn canonical_pt(&self, id: CarID, map: &Map) -> Option { + pub fn canonical_pt(&self, id: CarID, map: &Map, trips: &TripManager) -> Option { let p = self.parked_cars.get(&id)?; match p.spot { - ParkingSpot::Onstreet(_, _) => self.get_draw_car(id, map).map(|c| c.body.last_pt()), + ParkingSpot::Onstreet(_, _) => { + self.get_draw_car(id, map, trips).map(|c| c.body.last_pt()) + } ParkingSpot::Offstreet(b, _) => Some(map.get_b(b).label_center), } } - pub fn get_all_draw_cars(&self, map: &Map) -> Vec { + pub fn get_all_draw_cars(&self, map: &Map, trips: &TripManager) -> Vec { self.parked_cars .keys() - .filter_map(|id| self.get_draw_car(*id, map)) + .filter_map(|id| self.get_draw_car(*id, map, trips)) .collect() } diff --git a/sim/src/render.rs b/sim/src/render.rs index 157f0fcd1c..b6a9358e75 100644 --- a/sim/src/render.rs +++ b/sim/src/render.rs @@ -46,7 +46,8 @@ pub struct DrawCarInput { pub enum CarStatus { Moving, Stuck, - Parked, + ParkedWithoutTrip, + ParkedWithTrip, Debug, } diff --git a/sim/src/sim.rs b/sim/src/sim.rs index 1dbe56e7f8..4bf289c13d 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -296,7 +296,7 @@ impl GetDrawAgents for Sim { fn get_draw_cars(&self, on: Traversable, map: &Map) -> Vec { if let Traversable::Lane(l) = on { if map.get_l(l).is_parking() { - return self.parking.get_draw_cars(l, map); + return self.parking.get_draw_cars(l, map, &self.trips); } } self.driving @@ -315,7 +315,7 @@ impl GetDrawAgents for Sim { let mut result = self .driving .get_all_draw_cars(self.time, map, &self.transit); - result.extend(self.parking.get_all_draw_cars(map)); + result.extend(self.parking.get_all_draw_cars(map, &self.trips)); result } @@ -884,7 +884,7 @@ impl Sim { match id { AgentID::Car(id) => self .parking - .canonical_pt(id, map) + .canonical_pt(id, map, &self.trips) .or_else(|| Some(self.get_draw_car(id, map)?.body.last_pt())), AgentID::Pedestrian(id) => Some(self.get_draw_ped(id, map)?.pos), }