dont leak unfinished trips when things cant spawn

This commit is contained in:
Dustin Carlino 2019-08-19 15:05:10 -07:00
parent f62965b5e2
commit f9376cddcb
2 changed files with 9 additions and 2 deletions

View File

@ -221,7 +221,6 @@ impl Sim {
// Bypass some layers of abstraction that don't make sense for buses.
// TODO Aww, we create an orphan trip if the bus can't spawn.
let trip =
self.trips
.new_trip(self.time, None, vec![TripLeg::ServeBusRoute(id, route.id)]);
@ -247,6 +246,7 @@ impl Sim {
"No room for a bus headed towards stop {} of {} ({}), giving up",
next_stop_idx, route.name, route.id
));
self.trips.abort_trip_failed_start(trip);
}
}
results
@ -362,11 +362,11 @@ impl Sim {
Command::SpawnCar(create_car, retry_if_no_room),
);
} else {
// TODO Cancel the trip or something?
println!(
"No room to spawn car for {}. Not retrying!",
create_car.trip
);
self.trips.abort_trip_failed_start(create_car.trip);
}
}
Command::SpawnPed(create_ped) => {

View File

@ -361,6 +361,13 @@ impl TripManager {
self.unfinished_trips -= 1;
}
pub fn abort_trip_failed_start(&mut self, id: TripID) {
// TODO Maybe modify the Trip to indicate the cancelation
if !self.trips[id.0].is_bus_trip() {
self.unfinished_trips -= 1;
}
}
pub fn active_agents(&self) -> Vec<AgentID> {
self.active_trip_mode.keys().cloned().collect()
}