2 unstable releases
Uses new Rust 2024
new 0.2.0 | Mar 15, 2025 |
---|---|
0.1.0 | Mar 15, 2025 |
#19 in #instant
12KB
58 lines
Gemini Mainloop
An engine-agnostic mainloop abstraction library, originally part of gemini-engine
lib.rs
:
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