From a38b89ca26dde1353cf1a6bcb2dc338ebc20473d Mon Sep 17 00:00:00 2001 From: Daniel Glinka Date: Sun, 11 Jul 2021 19:33:05 +0000 Subject: [PATCH] Reduce idle cpu usage --- data/core/init.lua | 6 +++--- src/api/system.c | 8 -------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index cef305e..cff7b61 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -377,6 +377,9 @@ function core.step() end core.redraw = true end + + if not core.redraw and not system.window_has_focus() then return false end + if mouse_moved then core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy) end @@ -453,9 +456,6 @@ function core.run() core.frame_start = system.get_time() local did_redraw = core.step() run_threads() - if not did_redraw and not system.window_has_focus() then - system.wait_event(0.25) - end local elapsed = system.get_time() - core.frame_start system.sleep(math.max(0, 1 / config.fps - elapsed)) end diff --git a/src/api/system.c b/src/api/system.c index 235d582..73ecb25 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -132,13 +132,6 @@ top: } -static int f_wait_event(lua_State *L) { - double n = luaL_checknumber(L, 1); - lua_pushboolean(L, SDL_WaitEventTimeout(NULL, n * 1000)); - return 1; -} - - static SDL_Cursor* cursor_cache[SDL_SYSTEM_CURSOR_HAND + 1]; static const char *cursor_opts[] = { @@ -381,7 +374,6 @@ static int f_fuzzy_match(lua_State *L) { static const luaL_Reg lib[] = { { "poll_event", f_poll_event }, - { "wait_event", f_wait_event }, { "set_cursor", f_set_cursor }, { "set_window_title", f_set_window_title }, { "set_window_mode", f_set_window_mode },