Rename running_tps_average -> running_average_delta

This commit is contained in:
Imbris 2020-10-24 16:34:29 -04:00
parent 6566802b7f
commit 74ef766051

View File

@ -9,7 +9,7 @@ const CLOCK_SMOOTHING: f64 = 0.9;
pub struct Clock {
last_sys_time: Instant,
last_delta: Option<Duration>,
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()
};
}