Thread Tools Display Modes
08-07-10, 07:46 AM   #1
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Performance issue (action buttons)

Hello. I'm using rActionButtonStyler and I've modified it a little. Instead of using textures around my buttons, I'm using frames, so I can easily make it pixel perfect for any resolution. But that's where the problem is. While the regular action bar causes no issues, the part which styles the pet button will (temporarily) freeze WoW when entering a vehicle, and will drastically reduce fps when playing with a pet for a certain period of time (usually half an hour - an hour). Both of these problems can also result into a crash if the freeze is too long.

This is my code.

Code:
-- rActionButtonStyler - roth 2009

local _G = _G

---------------------------------------
-- FUNCTIONS
---------------------------------------

--initial style func
local function rActionButtonStyler_AB_style(self)
	if not self.rabsstyle then
		local action = self.action
		local name = self:GetName()
		local bu  = _G[name]
		local ic  = _G[name.."Icon"]
		local co  = _G[name.."Count"]
		local bo  = _G[name.."Border"]
		local ho  = _G[name.."HotKey"]
		local na  = _G[name.."Name"]
		local fl  = _G[name.."Flash"]
		local nt  = _G[name.."NormalTexture"]

		nt:SetHeight(bu:GetHeight())
		nt:SetWidth(bu:GetWidth())
		nt:SetPoint("Center", 0, 0)

		bo:Hide()
		bo.Show = dummy

		co:SetFont(FONT, 8 / .7, "OUTLINEMONOCHROME")
		co:ClearAllPoints()
		co:SetPoint("TOP", 0, -2)

		ho:Hide()
		ho.Show = dummy

		na:Hide()

		bu:SetCheckedTexture(QUEST_GLOW)
		bu:SetNormalTexture("")

		ic:SetTexCoord(.08, .92, .08, .92)
		ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 1 / .7, -1 / .7)
		ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -1 / .7, 1 / .7)

		nt.SetHeight = dummy
		nt.SetWidth = dummy
		fl.SetTexture = dummy
		bu.SetHighlightTexture = dummy
		bu.SetPushedTexture = dummy
		bu.SetCheckedTexture = dummy
		bu.SetNormalTexture = dummy
		co.SetPoint = dummy
		nt.SetVertexColor = dummy

		local bg = CreateFrame("Frame",nil, self)
		bg:SetBackdrop({ 
			bgFile = "", 
			edgeFile = BACKDROP, 
			edgeSize = 1 / .7, 
			insets = {left = 0, right = 0, top = 0, bottom = 0},
		})
		bg:SetBackdropBorderColor(0, 0, 0)
		bg:SetAllPoints(self)
		bg:SetFrameStrata("LOW")

		self.rabsstyle = true
	end
end

--style pet buttons
local function rActionButtonStyler_AB_stylepet()
	for i=1, NUM_PET_ACTION_SLOTS do
		local name = "PetActionButton"..i
		local bu  = _G[name]
		local ic  = _G[name.."Icon"]
		local fl  = _G[name.."Flash"]
		local nt  = _G[name.."NormalTexture2"]

		nt:SetHeight(bu:GetHeight())
		nt:SetWidth(bu:GetWidth())
		nt:SetPoint("Center", 0, 0)

		bu:SetCheckedTexture(QUEST_GLOW)
		bu:SetNormalTexture("")

		local pbg = CreateFrame("Frame",nil, bu)
		pbg:SetBackdrop({ 
			bgFile = "", 
			edgeFile = BACKDROP, 
			edgeSize = 1 / 1, 
			insets = {left = 0, right = 0, top = 0, bottom = 0},
		})
		pbg:SetBackdropBorderColor(0, 0, 0)
		pbg:SetAllPoints(bu)
		pbg:SetFrameStrata("LOW")

		ic:SetTexCoord(0.08, 0.92, 0.08, 0.92)
		ic:SetPoint("TOPLEFT", bu, "TOPLEFT", 1, -1)
		ic:SetPoint("BOTTOMRIGHT", bu, "BOTTOMRIGHT", -1, 1)
	end  
end

---------------------------------------
-- CALLS // HOOKS
---------------------------------------

hooksecurefunc("ActionButton_Update",   rActionButtonStyler_AB_style)
hooksecurefunc("PetActionBar_Update",   rActionButtonStyler_AB_stylepet)
The highlighted part is the problem. I'm fairly sure it's not the same with the regular action bar, because leaving out the highlighted part fixes the issue.

My guess is that for each button refreshed WoW will create a new frame which will result in the performance loss. How can I stop this?

Any help would be most appreciated, I've had this issue for a long time.

Last edited by Haleth : 08-07-10 at 07:48 AM.
  Reply With Quote
08-07-10, 08:18 AM   #2
Guardix
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 42
You don't have to hook any function to style the buttons. Right now you create a new frame everytime PetActionBar_Update is called. But if you really wish to use that function, you can create a new variable that turns nil when your function is run for the first time.

This is how often the function is called.
Code:
if ( event == "PET_BAR_UPDATE" or (event == "UNIT_PET" and arg1 == "player") ) then
	PetActionBar_Update(self);
	if ( PetHasActionBar() and UnitIsVisible("pet") ) then
		ShowPetActionBar();
		LockPetActionBar();
	else
		UnlockPetActionBar();
		HidePetActionBar();
	end
elseif ( event == "PLAYER_CONTROL_LOST" or event == "PLAYER_CONTROL_GAINED" or event == "PLAYER_FARSIGHT_FOCUS_CHANGED" or event == "PET_BAR_UPDATE_USABLE" ) then
	PetActionBar_Update(self);
elseif ( (event == "UNIT_FLAGS") or (event == "UNIT_AURA") ) then
	if ( arg1 == "pet" ) then
		PetActionBar_Update(self);
	end

Oh yea, same goes for ActionButton_Update.

I would suggest just calling the functions you've made when your addon is loading.
Code:
rActionButtonStyler_AB_style()
rActionButtonStyler_AB_stylepet()
__________________

Last edited by Guardix : 08-07-10 at 08:29 AM.
  Reply With Quote
08-07-10, 08:21 AM   #3
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
So you're suggesting I put the frames outside of the update function? I'll try that, thanks.
  Reply With Quote
08-07-10, 08:49 AM   #4
Guardix
A Cyclonian
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 42
Yes basically. That is what I do, so it's only performed once.
__________________
  Reply With Quote
08-07-10, 09:07 AM   #5
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
I've tested it a couple of times and it appears to work. Thank you so much, I can't believe I haven't thought of that before - this problem has been in my UI for ages.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Performance issue (action buttons)


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off