Expand description
A collection of utilities to make managing a main loop easier. Shown below is a simple main loop structure for gemini:
use main_loop_utils;
use std::time::Instant;
const FPS: f32 = 30.0;
fn main() {
// --initialisation--
let mut frame_skip = false;
loop {
let now = Instant::now();
// --clearing views and all necessary logic--
if !frame_skip {
// --all drawing and rendering goes here along with any visual logic--
}
let elapsed = now.elapsed();
frame_skip = main_loop_utils::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, but with less boilerplate. Read about how to use it in the fps_gameloop!
documentation
Macros§
- fps_
gameloop - You can use the
fps_gameloop!
macro to avoid writing a lot of boilerplate code. Take this block of code from a program written using thegemini-engine
crate, for example:
Traits§
- Main
Loop Root - A trait to abstract away the main loop and simplify code writing
Functions§
- sleep_
fps - Sleep for
1 / fps
seconds, accounting for elapsed time to maintain the desired FPS.