sdl2_extras/common/
delta_time.rs

1use std::ops;
2use std::time::Duration;
3use floating_duration::TimeAsFloat;
4
5#[derive(Default)]
6pub struct DeltaTime {
7    pub elapsed: Duration
8}
9
10impl<'a> ops::Mul<&'a DeltaTime> for f32 {
11    type Output = f32;
12
13    fn mul(self, rhs: &DeltaTime) -> Self {
14        self * rhs.elapsed.as_fractional_secs() as f32
15    }
16}
17
18impl<'a> ops::Mul<f32> for &'a DeltaTime {
19    type Output = f32;
20
21    fn mul(self, rhs: f32) -> Self::Output {
22        rhs * self
23    }
24}
25
26impl<'a> ops::Div<&'a DeltaTime> for f32 {
27    type Output = f32;
28
29    fn div(self, rhs: &DeltaTime) -> Self {
30        self / rhs.elapsed.as_fractional_secs() as f32
31    }
32}
33
34impl<'a> ops::Div<f32> for &'a DeltaTime {
35    type Output = f32;
36
37    fn div(self, rhs: f32) -> Self::Output {
38        self.elapsed.as_fractional_secs() as f32 / rhs
39    }
40}