oUF_Layout optimization
Hey all,
I've finally gotten around to writing my own personal oUF. I am nearly complete; completed modules work as desired. Party, pet, boss, and raid still to go, but wanted some feedback on better ways to optimize my layout. I've written this in a rather verbose manner, a lot of similar looking code for the sake of lots of customization on a unit to unit basis. The pastebin can be found here: http://pastebin.com/bB3MFkeM Thanks! |
Just took a glance at your code. I noticed that you can easily optimize by reusing similar code.
For instance, create health and power bar code just once and insert it for each unit. You could do this with using a "Shared" function, that contains code used for every unit and/or by creating single functions. Somewhat like this: Code:
local createPower = function(self) -- Power bar Code:
UnitSpecific.player = function(self, ...) €: Just to add to the confusion, let's say you create a "createPower" function; you don't want to put the SetPoint stuff in there. Unless every unit you use is exactly the same, ofc. Only put the CreateFrame, background, PostUpdate, color and stuff like that in there. Set your Points for each unit, after you inserted the createPower(self) function. like Code:
UnitSpecific.player = function(self, ...) |
Personally I've never seen the point in splitting each part of the spawn function out into a "make a health bar" function, a "make a power bar" function, a "do stuff for the player unit" and "do stuff for the target unit" functions, etc. You're only running that code once per frame created, so just have it all in the same place.
Code:
local health = CreateFrame("StatusBar", nil, self) ---------- This is also pretty inefficient: Code:
BuffBars.customFilter = function(_, _, _, _, _, _, _, _, _, _, _, _, spellID, _, _, _, _, _) Code:
local blacklist = { Code:
return not blacklist[spellID] Code:
BuffBars.customFilter = function(_, _, _, _, _, _, _, _, _, _, _, _, spellID, _, _, _, _, _) Code:
BuffBars.customFilter = function(_, _, _, _, _, _, _, _, _, _, _, _, spellID) Your focus frame is ... I don't even. Why are you creating a bunch of extra frames and listening for events yourself, instead of just using oUF elements and/or tags? ---------- Other than that, your #1 priority should be removing all that duplication. |
Thank you both for the replies. My initial thought was to have all that repeat code because as far as I know, and correct me if I'm wrong, no less CPU/men efficient than making a shared function that goes through all the frames and does the same code anyway. It's certainly more unwieldy to look at that, and for that it will get changed. I just wanted to easily be able to go to a certain line of code for a certain frame and make tweaks before I became satisfied.
In regards to the aura if checks, I'll change that as well as the unnecessary _ variables. As for the reason I didn't make my own tags in ouf. That code has to be put somewhere in the ouf folder, be it a tags file in my layout folder, or editing the ouf tags. while it would look cleaner if I just had tags in my layout, rather than functions and frame creations, it would ultimately be messy somewhere. Tl;Dr is what I've done, minus the buff checking, any less CPU/men efficient, or just unsightly? |
The biggest problem with duplication is that it makes things harder to debug and maintain in the long run. If you decide to change anything about your health bar, for example, you have to make the same change 4 times in 4 different places, which is boring, a waste of time, and easy to screw up. If you only have to make the change in one place, it's faster and less error-prone.
Also just noticed this: Code:
self.HealthBG = HealthBG Quote:
Code:
oUF.Tags.Events.healthtext = 'UNIT_HEALTH' Code:
local HealthText = Health:CreateFontString(nil, 'OVERLAY') |
As an update I did this: http://pastebin.com/FcVTCRA4
Obviously it's only the player, I have to raid or I'd finish the other units. Relevant tags I made can be found here: http://pastebin.com/KGfZFXEA I appreciate both of your initial, and hopefully ongoing, feedback. |
Tags:
Code:
return format('|cff%02x%02x%02x%s', r, g, 0, healthcurrent) Code:
return format('|cff%02x%02x00%s', r, g, healthcurrent) Code:
local color Code:
powertype = select(2,UnitPowerType(u)) Code:
local powercurrent, powertype, pr, pg, pb, _ Code:
powertype, powertype = UnitPowerType(u) Code:
elseif powertype == 'FOCUS' then Code:
else |
Other:
De-duplication looking much better overall. Code:
self.Health:SetHeight(29) The best way to avoid this would be to use relative positioning. Instead of anchoring the health bar by the TOPLEFT and TOPRIGHT corners and giving it an explicit height, add a third anchor to the BOTTOM point with a vertical offset to leave space for the power bar -- and then anchor the TOP of the power bar to the BOTTOM of the health bar. That way the only value you have to change is the frame height, and the health bar will automatically get bigger or smaller accordingly. ======================== Several problems in here: Code:
local leaderassistframe = CreateFrame('Button', 'PlayerLeaderAssistFrame', self) 2. These objects don't need to exist at all. Get rid of them and use oUF's native Assistant and Leader elements; you can set them both to use the same texture if you really don't want to know the difference. 3. Those file paths are invalid; you need to either escape your backslashes by doubling them, or use [[ literal string notation ]] instead of "double quotes" around the path. 4. This appears to be a bad copypasta: Code:
leaderassisttexture = leaderassistframe:CreateTexture('Interface\AddOns\oUF_P3lim\F1_StatusBox_Bar', 'OVERLAY') b. This usage of CreateTexture will actually produce a new texture object whose global name is that (malformed) file path. You should delete this line and uncomment the SetTexture line directly above it. ======================== oUF also already provides a combat indicator element and a resting indicator element; you don't need to create your own frames and manage them yourself with event handlers. Just use the elements and give them the textures, dimensions, etc. that you want. ======================== However, oUF does not provide any elements named "BuffBars" or "DebuffBars" so if you want those objects to do anything, you either need to use the proper names -- "Buffs" and "Debuffs" -- or install/write a third-party element/plugin to handle them. ======================== Code:
oUF:RegisterStyle('Terenna', Shared) |
1.
Code:
self.HealthBG = HealthBG ----------------------------------------------------------------------------- 2. Code:
self.Health:SetHeight(29) ----------------------------------------------------------------------------- 3. Several problems in here: A. I'm assuming global name is PlayerLeaderAssistFrame and PlayerLeaderAssistTexture, will remove B. Will use oUF elements and change texture path C. The texture paths do work. If they're not supposed to, IDK why, but I can assure you they do. D. That is bad copypasta. But it did work, so I didn't catch that. ----------------------------------------------------------------------------- 4. oUF also already provides a combat indicator element and a resting indicator element Noted. Will use those and change textures again if needed like assist frame. ----------------------------------------------------------------------------- 5. However, oUF does not provide any elements named "BuffBars" or "DebuffBars" This is from an element you rewrote for me, oUF_AuraBars. I still use it, although I think I'm literally the only person to do so. I just couldn't deal with elkbuffbars another god damn day. ----------------------------------------------------------------------------- 6. Code:
oUF:RegisterStyle('Terenna', Shared) oUF:RegisterStyle('oUF_Terenna_Player', UnitSpecific.player) as well as other units with the UnitSpecific.insertunitnamehere ? And then just have oUF:SetActiveStyle('oUF_Terenna') at the bottom of my code outside of all functions? |
Quote:
Code:
local func = UnitSpecific[unit] Quote:
|
All times are GMT -6. The time now is 04:07 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI