From aaa9f98a52c95a27b9d0dc73d2b53ec8368c0d7c Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sat, 2 Mar 2013 17:57:25 +0000 Subject: [PATCH] Cache active glyphs in OvaleData and update on GLYPH_* events. This change causes the OvaleData module to update the active glyph cache on GLYPH_* events. All modules now reference the OvaleData.glyphs table instead of looping through all of the glyph sockets and querying their contents each time we need to find out if a particular glyph is active. This is an efficiency boost for scripts. Also fix "/ovale glyph" to output the currently active glyphs. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@704 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- Ovale.lua | 18 -------------- OvaleCompile.lua | 15 ++---------- OvaleCondition.lua | 12 ++-------- OvaleData.lua | 67 ++++++++++++++++++++++++++++++++++++++++++++++++---- OvaleOptions.lua | 5 +--- 5 files changed, 68 insertions(+), 49 deletions(-) diff --git a/Ovale.lua b/Ovale.lua index 895b096..49ee079 100644 --- a/Ovale.lua +++ b/Ovale.lua @@ -132,8 +132,6 @@ function Ovale:OnEnable() self:RegisterEvent("PLAYER_REGEN_DISABLED"); self:RegisterEvent("PLAYER_TARGET_CHANGED") self:RegisterEvent("CHAT_MSG_ADDON") - self:RegisterEvent("GLYPH_UPDATED") - self:RegisterEvent("GLYPH_ADDED") self:RegisterMessage("Ovale_UpdateShapeshiftForm") self:UpdateVisibility() @@ -146,8 +144,6 @@ function Ovale:OnDisable() self:UnregisterEvent("PLAYER_REGEN_DISABLED") self:UnregisterEvent("PLAYER_TARGET_CHANGED") self:UnregisterEvent("CHAT_MSG_ADDON") - self:UnregisterEvent("GLYPH_UPDATED") - self:UnregisterEvent("GLYPH_ADDED") self:UnregisterMessage("Ovale_UpdateShapeshiftForm") self.frame:Hide() end @@ -178,20 +174,6 @@ function Ovale:PLAYER_TARGET_CHANGED() self:UpdateVisibility() end ---Called when a glyph has been added ---The script needs to be compiled -function Ovale:GLYPH_ADDED(event) - self:debugPrint("compile", event) - self.needCompile = true -end - ---Called when a glyph has been updated ---The script needs to be compiled -function Ovale:GLYPH_UPDATED(event) - self:debugPrint("compile", event) - self.needCompile = true -end - function Ovale:CHAT_MSG_ADDON(event, prefix, msg, type, author) if prefix ~= "Ovale" then return end if type ~= "RAID" and type~= "PARTY" then return end diff --git a/OvaleCompile.lua b/OvaleCompile.lua index 2b5a67f..5a4290b 100644 --- a/OvaleCompile.lua +++ b/OvaleCompile.lua @@ -10,6 +10,7 @@ OvaleCompile = {} -- +local Ovale = LibStub("AceAddon-3.0"):GetAddon("Ovale") local L = LibStub("AceLocale-3.0"):GetLocale("Ovale") local node={} @@ -21,7 +22,6 @@ local missingSpellList = {} local ipairs, pairs, tonumber = ipairs, pairs, tonumber local strfind, strgmatch, strgsub = string.find, string.gmatch, string.gsub local strlen, strlower, strmatch, strsub = string.len, string.lower, string.match, string.sub -local GetGlyphSocketInfo, GetNumGlyphSockets, GetSpecialization = GetGlyphSocketInfo, GetNumGlyphSockets, GetSpecialization -- -- @@ -57,17 +57,6 @@ local function ParseParameters(params) return paramList end - -local function HasGlyph(spellId) - for i = 1, GetNumGlyphSockets() do - local enabled, glyphType, glyphTooltipIndex, glyphSpellID = GetGlyphSocketInfo(i) - if (glyphSpellID == spellId) then - return true - end - end - return false -end - local function HasTalent(talentId) if not OvaleData.listeTalentsRemplie then OvaleData:RemplirListeTalents() @@ -85,7 +74,7 @@ local function HasTalent(talentId) end local function TestConditions(paramList) - if paramList.glyph and not HasGlyph(paramList.glyph) then + if paramList.glyph and not OvaleData.glyphs[paramList.glyph] then return false end if paramList.mastery and not OvaleStance:IsSpecialization(paramList.mastery) then diff --git a/OvaleCondition.lua b/OvaleCondition.lua index 8357130..b0c0ac0 100644 --- a/OvaleCondition.lua +++ b/OvaleCondition.lua @@ -44,7 +44,7 @@ local targetGUID = {} local lastSPD = {} local floor, pairs, select, strfind, tostring = math.floor, pairs, select, string.find, tostring -local GetGlyphSocketInfo, GetInventoryItemID, GetInventoryItemLink = GetGlyphSocketInfo, GetInventoryItemID, GetInventoryItemLink +local GetInventoryItemID, GetInventoryItemLink = GetInventoryItemID, GetInventoryItemLink local GetInventorySlotInfo, GetItemCooldown, GetItemCount = GetInventorySlotInfo, GetItemCooldown, GetItemCount local GetItemInfo, GetRune = GetItemInfo, GetRune local GetRuneCount, GetSpellCharges = GetRuneCount, GetSpellCharges @@ -1286,15 +1286,7 @@ end -- Spell(savage_roar) OvaleCondition.conditions.glyph = function(condition) - local present = false - for i = 1, GetNumGlyphSockets() do - local enabled, glypType, glyphTooltipIndex, glyphSpellID = GetGlyphSocketInfo(i) - if (glyphSpellID == condition[1]) then - present = true - break - end - end - return testbool(present, condition[2]) + return testbool(OvaleData.glyphs[condition[1]], condition[2]) end --- Test if the player has full control, i.e., isn't feared, charmed, etc. diff --git a/OvaleData.lua b/OvaleData.lua index f55bbe0..812607f 100644 --- a/OvaleData.lua +++ b/OvaleData.lua @@ -10,7 +10,11 @@ OvaleData = LibStub("AceAddon-3.0"):NewAddon("OvaleData", "AceEvent-3.0") -- +local Ovale = LibStub("AceAddon-3.0"):GetAddon("Ovale") + local ipairs, pairs, tinsert, tonumber, tostring, tsort = ipairs, pairs, table.insert, tonumber, tostring, table.sort +local GetNumGlyphSockets = GetNumGlyphSockets +local GetGlyphSocketInfo = GetGlyphSocketInfo local GetSpellBookItemInfo, GetSpellBookItemName = GetSpellBookItemInfo, GetSpellBookItemName local GetSpellInfo, GetSpellTabInfo, GetTalentInfo = GetSpellInfo, GetSpellTabInfo, GetTalentInfo local HasPetSpells, UnitBuff, UnitClass = HasPetSpells, UnitBuff, UnitClass @@ -30,6 +34,8 @@ OvaleData.pointsTalent = {} OvaleData.talentIdToName = {} --key: talent name / value: talent id OvaleData.talentNameToId = {} +--active glyphs: self.glyphs[glyphId] is true if the given glyphId is active +OvaleData.glyphs = {} --spell info from the current script (by spellId) OvaleData.spellInfo = {} --spells that count for scoring @@ -287,6 +293,11 @@ function OvaleData:OnEnable() self:FirstInit() self:RegisterEvent("CHARACTER_POINTS_CHANGED") + self:RegisterEvent("GLYPH_ADDED") + self:RegisterEvent("GLYPH_DISABLED") + self:RegisterEvent("GLYPH_ENABLED") + self:RegisterEvent("GLYPH_REMOVED") + self:RegisterEvent("GLYPH_UPDATED") self:RegisterEvent("PLAYER_LEVEL_UP") self:RegisterEvent("PLAYER_TALENT_UPDATE") self:RegisterEvent("SPELLS_CHANGED") @@ -294,11 +305,16 @@ function OvaleData:OnEnable() end function OvaleData:OnDisable() - self:UnregisterEvent("UNIT_PET") - self:UnregisterEvent("SPELLS_CHANGED") - self:UnregisterEvent("PLAYER_TALENT_UPDATE") - self:UnregisterEvent("PLAYER_LEVEL_UP") self:UnregisterEvent("CHARACTER_POINTS_CHANGED") + self:UnregisterEvent("GLYPH_ADDED") + self:UnregisterEvent("GLYPH_DISABLED") + self:UnregisterEvent("GLYPH_ENABLED") + self:UnregisterEvent("GLYPH_REMOVED") + self:UnregisterEvent("GLYPH_UPDATED") + self:UnregisterEvent("PLAYER_LEVEL_UP") + self:UnregisterEvent("PLAYER_TALENT_UPDATE") + self:UnregisterEvent("SPELLS_CHANGED") + self:UnregisterEvent("UNIT_PET") end function OvaleData:CHARACTER_POINTS_CHANGED() @@ -306,6 +322,26 @@ function OvaleData:CHARACTER_POINTS_CHANGED() -- Ovale:Print("CHARACTER_POINTS_CHANGED") end +function OvaleData:GLYPH_ADDED(event) + self:UpdateGlyphs() +end + +function OvaleData:GLYPH_DISABLED(event) + self:UpdateGlyphs() +end + +function OvaleData:GLYPH_ENABLED(event) + self:UpdateGlyphs() +end + +function OvaleData:GLYPH_REMOVED(event) + self:UpdateGlyphs() +end + +function OvaleData:GLYPH_UPDATED(event) + self:UpdateGlyphs() +end + function OvaleData:PLAYER_LEVEL_UP(event, level, ...) level = tonumber(level) if level then @@ -481,6 +517,29 @@ function OvaleData:GetSpellInfo(spellId) return self.spellInfo[spellId] end +function OvaleData:UpdateGlyphs() + wipe(self.glyphs) + for i = 1, GetNumGlyphSockets() do + local enabled, _, _, glyphSpell, _ = GetGlyphSocketInfo(i) + if enabled and glyphSpell then + self.glyphs[glyphSpell] = true + end + end + Ovale:debugPrint("compile", event) + Ovale.needCompile = true +end + +function OvaleData:DebugGlyphs() + local array = {} + for glyphId in pairs(self.glyphs) do + tinsert(array, GetSpellInfo(glyphId) .. ": " .. glyphId) + end + tsort(array) + for _, v in ipairs(array) do + Ovale:Print(v) + end +end + function OvaleData:ResetSpellInfo() self.spellInfo = {} end diff --git a/OvaleOptions.lua b/OvaleOptions.lua index 24f1094..09aa291 100644 --- a/OvaleOptions.lua +++ b/OvaleOptions.lua @@ -453,10 +453,7 @@ local options = name = "List player glyphs", type = "execute", func = function() - for i=1,GetNumGlyphs() do - local name, level, enabled, texture, spellId = GetGlyphInfo(i) - if spellId then Ovale:Print(name..": "..spellId.." ("..tostring(enabled)..")") end - end + OvaleData:DebugGlyphs() end }, spell = -- 1.7.9.5