fermium/timer.rs
1//! Timer related functionality.
2
3use crate::{c_int, c_void, stdinc::*};
4
5/// Function prototype for the timer callback function.
6///
7/// The callback function is passed the current timer interval and returns the
8/// next timer interval. If the returned value is the same as the one passed in,
9/// the periodic alarm continues, otherwise a new alarm is scheduled. If the
10/// callback returns 0, the periodic alarm is cancelled.
11pub type SDL_TimerCallback =
12 Option<unsafe extern "C" fn(interval: Uint32, param: *mut c_void) -> Uint32>;
13
14/// Definition of the timer ID type.
15#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
16#[repr(transparent)]
17pub struct SDL_TimerID(pub c_int);
18
19extern "C" {
20 /// Get the number of milliseconds since the SDL library initialization.
21 ///
22 /// **Note:** This value wraps if the program runs for more than ~49 days.
23 pub fn SDL_GetTicks() -> Uint32;
24
25 /// Get the current value of the high resolution counter.
26 pub fn SDL_GetPerformanceCounter() -> Uint64;
27
28 /// Get the count per second of the high resolution counter.
29 pub fn SDL_GetPerformanceFrequency() -> Uint64;
30
31 /// Wait a specified number of milliseconds before returning.
32 ///
33 /// This is essentially the same as
34 /// [`std::thread::sleep_ms`](https://doc.rust-lang.org/std/thread/fn.sleep_ms.html),
35 /// which incidentally is deprecated for being a slightly inferior interface
36 /// compared to
37 /// [`std::thread::sleep`](https://doc.rust-lang.org/std/thread/fn.sleep.html).
38 pub fn SDL_Delay(ms: Uint32);
39
40 /// Add a new timer to the pool of timers already running.
41 ///
42 /// **Returns:** A timer ID, or 0 when an error occurs.
43 pub fn SDL_AddTimer(
44 interval: Uint32, callback: SDL_TimerCallback, param: *mut c_void,
45 ) -> SDL_TimerID;
46
47 /// Remove a timer by ID.
48 ///
49 /// **Returns:** A boolean value indicating success or failure.
50 ///
51 /// **Warning:** It is not safe to remove a timer multiple times.
52 pub fn SDL_RemoveTimer(id: SDL_TimerID) -> SDL_bool;
53}