From: Aleksi Blinnikka Date: Sun, 29 Apr 2018 17:00:13 +0000 (+0300) Subject: Reduce number of UnitAura calls for each UNIT_AURA event X-Git-Url: https://www.aleksib.fi/git/wowui.git/commitdiff_plain/330739114047596de17fabf5182c25b065ebde39?hp=08783ecf65f49a14ffc0c47265e488ca4efedb24 Reduce number of UnitAura calls for each UNIT_AURA event --- diff --git a/OmaRF/DruidIndicators.lua b/OmaRF/DruidIndicators.lua index 9aeefbc..59e3c96 100644 --- a/OmaRF/DruidIndicators.lua +++ b/OmaRF/DruidIndicators.lua @@ -8,29 +8,27 @@ local square = "Interface\\AddOns\\OmaRF\\images\\square"; local M = {}; OmaRFIndicators.Class["DRUID"] = M; M.Auras = { - ["Lifebloom"] = "TOPLEFT", - ["Rejuvenation"] = "TR1", - ["Cenarion Ward"] = "TR2", - ["Spring Blossoms"] = "TR3", - ["Rejuvenation (Germination)"] = "TR3", - ["Regrowth"] = "TR4", - ["Cultivation"] = "TR5", + [33763] = "TOPLEFT", -- Lifebloom + [774] = "TR1", -- Rejuvenation + [102352] = "TR2", -- Cenarion Ward (102351 is the pre-buff) + [207386] = "TR3", -- Spring Blossoms (207385 is the talent) + [155777] = "TR3", -- Germination (either this or Spring Blossoms taken) + [8936] = "TR4", -- Regrowth + [200389] = "TR5", -- Cultivation } function M.Setup(base) local inds = {}; - for _, pos in pairs({"TOPLEFT"}) do - inds[pos] = base:CreateTexture(nil, "OVERLAY"); - inds[pos]:SetPoint(pos, base, pos); - inds[pos]:SetWidth(indSize); - inds[pos]:SetHeight(indSize); - inds[pos]:SetTexture(rhomb); - inds[pos]:SetVertexColor(0, 1, 0.5); - inds[pos]:Hide(); - inds[pos].text = base:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); - inds[pos].text:SetPoint("BOTTOMRIGHT", inds[pos], "BOTTOMRIGHT"); - inds[pos].text:Hide(); - end + inds["TOPLEFT"] = base:CreateTexture(nil, "OVERLAY"); + inds["TOPLEFT"]:SetPoint("TOPLEFT", base, "TOPLEFT"); + inds["TOPLEFT"]:SetWidth(indSize); + inds["TOPLEFT"]:SetHeight(indSize); + inds["TOPLEFT"]:SetTexture(rhomb); + inds["TOPLEFT"]:SetVertexColor(0, 1, 0.5); + inds["TOPLEFT"]:Hide(); + inds["TOPLEFT"].text = base:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); + inds["TOPLEFT"].text:SetPoint("BOTTOMRIGHT", inds["TOPLEFT"], "BOTTOMRIGHT"); + inds["TOPLEFT"].text:Hide(); for _, pos in pairs({"TR1", "TR2", "TR3", "TR4", "TR5"}) do inds[pos] = base:CreateTexture(nil, "OVERLAY"); inds[pos]:SetWidth(indSize/2); diff --git a/OmaRF/Events.lua b/OmaRF/Events.lua index 762cb99..d54a1df 100644 --- a/OmaRF/Events.lua +++ b/OmaRF/Events.lua @@ -179,8 +179,8 @@ end M.UpdateHealAbsorb = updateHealAbsorb; local function updateAuras(frame, unit) - local alert = checkIndicators(frame, unit); - if alert then + updateAuras(frame, unit); -- this is throttled + if updateMajorAuras(frame, unit) then if frame.overlay.color ~= overlayColorAlert then frame.overlay:SetVertexColor(unpack(overlayColorAlert)); frame.overlay.color = overlayColorAlert; diff --git a/OmaRF/Indicators.lua b/OmaRF/Indicators.lua index d37383a..49f3ba1 100644 --- a/OmaRF/Indicators.lua +++ b/OmaRF/Indicators.lua @@ -9,10 +9,11 @@ local CTimerAfter = C_Timer.After; local Settings = OmaRFSettings; local majorAuras = Settings.MajorAuras; -local watchedAuras = {}; +local watchedAuras = {}; local updaters = {}; local updating = {}; +local updateAuras; local M = {}; OmaRFIndicators = M; @@ -50,6 +51,11 @@ function M.SetupIndicators(frame, class) tex.icon = true; frame.majors[i] = tex; end + + frame.throttle = function() + frame.throttled = nil; + updateAuras(frame, frame.displayed); + end; end local function remaining(text, expires, current) @@ -119,31 +125,65 @@ local function hideInd(ind) ind:Hide(); end -function M.CheckIndicators(frame, unit) +function M.UpdateAuras(frame, unit) + local current = GetTime(); + if frame.throttled then + print("updateAuras throttled for ", unit); -- TODO debug print + return; + elseif frame.prevUpdate - current < 0.1 then + frame.throttled = true; + return CTimerAfter(0.1, frame.throttle); + end + for _, ind in pairs(frame.inds) do hideInd(ind); end + local icon, count, expires, id; + local showInds, needUpdate = false, false; + local i = 1; + while true do + _, _, icon, count, _, _, expires, _, _, _, id = UnitAura(unit, i, "PLAYER HELPFUL"); + if not id then break end + local pos = watchedAuras[id]; + if pos then + needUpdate = showInd(frame.inds[pos], expires, current, count, icon) or needUpdate; + showInds = true; + end + i = i + 1; + end + + if showInds then + frame.indBase:Show(); + if needUpdate and not updating[frame] then + updating[frame] = true; -- race? + -- create a function for updating the indicator + local func = updaters[frame]; + if not func then + func = function() updateIndicators(frame) end; + updaters[frame] = func; + end + CTimerAfter(0.20, func); + end + else + frame.indBase:Hide(); + end +end +updateAuras = M.UpdateAuras; + +function M.UpdateMajorAuras(frame, unit) for _, ind in pairs(frame.majors) do hideInd(ind); end - local name, icon, count, expires, caster, id; - local showInds, showMajors, needUpdate = false, false, false; + local icon, count, expires, id; + local showMajors, needUpdate = false, false; local majorPos = 1; local alert = false; -- color the whole bar local current = GetTime(); - for spell, pos in pairs(watchedAuras) do - name, _, icon, count, _, _, expires = UnitAura(unit, spell, nil, "PLAYER HELPFUL"); - if name then - needUpdate = showInd(frame.inds[pos], expires, current, count, icon) or needUpdate; - showInds = true; - end - end - local i = 1; while true do - name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, "HARMFUL"); + _, _, icon, count, _, _, expires, _, _, _, id = UnitAura(unit, i, "HARMFUL"); if not id or majorPos > 3 then break end - local major = majorAuras[id] or majorAuras[name]; + local major = majorAuras[id]; if major then needUpdate = showInd(frame.majors[majorPos], expires, current, count, icon) or needUpdate; if major.bar then alert = true end @@ -153,8 +193,7 @@ function M.CheckIndicators(frame, unit) i = i + 1; end - if showInds or showMajors then - frame.indBase:Show(); + if showMajors then frame.majorBase:Show(); if needUpdate and not updating[frame] then updating[frame] = true; -- race? @@ -167,7 +206,6 @@ function M.CheckIndicators(frame, unit) CTimerAfter(0.20, func); end else - frame.indBase:Hide(); frame.majorBase:Hide(); end diff --git a/OmaRF/PaladinIndicators.lua b/OmaRF/PaladinIndicators.lua index 762a525..d8b4f06 100644 --- a/OmaRF/PaladinIndicators.lua +++ b/OmaRF/PaladinIndicators.lua @@ -1,16 +1,13 @@ -- PaladinIndicators.lua -local pairs = pairs; - local indSize = OmaRFSettings.IndSize; local rhomb = "Interface\\AddOns\\OmaRF\\images\\rhomb"; local M = {}; OmaRFIndicators.Class["PALADIN"] = M; M.Auras = { - ["Beacon of Light"] = "TOPRIGHT", - ["Beacon of Faith"] = "TOPRIGHT", - ["Beacon of Virtue"] = "TOPRIGHT", - ["Tyr's Deliverance"] = "BOTTOMLEFT", + [53563] = "TOPRIGHT", -- Beacon of Light + [156910] = "TOPRIGHT", -- Beacon of Faith + [200025] = "TOPRIGHT", -- Beacon of Virtue } function M.Setup(base) @@ -22,15 +19,5 @@ function M.Setup(base) inds["TOPRIGHT"]:SetTexture(rhomb); inds["TOPRIGHT"]:SetVertexColor(1, 0, 0); inds["TOPRIGHT"]:Hide(); - inds["BOTTOMLEFT"] = base:CreateTexture(nil, "OVERLAY"); - inds["BOTTOMLEFT"]:SetPoint("BOTTOMLEFT", base, "BOTTOMLEFT"); - inds["BOTTOMLEFT"]:SetWidth(indSize); - inds["BOTTOMLEFT"]:SetHeight(indSize); - inds["BOTTOMLEFT"]:SetTexture(rhomb); - inds["BOTTOMLEFT"]:SetVertexColor(1, 0.5, 0); - inds["BOTTOMLEFT"]:Hide(); - inds["BOTTOMLEFT"].text = base:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); - inds["BOTTOMLEFT"].text:SetPoint("BOTTOMRIGHT", inds["BOTTOMLEFT"], "BOTTOMRIGHT"); - inds["BOTTOMLEFT"].text:Hide(); return inds; end diff --git a/OmaRF/ShamanIndicators.lua b/OmaRF/ShamanIndicators.lua index 17034d2..b1326e2 100644 --- a/OmaRF/ShamanIndicators.lua +++ b/OmaRF/ShamanIndicators.lua @@ -1,13 +1,11 @@ -- PaladinIndicators.lua -local pairs = pairs; - local indSize = OmaRFSettings.IndSize; local rhomb = "Interface\\AddOns\\OmaRF\\images\\rhomb"; local M = {}; OmaRFIndicators.Class["SHAMAN"] = M; M.Auras = { - ["Riptide"] = "TOPRIGHT", + [61295] = "TOPRIGHT", -- Riptide } function M.Setup(base)