rich_sdl2_rust/timer/
ticks.rs

1use std::ops;
2
3use crate::{bind, Sdl};
4
5/// An elapsed time from when SDL2 has initialized. Please note that the value formed 32-bit, overflowing after about 49 days.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
7pub struct Ticks(pub u32);
8
9impl Ticks {
10    /// Gets a current [`Ticks`].
11    #[must_use]
12    pub fn now(_: &Sdl) -> Self {
13        let ticks = unsafe { bind::SDL_GetTicks() };
14        Ticks(ticks)
15    }
16}
17
18impl ops::Add<u32> for Ticks {
19    type Output = Ticks;
20
21    fn add(self, rhs: u32) -> Self::Output {
22        Ticks(self.0 + rhs)
23    }
24}
25
26impl ops::Add<Ticks> for u32 {
27    type Output = Ticks;
28
29    fn add(self, rhs: Ticks) -> Self::Output {
30        Ticks(self + rhs.0)
31    }
32}
33
34impl ops::Add<Ticks> for Ticks {
35    type Output = Ticks;
36
37    fn add(self, rhs: Ticks) -> Self::Output {
38        Ticks(self.0 + rhs.0)
39    }
40}
41
42impl ops::Sub for Ticks {
43    type Output = i32;
44
45    fn sub(self, rhs: Self) -> Self::Output {
46        self.0 as i32 - rhs.0 as i32
47    }
48}