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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![feature(arc_new_cyclic)]

/*!

Riddle crate supporting some basic game-centric time functionality.

The most significant of which is keeping track of framerate, and providing
a centralized place to access a consistent delta_t when running game logic.

# Riddle Example

The **recommended** way to use this crate is through the main `riddle` crate.
Riddle exposes this crate through `riddle::time`.

```no_run
use riddle::*;
use std::sync::{Arc, atomic::{AtomicBool, Ordering}};

fn main() -> Result<(), RiddleError> {
    let rdl =  RiddleLib::new()?;

    let quit_flag = Arc::new(AtomicBool::new(false));
    rdl.state().time().register_timer(std::time::Duration::from_millis(200), {
        let quit_flag = quit_flag.clone();
        move || { quit_flag.store(true, Ordering::Relaxed); }
    });

    rdl.run(move |rdl| {
        if quit_flag.load(Ordering::Relaxed) {
            rdl.quit();
        }

        if let Event::ProcessFrame = rdl.event() {
            // FPS: rdl.time().fps()
        }
    })
}
```

# Direct Example

If you don't want to depend on `riddle`, you can use this crate directly.

```
use riddle_time::*;
use std::sync::{Arc, atomic::{AtomicBool, Ordering}};

fn main() {
    let time = TimeSystem::new();

    let quit_flag = Arc::new(AtomicBool::new(false));
    time.register_timer(std::time::Duration::from_millis(200), {
        let quit_flag = quit_flag.clone();
        move || { quit_flag.store(true, Ordering::Relaxed); }
    });

    while !quit_flag.load(Ordering::Relaxed) {
        std::thread::sleep(std::time::Duration::from_millis(100));
        time.process_frame();

        // FPS: time.fps()
    }
}
```
*/

mod time_system;
mod timer;

pub mod doctest;

pub use time_system::*;
pub use timer::*;