stop eating CPU time when window is in background

This commit is contained in:
Alula 2021-05-02 02:07:44 +02:00
parent d6316aa718
commit 490f02f2fe
No known key found for this signature in database
GPG Key ID: 3E00485503A1D8BA
1 changed files with 2 additions and 0 deletions

View File

@ -24,6 +24,7 @@ use crate::framework::render_opengl::{GLContext, OpenGLRenderer};
use crate::framework::ui::init_imgui;
use crate::Game;
use crate::GAME_SUSPENDED;
use std::time::Duration;
pub struct SDL2Backend {
context: Sdl,
@ -176,6 +177,7 @@ impl BackendEventLoop for SDL2EventLoop {
{
let mutex = GAME_SUSPENDED.lock().unwrap();
if *mutex {
std::thread::sleep(Duration::from_millis(10));
continue;
}
}