Quantcast

Filter out spells that we don't care about from the aura-tracking code.

Johnny C. Lam [10-26-12 - 05:25]
Filter out spells that we don't care about from the aura-tracking code.

This reduces the number of events for which Ovale updates auras.  Also fix
a bug in the compilation where missing spells weren't re-added to the
spellbook after reloading the UI or zoning into a new zone.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@625 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.lua
OvaleAura.lua
OvaleCompile.lua
OvaleData.lua
diff --git a/Ovale.lua b/Ovale.lua
index 208cb54..d7bc601 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -93,12 +93,14 @@ function Ovale:CompileAll()
 	if code then
 		if self.needCompile == "quick" then
 			self:debugPrint("compile", "quick compile")
+			code = OvaleCompile:CompileComments(code)
 			code = OvaleCompile:CompileDeclarations(code)
 			code = OvaleCompile:CompileInputs(code)
 		elseif self.needCompile then
 			self:debugPrint("compile", "FULL compile")
 			self.masterNodes = OvaleCompile:Compile(code)
 		end
+		OvaleData:FillMissingSpells()
 		OvaleCompile:UpdateNodesEnabled(self.masterNodes, self.masterNodesEnabled)
 		self.refreshNeeded.player = true
 		self.needCompile = false
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 38adf55..dfc6f4c 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -57,13 +57,19 @@ function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, ...)

 	if strfind(event, "SPELL_AURA_") == 1 then
 		local spellId, spellName, spellSchool, auraType = select(12, ...)
-
+
+		if sourceGUID == self.playerGUID and not OvaleData.spellFilter.mine[spellId] then
+			return
+		elseif not OvaleData.spellFilter.any[spellId] then
+			return
+		end
+
 		local unitId = OvaleGUID:GetUnitId(destGUID)
-
+
 		if unitId then
 			self:UpdateAuras(unitId, destGUID)
 		end
-
+
 		if sourceGUID == self.playerGUID and (event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REFRESH" or event == "SPELL_AURA_APPLIED_DOSE") then
 			local aura = self:GetAuraByGUID(destGUID, spellId, true)
 			if aura then
@@ -71,7 +77,7 @@ function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
 			end
 		end
 	end
-
+
 	if event == "UNIT_DIED" then
 		self.aura[destGUID] = nil
 		local unitId = OvaleGUID:GetUnitId(destGUID)
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 764dd85..337c601 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -177,22 +177,34 @@ local function ParseFunction(prefix, func, params)
 	local newNode = { type="function", func=func, params=paramList}
 	local newNodeName = AddNode(newNode)

-	-- For the spell() and spellcooldown() functions, check if the spell ID
-	-- is a variant of a spell with the same name as one already in the
-	-- spellbook.  If it is, then add that variant spell ID to our spellList.
-	if func == "spell" or func == "spellcooldown" then
-		local spellId = paramList[1]
-		if spellId and not OvaleData.spellList[spellId] then
-			local spellName = GetSpellInfo(spellId)
-			if spellName then
-				if spellName == GetSpellInfo(spellName) then
-					Ovale:debugPrint("missing_spells", "Learning spell "..tostring(spellName).." with ID "..spellId)
-					OvaleData.spellList[spellId] = spellName
-				else
-					unknownSpellNodes[newNode.nodeId] = spellId
+	local mine = true
+	if paramList.any then
+		mine = false
+	end
+
+	local spellId = paramList[1]
+	if spellId then
+		-- For the spell() and spellcooldown() functions, check if the spell ID
+		-- is a variant of a spell with the same name as one already in the
+		-- spellbook.  If it is, then add that variant spell ID to our spellList.
+		if type(spellId) == "number" then
+			if not OvaleData.spellList[spellId] and not OvaleData.missingSpellList[spellId] then
+				if func == "spell" or func == "spellcooldown" then
+					local spellName = GetSpellInfo(spellId)
+					if spellName then
+						if spellName == GetSpellInfo(spellName) then
+							Ovale:debugPrint("missing_spells", "Learning spell "..tostring(spellName).." with ID "..spellId)
+							OvaleData.missingSpellList[spellId] = spellName
+						else
+							unknownSpellNodes[newNode.nodeId] = spellId
+						end
+					end
 				end
-			else
-				Ovale:Print("Unknown spell with ID "..spellId)
+			end
+			OvaleData:AddSpellToFilter(spellId, mine)
+		elseif OvaleData.buffSpellList[spellId] then
+			for _, v in pairs(OvaleData.buffSpellList[spellId]) do
+				OvaleData:AddSpellToFilter(v, mine)
 			end
 		end
 	end
@@ -521,6 +533,12 @@ end
 --</private-static-methods>

 --<public-static-methods>
+function OvaleCompile:CompileComments(text)
+	text = strgsub(text, "#.-\n","")
+	text = strgsub(text, "#.*$","")
+	return text
+end
+
 function OvaleCompile:CompileInputs(text)
 	Ovale.casesACocher = {}
 	Ovale.listes = {}
@@ -577,8 +595,7 @@ function OvaleCompile:Compile(text)
 	unknownSpellNodes = {}

 	-- Suppression des commentaires
-	text = strgsub(text, "#.-\n","")
-	text = strgsub(text, "#.*$","")
+	text = self:CompileComments(text)

 	-- Compile non-function and non-icon declarations.
 	text = self:CompileDeclarations(text)
@@ -586,6 +603,8 @@ function OvaleCompile:Compile(text)
 	-- On compile les AddCheckBox et AddListItem
 	text = self:CompileInputs(text)

+	OvaleData:ResetSpellFilter()
+
 	for p,t in strgmatch(text, "AddFunction%s+(%w+)%s*(%b{})") do
 		local newNode = ParseCommands(t)
 		if newNode then
diff --git a/OvaleData.lua b/OvaleData.lua
index c433e08..d77ee9c 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -19,6 +19,7 @@ local BOOKTYPE_SPELL, BOOKTYPE_PET = BOOKTYPE_SPELL, BOOKTYPE_PET

 --<public-static-properties>
 OvaleData.spellList = {}
+OvaleData.missingSpellList = {}
 OvaleData.firstInit = false
 OvaleData.className = nil
 OvaleData.level = nil
@@ -34,6 +35,8 @@ OvaleData.talentNameToId = {}
 OvaleData.spellInfo = {}
 --spells that count for scoring
 OvaleData.scoreSpell = {}
+--spells that should be tracked
+OvaleData.spellFilter = { any = {}, mine = {} }

 OvaleData.power =
 {
@@ -370,6 +373,12 @@ function OvaleData:FillPetSpellList()
 	end
 end

+function OvaleData:FillMissingSpells()
+	for k, v in pairs(self.missingSpellList) do
+		self.spellList[k] = v
+	end
+end
+
 function OvaleData:FillSpellList()
 	self.spellList = {}

@@ -388,6 +397,7 @@ function OvaleData:FillSpellList()
 		end
 		i = i + 1
 	end
+	self:FillMissingSpells()
 	self:FillPetSpellList()
 end

@@ -454,6 +464,19 @@ function OvaleData:ResetSpellInfo()
 	self.spellInfo = {}
 end

+function OvaleData:ResetSpellFilter()
+	self.spellFilter.any = {}
+	self.spellFilter.mine = {}
+end
+
+function OvaleData:AddSpellToFilter(spellId, mine)
+	if mine then
+		self.spellFilter.mine[spellId] = true
+	else
+		self.spellFilter.any[spellId] = true
+	end
+end
+
 function OvaleData:GetGCD(spellId)
 	if spellId and self.spellInfo[spellId] then
 		if self.spellInfo[spellId].haste == "spell" then