mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
distinguish parked cars that have a trip scheduled or not
This commit is contained in:
parent
012d5bdd1d
commit
dba7ced094
@ -457,7 +457,12 @@ impl AgentColorScheme {
|
|||||||
CarStatus::Debug => cs.get_def("debug car", Color::BLUE.alpha(0.8)),
|
CarStatus::Debug => cs.get_def("debug car", Color::BLUE.alpha(0.8)),
|
||||||
CarStatus::Moving => cs.get_def("moving car", Color::CYAN),
|
CarStatus::Moving => cs.get_def("moving car", Color::CYAN),
|
||||||
CarStatus::Stuck => cs.get_def("stuck car", Color::rgb(222, 184, 135)),
|
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
|
// TODO Hard to see on the greenish bike lanes? :P
|
||||||
CarStatus::Moving => cs.get_def("moving bike", Color::GREEN),
|
CarStatus::Moving => cs.get_def("moving bike", Color::GREEN),
|
||||||
CarStatus::Stuck => cs.get_def("stuck bike", Color::RED),
|
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),
|
_ => self.by_metadata(&input.metadata),
|
||||||
}
|
}
|
||||||
|
@ -154,10 +154,10 @@ impl Car {
|
|||||||
CarState::WaitingToAdvance => CarStatus::Stuck,
|
CarState::WaitingToAdvance => CarStatus::Stuck,
|
||||||
CarState::Crossing(_, _) => CarStatus::Moving,
|
CarState::Crossing(_, _) => CarStatus::Moving,
|
||||||
// Eh they're technically moving, but this is a bit easier to spot
|
// Eh they're technically moving, but this is a bit easier to spot
|
||||||
CarState::Unparking(_, _, _) => CarStatus::Parked,
|
CarState::Unparking(_, _, _) => CarStatus::ParkedWithTrip,
|
||||||
CarState::Parking(_, _, _) => CarStatus::Parked,
|
CarState::Parking(_, _, _) => CarStatus::ParkedWithTrip,
|
||||||
// Changing color for idling buses is helpful
|
// Changing color for idling buses is helpful
|
||||||
CarState::Idling(_, _) => CarStatus::Parked,
|
CarState::Idling(_, _) => CarStatus::ParkedWithTrip,
|
||||||
},
|
},
|
||||||
on: self.router.head(),
|
on: self.router.head(),
|
||||||
label: if self.vehicle.vehicle_type == VehicleType::Bus {
|
label: if self.vehicle.vehicle_type == VehicleType::Bus {
|
||||||
|
@ -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::{
|
use abstutil::{
|
||||||
deserialize_btreemap, deserialize_multimap, serialize_btreemap, serialize_multimap, MultiMap,
|
deserialize_btreemap, deserialize_multimap, serialize_btreemap, serialize_multimap, MultiMap,
|
||||||
};
|
};
|
||||||
@ -142,27 +144,37 @@ impl ParkingSimState {
|
|||||||
self.dynamically_reserved_cars.remove(&p.vehicle.id);
|
self.dynamically_reserved_cars.remove(&p.vehicle.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_draw_cars(&self, id: LaneID, map: &Map) -> Vec<DrawCarInput> {
|
pub fn get_draw_cars(&self, id: LaneID, map: &Map, trips: &TripManager) -> Vec<DrawCarInput> {
|
||||||
let mut cars = Vec::new();
|
let mut cars = Vec::new();
|
||||||
if let Some(ref lane) = self.onstreet_lanes.get(&id) {
|
if let Some(ref lane) = self.onstreet_lanes.get(&id) {
|
||||||
for spot in lane.spots() {
|
for spot in lane.spots() {
|
||||||
if let Some(car) = self.occupants.get(&spot) {
|
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
|
cars
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_draw_car(&self, id: CarID, map: &Map) -> Option<DrawCarInput> {
|
pub fn get_draw_car(&self, id: CarID, map: &Map, trips: &TripManager) -> Option<DrawCarInput> {
|
||||||
let p = self.parked_cars.get(&id)?;
|
let p = self.parked_cars.get(&id)?;
|
||||||
match p.spot {
|
match p.spot {
|
||||||
ParkingSpot::Onstreet(lane, idx) => {
|
ParkingSpot::Onstreet(lane, idx) => {
|
||||||
let front_dist = self.onstreet_lanes[&lane].dist_along_for_car(idx, &p.vehicle);
|
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 {
|
Some(DrawCarInput {
|
||||||
id: p.vehicle.id,
|
id: p.vehicle.id,
|
||||||
waiting_for_turn: None,
|
waiting_for_turn: None,
|
||||||
status: CarStatus::Parked,
|
status,
|
||||||
on: Traversable::Lane(lane),
|
on: Traversable::Lane(lane),
|
||||||
label: None,
|
label: None,
|
||||||
metadata: AgentMetadata {
|
metadata: AgentMetadata {
|
||||||
@ -182,18 +194,20 @@ impl ParkingSimState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// There's no DrawCarInput for cars parked offstreet, so we need this.
|
// There's no DrawCarInput for cars parked offstreet, so we need this.
|
||||||
pub fn canonical_pt(&self, id: CarID, map: &Map) -> Option<Pt2D> {
|
pub fn canonical_pt(&self, id: CarID, map: &Map, trips: &TripManager) -> Option<Pt2D> {
|
||||||
let p = self.parked_cars.get(&id)?;
|
let p = self.parked_cars.get(&id)?;
|
||||||
match p.spot {
|
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),
|
ParkingSpot::Offstreet(b, _) => Some(map.get_b(b).label_center),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all_draw_cars(&self, map: &Map) -> Vec<DrawCarInput> {
|
pub fn get_all_draw_cars(&self, map: &Map, trips: &TripManager) -> Vec<DrawCarInput> {
|
||||||
self.parked_cars
|
self.parked_cars
|
||||||
.keys()
|
.keys()
|
||||||
.filter_map(|id| self.get_draw_car(*id, map))
|
.filter_map(|id| self.get_draw_car(*id, map, trips))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ pub struct DrawCarInput {
|
|||||||
pub enum CarStatus {
|
pub enum CarStatus {
|
||||||
Moving,
|
Moving,
|
||||||
Stuck,
|
Stuck,
|
||||||
Parked,
|
ParkedWithoutTrip,
|
||||||
|
ParkedWithTrip,
|
||||||
Debug,
|
Debug,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +296,7 @@ impl GetDrawAgents for Sim {
|
|||||||
fn get_draw_cars(&self, on: Traversable, map: &Map) -> Vec<DrawCarInput> {
|
fn get_draw_cars(&self, on: Traversable, map: &Map) -> Vec<DrawCarInput> {
|
||||||
if let Traversable::Lane(l) = on {
|
if let Traversable::Lane(l) = on {
|
||||||
if map.get_l(l).is_parking() {
|
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
|
self.driving
|
||||||
@ -315,7 +315,7 @@ impl GetDrawAgents for Sim {
|
|||||||
let mut result = self
|
let mut result = self
|
||||||
.driving
|
.driving
|
||||||
.get_all_draw_cars(self.time, map, &self.transit);
|
.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
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,7 +884,7 @@ impl Sim {
|
|||||||
match id {
|
match id {
|
||||||
AgentID::Car(id) => self
|
AgentID::Car(id) => self
|
||||||
.parking
|
.parking
|
||||||
.canonical_pt(id, map)
|
.canonical_pt(id, map, &self.trips)
|
||||||
.or_else(|| Some(self.get_draw_car(id, map)?.body.last_pt())),
|
.or_else(|| Some(self.get_draw_car(id, map)?.body.last_pt())),
|
||||||
AgentID::Pedestrian(id) => Some(self.get_draw_ped(id, map)?.pos),
|
AgentID::Pedestrian(id) => Some(self.get_draw_ped(id, map)?.pos),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user