From 74ef7660512af86ad954faae3dc99acd498092bd Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 24 Oct 2020 16:34:29 -0400 Subject: [PATCH] Rename running_tps_average -> running_average_delta --- common/src/clock.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/src/clock.rs b/common/src/clock.rs index 02d4946e5f..5fc354622f 100644 --- a/common/src/clock.rs +++ b/common/src/clock.rs @@ -9,7 +9,7 @@ const CLOCK_SMOOTHING: f64 = 0.9; pub struct Clock { last_sys_time: Instant, last_delta: Option, - running_tps_average: f64, + running_average_delta: f64, compensation: f64, } @@ -18,18 +18,18 @@ impl Clock { Self { last_sys_time: Instant::now(), last_delta: None, - running_tps_average: 0.0, + running_average_delta: 0.0, compensation: 1.0, } } - pub fn get_tps(&self) -> f64 { 1.0 / self.running_tps_average } + pub fn get_tps(&self) -> f64 { 1.0 / self.running_average_delta } pub fn get_last_delta(&self) -> Duration { self.last_delta.unwrap_or_else(|| Duration::new(0, 0)) } - pub fn get_avg_delta(&self) -> Duration { Duration::from_secs_f64(self.running_tps_average) } + pub fn get_avg_delta(&self) -> Duration { Duration::from_secs_f64(self.running_average_delta) } pub fn tick(&mut self, tgt: Duration) { span!(_guard, "tick", "Clock::tick"); @@ -37,9 +37,9 @@ impl Clock { // Attempt to sleep to fill the gap. if let Some(sleep_dur) = tgt.checked_sub(delta) { - if self.running_tps_average != 0.0 { + if self.running_average_delta != 0.0 { self.compensation = - (self.compensation + (tgt.as_secs_f64() / self.running_tps_average) - 1.0) + (self.compensation + (tgt.as_secs_f64() / self.running_average_delta) - 1.0) .max(0.0) } @@ -53,10 +53,10 @@ impl Clock { self.last_sys_time = Instant::now(); self.last_delta = Some(delta); - self.running_tps_average = if self.running_tps_average == 0.0 { + self.running_average_delta = if self.running_average_delta == 0.0 { delta.as_secs_f64() } else { - CLOCK_SMOOTHING * self.running_tps_average + CLOCK_SMOOTHING * self.running_average_delta + (1.0 - CLOCK_SMOOTHING) * delta.as_secs_f64() }; }