Quantcast

Fix for CPU spikes.

Daniel Yates [02-19-11 - 01:56]
Fix for CPU spikes.
Filename
Modules/Auras.lua
Modules/Buttons.lua
diff --git a/Modules/Auras.lua b/Modules/Auras.lua
index f66286b..543ece7 100644
--- a/Modules/Auras.lua
+++ b/Modules/Auras.lua
@@ -16,7 +16,7 @@ Variables
 	BlizzAuras         Stores a list of active spell overlays fired by Blizzard's spell events.
 ----------------------------------------------------------------------------------------------------
 --]]
-local ActionTable      = {};
+-- -- local ActionTable      = {};
 local ActiveAuras      = {};
 local BlizzAuras       = {};
 --[[
@@ -89,41 +89,39 @@ function ModuleFrame:SPELL_ACTIVATION_OVERLAY_GLOW_HIDE(auraID)
 	-- Right, fire events.
 	CoreFrame:FireModuleEvent("OnAuraHide", auraID);
 end
---[[
-----------------------------------------------------------------------------------------------------
-CalculateActionTable
+-- -- --[[
+-- -- ----------------------------------------------------------------------------------------------------
+-- -- CalculateActionTable

-Calculates a table of actions (uniquely seperated by a key composed of action type and ID) which
-contains a list of auras which could modify the display of buttons which match the actions.
-----------------------------------------------------------------------------------------------------
---]]
-function ModuleFrame:CalculateActionTable()
-	-- Wipe the existing table.
-	wipe(ActionTable);
-	-- Go over every single possible aura we have.
-	local actions, key;
-	for auraID=1,360 do
-		-- Reset vars.
-		actions, key = ModuleFrame:GetAuraActions(auraID), nil;
-		if(actions and #(actions) > 0) then
-			-- Go over them.
-			for actionID, actionData in pairs(actions) do
-				-- Calculate a key from the data.
-				if(actionData and actionData["id"] and actionData["id"] > 0) then
-					key = strupper(strsub(actionData["type"], 0, 1)) .. actionData["id"];
-					-- Does a table for auras with this key already exist?
-					if(not ActionTable[key]) then
-						ActionTable[key] = {};
-					end
-					-- Add the aura.
-					tinsert(ActionTable[key], format("%03d", auraID) .. actionID);
-				end
-			end
-		end
-	end
-	-- Perform GC.
-	collectgarbage("collect");
-end
+-- -- Calculates a table of actions (uniquely seperated by a key composed of action type and ID) which
+-- -- contains a list of auras which could modify the display of buttons which match the actions.
+-- -- ----------------------------------------------------------------------------------------------------
+-- -- --]]
+-- -- function ModuleFrame:CalculateActionTable()
+	-- -- -- Wipe the existing table.
+	-- -- wipe(ActionTable);
+	-- -- -- Go over every single possible aura we have.
+	-- -- local actions, key;
+	-- -- for auraID=1,360 do
+		-- -- -- Reset vars.
+		-- -- actions, key = ModuleFrame:GetAuraActions(auraID), nil;
+		-- -- if(actions and #(actions) > 0) then
+			-- -- -- Go over them.
+			-- -- for actionID, actionData in pairs(actions) do
+				-- -- -- Calculate a key from the data.
+				-- -- if(actionData and actionData["id"] and actionData["id"] > 0) then
+					-- -- key = strupper(strsub(actionData["type"], 0, 1)) .. actionData["id"];
+					-- -- -- Does a table for auras with this key already exist?
+					-- -- if(not ActionTable[key]) then
+						-- -- ActionTable[key] = {};
+					-- -- end
+					-- -- -- Add the aura.
+					-- -- tinsert(ActionTable[key], format("%03d", auraID) .. actionID);
+				-- -- end
+			-- -- end
+		-- -- end
+	-- -- end
+-- -- end
 --[[
 ----------------------------------------------------------------------------------------------------
 GetActionTable
@@ -161,7 +159,7 @@ function ModuleFrame:ResetAuras()
 		end
 	end
 	-- On a reset, recalculate the table too.
-	ModuleFrame:CalculateActionTable();
+	-- -- ModuleFrame:CalculateActionTable();
 end
 --[[
 ----------------------------------------------------------------------------------------------------
@@ -325,7 +323,7 @@ function ModuleFrame:OnInitialize()
 	CoreFrame:RegisterModuleEvent("OnAuraShow");
 	CoreFrame:RegisterModuleEvent("OnAuraHide");
 	-- Calculate some actions baby.
-	ModuleFrame:CalculateActionTable();
+	-- -- ModuleFrame:CalculateActionTable();
 	-- Done.
 	return true;
 end
\ No newline at end of file
diff --git a/Modules/Buttons.lua b/Modules/Buttons.lua
index d56be0a..ac3aaa3 100644
--- a/Modules/Buttons.lua
+++ b/Modules/Buttons.lua
@@ -65,104 +65,185 @@ be glowing, showing displays, etc.
 ----------------------------------------------------------------------------------------------------
 --]]
 function ModuleFrame:ProcessButtonActions(button)
-	-- Few button data related locals.
+	-- Few locals.
 	local buttonID = button:GetName();
-	if(not ButtonData[buttonID]) then ButtonData[buttonID] = {}; end
-	wipe(ButtonData[buttonID]);
+	-- Get the button data table if it exists. Otherwise, make a new one. We recycle the old one
+	-- so the memory size won't fluctuate.
+	local buttonData = ButtonData[buttonID] or {};
+	-- Wipe the data.
+	wipe(buttonData);
 	-- Fire button processing event.
 	CoreFrame:FireModuleEvent("OnButtonProcess", buttonID);
-	-- Determine the action key from the button.
-	local buttonAction = button._state_action or button.action;
-	-- Action must be a number.
-	if(not buttonAction or type(buttonAction) ~= "number") then return; end
-	local buttonActionType, buttonActionID = GetActionInfo(buttonAction);
-	-- Make sure we got the stuff.
-	if(not buttonActionType or not buttonActionID) then return; end
-	-- Key it.
-	local key = strupper(strsub(buttonActionType, 0, 1)) .. buttonActionID;
-	-- Blizzard auras need checking first off, but only if enabled.
+	-- Get the non blizzard auras.
+	local CustomAuras, BlizzAuras = Modules.Auras:GetAuras();
+	-- More locals.
+	local buttonAction, buttonActionType, buttonActionID, buttonMacro, displayCount;
+	-- Get the button action ID.
+	buttonAction = button._state_action or button.action;
+	-- Action needs to be integer.
+	if(not buttonAction or type(buttonAction) ~= "number") then
+		-- Action isn't valid.
+		ButtonData[buttonID] = buttonData;
+		return;
+	end
+	-- Get the button action data.
+	buttonActionType, buttonActionID = GetActionInfo(buttonAction);
+	-- Get macro names if needed.
+	if(buttonActionType == "macro") then
+		buttonMacro = GetMacroSpell(buttonActionID) or GetMacroItem(buttonActionID);
+	end
+	-- Right, first off we need to go over all the auras see if they're linked to this one.
+	for auraID, _ in pairs(CustomAuras) do
+		-- Aura needs to be active.
+		if(Modules.Auras:IsAuraShown(auraID)) then
+			-- And go over the actions.
+			for auraActionID, auraActionData in pairs(Modules.Auras:GetAuraActions(auraID)) do
+				-- Action needs to be a valid ID (> 0)
+				if(auraActionData["id"] and auraActionData["id"] > 0) then
+					-- If the type/data keys match, or this is a macro/spell combo then continue.
+					if(buttonActionType == auraActionData["type"]
+					or (buttonActionType == "macro" and auraActionData["type"] == "spell")
+					or (buttonActionType == "macro" and auraActionData["type"] == "item")) then
+						-- Compare ID's. If they match, we're golden. If they don't, do macro
+						-- comparisons.
+						if((buttonActionID == auraActionData["id"]
+						and buttonActionType == auraActionData["type"])
+						or buttonMacro and (auraActionData["type"] == "spell"
+						and GetSpellInfo(auraActionData["id"]) == buttonMacro
+						or auraActionData["type"] == "item"
+						and GetItemInfo(auraActionData["id"]) == buttonMacro)) then
+							-- Enable glows if the action says so.
+							Modules.Auras:MergeAuraAction(buttonData, auraActionData);
+							-- Fire the OnAuraDisplay event.
+							CoreFrame:FireModuleEvent("OnButtonDisplayAura", buttonID, auraID,
+								auraActionData, auraActionID);
+						end
+					end
+				end
+			end
+		end
+	end
+	-- Blizzard auras need checking if glow isn't on, and if enabled.
 	if(CoreFrame:GetModuleSetting("Buttons", "ShowBlizzardGlows")) then
-		if(buttonActionType == "spell" and IsSpellOverlayed(buttonActionID)) then
+		if(not buttonData["glow"] and buttonActionType == "spell"
+		and IsSpellOverlayed(buttonActionID)) then
 			-- It needs to glow.
-			ButtonData[buttonID]["glow"] = true;
-		elseif(buttonActionType == "macro") then
+			buttonData["glow"] = true;
+		elseif(not buttonData["glow"] and buttonActionType == "macro") then
 			-- Macros should glow too.
-			local buttonMacro = GetMacroSpell(buttonActionID);
+			buttonMacro = GetMacroSpell(buttonActionID) or GetMacroItem(buttonActionID);
 			-- Loop over active Blizzard auras.
-			local _, BlizzAuras = Modules.Auras:GetAuras();
 			for blizzAuraID, _ in pairs(BlizzAuras) do
 				-- Check ID.
-				if(not ButtonData[buttonID]["glow"] and buttonMacro
-				and buttonMacro == GetSpellInfo(blizzAuraID)) then
+				if(not buttonData["glow"] and buttonMacro
+				and (buttonMacro == GetSpellInfo(blizzAuraID)
+				or GetItemInfo(blizzAuraID) == buttonMacro)) then
 					-- Yeah, it's a match. Timers/Stacks aren't on for blizz ones.
-					ButtonData[buttonID]["glow"] = true;
+					buttonData["glow"] = true;
 				end
 			end
 		end
 	end
-	-- Does this key exist anywhere?
-	local auras = Modules.Auras:GetActionTable(key);
-	if(not auras) then
-		-- It's not necessarily the end, is this a macro?
-		if(buttonActionType == "macro") then
-			-- In that case, get the spell or item name the button represents.
-			local buttonMacro = GetMacroSpell(buttonActionID) or GetMacroItem(buttonActionID);
-			local actionData;
-			-- Go over all of the actions. Slow, I know, but decent enough for now...
-			for actionKey, auras in pairs(Modules.Auras:GetActionTable()) do
-				-- And for this one, figure out what the hell spell or item name it represents.
-				local actionType = strsub(actionKey, 0, 1);
-				actionData = (actionType == "S"
-					and GetSpellInfo(tonumber(strsub(actionKey, 2))))
-					or (actionType == "I"
-					and GetSpellInfo(tonumber(strsub(actionKey, 2))))
-					or nil;
-				if(actionData and actionData == buttonMacro) then
-					-- Right, it's a match. A complicated match. Go over the auras.
-					for _, auraID in pairs(auras) do
-						-- I hate duplicating code but I don't want to create tables.
-						local auraActionID = tonumber(strsub(auraID, 4, 5));
-						auraID = tonumber(strsub(auraID, 0, 3));
-						-- Is the aura active?
-						if(Modules.Auras:IsAuraShown(auraID)) then
-							-- Get the action data.
-							local actionData = Modules.Auras:GetAuraAction(auraID, auraActionID);
-							-- One difference for macros is we check the type.
-							if(actionType == strupper(strsub(actionData["type"], 0, 1))) then
-								-- Enable displays for this aura.
-								Modules.Auras:MergeAuraAction(ButtonData[buttonID], actionData);
-								-- Fire aura display event.
-								CoreFrame:FireModuleEvent("OnButtonDisplayAura", buttonID, auraID,
-									actionData, auraActionID);
-							end
-						end
-					end
-				end
-			end
-			-- Done.
-			return;
-		else
-			-- Not a macro, end it.
-			return;
-		end
-	end
-	-- Go over the auras this key has.
-	for _, auraID in pairs(auras) do
-		-- The action ID is actually the auraID padded to 3 digits + the action ID appended.
-		-- So split it up.
-		local auraActionID = tonumber(strsub(auraID, 4, 5));
-		auraID = tonumber(strsub(auraID, 0, 3));
-		-- Is the aura active?
-		if(Modules.Auras:IsAuraShown(auraID)) then
-			-- Get the action data.
-			local actions = Modules.Auras:GetAuraAction(auraID, auraActionID);
-			-- Enable displays for this aura.
-			Modules.Auras:MergeAuraAction(ButtonData[buttonID], actions);
-			-- Fire aura display event.
-			CoreFrame:FireModuleEvent("OnButtonDisplayAura", buttonID, auraID, actions,
-				auraActionID);
-		end
-	end
+	-- Update.
+	ButtonData[buttonID] = buttonData;
+	-- -- -- Few button data related locals.
+	-- -- local buttonID = button:GetName();
+	-- -- if(not ButtonData[buttonID]) then ButtonData[buttonID] = {}; end
+	-- -- wipe(ButtonData[buttonID]);
+	-- -- -- Fire button processing event.
+	-- -- CoreFrame:FireModuleEvent("OnButtonProcess", buttonID);
+	-- -- -- Determine the action key from the button.
+	-- -- local buttonAction = button._state_action or button.action;
+	-- -- -- Action must be a number.
+	-- -- if(not buttonAction or type(buttonAction) ~= "number") then return; end
+	-- -- local buttonActionType, buttonActionID = GetActionInfo(buttonAction);
+	-- -- -- Make sure we got the stuff.
+	-- -- if(not buttonActionType or not buttonActionID) then return; end
+	-- -- -- Key it.
+	-- -- local key = strupper(strsub(buttonActionType, 0, 1)) .. buttonActionID;
+	-- -- -- Blizzard auras need checking first off, but only if enabled.
+	-- -- if(CoreFrame:GetModuleSetting("Buttons", "ShowBlizzardGlows")) then
+		-- -- if(buttonActionType == "spell" and IsSpellOverlayed(buttonActionID)) then
+			-- -- -- It needs to glow.
+			-- -- ButtonData[buttonID]["glow"] = true;
+		-- -- elseif(buttonActionType == "macro") then
+			-- -- -- Macros should glow too.
+			-- -- local buttonMacro = GetMacroSpell(buttonActionID);
+			-- -- -- Loop over active Blizzard auras.
+			-- -- local _, BlizzAuras = Modules.Auras:GetAuras();
+			-- -- for blizzAuraID, _ in pairs(BlizzAuras) do
+				-- -- -- Check ID.
+				-- -- if(not ButtonData[buttonID]["glow"] and buttonMacro
+				-- -- and buttonMacro == GetSpellInfo(blizzAuraID)) then
+					-- -- -- Yeah, it's a match. Timers/Stacks aren't on for blizz ones.
+					-- -- ButtonData[buttonID]["glow"] = true;
+				-- -- end
+			-- -- end
+		-- -- end
+	-- -- end
+	-- -- -- Does this key exist anywhere?
+	-- -- local auras = Modules.Auras:GetActionTable(key);
+	-- -- if(not auras) then
+		-- -- -- It's not necessarily the end, is this a macro?
+		-- -- if(buttonActionType == "macro") then
+			-- -- -- In that case, get the spell or item name the button represents.
+			-- -- local buttonMacro = GetMacroSpell(buttonActionID) or GetMacroItem(buttonActionID);
+			-- -- local actionData;
+			-- -- -- Go over all of the actions. Slow, I know, but decent enough for now...
+			-- -- for actionKey, auras in pairs(Modules.Auras:GetActionTable()) do
+				-- -- -- And for this one, figure out what the hell spell or item name it represents.
+				-- -- local actionType = strsub(actionKey, 0, 1);
+				-- -- actionData = (actionType == "S"
+					-- -- and GetSpellInfo(tonumber(strsub(actionKey, 2))))
+					-- -- or (actionType == "I"
+					-- -- and GetSpellInfo(tonumber(strsub(actionKey, 2))))
+					-- -- or nil;
+				-- -- if(actionData and actionData == buttonMacro) then
+					-- -- -- Right, it's a match. A complicated match. Go over the auras.
+					-- -- for _, auraID in pairs(auras) do
+						-- -- -- I hate duplicating code but I don't want to create tables.
+						-- -- local auraActionID = tonumber(strsub(auraID, 4, 5));
+						-- -- auraID = tonumber(strsub(auraID, 0, 3));
+						-- -- -- Is the aura active?
+						-- -- if(Modules.Auras:IsAuraShown(auraID)) then
+							-- -- -- Get the action data.
+							-- -- local actionData = Modules.Auras:GetAuraAction(auraID, auraActionID);
+							-- -- -- One difference for macros is we check the type.
+							-- -- if(actionType == strupper(strsub(actionData["type"], 0, 1))) then
+								-- -- -- Enable displays for this aura.
+								-- -- Modules.Auras:MergeAuraAction(ButtonData[buttonID], actionData);
+								-- -- -- Fire aura display event.
+								-- -- CoreFrame:FireModuleEvent("OnButtonDisplayAura", buttonID, auraID,
+									-- -- actionData, auraActionID);
+							-- -- end
+						-- -- end
+					-- -- end
+				-- -- end
+			-- -- end
+			-- -- -- Done.
+			-- -- return;
+		-- -- else
+			-- -- -- Not a macro, end it.
+			-- -- return;
+		-- -- end
+	-- -- end
+	-- -- -- Go over the auras this key has.
+	-- -- for _, auraID in pairs(auras) do
+		-- -- -- The action ID is actually the auraID padded to 3 digits + the action ID appended.
+		-- -- -- So split it up.
+		-- -- local auraActionID = tonumber(strsub(auraID, 4, 5));
+		-- -- auraID = tonumber(strsub(auraID, 0, 3));
+		-- -- -- Is the aura active?
+		-- -- if(Modules.Auras:IsAuraShown(auraID)) then
+			-- -- -- Get the action data.
+			-- -- local actions = Modules.Auras:GetAuraAction(auraID, auraActionID);
+			-- -- -- Enable displays for this aura.
+			-- -- Modules.Auras:MergeAuraAction(ButtonData[buttonID], actions);
+			-- -- -- Fire aura display event.
+			-- -- CoreFrame:FireModuleEvent("OnButtonDisplayAura", buttonID, auraID, actions,
+				-- -- auraActionID);
+		-- -- end
+	-- -- end
 end
 --[[
 ----------------------------------------------------------------------------------------------------