mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
fix up time limits for headless/tests. fix a few tests now that peds
walk slowly.
This commit is contained in:
parent
fce5d0f6dc
commit
a4f6a773a9
@ -137,7 +137,3 @@
|
||||
- priority_queue crate... internally uses hash, so serialization and determinism probably borked
|
||||
- dig into individual events, still too many?
|
||||
- for laggy heads, often round down and try slightly too early
|
||||
|
||||
- change sim.step API to something like step_to_time
|
||||
- handle savestating better... use scheduler, but ensure at the end of that time
|
||||
- make the desired speed in editor work better
|
||||
|
@ -63,6 +63,8 @@
|
||||
|
||||
- it's a pity we have to redo DrawCar work for all those parked cars every tick
|
||||
- show FPS or some kind of measure of lag
|
||||
- sim Benchmark seems less useful now
|
||||
- some desired_speed should cause lag; cap it
|
||||
- sleep better in the event loop
|
||||
- first make UserInput borrow state and not need to consume
|
||||
- more speculative performance ideas
|
||||
|
@ -38,7 +38,9 @@ pub enum Mode {
|
||||
|
||||
impl GameState {
|
||||
pub fn new(flags: Flags, ctx: &mut EventCtx) -> GameState {
|
||||
let splash = !flags.no_splash;
|
||||
let splash = !flags.no_splash
|
||||
&& !format!("{}", flags.sim_flags.load.display()).contains("data/save");
|
||||
|
||||
let mut rng = flags.sim_flags.make_rng();
|
||||
let mut game = GameState {
|
||||
mode: Mode::Sandbox(SandboxMode::new(ctx)),
|
||||
|
@ -64,7 +64,7 @@ impl DrawPedestrian {
|
||||
if input.waiting_for_turn.is_some() {
|
||||
draw_default.push((foot_color, left_foot.to_polygon()));
|
||||
draw_default.push((foot_color, right_foot.to_polygon()));
|
||||
} else if (jitter && remainder < 3) || (!jitter && remainder >= 3) {
|
||||
} else if jitter == (remainder < 3) {
|
||||
draw_default.push((foot_color, left_foot.to_polygon()));
|
||||
draw_default.push((
|
||||
foot_color,
|
||||
|
@ -112,7 +112,7 @@ impl Duration {
|
||||
remainder -= minutes * 60.0;
|
||||
let seconds = remainder.floor();
|
||||
remainder -= seconds;
|
||||
let centis = (remainder / 0.1).round();
|
||||
let centis = (remainder / 0.1).floor();
|
||||
|
||||
(
|
||||
hours as usize,
|
||||
|
@ -66,9 +66,10 @@ fn main() {
|
||||
sim.run_until_done(
|
||||
&map,
|
||||
move |sim, map| {
|
||||
// TODO We want to savestate at the end of this time; this'll happen at the beginning.
|
||||
if Some(sim.time()) == save_at {
|
||||
sim.save();
|
||||
// Some simulatiosn run for a really long time, just do this.
|
||||
// Some simulations run for a really long time, just do this.
|
||||
if enable_profiler {
|
||||
cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
|
||||
}
|
||||
|
@ -429,13 +429,20 @@ impl Sim {
|
||||
&mut self,
|
||||
map: &Map,
|
||||
callback: F,
|
||||
// Interpreted as a relative time
|
||||
time_limit: Option<Duration>,
|
||||
) {
|
||||
let mut benchmark = self.start_benchmark();
|
||||
loop {
|
||||
let dt = if let Some(lim) = time_limit {
|
||||
// TODO Regular benchmark printing then doesn't happen :\
|
||||
self.time() + lim
|
||||
} else {
|
||||
Duration::seconds(30.0)
|
||||
};
|
||||
|
||||
match panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
// TODO Doesn't respect time_limit!
|
||||
self.step(&map, Duration::seconds(30.0));
|
||||
self.step(&map, dt);
|
||||
})) {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
@ -454,9 +461,6 @@ impl Sim {
|
||||
);
|
||||
}
|
||||
callback(self, map);
|
||||
if Some(self.time()) >= time_limit {
|
||||
panic!("Time limit {} hit", self.time);
|
||||
}
|
||||
if self.is_done() {
|
||||
println!(
|
||||
"{}, speed = {}",
|
||||
@ -465,6 +469,10 @@ impl Sim {
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if let Some(lim) = time_limit {
|
||||
panic!("Time limit {} hit", lim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -472,40 +480,30 @@ impl Sim {
|
||||
&mut self,
|
||||
map: &Map,
|
||||
all_expectations: Vec<Event>,
|
||||
// Interpreted as a relative time
|
||||
time_limit: Duration,
|
||||
) {
|
||||
// TODO Maybe can use run_until_done for this.
|
||||
let mut benchmark = self.start_benchmark();
|
||||
// TODO No benchmark printing at all this way.
|
||||
// TODO Doesn't stop early once all expectations are met.
|
||||
|
||||
let mut expectations = VecDeque::from(all_expectations);
|
||||
loop {
|
||||
if expectations.is_empty() {
|
||||
return;
|
||||
}
|
||||
// TODO Doesn't respect time_limit!
|
||||
self.step(&map, Duration::seconds(30.0));
|
||||
for ev in self.get_events_since_last_step() {
|
||||
if ev == expectations.front().unwrap() {
|
||||
println!("At {}, met expectation {:?}", self.time, ev);
|
||||
expectations.pop_front();
|
||||
if expectations.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.step(&map, self.time() + time_limit);
|
||||
for ev in self.get_events_since_last_step() {
|
||||
if ev == expectations.front().unwrap() {
|
||||
println!("At {}, met expectation {:?}", self.time, ev);
|
||||
expectations.pop_front();
|
||||
if expectations.is_empty() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if benchmark.has_real_time_passed(Duration::seconds(1.0)) {
|
||||
println!(
|
||||
"{}, speed = {}",
|
||||
self.summary(),
|
||||
self.measure_speed(&mut benchmark, true)
|
||||
);
|
||||
}
|
||||
if self.time() == time_limit {
|
||||
panic!(
|
||||
"Time limit {} hit, but some expectations never met: {:?}",
|
||||
self.time, expectations
|
||||
);
|
||||
}
|
||||
}
|
||||
if expectations.is_empty() {
|
||||
return;
|
||||
}
|
||||
panic!(
|
||||
"Time limit {} hit, but some expectations never met: {:?}",
|
||||
time_limit, expectations
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,9 @@ pub fn run(t: &mut TestRunner) {
|
||||
car,
|
||||
ParkingSpot::new(north_parking, 4),
|
||||
)],
|
||||
Duration::minutes(2),
|
||||
Duration::minutes(6),
|
||||
);
|
||||
sim.just_run_until_done(&map, Some(Duration::minutes(4)));
|
||||
sim.just_run_until_done(&map, Some(Duration::minutes(1)));
|
||||
});
|
||||
|
||||
t.run_slow("wander_around_for_parking", |h| {
|
||||
@ -76,8 +76,8 @@ pub fn run(t: &mut TestRunner) {
|
||||
car,
|
||||
ParkingSpot::new(south_parking, 0),
|
||||
)],
|
||||
Duration::minutes(2),
|
||||
Duration::minutes(6),
|
||||
);
|
||||
sim.just_run_until_done(&map, Some(Duration::minutes(4)));
|
||||
sim.just_run_until_done(&map, Some(Duration::minutes(1)));
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::runner::TestRunner;
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
use sim::{Scenario, Sim, SimFlags};
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
@ -32,6 +33,7 @@ pub fn run(t: &mut TestRunner) {
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
|
||||
let dt = Duration::seconds(0.1);
|
||||
for _ in 1..600 {
|
||||
if sim1 != sim2 {
|
||||
// TODO need to sort dicts in json output to compare
|
||||
@ -41,8 +43,8 @@ pub fn run(t: &mut TestRunner) {
|
||||
sim2.save()
|
||||
);
|
||||
}
|
||||
sim1.step(&map);
|
||||
sim2.step(&map);
|
||||
sim1.step(&map, dt);
|
||||
sim2.step(&map, dt);
|
||||
}
|
||||
});
|
||||
|
||||
@ -64,10 +66,8 @@ pub fn run(t: &mut TestRunner) {
|
||||
&mut Timer::throwaway(),
|
||||
);
|
||||
|
||||
for _ in 1..600 {
|
||||
sim1.step(&map);
|
||||
sim2.step(&map);
|
||||
}
|
||||
sim1.step(&map, Duration::minutes(10));
|
||||
sim2.step(&map, Duration::minutes(10));
|
||||
|
||||
if sim1 != sim2 {
|
||||
panic!(
|
||||
@ -79,9 +79,7 @@ pub fn run(t: &mut TestRunner) {
|
||||
|
||||
let sim1_save = sim1.save();
|
||||
|
||||
for _ in 1..60 {
|
||||
sim1.step(&map);
|
||||
}
|
||||
sim1.step(&map, Duration::seconds(30.0));
|
||||
|
||||
if sim1 == sim2 {
|
||||
panic!(
|
||||
|
@ -32,8 +32,8 @@ pub fn run(t: &mut TestRunner) {
|
||||
),
|
||||
Event::PedReachedBuilding(ped.unwrap(), goal_bldg),
|
||||
],
|
||||
Duration::minutes(3),
|
||||
Duration::minutes(7),
|
||||
);
|
||||
sim.just_run_until_done(&map, Some(Duration::minutes(4)));
|
||||
sim.just_run_until_done(&map, Some(Duration::minutes(1)));
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user