From ba71d2d5e6d7ff320f070088c0b0795ad122206e Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 12 May 2019 14:54:44 -0700 Subject: [PATCH] dont be so confusing with CarAppearing in interactive commands -- dont retry if there's not room --- editor/src/sandbox/spawner.rs | 5 ++--- sim/src/make/scenario.rs | 2 +- sim/src/make/spawner.rs | 8 +++++--- sim/src/scheduler.rs | 3 ++- sim/src/sim.rs | 15 +++++++++++---- sim/src/trips.rs | 17 ++++++++--------- tests/src/parking.rs | 4 ++-- tests/src/transit.rs | 2 +- tests/src/trips.rs | 2 +- 9 files changed, 33 insertions(+), 25 deletions(-) diff --git a/editor/src/sandbox/spawner.rs b/editor/src/sandbox/spawner.rs index 2c4eaa63d7..e75058525b 100644 --- a/editor/src/sandbox/spawner.rs +++ b/editor/src/sandbox/spawner.rs @@ -253,7 +253,7 @@ impl AgentSpawner { } } }; - sim.spawn_all_trips(map, &mut Timer::new("spawn trip")); + sim.spawn_all_trips(map, &mut Timer::new("spawn trip"), false); sim.step(map, SMALL_DT); //*ctx.recalculate_current_selection = true; return true; @@ -294,7 +294,6 @@ fn spawn_agents_around(i: IntersectionID, ui: &mut UI) { continue; } sim.schedule_trip( - // TODO +1? sim.time(), TripSpec::CarAppearing { start_pos: Position::new( @@ -332,7 +331,7 @@ fn spawn_agents_around(i: IntersectionID, ui: &mut UI) { } } - sim.spawn_all_trips(map, &mut Timer::throwaway()); + sim.spawn_all_trips(map, &mut Timer::throwaway(), false); sim.step(map, SMALL_DT); //*ctx.recalculate_current_selection = true; } diff --git a/sim/src/make/scenario.rs b/sim/src/make/scenario.rs index 9468355905..b8d41d2ade 100644 --- a/sim/src/make/scenario.rs +++ b/sim/src/make/scenario.rs @@ -118,7 +118,7 @@ impl Scenario { s.spawn_bikes(rng, sim, &neighborhoods, map, timer); } - sim.spawn_all_trips(map, timer); + sim.spawn_all_trips(map, timer, true); timer.stop(&format!("Instantiating {}", self.scenario_name)); } diff --git a/sim/src/make/spawner.rs b/sim/src/make/spawner.rs index 0fa37faef5..ff7463e84c 100644 --- a/sim/src/make/spawner.rs +++ b/sim/src/make/spawner.rs @@ -153,6 +153,7 @@ impl TripSpawner { trips: &mut TripManager, scheduler: &mut Scheduler, timer: &mut Timer, + retry_if_no_room: bool, ) { let paths = calculate_paths( map, @@ -190,9 +191,10 @@ impl TripSpawner { let router = goal.make_router(path, map, vehicle.vehicle_type); scheduler.push( start_time, - Command::SpawnCar(CreateCar::for_appearing( - vehicle, start_pos, router, trip, - )), + Command::SpawnCar( + CreateCar::for_appearing(vehicle, start_pos, router, trip), + retry_if_no_room, + ), ); } TripSpec::UsingParkedCar { diff --git a/sim/src/scheduler.rs b/sim/src/scheduler.rs index ccea8b6854..1bbd74de8b 100644 --- a/sim/src/scheduler.rs +++ b/sim/src/scheduler.rs @@ -7,7 +7,8 @@ use serde_derive::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, PartialEq)] pub enum Command { - SpawnCar(CreateCar), + // If true, retry when there's no room to spawn somewhere + SpawnCar(CreateCar, bool), SpawnPed(CreatePedestrian), UpdateCar(CarID), // Distinguish this from UpdateCar to avoid confusing things diff --git a/sim/src/sim.rs b/sim/src/sim.rs index d274ea7e1c..efba40babf 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -128,13 +128,14 @@ impl Sim { (ped_id, car_id) } - pub fn spawn_all_trips(&mut self, map: &Map, timer: &mut Timer) { + pub fn spawn_all_trips(&mut self, map: &Map, timer: &mut Timer, retry_if_no_room: bool) { self.spawner.spawn_all( map, &self.parking, &mut self.trips, &mut self.scheduler, timer, + retry_if_no_room, ); } @@ -304,7 +305,7 @@ impl Sim { self.time = time; match cmd { - Command::SpawnCar(create_car) => { + Command::SpawnCar(create_car, retry_if_no_room) => { if self.driving.start_car_on_lane( self.time, create_car.clone(), @@ -320,10 +321,16 @@ impl Sim { if let Some(parked_car) = create_car.maybe_parked_car { self.parking.remove_parked_car(parked_car); } - } else { + } else if retry_if_no_room { self.scheduler.push( self.time + BLIND_RETRY_TO_SPAWN, - Command::SpawnCar(create_car), + 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 ); } } diff --git a/sim/src/trips.rs b/sim/src/trips.rs index f3dd102f97..689d8ec990 100644 --- a/sim/src/trips.rs +++ b/sim/src/trips.rs @@ -126,9 +126,10 @@ impl TripManager { let router = drive_to.make_router(path, map, parked_car.vehicle.vehicle_type); scheduler.push( time, - Command::SpawnCar(CreateCar::for_parked_car( - parked_car, router, trip.id, parking, map, - )), + Command::SpawnCar( + CreateCar::for_parked_car(parked_car, router, trip.id, parking, map), + true, + ), ); } @@ -175,12 +176,10 @@ impl TripManager { let router = drive_to.make_router(path, map, vehicle.vehicle_type); scheduler.push( time, - Command::SpawnCar(CreateCar::for_appearing( - vehicle, - driving_pos, - router, - trip.id, - )), + Command::SpawnCar( + CreateCar::for_appearing(vehicle, driving_pos, router, trip.id), + true, + ), ); } diff --git a/tests/src/parking.rs b/tests/src/parking.rs index a3be05042f..86a4332a69 100644 --- a/tests/src/parking.rs +++ b/tests/src/parking.rs @@ -29,7 +29,7 @@ pub fn run(t: &mut TestRunner) { }, &map, ); - sim.spawn_all_trips(&map, &mut Timer::throwaway()); + sim.spawn_all_trips(&map, &mut Timer::throwaway(), false); h.setup_done(&sim); sim.run_until_expectations_met( @@ -67,7 +67,7 @@ pub fn run(t: &mut TestRunner) { }, &map, ); - sim.spawn_all_trips(&map, &mut Timer::throwaway()); + sim.spawn_all_trips(&map, &mut Timer::throwaway(), false); h.setup_done(&sim); sim.run_until_expectations_met( diff --git a/tests/src/transit.rs b/tests/src/transit.rs index 50c274089b..02cfa36dd3 100644 --- a/tests/src/transit.rs +++ b/tests/src/transit.rs @@ -58,7 +58,7 @@ pub fn run(t: &mut TestRunner) { ) .0 .unwrap(); - sim.spawn_all_trips(&map, &mut Timer::throwaway()); + sim.spawn_all_trips(&map, &mut Timer::throwaway(), false); h.setup_done(&sim); sim.run_until_expectations_met( diff --git a/tests/src/trips.rs b/tests/src/trips.rs index 89d4b6fefd..493949318c 100644 --- a/tests/src/trips.rs +++ b/tests/src/trips.rs @@ -20,7 +20,7 @@ pub fn run(t: &mut TestRunner) { }, &map, ); - sim.spawn_all_trips(&map, &mut Timer::throwaway()); + sim.spawn_all_trips(&map, &mut Timer::throwaway(), false); h.setup_done(&sim); sim.run_until_expectations_met(