306a575 - Optimizations to events, removal of heal prediction
[wowui.git] / kehys / events.lua
index f030057..16c6479 100644 (file)
@@ -22,6 +22,7 @@ local READY_CHECK_NOT_READY_TEXTURE = READY_CHECK_NOT_READY_TEXTURE;
 local READY_CHECK_WAITING_TEXTURE = READY_CHECK_WAITING_TEXTURE;
 
 local _, addon = ...;
 local READY_CHECK_WAITING_TEXTURE = READY_CHECK_WAITING_TEXTURE;
 
 local _, addon = ...;
+addon.Events = {};
 local baseColor = {0, 0, 0};
 local overlayColorDispel = {1, 0.5, 0, 0.5};
 local overlayColorCharm = {0.8, 0, 1, 0.5};
 local baseColor = {0, 0, 0};
 local overlayColorDispel = {1, 0.5, 0, 0.5};
 local overlayColorCharm = {0.8, 0, 1, 0.5};
@@ -45,7 +46,7 @@ function addon.RegisterUnitEvents(frame)
     frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_MAXHEALTH", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
-    frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
+    --frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_HEAL_ABSORB_AMOUNT_CHANGED", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
@@ -76,13 +77,19 @@ local function updateText(frame, unit)
         frame.text:Hide();
     end
 end
         frame.text:Hide();
     end
 end
+addon.Events.UpdateText = updateText;
 
 local function updateMaxHealth(frame, unit)
     frame.health.max = UnitHealthMax(unit);
 end
 
 local function updateMaxHealth(frame, unit)
     frame.health.max = UnitHealthMax(unit);
 end
+addon.Events.UpdateMaxHealth = updateMaxHealth;
 
 local function updateHealth(frame, unit)
     local current, max = UnitHealth(unit), frame.health.max;
 
 local function updateHealth(frame, unit)
     local current, max = UnitHealth(unit), frame.health.max;
+    if current == frame.prev.health then
+        return false;
+    end
+    frame.prev.health = current;
     if current > max or max <= 0 then
         -- somehow current health has gone over the maximum (missed maxhealth event possibly)
         -- just put health bar full and update max health for next event
     if current > max or max <= 0 then
         -- somehow current health has gone over the maximum (missed maxhealth event possibly)
         -- just put health bar full and update max health for next event
@@ -92,7 +99,7 @@ local function updateHealth(frame, unit)
         frame.health:Show();
     elseif current <= 0 or UnitIsDeadOrGhost(unit) then
         frame.health:Hide();
         frame.health:Show();
     elseif current <= 0 or UnitIsDeadOrGhost(unit) then
         frame.health:Hide();
-        return updateText(frame, unit); -- update death
+        updateText(frame, unit); -- update death
     else
         local w = current/max*width;
         frame.health:SetWidth(w);
     else
         local w = current/max*width;
         frame.health:SetWidth(w);
@@ -104,7 +111,9 @@ local function updateHealth(frame, unit)
         frame.dead = nil;
         updateText(frame, unit); -- update revive
     end
         frame.dead = nil;
         updateText(frame, unit); -- update revive
     end
+    return true;
 end
 end
+addon.Events.UpdateHealth = updateHealth;
 
 local function updateName(frame, unit)
     local name = UnitName(unit);
 
 local function updateName(frame, unit)
     local name = UnitName(unit);
@@ -120,6 +129,7 @@ local function updateName(frame, unit)
     local color = RAID_CLASS_COLORS[class];
     if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
 end
     local color = RAID_CLASS_COLORS[class];
     if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
 end
+addon.Events.UpdateName = updateName;
 
 local function updateHealPred(frame, unit)
     local incoming = UnitGetIncomingHeals(unit) or 0;
 
 local function updateHealPred(frame, unit)
     local incoming = UnitGetIncomingHeals(unit) or 0;
@@ -127,11 +137,12 @@ local function updateHealPred(frame, unit)
         incoming = (incoming / frame.health.max) * width;
         -- always at least 1 pixel space for heal prediction
         frame.healpred:SetWidth(min(width - frame.health.width + 1, incoming));
         incoming = (incoming / frame.health.max) * width;
         -- always at least 1 pixel space for heal prediction
         frame.healpred:SetWidth(min(width - frame.health.width + 1, incoming));
-        frame.healpred:Show();
+        if not frame.healpred:IsShown() then frame.healpred:Show() end
     else
     else
-        frame.healpred:Hide();
+        if frame.healpred:IsShown() then frame.healpred:Hide() end
     end
 end
     end
 end
+addon.Events.UpdateHealPred = updateHealPred;
 
 local function updateShield(frame, unit)
     local shield = UnitGetTotalAbsorbs(unit) or 0;
 
 local function updateShield(frame, unit)
     local shield = UnitGetTotalAbsorbs(unit) or 0;
@@ -139,22 +150,23 @@ local function updateShield(frame, unit)
         local space = width - frame.health.width;
         shield = (shield / frame.health.max) * width;
         if space == 0 then
         local space = width - frame.health.width;
         shield = (shield / frame.health.max) * width;
         if space == 0 then
-            frame.shield:Hide();
-            frame.shieldhl:Show();
+            if frame.shield:IsShown() then frame.shield:Hide() end
+            if not frame.shieldhl:IsShown() then frame.shieldhl:Show() end
         elseif space < shield then
             frame.shield:SetWidth(space);
         elseif space < shield then
             frame.shield:SetWidth(space);
-            frame.shield:Show();
-            frame.shieldhl:Show();
+            if not frame.shield:IsShown() then frame.shield:Show() end
+            if not frame.shieldhl:IsShown() then frame.shieldhl:Show() end
         else
             frame.shield:SetWidth(shield);
         else
             frame.shield:SetWidth(shield);
-            frame.shield:Show();
-            frame.shieldhl:Hide();
+            if not frame.shield:IsShown() then frame.shield:Show() end
+            if frame.shieldhl:IsShown() then frame.shieldhl:Hide() end
         end
     else
         end
     else
-        frame.shield:Hide();
-        frame.shieldhl:Hide();
+        if frame.shield:IsShown() then frame.shield:Hide() end
+        if frame.shieldhl:IsShown() then frame.shieldhl:Hide() end
     end
 end
     end
 end
+addon.Events.UpdateShield = updateShield;
 
 local function updateHealAbsorb(frame, unit)
     local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
 
 local function updateHealAbsorb(frame, unit)
     local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
@@ -166,29 +178,32 @@ local function updateHealAbsorb(frame, unit)
         frame.healabsorb:Hide();
     end
 end
         frame.healabsorb:Hide();
     end
 end
+addon.Events.UpdateHealAbsorb = updateHealAbsorb;
 
 local function updateAuras(frame, unit)
     -- don't overlay charmed when in vehicle
 
 local function updateAuras(frame, unit)
     -- don't overlay charmed when in vehicle
-    if UnitIsCharmed(unit) and unit == frame.unit then
+    --[[if UnitIsCharmed(unit) and unit == frame.unit then
         if frame.overlay.color ~= overlayColorCharm then
             frame.overlay:SetVertexColor(unpack(overlayColorCharm));
             frame.overlay.color = overlayColorCharm;
             frame.overlay:Show();
         end
         if frame.overlay.color ~= overlayColorCharm then
             frame.overlay:SetVertexColor(unpack(overlayColorCharm));
             frame.overlay.color = overlayColorCharm;
             frame.overlay:Show();
         end
-    elseif UnitDebuff(unit, 1, "RAID") ~= nil then
+    else--]]
+    if UnitDebuff(unit, 1, "RAID") ~= nil then
         -- something dispellable
         if frame.overlay.color ~= overlayColorDispel then
             frame.overlay:SetVertexColor(unpack(overlayColorDispel));
             frame.overlay.color = overlayColorDispel;
         -- something dispellable
         if frame.overlay.color ~= overlayColorDispel then
             frame.overlay:SetVertexColor(unpack(overlayColorDispel));
             frame.overlay.color = overlayColorDispel;
-            frame.overlay:Show();
+            if not frame.overlay:IsShown() then frame.overlay:Show() end
         end
     else
         if frame.overlay.color ~= nil then
             frame.overlay.color = nil;
         end
     else
         if frame.overlay.color ~= nil then
             frame.overlay.color = nil;
-            frame.overlay:Hide();
+            if frame.overlay:IsShown() then frame.overlay:Hide() end
         end
     end
 end
         end
     end
 end
+addon.Events.UpdateAuras = updateAuras;
 
 local function updateAggro(frame, unit)
     local status = UnitThreatSituation(unit);
 
 local function updateAggro(frame, unit)
     local status = UnitThreatSituation(unit);
@@ -198,6 +213,7 @@ local function updateAggro(frame, unit)
         frame.base:SetVertexColor(unpack(baseColor));
     end
 end
         frame.base:SetVertexColor(unpack(baseColor));
     end
 end
+addon.Events.UpdateAggro = updateAggro;
 
 local function updateVehicle(frame)
     local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
 
 local function updateVehicle(frame)
     local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
@@ -214,6 +230,7 @@ local function updateVehicle(frame)
         registerUnitEvents(frame);
     end
 end
         registerUnitEvents(frame);
     end
 end
+addon.Events.UpdateVehicle = updateVehicle;
 
 local function updateRole(frame, unit)
     local role = UnitGroupRolesAssigned(unit);
 
 local function updateRole(frame, unit)
     local role = UnitGroupRolesAssigned(unit);
@@ -227,6 +244,7 @@ local function updateRole(frame, unit)
         frame.role:Hide();
     end
 end
         frame.role:Hide();
     end
 end
+addon.Events.UpdateRole = updateRole;
 
 local function updateReadyCheck(frame, unit)
     local status = GetReadyCheckStatus(unit);
 
 local function updateReadyCheck(frame, unit)
     local status = GetReadyCheckStatus(unit);
@@ -243,6 +261,7 @@ local function updateReadyCheck(frame, unit)
         frame.ready:Hide()
     end
 end
         frame.ready:Hide()
     end
 end
+addon.Events.UpdateReadyCheck = updateReadyCheck;
 
 local function updateRaidMarker(frame, unit)
     local index = GetRaidTargetIndex(unit);
 
 local function updateRaidMarker(frame, unit)
     local index = GetRaidTargetIndex(unit);
@@ -253,13 +272,15 @@ local function updateRaidMarker(frame, unit)
         frame.targeticon:Hide();
     end
 end
         frame.targeticon:Hide();
     end
 end
+addon.Events.UpdateRaidMarker = updateRaidMarker;
 
 local eventFuncs = {
     ["UNIT_HEALTH"] = function(frame)
 
 local eventFuncs = {
     ["UNIT_HEALTH"] = function(frame)
-        updateHealth(frame, frame.displayed);
-        updateShield(frame, frame.displayed);
-        updateHealAbsorb(frame, frame.displayed);
-        -- no heal prediction update, that doesn't overflow too much
+        if updateHealth(frame, frame.displayed) then
+            updateShield(frame, frame.displayed);
+            updateHealAbsorb(frame, frame.displayed);
+            -- no heal prediction update, that doesn't overflow too much
+        end
     end,
     ["UNIT_AURA"] = function(frame)
         updateAuras(frame, frame.displayed);
     end,
     ["UNIT_AURA"] = function(frame)
         updateAuras(frame, frame.displayed);
@@ -305,7 +326,7 @@ local eventFuncs = {
         updateText(frame, frame.displayed);
         updateAuras(frame, frame.displayed);
         updateShield(frame, frame.displayed);
         updateText(frame, frame.displayed);
         updateAuras(frame, frame.displayed);
         updateShield(frame, frame.displayed);
-        updateHealPred(frame, frame.displayed);
+        --updateHealPred(frame, frame.displayed);
         updateHealAbsorb(frame, frame.displayed);
         updateAggro(frame, frame.displayed);
         updateName(frame, frame.unit);
         updateHealAbsorb(frame, frame.displayed);
         updateAggro(frame, frame.displayed);
         updateName(frame, frame.unit);