performance optimizations:

- only run the OnUpdate code for the player mana bar when the player's power is not full
- never run the every-frame OnUpdate for TargetMana or DruidMana bars since we don't need quite that level of granularity
This commit is contained in:
Parnic
2008-10-29 04:01:11 +00:00
parent eaa7b73b85
commit 2814ba0d20
4 changed files with 45 additions and 54 deletions

View File

@ -503,7 +503,7 @@ function IceBarElement.prototype:CreateFrame()
-- never register the OnUpdate for the mirror bar since it's handled internally
-- in addition, do not register OnUpdate if predictedPower is set and this is the player mana or target mana bar
if not string.find(self.elementName, "MirrorBar")
and ((IceHUD.WowVer < 30000 or not GetCVarBool("predictedPower")) or (not string.find(self.elementName, "PlayerMana") and not string.find(self.elementName, "TargetMana"))) then
and ((IceHUD.WowVer < 30000 or not GetCVarBool("predictedPower")) or (not string.find(self.elementName, "PlayerMana"))) then
self.frame:SetScript("OnUpdate", function() self:MyOnUpdate() end)
end
end

View File

@ -35,17 +35,8 @@ function DruidMana.prototype:Enable(core)
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM", "Update")
self:RegisterEvent("UNIT_MAXMANA", "Update")
if IceHUD.WowVer >= 30000 then
if GetCVarBool("predictedPower") and self.frame then
self.frame:SetScript("OnUpdate", function() self:Update() end)
else
self:RegisterEvent("UNIT_MANA", "Update")
end
else
self:RegisterEvent("UNIT_MANA", "Update")
end
end
function DruidMana.prototype:Disable(core)

View File

@ -103,23 +103,16 @@ function PlayerMana.prototype:Enable(core)
self:RegisterEvent("UNIT_MAXMANA", "Update")
self:RegisterEvent("UNIT_MAXRAGE", "Update")
self:RegisterEvent("UNIT_MAXENERGY", "Update")
-- DK rune / wotlk stuff
if IceHUD.WowVer >= 30000 then
-- allow new 'predicted power' stuff to show the power updates constantly instead of ticking
if GetCVarBool("predictedPower") and self.frame then
self.frame:SetScript("OnUpdate", function() self:Update(self.unit) end)
else
self:RegisterEvent("UNIT_MAXRUNIC_POWER", "Update")
self:RegisterEvent("UNIT_MANA", "Update")
self:RegisterEvent("UNIT_RAGE", "Update")
self:RegisterEvent("UNIT_ENERGY", "UpdateEnergy")
self:RegisterEvent("UNIT_RUNIC_POWER", "Update")
end
self:RegisterEvent("UNIT_MAXRUNIC_POWER", "Update")
else
self:RegisterEvent("UNIT_MANA", "Update")
self:RegisterEvent("UNIT_RAGE", "Update")
self:RegisterEvent("UNIT_ENERGY", "UpdateEnergy")
-- allow new 'predicted power' stuff to show the power updates constantly instead of ticking
if GetCVarBool("predictedPower") then
self:SetupOnUpdate(true)
end
self:RegisterEvent("UNIT_DISPLAYPOWER", "ManaType")
@ -131,6 +124,14 @@ function PlayerMana.prototype:ShouldUseTicker()
return IceHUD.WowVer < 30000 or not GetCVarBool("predictedPower")
end
function PlayerMana.prototype:SetupOnUpdate(enable)
if enable then
self.frame:SetScript("OnUpdate", function() self:Update(self.unit) end)
else
self.frame:SetScript("OnUpdate", nil)
end
end
-- OVERRIDE
function PlayerMana.prototype:Redraw()
@ -180,6 +181,12 @@ function PlayerMana.prototype:Update(unit)
return
end
if self.manaPercentage == 1 then
self:SetupOnUpdate(false)
elseif GetCVarBool("predictedPower") then
self:SetupOnUpdate(true)
end
-- the user can toggle the predictedPower cvar at any time and the addon will not get notified. handle it.
if not self.tickerFrame and self:ShouldUseTicker() then
self:CreateTickerFrame()
@ -203,7 +210,7 @@ function PlayerMana.prototype:Update(unit)
end
end
self:UpdateBar(self.mana/self.maxMana, color)
self:UpdateBar(self.manaPercentage, color)
if self:ShouldUseTicker() then
-- hide ticker if rest of the bar is not visible
@ -246,18 +253,19 @@ end
function PlayerMana.prototype:UpdateEnergy(unit)
if (unit and (unit ~= "player")) or (not self:ShouldUseTicker()) then
if (unit and (unit ~= "player")) then
return
end
if ((not (self.previousEnergy) or (self.previousEnergy <= UnitMana(self.unit))) and
(self.moduleSettings.tickerEnabled)) then
self.tickStart = GetTime()
self.tickerFrame:Show()
end
self.previousEnergy = UnitMana(self.unit)
self:Update(unit)
if self:ShouldUseTicker() and
((not (self.previousEnergy) or (self.previousEnergy <= UnitMana(self.unit))) and
(self.moduleSettings.tickerEnabled)) then
self.tickStart = GetTime()
self.tickerFrame:Show()
end
end

View File

@ -42,24 +42,16 @@ function IceTargetMana.prototype:Enable(core)
self:RegisterEvent("UNIT_MAXFOCUS", "Update")
self:RegisterEvent("UNIT_AURA", "Update")
self:RegisterEvent("UNIT_FLAGS", "Update")
self:RegisterEvent("UNIT_MANA", "Update")
self:RegisterEvent("UNIT_RAGE", "Update")
self:RegisterEvent("UNIT_ENERGY", "Update")
self:RegisterEvent("UNIT_FOCUS", "Update")
-- DK rune stuff
if IceHUD.WowVer >= 30000 then
if GetCVarBool("predictedPower") and self.frame then
self.frame:SetScript("OnUpdate", function() self:Update(self.unit) end)
else
self:RegisterEvent("UNIT_MANA", "Update")
self:RegisterEvent("UNIT_RAGE", "Update")
self:RegisterEvent("UNIT_ENERGY", "Update")
self:RegisterEvent("UNIT_FOCUS", "Update")
self:RegisterEvent("UNIT_RUNIC_POWER", "Update")
end
self:RegisterEvent("UNIT_MAXRUNIC_POWER", "Update")
else
self:RegisterEvent("UNIT_MANA", "Update")
self:RegisterEvent("UNIT_RAGE", "Update")
self:RegisterEvent("UNIT_ENERGY", "Update")
self:RegisterEvent("UNIT_FOCUS", "Update")
end
end
@ -81,14 +73,14 @@ function IceTargetMana.prototype:Update(unit)
self:Show(true)
end
if self.moduleSettings.onlyShowMana and UnitPowerType(self.unit) ~= 0 then
local manaType = UnitPowerType(self.unit)
if self.moduleSettings.onlyShowMana and manaType ~= 0 then
self:Show(false)
return
end
local manaType = UnitPowerType(self.unit)
local color = "TargetMana"
if (self.moduleSettings.scaleManaColor) then
color = "ScaledManaColor"
@ -105,7 +97,7 @@ function IceTargetMana.prototype:Update(unit)
color = "Tapped"
end
self:UpdateBar(self.mana/self.maxMana, color)
self:UpdateBar(self.manaPercentage, color)
if not IceHUD.IceCore:ShouldUseDogTags() then
self:SetBottomText1(math.floor(self.manaPercentage * 100))