From 201a5f9d0021a8cfd8aa1ca1cd1a804eeb77753c Mon Sep 17 00:00:00 2001 From: shagu Date: Tue, 18 Jul 2017 16:54:50 +0200 Subject: [PATCH] nameplates: reduce load by caching the name --- modules/nameplates.lua | 65 +++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/modules/nameplates.lua b/modules/nameplates.lua index 7a72b93d..31a04922 100644 --- a/modules/nameplates.lua +++ b/modules/nameplates.lua @@ -304,26 +304,27 @@ pfUI:RegisterModule("nameplates", function () local healthbar = this.healthbar local border, glow, name, level, levelicon , raidicon = this.border, this.glow, this.name, this.level, this.levelicon , this.raidicon + local unitname = name:GetText() -- add scan entry if not existing - if this.needNameUpdate and name:GetText() ~= UNKNOWN then - if not pfUI.nameplates.targets[this.name:GetText()] then - table.insert(pfUI.nameplates.scanqueue, this.name:GetText()) + if this.needNameUpdate and unitname ~= UNKNOWN then + if not pfUI.nameplates.targets[unitname] then + table.insert(pfUI.nameplates.scanqueue, unitname) end this.needNameUpdate = nil end -- hide non-player frames if C.nameplates.players == "1" and not this.needNameUpdate then - if pfUI.nameplates.targets[name:GetText()] == "OK" then - if not pfUI.nameplates.players[name:GetText()] then this:Hide() end + if pfUI.nameplates.targets[unitname] == "OK" then + if not pfUI.nameplates.players[unitname] then this:Hide() end end end -- hide critters if C.nameplates.critters == "1" and not this.needNameUpdate then local red, green, blue, _ = healthbar:GetStatusBarColor() - local name_val = name:GetText() + local name_val = unitname for i, critter_val in pairs(L["critters"]) do if red > 0.9 and green > 0.9 and blue < 0.2 and name_val == critter_val then this:Hide() @@ -332,13 +333,13 @@ pfUI:RegisterModule("nameplates", function () end -- level elite indicator - if this.needEliteUpdate and pfUI.nameplates.mobs[name:GetText()] then + if this.needEliteUpdate and pfUI.nameplates.mobs[unitname] then if level:GetText() ~= nil then - if pfUI.nameplates.mobs[name:GetText()] == "elite" then + if pfUI.nameplates.mobs[unitname] == "elite" then level:SetText(level:GetText() .. "+") - elseif pfUI.nameplates.mobs[name:GetText()] == "rareelite" then + elseif pfUI.nameplates.mobs[unitname] == "rareelite" then level:SetText(level:GetText() .. "R+") - elseif pfUI.nameplates.mobs[name:GetText()] == "rare" then + elseif pfUI.nameplates.mobs[unitname] == "rare" then level:SetText(level:GetText() .. "R") end end @@ -380,30 +381,30 @@ pfUI:RegisterModule("nameplates", function () end -- add class colors - if this.needClassColorUpdate and pfUI.nameplates.targets[name:GetText()] == "OK" then + if this.needClassColorUpdate and pfUI.nameplates.targets[unitname] == "OK" then -- show class names? if healthbar.reaction == 0 then if C.nameplates["enemyclassc"] == "1" - and pfUI.nameplates.players[name:GetText()] - and pfUI.nameplates.players[name:GetText()]["class"] - and RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]] + and pfUI.nameplates.players[unitname] + and pfUI.nameplates.players[unitname]["class"] + and RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]] then healthbar:SetStatusBarColor( - RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]].r, - RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]].g, - RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]].b, + RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].r, + RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].g, + RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].b, 0.9) end elseif healthbar.reaction == 2 then if C.nameplates["friendclassc"] == "1" - and pfUI.nameplates.players[name:GetText()] - and pfUI.nameplates.players[name:GetText()]["class"] - and RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]] + and pfUI.nameplates.players[unitname] + and pfUI.nameplates.players[unitname]["class"] + and RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]] then healthbar:SetStatusBarColor( - RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]].r, - RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]].g, - RAID_CLASS_COLORS[pfUI.nameplates.players[name:GetText()]["class"]].b, + RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].r, + RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].g, + RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].b, 0.9) end end @@ -421,16 +422,16 @@ pfUI:RegisterModule("nameplates", function () end -- show castbar - if healthbar.castbar and pfUI.castbar and C.nameplates["showcastbar"] == "1" and pfUI.castbar.target.casterDB[name:GetText()] ~= nil and pfUI.castbar.target.casterDB[name:GetText()]["cast"] ~= nil then - if pfUI.castbar.target.casterDB[name:GetText()]["starttime"] + pfUI.castbar.target.casterDB[name:GetText()]["casttime"] <= GetTime() then - pfUI.castbar.target.casterDB[name:GetText()] = nil + if healthbar.castbar and pfUI.castbar and C.nameplates["showcastbar"] == "1" and pfUI.castbar.target.casterDB[unitname] ~= nil and pfUI.castbar.target.casterDB[unitname]["cast"] ~= nil then + if pfUI.castbar.target.casterDB[unitname]["starttime"] + pfUI.castbar.target.casterDB[unitname]["casttime"] <= GetTime() then + pfUI.castbar.target.casterDB[unitname] = nil healthbar.castbar:Hide() else - healthbar.castbar:SetMinMaxValues(0, pfUI.castbar.target.casterDB[name:GetText()]["casttime"]) - healthbar.castbar:SetValue(GetTime() - pfUI.castbar.target.casterDB[name:GetText()]["starttime"]) - healthbar.castbar.text:SetText(round( pfUI.castbar.target.casterDB[name:GetText()]["starttime"] + pfUI.castbar.target.casterDB[name:GetText()]["casttime"] - GetTime(),1)) + healthbar.castbar:SetMinMaxValues(0, pfUI.castbar.target.casterDB[unitname]["casttime"]) + healthbar.castbar:SetValue(GetTime() - pfUI.castbar.target.casterDB[unitname]["starttime"]) + healthbar.castbar.text:SetText(round( pfUI.castbar.target.casterDB[unitname]["starttime"] + pfUI.castbar.target.casterDB[unitname]["casttime"] - GetTime(),1)) if C.nameplates.spellname == "1" and healthbar.castbar.spell then - healthbar.castbar.spell:SetText(pfUI.castbar.target.casterDB[name:GetText()]["cast"]) + healthbar.castbar.spell:SetText(pfUI.castbar.target.casterDB[unitname]["cast"]) else healthbar.castbar.spell:SetText("") end @@ -439,8 +440,8 @@ pfUI:RegisterModule("nameplates", function () this.debuffs[1]:SetPoint("TOPLEFT", healthbar.castbar, "BOTTOMLEFT", 0, -3) end - if pfUI.castbar.target.casterDB[name:GetText()]["icon"] then - healthbar.castbar.icon:SetTexture("Interface\\Icons\\" .. pfUI.castbar.target.casterDB[name:GetText()]["icon"]) + if pfUI.castbar.target.casterDB[unitname]["icon"] then + healthbar.castbar.icon:SetTexture("Interface\\Icons\\" .. pfUI.castbar.target.casterDB[unitname]["icon"]) healthbar.castbar.icon:SetTexCoord(.1,.9,.1,.9) end end