Skip to content

Commit

Permalink
minor optimizations for OnUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
wardz committed Apr 2, 2020
1 parent 7672b50 commit 0b61a92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ClassicCastbars/ClassicCastbars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ function addon:CheckCastModifier(unitID, cast)
end

function addon:StartCast(unitGUID, unitID)
if not unitGUID then return end

local cast = activeTimers[unitGUID]
if not cast then return end

Expand Down Expand Up @@ -205,6 +207,7 @@ function addon:StoreCast(unitGUID, spellName, spellID, iconTexturePath, castTime
cast.isInterrupted = nil
cast.isCastComplete = nil
cast.isFailed = nil
cast.isUnknownState = nil

self:StartAllCasts(unitGUID)
end
Expand Down Expand Up @@ -564,9 +567,10 @@ function addon:COMBAT_LOG_EVENT_UNFILTERED()
-- Channeled spells are started on SPELL_CAST_SUCCESS instead of stopped.
-- Also there's no castTime returned from GetSpellInfo for channeled spells so we need to get it from our own list
if channelCast then
-- Arcane Missiles triggers this event for every tick so ignore after first tick has been detected
if (spellName == ARCANE_MISSILES or spellName == ARCANE_MISSILE) and activeTimers[srcGUID] then
if activeTimers[srcGUID].spellName == ARCANE_MISSILES or activeTimers[srcGUID].spellName == ARCANE_MISSILE then return end
local cast = activeTimers[srcGUID]
if cast and (spellName == ARCANE_MISSILES or spellName == ARCANE_MISSILE) then
-- Arcane Missiles triggers this event for every tick so ignore after first tick has been detected
if cast.spellName == ARCANE_MISSILES or cast.spellName == ARCANE_MISSILE then return end
end

return self:StoreCast(srcGUID, spellName, spellID, GetSpellTexture(spellID), channelCast, isSrcPlayer, true)
Expand All @@ -589,7 +593,7 @@ function addon:COMBAT_LOG_EVENT_UNFILTERED()
elseif eventType == "SPELL_AURA_REMOVED" then
-- Channeled spells has no proper event for channel stop,
-- so check if aura is gone instead since most channels has an aura effect.
if channeledSpells[spellName] and srcGUID == dstGUID then
if srcGUID == dstGUID and channeledSpells[spellName] then
return self:DeleteCast(srcGUID, nil, nil, true)
end
elseif eventType == "SPELL_CAST_FAILED" then
Expand Down Expand Up @@ -671,7 +675,7 @@ addon:SetScript("OnUpdate", function(self, elapsed)
refresh = refresh - elapsed
if refresh < 0 then
if next(activeGUIDs) then
for unitID, unitGUID in pairs(activeGUIDs) do
for unitID, unitGUID in next, activeGUIDs do
if unitID ~= "focus" then
local cast = activeTimers[unitGUID]
-- Only stop cast for players since some mobs runs while casting, also because
Expand All @@ -696,7 +700,7 @@ addon:SetScript("OnUpdate", function(self, elapsed)
end

-- Update all shown castbars in a single OnUpdate call
for unit, castbar in pairs(activeFrames) do
for unit, castbar in next, activeFrames do
local cast = castbar._data
if cast then
local castTime = cast.endTime - currTime
Expand All @@ -711,12 +715,12 @@ addon:SetScript("OnUpdate", function(self, elapsed)
castbar:SetMinMaxValues(0, maxValue)
castbar:SetValue(value)
castbar.Timer:SetFormattedText("%.1f", castTime)
local sparkPosition = (value / maxValue) * castbar:GetWidth()
local sparkPosition = (value / maxValue) * (castbar.currWidth or castbar:GetWidth())
castbar.Spark:SetPoint("CENTER", castbar, "LEFT", sparkPosition, 0)
else
-- slightly adjust color of the castbar when its not 100% sure if the cast is casted or failed
-- (gotta put it here to run before fadeout anim)
if not cast.isCastComplete and not cast.isInterrupted and not cast.isFailed then
if not cast.isUnknownState and not cast.isCastComplete and not cast.isInterrupted and not cast.isFailed then
castbar.Spark:SetAlpha(0)
if not cast.isChanneled then
local c = self.db[self:GetUnitType(unit)].statusColor
Expand All @@ -726,6 +730,7 @@ addon:SetScript("OnUpdate", function(self, elapsed)
else
castbar:SetValue(0)
end
cast.isUnknownState = true
end

-- Delete cast incase stop event wasn't detected in CLEU
Expand Down
1 change: 1 addition & 0 deletions ClassicCastbars/core/Frames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function addon:SetCastbarStyle(castbar, cast, db, unitID)
castbar:SetStatusBarTexture(db.castStatusBar)
castbar:SetFrameLevel(db.frameLevel)
castbar.Text:SetWidth(db.width - 10) -- ensures text gets truncated
castbar.currWidth = db.width -- avoids having to use a function call later on

if cast and cast.isChanneled then
castbar.Spark:SetAlpha(0)
Expand Down

0 comments on commit 0b61a92

Please sign in to comment.