gemini_mainloop/lib.rs
1//! A collection of utilities to make managing a main loop easier. Shown below is a simple main loop structure for gemini:
2//! ```no_run
3//! use main_loop_utils;
4//! use std::time::Instant;
5//!
6//! const FPS: f32 = 30.0;
7//!
8//! fn main() {
9//! // --initialisation--
10//! let mut frame_skip = false;
11//!
12//! loop {
13//! let now = Instant::now();
14//! // --clearing views and all necessary logic--
15//!
16//! if !frame_skip {
17//! // --all drawing and rendering goes here along with any visual logic--
18//! }
19//!
20//! let elapsed = now.elapsed();
21//! frame_skip = main_loop_utils::sleep_fps(FPS, Some(elapsed));
22//! }
23//! }
24//! ```
25//! Writing your code like this ensures that it wont affect the game's intentional speed too much, and also makes it easy for you to benchmark your game's speed with something like `println!("Elapsed: {:.2?}µs", elapsed.as_micros());` after `let elapsed`.
26//!
27//! You can use the `fps_gameloop!` macro to achieve the same result, but with less boilerplate. Read about how to use it in the [`fps_gameloop!`](crate::fps_gameloop) documentation
28
29mod sleep_fps;
30pub use sleep_fps::sleep_fps;
31
32mod with_root;
33pub use with_root::MainLoopRoot;
34
35mod macros;