more frequent status updates, based on real time passing, not sim time

This commit is contained in:
Dustin Carlino 2019-03-05 17:05:55 -08:00
parent 063fb85155
commit ce340f5668
3 changed files with 6 additions and 8 deletions

View File

@ -199,7 +199,7 @@ impl AmbientPluginWithPrimaryPlugins for SimControls {
*last_step = Instant::now();
}
if benchmark.has_real_time_passed(std::time::Duration::from_secs(1)) {
if benchmark.has_real_time_passed(Duration::seconds(1.0)) {
// I think the benchmark should naturally account for the delay of the
// secondary sim.
*speed = ctx.primary.sim.measure_speed(benchmark);

View File

@ -25,8 +25,9 @@ pub struct Benchmark {
}
impl Benchmark {
pub fn has_real_time_passed(&self, d: std::time::Duration) -> bool {
self.last_real_time.elapsed() >= d
pub fn has_real_time_passed(&self, d: Duration) -> bool {
// TODO convert to std::time::Duration better
self.last_real_time.elapsed() >= std::time::Duration::from_secs(d.inner_seconds() as u64)
}
}

View File

@ -382,7 +382,7 @@ impl Sim {
}
}
if self.time().is_multiple_of(Duration::minutes(1)) {
if benchmark.has_real_time_passed(Duration::seconds(1.0)) {
println!("{}, {}", self.summary(), self.measure_speed(&mut benchmark));
}
callback(self);
@ -417,7 +417,7 @@ impl Sim {
}
}
}
if self.time().is_multiple_of(Duration::minutes(1)) {
if benchmark.has_real_time_passed(Duration::seconds(1.0)) {
println!("{}, {}", self.summary(), self.measure_speed(&mut benchmark));
}
if self.time() == time_limit {
@ -492,9 +492,6 @@ impl Sim {
pub fn measure_speed(&self, b: &mut Benchmark) -> String {
let dt = Duration::seconds(abstutil::elapsed_seconds(b.last_real_time));
if dt == Duration::ZERO {
return "instantly".to_string();
}
let speed = (self.time - b.last_sim_time) / dt;
b.last_real_time = Instant::now();
b.last_sim_time = self.time;