Expand description
Gemini includes some tools to make managing your core gameloop easier. If you read the Quick Start guide, you’ll have seen that the example there didn’t have a fully written gameloop. When you begin building larger projects with Gemini, this is what your code might look like:
use gemini_engine::gameloop;
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 {
frame_skip = false
} else {
// --all drawing 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, but with less boilerplate. Read about how to use it in the fps_gameloop! documentation
Traits§
- Main
Loop Root - This is an alternative way to handle the gameloop, separate from
fps_gameloop!. It takes on a more object-oriented approach - here, everything related to the game is stored inside a single struct which implementsMainLoopRoot.
Functions§
- sleep_
fps - Sleep for a single frame at the declared FPS, subtracting the input
Durationto account for any time spent processing the frame. Returns aboolindicating whether the frame took longer to render than the intended fps wait (i.e. if there was an FPS drop)