Reduce CPU usage while window is unfocused and not hovered over
Only render if window is focused, hovered, subscript is running, or coroutine is active. Closes #18
This commit is contained in:
1 parent
0066a05e13
commit
ae6a24f82c
9 files changed
+116
-30
No files matched your search
+24
-1
@@ -13,7 +13,7 @@ use crate::{
|
||||
window::WindowState,
|
||||
};
|
||||
use clap::Parser;
|
||||
use mlua::{Lua, Result as LuaResult, Table};
|
||||
use mlua::{Function, Lua, Result as LuaResult, Table, ThreadStatus};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
path::PathBuf,
|
||||
@@ -228,6 +228,29 @@ impl LuaInstance {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_running_subscripts(&self) -> bool {
|
||||
self.subscript_manager.borrow().has_running_subscripts()
|
||||
}
|
||||
|
||||
pub fn has_active_coroutine(&self) -> bool {
|
||||
self.get_coroutines().is_ok_and(|coroutines| {
|
||||
coroutines.pairs::<mlua::Thread, bool>().any(|pair| {
|
||||
pair.is_ok_and(|(thread, _)| {
|
||||
matches!(
|
||||
thread.status(),
|
||||
ThreadStatus::Resumable | ThreadStatus::Running
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn get_coroutines(&self) -> LuaResult<Table> {
|
||||
let coroutine_module: Table = self.lua.globals().get("coroutine")?;
|
||||
let list_func: Function = coroutine_module.get("_list")?;
|
||||
list_func.call::<Table>(())
|
||||
}
|
||||
|
||||
pub fn handle_event(&self, event: PoBEvent, pob_ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
profiling::scope!("handle_event", format!("{}", event));
|
||||
|
||||
|
||||
Reference in new issue
Block a user