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
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2017 by Matthew S.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! This crate provides a struct for keeping your game loops running at a certian FPS (frames per second)
//!
//! # Usage
//!
//! This crate is [on crates.io](https://crates.io/crates/fps_clock) and can be
//! used by adding `fps_clock` to the dependencies in your project's `Cargo.toml`.
//!
//! ```toml
//! [dependencies]
//! fps_clock = "2.0"
//! ```
//!
//! and this to your crate root:
//!
//! ```rust,no_run
//! extern crate fps_clock;
//! ```
//!
//! To use the FPS clock, just create one with the `FpsClock::new(fps: u32) `method.
//! Then call the `tick()` method at the end of your game loop.
//!
//! # Examples
//! Running your game loop at 30 FPS:
//!
//! ``` rust,no_run
//! extern crate fps_clock;
//! fn main() {
//! // Set up your game here
//! let mut fps = fps_clock::FpsClock::new(30);
//! let mut nanosecs_since_last_tick = 0.0;
//! loop {
//! // Complicated game loop stuff here
//! nanosecs_since_last_tick = fps.tick();
//! }
//! }
//! ```
use time;
use thread;
/// A structure that keeps your game loop running at a constant FPS