3307391 - Reduce number of UnitAura calls for each UNIT_AURA event
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 29 Apr 2018 17:00:13 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 29 Apr 2018 17:00:13 +0000
OmaRF/DruidIndicators.lua
OmaRF/Events.lua
OmaRF/Indicators.lua
OmaRF/PaladinIndicators.lua
OmaRF/ShamanIndicators.lua

index 9aeefbc..59e3c96 100644 (file)
@@ -8,29 +8,27 @@ local square = "Interface\\AddOns\\OmaRF\\images\\square";
 local M = {};
 OmaRFIndicators.Class["DRUID"] = M;
 M.Auras = {
 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 = {};
 }
 
 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);
     for _, pos in pairs({"TR1", "TR2", "TR3", "TR4", "TR5"}) do
         inds[pos] = base:CreateTexture(nil, "OVERLAY");
         inds[pos]:SetWidth(indSize/2);
index 762cb99..d54a1df 100644 (file)
@@ -179,8 +179,8 @@ end
 M.UpdateHealAbsorb = updateHealAbsorb;
 
 local function updateAuras(frame, unit)
 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;
         if frame.overlay.color ~= overlayColorAlert then
             frame.overlay:SetVertexColor(unpack(overlayColorAlert));
             frame.overlay.color = overlayColorAlert;
index d37383a..49f3ba1 100644 (file)
@@ -9,10 +9,11 @@ local CTimerAfter = C_Timer.After;
 
 local Settings = OmaRFSettings;
 local majorAuras = Settings.MajorAuras;
 
 local Settings = OmaRFSettings;
 local majorAuras = Settings.MajorAuras;
-local watchedAuras = {};
 
 
+local watchedAuras = {};
 local updaters = {};
 local updating = {};
 local updaters = {};
 local updating = {};
+local updateAuras;
 
 local M = {};
 OmaRFIndicators = M;
 
 local M = {};
 OmaRFIndicators = M;
@@ -50,6 +51,11 @@ function M.SetupIndicators(frame, class)
         tex.icon = true;
         frame.majors[i] = tex;
     end
         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)
 end
 
 local function remaining(text, expires, current)
@@ -119,31 +125,65 @@ local function hideInd(ind)
     ind:Hide();
 end
 
     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
     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
     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();
     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
     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
         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
         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
 
         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?
         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
             CTimerAfter(0.20, func);
         end
     else
-        frame.indBase:Hide();
         frame.majorBase:Hide();
     end
 
         frame.majorBase:Hide();
     end
 
index 762a525..d8b4f06 100644 (file)
@@ -1,16 +1,13 @@
 -- PaladinIndicators.lua
 -- PaladinIndicators.lua
-local pairs = pairs;
-
 local indSize = OmaRFSettings.IndSize;
 local rhomb = "Interface\\AddOns\\OmaRF\\images\\rhomb";
 
 local M = {};
 OmaRFIndicators.Class["PALADIN"] = M;
 M.Auras = {
 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)
 }
 
 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["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
     return inds;
 end
index 17034d2..b1326e2 100644 (file)
@@ -1,13 +1,11 @@
 -- PaladinIndicators.lua
 -- PaladinIndicators.lua
-local pairs = pairs;
-
 local indSize = OmaRFSettings.IndSize;
 local rhomb = "Interface\\AddOns\\OmaRF\\images\\rhomb";
 
 local M = {};
 OmaRFIndicators.Class["SHAMAN"] = M;
 M.Auras = {
 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)
 }
 
 function M.Setup(base)