refactor: more compact request_render() (#299)

This commit is contained in:
christoph-heinrich
2022-10-06 21:42:49 +02:00
committed by GitHub
parent 5fdcddd548
commit 521f880a18

View File

@@ -1329,25 +1329,6 @@ end
--[[ RENDERING ]] --[[ RENDERING ]]
-- Request that render() is called.
-- The render is then either executed immediately, or rate-limited if it was
-- called a small time ago.
function request_render()
if state.render_timer == nil then
state.render_timer = mp.add_timeout(0, render)
end
if not state.render_timer:is_enabled() then
local now = mp.get_time()
local timeout = state.render_delay - (now - state.render_last_time)
if timeout < 0 then
timeout = 0
end
state.render_timer.timeout = timeout
state.render_timer:resume()
end
end
function render() function render()
state.render_last_time = mp.get_time() state.render_last_time = mp.get_time()
@@ -1378,6 +1359,18 @@ function render()
update_margins() update_margins()
end end
-- Request that render() is called.
-- The render is then either executed immediately, or rate-limited if it was
-- called a small time ago.
state.render_timer = mp.add_timeout(0, render)
state.render_timer:kill()
function request_render()
if state.render_timer:is_enabled() then return end
local timeout = math.max(0, state.render_delay - (mp.get_time() - state.render_last_time))
state.render_timer.timeout = timeout
state.render_timer:resume()
end
--[[ CLASSES ]] --[[ CLASSES ]]
---@class Class ---@class Class