Make auto-panning speed uniform (#1690)

* Make auto-panning speed uniform

* Abstract time-delta calculation to `TimeInfo`

* Update docs and add additional check

* Apply code review changes
This commit is contained in:
Elbert Ronnie
2024-03-16 06:36:22 +00:00
committed by GitHub
parent 56f8ecacc9
commit 42c822020e
17 changed files with 140 additions and 113 deletions
@@ -4,6 +4,7 @@ use crate::messages::input_mapper::utility_types::input_keyboard::{KeyStates, NU
use crate::messages::input_mapper::utility_types::input_mouse::NUMBER_OF_MOUSE_BUTTONS;
use crate::messages::prelude::*;
use core::time::Duration;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
@@ -146,3 +147,22 @@ impl ActionKeys {
}
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct FrameTimeInfo {
timestamp: Duration,
prev_timestamp: Option<Duration>,
}
impl FrameTimeInfo {
pub fn frame_duration(&self) -> Option<Duration> {
self.prev_timestamp.map(|prev| self.timestamp - prev)
}
pub fn advance_timestamp(&mut self, next_timestamp: Duration) {
debug_assert!(next_timestamp >= self.timestamp);
self.prev_timestamp = Some(self.timestamp);
self.timestamp = next_timestamp;
}
}