Module gemini_engine::gameloop
source · Expand description
The gameloop is one of Gemini’s most important features. If you read the Quick Start guide, you’ll have seen that the example there didnt have a fully written gameloop. When you begin building larger projects with Gemini, this is what your code should look like
use gemini_engine::gameloop;
const FPS: f32 = 30.0;
fn main() {
// --initialisation--
let mut frame_skip = false;
loop {
let now = gameloop::Instant::now();
// --clearing views and all necessary logic--
if frame_skip {
frame_skip = false
} else {
// --all blitting and rendering goes here along with any visual logic--
}
let elapsed = now.elapsed();
frame_skip = gameloop::sleep_fps(FPS, Some(elapsed));
}
}
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
.
You can use the fps_gameloop!
macro to achieve the same result. Read about how to use it in the fps_gameloop!
documentation
Re-exports§
pub use with_root::MainLoopRoot;
Modules§
- An object oriented approach to the gameloop, separate from
fps_gameloop!
. Read theMainLoopRoot
documentation for more info
Structs§
- A
Duration
type to represent a span of time, typically used for system timeouts. - A measurement of a monotonically nondecreasing clock. Opaque and useful only with
Duration
.
Functions§
- Sleep for a single frame at the declared FPS, subtracting the input
Duration
to account for any time spent processing the frame. Returns a bool value depending on whether or not the frame took longer to render than the intended fps