Sleep to not have 100% CPU usage
This commit is contained in:
parent
2d8a1f0448
commit
f6dd2a34ad
|
@ -6,6 +6,7 @@ extern crate model_converter;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::time::{Instant, Duration};
|
use std::time::{Instant, Duration};
|
||||||
|
use std::thread::sleep;
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
|
|
||||||
|
@ -133,6 +134,9 @@ fn main() {
|
||||||
renderer.show();
|
renderer.show();
|
||||||
|
|
||||||
use model_converter::controls::Controls;
|
use model_converter::controls::Controls;
|
||||||
|
|
||||||
|
let mut before = Instant::now();
|
||||||
|
|
||||||
while !closed {
|
while !closed {
|
||||||
|
|
||||||
events_loop.poll_events(|ev| {
|
events_loop.poll_events(|ev| {
|
||||||
|
@ -160,6 +164,12 @@ fn main() {
|
||||||
|
|
||||||
controls.update(&mut camera, &renderer);
|
controls.update(&mut camera, &renderer);
|
||||||
renderer.render(&scene, &camera);
|
renderer.render(&scene, &camera);
|
||||||
|
let elapsed = as_millis(Instant::now().duration_since(before));
|
||||||
|
|
||||||
|
if elapsed < 20 {
|
||||||
|
sleep(Duration::from_millis(20 - elapsed));
|
||||||
|
}
|
||||||
|
|
||||||
|
before = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue