mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +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);
|
sim.step(map, SMALL_DT);
|
||||||
//*ctx.recalculate_current_selection = true;
|
//*ctx.recalculate_current_selection = true;
|
||||||
return true;
|
return true;
|
||||||
@ -294,7 +294,6 @@ fn spawn_agents_around(i: IntersectionID, ui: &mut UI) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sim.schedule_trip(
|
sim.schedule_trip(
|
||||||
// TODO +1?
|
|
||||||
sim.time(),
|
sim.time(),
|
||||||
TripSpec::CarAppearing {
|
TripSpec::CarAppearing {
|
||||||
start_pos: Position::new(
|
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);
|
sim.step(map, SMALL_DT);
|
||||||
//*ctx.recalculate_current_selection = true;
|
//*ctx.recalculate_current_selection = true;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ impl Scenario {
|
|||||||
s.spawn_bikes(rng, sim, &neighborhoods, map, timer);
|
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));
|
timer.stop(&format!("Instantiating {}", self.scenario_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ impl TripSpawner {
|
|||||||
trips: &mut TripManager,
|
trips: &mut TripManager,
|
||||||
scheduler: &mut Scheduler,
|
scheduler: &mut Scheduler,
|
||||||
timer: &mut Timer,
|
timer: &mut Timer,
|
||||||
|
retry_if_no_room: bool,
|
||||||
) {
|
) {
|
||||||
let paths = calculate_paths(
|
let paths = calculate_paths(
|
||||||
map,
|
map,
|
||||||
@ -190,9 +191,10 @@ impl TripSpawner {
|
|||||||
let router = goal.make_router(path, map, vehicle.vehicle_type);
|
let router = goal.make_router(path, map, vehicle.vehicle_type);
|
||||||
scheduler.push(
|
scheduler.push(
|
||||||
start_time,
|
start_time,
|
||||||
Command::SpawnCar(CreateCar::for_appearing(
|
Command::SpawnCar(
|
||||||
vehicle, start_pos, router, trip,
|
CreateCar::for_appearing(vehicle, start_pos, router, trip),
|
||||||
)),
|
retry_if_no_room,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
TripSpec::UsingParkedCar {
|
TripSpec::UsingParkedCar {
|
||||||
|
@ -7,7 +7,8 @@ use serde_derive::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq)]
|
#[derive(Serialize, Deserialize, PartialEq)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
SpawnCar(CreateCar),
|
// If true, retry when there's no room to spawn somewhere
|
||||||
|
SpawnCar(CreateCar, bool),
|
||||||
SpawnPed(CreatePedestrian),
|
SpawnPed(CreatePedestrian),
|
||||||
UpdateCar(CarID),
|
UpdateCar(CarID),
|
||||||
// Distinguish this from UpdateCar to avoid confusing things
|
// Distinguish this from UpdateCar to avoid confusing things
|
||||||
|
@ -128,13 +128,14 @@ impl Sim {
|
|||||||
(ped_id, car_id)
|
(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(
|
self.spawner.spawn_all(
|
||||||
map,
|
map,
|
||||||
&self.parking,
|
&self.parking,
|
||||||
&mut self.trips,
|
&mut self.trips,
|
||||||
&mut self.scheduler,
|
&mut self.scheduler,
|
||||||
timer,
|
timer,
|
||||||
|
retry_if_no_room,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +305,7 @@ impl Sim {
|
|||||||
|
|
||||||
self.time = time;
|
self.time = time;
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::SpawnCar(create_car) => {
|
Command::SpawnCar(create_car, retry_if_no_room) => {
|
||||||
if self.driving.start_car_on_lane(
|
if self.driving.start_car_on_lane(
|
||||||
self.time,
|
self.time,
|
||||||
create_car.clone(),
|
create_car.clone(),
|
||||||
@ -320,10 +321,16 @@ impl Sim {
|
|||||||
if let Some(parked_car) = create_car.maybe_parked_car {
|
if let Some(parked_car) = create_car.maybe_parked_car {
|
||||||
self.parking.remove_parked_car(parked_car);
|
self.parking.remove_parked_car(parked_car);
|
||||||
}
|
}
|
||||||
} else {
|
} else if retry_if_no_room {
|
||||||
self.scheduler.push(
|
self.scheduler.push(
|
||||||
self.time + BLIND_RETRY_TO_SPAWN,
|
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);
|
let router = drive_to.make_router(path, map, parked_car.vehicle.vehicle_type);
|
||||||
scheduler.push(
|
scheduler.push(
|
||||||
time,
|
time,
|
||||||
Command::SpawnCar(CreateCar::for_parked_car(
|
Command::SpawnCar(
|
||||||
parked_car, router, trip.id, parking, map,
|
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);
|
let router = drive_to.make_router(path, map, vehicle.vehicle_type);
|
||||||
scheduler.push(
|
scheduler.push(
|
||||||
time,
|
time,
|
||||||
Command::SpawnCar(CreateCar::for_appearing(
|
Command::SpawnCar(
|
||||||
vehicle,
|
CreateCar::for_appearing(vehicle, driving_pos, router, trip.id),
|
||||||
driving_pos,
|
true,
|
||||||
router,
|
),
|
||||||
trip.id,
|
|
||||||
)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
},
|
},
|
||||||
&map,
|
&map,
|
||||||
);
|
);
|
||||||
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
sim.spawn_all_trips(&map, &mut Timer::throwaway(), false);
|
||||||
h.setup_done(&sim);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
@ -67,7 +67,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
},
|
},
|
||||||
&map,
|
&map,
|
||||||
);
|
);
|
||||||
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
sim.spawn_all_trips(&map, &mut Timer::throwaway(), false);
|
||||||
h.setup_done(&sim);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
|
@ -58,7 +58,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
)
|
)
|
||||||
.0
|
.0
|
||||||
.unwrap();
|
.unwrap();
|
||||||
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
sim.spawn_all_trips(&map, &mut Timer::throwaway(), false);
|
||||||
h.setup_done(&sim);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
|
@ -20,7 +20,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
},
|
},
|
||||||
&map,
|
&map,
|
||||||
);
|
);
|
||||||
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
sim.spawn_all_trips(&map, &mut Timer::throwaway(), false);
|
||||||
h.setup_done(&sim);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
|
Loading…
Reference in New Issue
Block a user