added framerate lock
parent
19eb37a455
commit
0ba9b8698c
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue