Sleep to not have 100% CPU usage

This commit is contained in:
Thomas Forgione 2018-06-15 16:21:04 +02:00
parent 2d8a1f0448
commit f6dd2a34ad
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 10 additions and 0 deletions

View File

@ -6,6 +6,7 @@ extern crate model_converter;
use std::process::exit;
use std::time::{Instant, Duration};
use std::thread::sleep;
use clap::{App, Arg};
@ -133,6 +134,9 @@ fn main() {
renderer.show();
use model_converter::controls::Controls;
let mut before = Instant::now();
while !closed {
events_loop.poll_events(|ev| {
@ -160,6 +164,12 @@ fn main() {
controls.update(&mut camera, &renderer);
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();
}
}