added framerate lock

pull/4/head
Milk.H 2024-04-25 17:25:17 +01:00
parent 19eb37a455
commit 0ba9b8698c
Signed by: milk
GPG Key ID: 94C7CB70FFF80593
1 changed files with 7 additions and 0 deletions

View File

@ -1,6 +1,8 @@
use std::rc::Rc;
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant};
use glow::HasContext;
@ -115,6 +117,8 @@ fn main() {
// TODO write bevy Init code here
let _ = event_loop.run(move |event, control_flow| {
// new_frame for Framerate Locking
let new_frame = Instant::now() + Duration::from_secs_f32(1.0/60.0);
match event
{
Event::WindowEvent { event, .. } => {
@ -141,5 +145,8 @@ fn main() {
_ => ()
}
// will wait until it's time for the next frame
thread::sleep(Instant::now() - new_frame);
});
}