mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
dont be so confusing with CarAppearing in interactive commands -- dont retry if there's not room
This commit is contained in:
parent
6ab8372b01
commit
ba71d2d5e6
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user