Merge branch 'HiggsTardigradeTau/fix-slow-motion-effect-after-lag' into 'master'

Fixed slow motion effect after lag

See merge request veloren/veloren!1634
This commit is contained in:
Marcel 2020-12-15 14:31:05 +00:00
commit 754b149316

View File

@ -77,20 +77,18 @@ impl Clock {
pub fn dt(&self) -> Duration { self.last_dt }
pub fn get_stable_dt(&self) -> Duration {
if self.last_dts.len() < NUMBER_OF_DELTAS_COMPARED {
self.last_dt
} else {
let stable_dt = Duration::from_secs_f32(
self.last_dts
.iter()
.skip(self.last_dts.len() - NUMBER_OF_DELTAS_COMPARED)
.min()
.map_or(self.last_dt.as_secs_f32(), |t| t.into_inner()),
);
if self.last_dt > 2 * stable_dt {
tracing::debug!(?self.last_dt, ?self.total_tick_time, "lag spike detected, unusually slow tick");
}
let stable_dt = Duration::from_secs_f32(
self.last_dts
.iter()
.skip(self.last_dts.len() - NUMBER_OF_DELTAS_COMPARED)
.min()
.map_or(self.last_dt.as_secs_f32(), |t| t.into_inner()),
);
if self.last_dts.len() >= NUMBER_OF_DELTAS_COMPARED && self.last_dt > 2 * stable_dt {
tracing::debug!(?self.last_dt, ?self.total_tick_time, "lag spike detected, unusually slow tick");
stable_dt
} else {
self.last_dt
}
}