Reduce idle cpu usage

This commit is contained in:
Daniel Glinka 2021-07-11 19:33:05 +00:00
parent 38bd9b3326
commit a38b89ca26
2 changed files with 3 additions and 11 deletions

View File

@ -377,6 +377,9 @@ function core.step()
end end
core.redraw = true core.redraw = true
end end
if not core.redraw and not system.window_has_focus() then return false end
if mouse_moved then if mouse_moved then
core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy) core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy)
end end
@ -453,9 +456,6 @@ function core.run()
core.frame_start = system.get_time() core.frame_start = system.get_time()
local did_redraw = core.step() local did_redraw = core.step()
run_threads() 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 local elapsed = system.get_time() - core.frame_start
system.sleep(math.max(0, 1 / config.fps - elapsed)) system.sleep(math.max(0, 1 / config.fps - elapsed))
end end

View File

@ -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 SDL_Cursor* cursor_cache[SDL_SYSTEM_CURSOR_HAND + 1];
static const char *cursor_opts[] = { static const char *cursor_opts[] = {
@ -381,7 +374,6 @@ static int f_fuzzy_match(lua_State *L) {
static const luaL_Reg lib[] = { static const luaL_Reg lib[] = {
{ "poll_event", f_poll_event }, { "poll_event", f_poll_event },
{ "wait_event", f_wait_event },
{ "set_cursor", f_set_cursor }, { "set_cursor", f_set_cursor },
{ "set_window_title", f_set_window_title }, { "set_window_title", f_set_window_title },
{ "set_window_mode", f_set_window_mode }, { "set_window_mode", f_set_window_mode },