From b521f15ae9799a08d1cb328e3c1ef294d75f30c2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 21 Sep 2016 14:32:58 +0200 Subject: lua: run timers only after draining the event queue Instead of rechecking the timers every time after an event is read, do it only once the event queue is empty. This is probably slightly more efficient, and facilitates the next commit. --- player/lua/defaults.lua | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'player/lua') diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 901a8cf246..2c38361994 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -451,16 +451,14 @@ function mp.dispatch_events(allow_wait) mp.suspend() end while mp.keep_running do - local wait = process_timers() - if wait == nil then - wait = 1e20 -- infinity for all practical purposes - end - if more_events or wait < 0 then - wait = 0 - end - -- Resume playloop - important especially if an error happened while - -- suspended, and the error was handled, but no resume was done. - if wait > 0 then + local wait = 0 + if not more_events then + wait = process_timers() + if wait == nil then + wait = 1e20 -- infinity for all practical purposes + end + -- Resume playloop - important especially if an error happened while + -- suspended, and the error was handled, but no resume was done. mp.resume_all() if allow_wait ~= true then return @@ -472,9 +470,10 @@ function mp.dispatch_events(allow_wait) if mp.use_suspend then mp.suspend() end - more_events = (e.event ~= "none") - if more_events then + more_events = false + if e.event ~= "none" then call_event_handlers(e) + more_events = true end end end -- cgit v1.2.3