mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 16:36:02 +03:00
speed up initial trip spawning by not constantly maintaining an in-order priority queue
This commit is contained in:
parent
69a7b92499
commit
12d981c654
@ -167,7 +167,7 @@ impl TripSpawner {
|
||||
for ((start_time, ped_id, car_id, spec), req, maybe_path) in paths {
|
||||
timer.next();
|
||||
if maybe_path.is_none() {
|
||||
timer.warn(format!("{:?} couldn't find the first path {}", spec, req));
|
||||
timer.warn(format!("Some trip couldn't find the first path {}", req));
|
||||
continue;
|
||||
}
|
||||
let path = maybe_path.unwrap();
|
||||
@ -189,7 +189,7 @@ impl TripSpawner {
|
||||
}
|
||||
let trip = trips.new_trip(start_time, legs);
|
||||
let router = goal.make_router(path, map, vehicle.vehicle_type);
|
||||
scheduler.push(
|
||||
scheduler.quick_push(
|
||||
start_time,
|
||||
Command::SpawnCar(
|
||||
CreateCar::for_appearing(vehicle, start_pos, router, trip),
|
||||
@ -227,7 +227,7 @@ impl TripSpawner {
|
||||
}
|
||||
let trip = trips.new_trip(start_time, legs);
|
||||
|
||||
scheduler.push(
|
||||
scheduler.quick_push(
|
||||
start_time,
|
||||
Command::SpawnPed(CreatePedestrian {
|
||||
id: ped_id.unwrap(),
|
||||
@ -249,7 +249,7 @@ impl TripSpawner {
|
||||
vec![TripLeg::Walk(ped_id.unwrap(), ped_speed, goal.clone())],
|
||||
);
|
||||
|
||||
scheduler.push(
|
||||
scheduler.quick_push(
|
||||
start_time,
|
||||
Command::SpawnPed(CreatePedestrian {
|
||||
id: ped_id.unwrap(),
|
||||
@ -284,7 +284,7 @@ impl TripSpawner {
|
||||
};
|
||||
let trip = trips.new_trip(start_time, legs);
|
||||
|
||||
scheduler.push(
|
||||
scheduler.quick_push(
|
||||
start_time,
|
||||
Command::SpawnPed(CreatePedestrian {
|
||||
id: ped_id.unwrap(),
|
||||
@ -314,7 +314,7 @@ impl TripSpawner {
|
||||
],
|
||||
);
|
||||
|
||||
scheduler.push(
|
||||
scheduler.quick_push(
|
||||
start_time,
|
||||
Command::SpawnPed(CreatePedestrian {
|
||||
id: ped_id.unwrap(),
|
||||
@ -328,6 +328,10 @@ impl TripSpawner {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timer.start("finalize spawned trips");
|
||||
scheduler.finalize_batch();
|
||||
timer.stop("finalize spawned trips");
|
||||
}
|
||||
|
||||
pub fn is_done(&self) -> bool {
|
||||
|
@ -73,6 +73,16 @@ impl Scheduler {
|
||||
self.items.insert(idx, (time, cmd));
|
||||
}
|
||||
|
||||
// Doesn't sort or touch the histogram. Have to call finalize_batch() after. Only for
|
||||
// scheduling lots of stuff at the beginning of a simulation.
|
||||
pub fn quick_push(&mut self, time: Duration, cmd: Command) {
|
||||
self.items.push((time, cmd));
|
||||
}
|
||||
|
||||
pub fn finalize_batch(&mut self) {
|
||||
self.items.sort_by_key(|(time, _)| -*time);
|
||||
}
|
||||
|
||||
pub fn update(&mut self, cmd: Command, new_time: Duration) {
|
||||
if new_time < self.latest_time {
|
||||
panic!(
|
||||
|
Loading…
Reference in New Issue
Block a user