mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
track num_active_trips to speedup is_done query
This commit is contained in:
parent
8f5dd61ce5
commit
5bba5ce31e
@ -18,6 +18,7 @@ pub struct TripManager {
|
||||
deserialize_with = "deserialize_btreemap"
|
||||
)]
|
||||
active_trip_mode: BTreeMap<AgentID, TripID>,
|
||||
num_bus_trips: usize,
|
||||
|
||||
events: Vec<Event>,
|
||||
}
|
||||
@ -27,6 +28,7 @@ impl TripManager {
|
||||
TripManager {
|
||||
trips: Vec::new(),
|
||||
active_trip_mode: BTreeMap::new(),
|
||||
num_bus_trips: 0,
|
||||
events: Vec::new(),
|
||||
}
|
||||
}
|
||||
@ -50,6 +52,9 @@ impl TripManager {
|
||||
// TODO ensure a trip only has one active agent (aka, not walking and driving at the same
|
||||
// time)
|
||||
self.active_trip_mode.insert(agent, trip);
|
||||
if self.trips[trip.0].is_bus_trip() {
|
||||
self.num_bus_trips += 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn car_reached_parking_spot(
|
||||
@ -377,10 +382,7 @@ impl TripManager {
|
||||
|
||||
// Not including buses
|
||||
pub fn num_active_trips(&self) -> usize {
|
||||
self.active_trip_mode
|
||||
.values()
|
||||
.filter(|trip| !self.trips[trip.0].is_bus_trip())
|
||||
.count()
|
||||
self.active_trip_mode.len() - self.num_bus_trips
|
||||
}
|
||||
|
||||
pub fn is_done(&self) -> bool {
|
||||
|
Loading…
Reference in New Issue
Block a user