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