Improved idle CPU utilisation when not-focused, added system.wait_event()

This commit is contained in:
rxi 2020-05-10 21:00:40 +01:00
parent b67b680975
commit c215eff6d8
2 changed files with 12 additions and 1 deletions

View file

@ -347,7 +347,10 @@ function core.step()
-- update -- update
core.root_view.size.x, core.root_view.size.y = width, height core.root_view.size.x, core.root_view.size.y = width, height
core.root_view:update() core.root_view:update()
if not core.redraw then return end if not core.redraw then
if not system.window_has_focus() then system.wait_event(0.5) end
return
end
core.redraw = false core.redraw = false
-- close unreferenced docs -- close unreferenced docs

View file

@ -123,6 +123,13 @@ 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[] = {
@ -339,6 +346,7 @@ 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 },