From 387854e801960b15ca1127c62fb73c2eca0b553d Mon Sep 17 00:00:00 2001 From: shagu Date: Sun, 15 Jul 2018 21:32:19 +0200 Subject: [PATCH] tracking: reduce memory load on aura change --- modules/tracking.lua | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/modules/tracking.lua b/modules/tracking.lua index 4cac8f44..380b0fc9 100644 --- a/modules/tracking.lua +++ b/modules/tracking.lua @@ -3,6 +3,13 @@ pfUI:RegisterModule("tracking", function () MiniMapTrackingFrame:UnregisterAllEvents() MiniMapTrackingFrame:Hide() + local function HasEntries(tbl) + for _ in pairs(tbl) do + return true + end + return nil + end + local config = { border = C.appearance.border.default, size = tonumber(C.appearance.minimap.tracking_size), @@ -71,7 +78,7 @@ pfUI:RegisterModule("tracking", function () elseif not texture then state.texture = nil - if config.pulse and table.getn(state.spells) > 0 then + if config.pulse and HasEntries(state.spells) then this.pulse = true this.icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark") this.icon:SetVertexColor(1,1,1,1) @@ -126,28 +133,37 @@ pfUI:RegisterModule("tracking", function () local _, playerClass = UnitClass("player") local isCatForm = pfUI.tracking:PlayerIsDruidInCatForm(playerClass) - state.spells = {} for tabIndex = 1, GetNumSpellTabs() do local _, _, offset, numSpells = GetSpellTabInfo(tabIndex) for spellIndex = offset + 1, offset + numSpells do local spellTexture = GetSpellTexture(spellIndex, BOOKTYPE_SPELL) - for _, c in pairs({"any", playerClass}) do - for _, t in pairs(knownTrackingSpellTextures[c] or {}) do - if c == "DRUID" and not isCatForm then - break - end - if strfind(spellTexture, t) then - table.insert(state.spells, { + + for _, texture in pairs(knownTrackingSpellTextures["any"]) do + if strfind(spellTexture, texture) and not state.spells[texture] then + state.spells[texture] = { + index = spellIndex, + name = GetSpellName(spellIndex, BOOKTYPE_SPELL), + texture = spellTexture + } + end + end + + for _, texture in pairs(knownTrackingSpellTextures[playerClass]) do + if strfind(spellTexture, texture) and not state.spells[texture] then + state.spells[texture] = { index = spellIndex, name = GetSpellName(spellIndex, BOOKTYPE_SPELL), texture = spellTexture - }) - break - end + } end end end end + + -- remove humanoid tracking for non-cat druids + if playerClass == "DRUID" and not isCatForm then + state.spells["Ability_Tracking"] = nil + end end function pfUI.tracking:PlayerIsDruidInCatForm(playerClass)