mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 16:02:23 +03:00
use run_until_done in more places
This commit is contained in:
parent
3333aa69a8
commit
9115a9e7f1
@ -29,7 +29,7 @@ struct Flags {
|
|||||||
big_sim: bool,
|
big_sim: bool,
|
||||||
|
|
||||||
/// Scenario name for savestating
|
/// Scenario name for savestating
|
||||||
#[structopt(long = "scenario_name", default_value = "editor")]
|
#[structopt(long = "scenario_name", default_value = "headless")]
|
||||||
scenario_name: String,
|
scenario_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,15 +62,15 @@ fn main() {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut benchmark = sim.start_benchmark();
|
sim::init::run_until_done(
|
||||||
loop {
|
&mut sim,
|
||||||
sim.step(&map, &control_map);
|
&map,
|
||||||
if sim.time.is_multiple_of(sim::Tick::from_seconds(60)) {
|
&control_map,
|
||||||
let speed = sim.measure_speed(&mut benchmark);
|
|sim| {
|
||||||
println!("{0}, speed = {1:.2}x", sim.summary(), speed);
|
if Some(sim.time) == save_at {
|
||||||
}
|
sim.save();
|
||||||
if Some(sim.time) == save_at {
|
}
|
||||||
sim.save();
|
},
|
||||||
}
|
|_parked| {},
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use abstutil;
|
use abstutil;
|
||||||
use control::ControlMap;
|
use control::ControlMap;
|
||||||
use map_model::{Edits, Map};
|
use map_model::{Edits, Map};
|
||||||
use {Sim, Tick};
|
use {ParkedCar, Sim, Tick};
|
||||||
|
|
||||||
// Convenience method to setup everything.
|
// Convenience method to setup everything.
|
||||||
pub fn load(
|
pub fn load(
|
||||||
@ -45,14 +45,24 @@ pub fn big_spawn(sim: &mut Sim, map: &Map) {
|
|||||||
// TODO share the helpers for spawning specific parking spots and stuff?
|
// TODO share the helpers for spawning specific parking spots and stuff?
|
||||||
|
|
||||||
// TODO time limit and a callback for the step results?
|
// TODO time limit and a callback for the step results?
|
||||||
pub fn run_until_done(sim: &mut Sim, map: &Map, control_map: &ControlMap) {
|
pub fn run_until_done<CB1, CB2>(
|
||||||
|
sim: &mut Sim,
|
||||||
|
map: &Map,
|
||||||
|
control_map: &ControlMap,
|
||||||
|
sim_cb: CB1,
|
||||||
|
handle_step: CB2,
|
||||||
|
) where
|
||||||
|
CB1: Fn(&Sim),
|
||||||
|
CB2: Fn(Vec<ParkedCar>),
|
||||||
|
{
|
||||||
let mut benchmark = sim.start_benchmark();
|
let mut benchmark = sim.start_benchmark();
|
||||||
loop {
|
loop {
|
||||||
sim.step(&map, &control_map);
|
handle_step(sim.step(&map, &control_map));
|
||||||
if sim.time.is_multiple_of(Tick::from_seconds(60)) {
|
if sim.time.is_multiple_of(Tick::from_seconds(60)) {
|
||||||
let speed = sim.measure_speed(&mut benchmark);
|
let speed = sim.measure_speed(&mut benchmark);
|
||||||
println!("{0}, speed = {1:.2}x", sim.summary(), speed);
|
println!("{0}, speed = {1:.2}x", sim.summary(), speed);
|
||||||
}
|
}
|
||||||
|
sim_cb(sim);
|
||||||
if sim.is_done() {
|
if sim.is_done() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ fn aorta_model_completes() {
|
|||||||
Some(sim::Tick::from_seconds(30)),
|
Some(sim::Tick::from_seconds(30)),
|
||||||
);
|
);
|
||||||
sim::init::small_spawn(&mut sim, &map);
|
sim::init::small_spawn(&mut sim, &map);
|
||||||
sim::init::run_until_done(&mut sim, &map, &control_map);
|
sim::init::run_until_done(&mut sim, &map, &control_map, |_sim| {}, |_parked| {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO other tests (not completion) to add:
|
// TODO other tests (not completion) to add:
|
||||||
|
@ -20,19 +20,19 @@ fn park_on_goal_st() {
|
|||||||
sim.seed_specific_parked_cars(parking2, (5..8).collect());
|
sim.seed_specific_parked_cars(parking2, (5..8).collect());
|
||||||
sim.start_parked_car_with_goal(&map, car, driving2);
|
sim.start_parked_car_with_goal(&map, car, driving2);
|
||||||
|
|
||||||
loop {
|
sim::init::run_until_done(
|
||||||
if let Some(p) = sim.step(&map, &control_map).first() {
|
&mut sim,
|
||||||
assert_eq!(p.car, car);
|
&map,
|
||||||
assert_eq!(p.spot.lane, parking2);
|
&control_map,
|
||||||
assert_eq!(p.spot.idx, 4);
|
|_sim| {},
|
||||||
break;
|
|parked| {
|
||||||
}
|
if let Some(p) = parked.first() {
|
||||||
if sim.time.is_multiple_of(sim::Tick::from_seconds(60)) {
|
assert_eq!(p.car, car);
|
||||||
println!("{}", sim.summary());
|
assert_eq!(p.spot.lane, parking2);
|
||||||
}
|
assert_eq!(p.spot.idx, 4);
|
||||||
// TODO time limit
|
}
|
||||||
}
|
},
|
||||||
println!("Expected conditions met at {}", sim.time);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -48,19 +48,19 @@ fn wander_around_for_parking() {
|
|||||||
sim.seed_specific_parked_cars(parking2, (0..8).collect());
|
sim.seed_specific_parked_cars(parking2, (0..8).collect());
|
||||||
sim.start_parked_car_with_goal(&map, car, driving2);
|
sim.start_parked_car_with_goal(&map, car, driving2);
|
||||||
|
|
||||||
loop {
|
sim::init::run_until_done(
|
||||||
if let Some(p) = sim.step(&map, &control_map).first() {
|
&mut sim,
|
||||||
assert_eq!(p.car, car);
|
&map,
|
||||||
assert_eq!(p.spot.lane, parking1);
|
&control_map,
|
||||||
assert_eq!(p.spot.idx, 0);
|
|_sim| {},
|
||||||
break;
|
|parked| {
|
||||||
}
|
if let Some(p) = parked.first() {
|
||||||
if sim.time.is_multiple_of(sim::Tick::from_seconds(60)) {
|
assert_eq!(p.car, car);
|
||||||
println!("{}", sim.summary());
|
assert_eq!(p.spot.lane, parking1);
|
||||||
}
|
assert_eq!(p.spot.idx, 0);
|
||||||
// TODO time limit
|
}
|
||||||
}
|
},
|
||||||
println!("Expected conditions met at {}", sim.time);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
|
Loading…
Reference in New Issue
Block a user