Sleep heal prediction timeout loop when idle

This commit is contained in:
Dusk-92
2026-08-24 21:28:35 +02:00
parent c21caf9283
commit 06c52891a4
+22 -6
View File
@@ -40,14 +40,25 @@ libpredict:SetScript("OnEvent", function()
end
end)
libpredict:SetScript("OnUpdate", function()
-- update on timeout events
for timestamp, targets in pairs(events) do
if GetTime() >= timestamp then
local function UpdateTimeouts()
local now = GetTime()
local pending
for timestamp in pairs(events) do
if now >= timestamp then
events[timestamp] = nil
else
pending = true
end
end
end)
-- No prediction timeout is pending: completely remove OnUpdate until the
-- next AddEvent() instead of waking this library on every rendered frame.
if not pending then
libpredict.timeoutActive = nil
libpredict:SetScript("OnUpdate", nil)
end
end
function libpredict:ParseComm(sender, msg)
local msgtype, target, heal, time
@@ -147,6 +158,11 @@ end
function libpredict:AddEvent(time, target)
events[time] = events[time] or {}
table.insert(events[time], target)
if not self.timeoutActive then
self.timeoutActive = true
self:SetScript("OnUpdate", UpdateTimeouts)
end
end
function libpredict:Heal(sender, target, amount, duration)
@@ -466,4 +482,4 @@ libpredict.sender:SetScript("OnEvent", function()
end
end)
ShaguTweaks.libpredict = libpredict
ShaguTweaks.libpredict = libpredict