From c7f31fe9b038a88b3b11ccee2cc7a2ae0794d672 Mon Sep 17 00:00:00 2001 From: shagu Date: Fri, 5 Aug 2022 16:50:52 +0200 Subject: [PATCH] nameplates: increase nameplate render performance increase renderer performance by not creating all debuff slots on each nameplate on creation, but rather only build those who are really needed on the fly. This heavily reduces the overall frame- and cooldown anmiation count in most scenarios. --- modules/nameplates.lua | 108 ++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 44 deletions(-) diff --git a/modules/nameplates.lua b/modules/nameplates.lua index 65451f28..ca337dd8 100644 --- a/modules/nameplates.lua +++ b/modules/nameplates.lua @@ -168,6 +168,58 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function () return c.effect, c.rank, c.texture, c.stacks, c.dtype, c.duration, (c.stop - GetTime()) end + local function CreateDebuffIcon(plate, index) + plate.debuffs[index] = CreateFrame("Frame", plate.platename.."Debuff"..index, plate) + plate.debuffs[index]:Hide() + plate.debuffs[index]:SetFrameLevel(1) + + plate.debuffs[index].icon = plate.debuffs[index]:CreateTexture(nil, "BACKGROUND") + plate.debuffs[index].icon:SetTexture(.3,1,.8,1) + plate.debuffs[index].icon:SetAllPoints(plate.debuffs[index]) + + plate.debuffs[index].stacks = plate.debuffs[index]:CreateFontString(nil, "OVERLAY") + plate.debuffs[index].stacks:SetAllPoints(plate.debuffs[index]) + plate.debuffs[index].stacks:SetJustifyH("RIGHT") + plate.debuffs[index].stacks:SetJustifyV("BOTTOM") + plate.debuffs[index].stacks:SetTextColor(1,1,0) + + plate.debuffs[index].cd = CreateFrame(COOLDOWN_FRAME_TYPE, plate.platename.."Debuff"..index.."Cooldown", plate.debuffs[index], "CooldownFrameTemplate") + plate.debuffs[index].cd.pfCooldownStyleAnimation = 0 + plate.debuffs[index].cd.pfCooldownType = "ALL" + end + + local function UpdateDebuffConfig(nameplate, i) + if not nameplate.debuffs[i] then return end + + -- update debuff positions + local width = tonumber(C.nameplates.width) + local debuffsize = tonumber(C.nameplates.debuffsize) + local limit = floor(width / debuffsize) + local font = C.nameplates.use_unitfonts == "1" and pfUI.font_unit or pfUI.font_default + local font_size = C.nameplates.use_unitfonts == "1" and C.global.font_unit_size or C.global.font_size + local font_style = C.nameplates.name.fontstyle + + local aligna, alignb, offs, space + if C.nameplates.debuffs["position"] == "BOTTOM" then + aligna, alignb, offs, space = "TOPLEFT", "BOTTOMLEFT", -4, -1 + else + aligna, alignb, offs, space = "BOTTOMLEFT", "TOPLEFT", 20, 1 + end + + nameplate.debuffs[i].stacks:SetFont(font, font_size, font_style) + nameplate.debuffs[i]:ClearAllPoints() + if i == 1 then + nameplate.debuffs[i]:SetPoint(aligna, nameplate.health, alignb, 0, offs) + elseif i <= limit then + nameplate.debuffs[i]:SetPoint("LEFT", nameplate.debuffs[i-1], "RIGHT", 1, 0) + elseif i > limit and limit > 0 then + nameplate.debuffs[i]:SetPoint(aligna, nameplate.debuffs[i-limit], alignb, 0, space) + end + + nameplate.debuffs[i]:SetWidth(tonumber(C.nameplates.debuffsize)) + nameplate.debuffs[i]:SetHeight(tonumber(C.nameplates.debuffsize)) + end + -- create nameplate core local nameplates = CreateFrame("Frame", "pfNameplates", UIParent) nameplates:RegisterEvent("PLAYER_ENTERING_WORLD") @@ -212,6 +264,7 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function () -- create pfUI nameplate overlay local nameplate = CreateFrame("Button", platename, parent) + nameplate.platename = platename nameplate:EnableMouse(0) nameplate.parent = parent nameplate.cache = {} @@ -271,27 +324,8 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function () CreateBackdrop(nameplate.totem) do -- debuffs - local debuffs = {} - for i=1, 16, 1 do - debuffs[i] = CreateFrame("Frame", platename.."Debuff"..i, nameplate) - debuffs[i]:Hide() - debuffs[i]:SetFrameLevel(1) - - debuffs[i].icon = debuffs[i]:CreateTexture(nil, "BACKGROUND") - debuffs[i].icon:SetTexture(.3,1,.8,1) - debuffs[i].icon:SetAllPoints(debuffs[i]) - - debuffs[i].stacks = debuffs[i]:CreateFontString(nil, "OVERLAY") - debuffs[i].stacks:SetAllPoints(debuffs[i]) - debuffs[i].stacks:SetJustifyH("RIGHT") - debuffs[i].stacks:SetJustifyV("BOTTOM") - debuffs[i].stacks:SetTextColor(1,1,0) - - debuffs[i].cd = CreateFrame(COOLDOWN_FRAME_TYPE, platename.."Debuff"..i.."Cooldown", debuffs[i], "CooldownFrameTemplate") - debuffs[i].cd.pfCooldownStyleAnimation = 0 - debuffs[i].cd.pfCooldownType = "ALL" - end - nameplate.debuffs = debuffs + nameplate.debuffs = {} + CreateDebuffIcon(nameplate, 1) end do -- combopoints @@ -409,29 +443,8 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function () nameplate.raidicon:SetWidth(C.nameplates.raidiconsize) nameplate.raidicon:SetHeight(C.nameplates.raidiconsize) - -- update debuff positions - local limit = floor(width / debuffsize) - - local aligna, alignb, offs, space - if C.nameplates.debuffs["position"] == "BOTTOM" then - aligna, alignb, offs, space = "TOPLEFT", "BOTTOMLEFT", -4, -1 - else - aligna, alignb, offs, space = "BOTTOMLEFT", "TOPLEFT", 20, 1 - end - for i=1,16 do - nameplate.debuffs[i].stacks:SetFont(font, font_size, font_style) - nameplate.debuffs[i]:ClearAllPoints() - if i == 1 then - nameplate.debuffs[i]:SetPoint(aligna, nameplate.health, alignb, 0, offs) - elseif i <= limit then - nameplate.debuffs[i]:SetPoint("LEFT", nameplate.debuffs[i-1], "RIGHT", 1, 0) - elseif i > limit and limit > 0 then - nameplate.debuffs[i]:SetPoint(aligna, nameplate.debuffs[i-limit], alignb, 0, space) - end - - nameplate.debuffs[i]:SetWidth(tonumber(C.nameplates.debuffsize)) - nameplate.debuffs[i]:SetHeight(tonumber(C.nameplates.debuffsize)) + UpdateDebuffConfig(nameplate, i) end for i=1,5 do @@ -648,6 +661,11 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function () end if effect and texture and DebuffFilter(effect) then + if not plate.debuffs[index] then + CreateDebuffIcon(plate, index) + UpdateDebuffConfig(plate, index) + end + plate.debuffs[index]:Show() plate.debuffs[index].icon:SetTexture(texture) plate.debuffs[index].icon:SetTexCoord(.078, .92, .079, .937) @@ -672,7 +690,9 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function () -- hide remaining debuffs for i = index, 16 do - plate.debuffs[i]:Hide() + if plate.debuffs[i] then + plate.debuffs[i]:Hide() + end end end