From 490f02f2fec3b6912d0f76f5125a0200e20d45a4 Mon Sep 17 00:00:00 2001 From: Alula <6276139+alula@users.noreply.github.com> Date: Sun, 2 May 2021 02:07:44 +0200 Subject: [PATCH] stop eating CPU time when window is in background --- src/framework/backend_sdl2.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/framework/backend_sdl2.rs b/src/framework/backend_sdl2.rs index c194bbd..fd9afb2 100644 --- a/src/framework/backend_sdl2.rs +++ b/src/framework/backend_sdl2.rs @@ -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; } }