avoid creating new table each loop to reduce memory usage
This commit is contained in:
@@ -7,7 +7,7 @@ local L = AceLibrary("AceLocale-2.2"):new("Cursive")
|
||||
local utils = Cursive.utils
|
||||
local filter = Cursive.filter
|
||||
|
||||
local ui = CreateFrame("Frame", nil, UIParent)
|
||||
local ui = CreateFrame("Frame", "CursiveUI", UIParent)
|
||||
|
||||
ui.border = {
|
||||
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
||||
@@ -260,7 +260,7 @@ end
|
||||
|
||||
local function CreateBarFirstSection(unitFrame, guid)
|
||||
local config = Cursive.db.profile
|
||||
local firstSection = CreateFrame("Frame", nil, unitFrame)
|
||||
local firstSection = CreateFrame("Frame", "Cursive1stSection", unitFrame)
|
||||
firstSection:SetPoint("LEFT", unitFrame, "LEFT", 0, 0)
|
||||
firstSection:SetWidth(GetBarFirstSectionWidth())
|
||||
firstSection:SetHeight(config.height)
|
||||
@@ -292,7 +292,7 @@ end
|
||||
|
||||
local function CreateBarSecondSection(unitFrame, guid)
|
||||
local config = Cursive.db.profile
|
||||
local secondSection = CreateFrame("Button", nil, unitFrame)
|
||||
local secondSection = CreateFrame("Button", "Cursive2ndSection", unitFrame)
|
||||
secondSection:SetPoint("LEFT", unitFrame.firstSection, "RIGHT", 0, 0)
|
||||
secondSection:SetWidth(GetBarSecondSectionWidth())
|
||||
secondSection:SetHeight(config.height)
|
||||
@@ -305,7 +305,7 @@ local function CreateBarSecondSection(unitFrame, guid)
|
||||
|
||||
-- create health bar
|
||||
if config.showhealthbar then
|
||||
local healthBar = CreateFrame("StatusBar", nil, secondSection)
|
||||
local healthBar = CreateFrame("StatusBar", "CursiveHealthBar", secondSection)
|
||||
healthBar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
|
||||
healthBar:SetStatusBarColor(1, .8, .2, 1)
|
||||
healthBar:SetMinMaxValues(0, 100)
|
||||
@@ -340,7 +340,7 @@ local function CreateBarSecondSection(unitFrame, guid)
|
||||
healthBar:SetBackdrop(ui.background)
|
||||
healthBar:SetBackdropColor(0, 0, 0, 1)
|
||||
|
||||
local border = CreateFrame("Frame", nil, healthBar.bar)
|
||||
local border = CreateFrame("Frame", "CursiveBorder", healthBar.bar)
|
||||
border:SetBackdrop(ui.border)
|
||||
border:SetBackdropColor(.2, .2, .2, 1)
|
||||
border:SetPoint("TOPLEFT", healthBar.bar, "TOPLEFT", -2, 2)
|
||||
@@ -364,7 +364,7 @@ end
|
||||
local function CreateBarThirdSection(unitFrame, guid)
|
||||
local config = Cursive.db.profile
|
||||
|
||||
local thirdSection = CreateFrame("Frame", nil, unitFrame)
|
||||
local thirdSection = CreateFrame("Frame", "Cursive3rdSection", unitFrame)
|
||||
thirdSection:SetPoint("LEFT", unitFrame.secondSection, "RIGHT", 0, 0)
|
||||
thirdSection:SetWidth(GetBarThirdSectionWidth())
|
||||
thirdSection:SetHeight(config.height)
|
||||
@@ -391,7 +391,7 @@ local function CreateBarThirdSection(unitFrame, guid)
|
||||
end
|
||||
|
||||
local function CreateBar(row, col, guid)
|
||||
local unitFrame = CreateFrame("Frame", nil, ui.rootBarFrame)
|
||||
local unitFrame = CreateFrame("Frame", "CursiveUnitFrame", ui.rootBarFrame)
|
||||
unitFrame.guid = guid
|
||||
|
||||
unitFrame:SetScript("OnUpdate", ui.BarUpdate)
|
||||
@@ -541,6 +541,10 @@ local function CheckForCleanup(guid, time)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local shouldDisplayGuids = {};
|
||||
local displayedGuids = {};
|
||||
|
||||
ui:SetAllPoints()
|
||||
ui:SetScript("OnUpdate", function()
|
||||
local config = Cursive.db.profile
|
||||
@@ -570,6 +574,16 @@ ui:SetScript("OnUpdate", function()
|
||||
ui.maxBarsDisplayed = false
|
||||
ui.numDisplayed = 0
|
||||
|
||||
-- clear shouldDisplayGuids
|
||||
for guid, _ in pairs(shouldDisplayGuids) do
|
||||
shouldDisplayGuids[guid] = nil
|
||||
end
|
||||
|
||||
-- clear displayedGuids
|
||||
for guid, _ in pairs(displayedGuids) do
|
||||
displayedGuids[guid] = nil
|
||||
end
|
||||
|
||||
-- run through all guids and fill with bars
|
||||
local title_size = 12 + config.spacing
|
||||
|
||||
@@ -585,9 +599,6 @@ ui:SetScript("OnUpdate", function()
|
||||
|
||||
local averageMaxHp = 0
|
||||
|
||||
local shouldDisplayGuids = {};
|
||||
local displayedGuids = {};
|
||||
|
||||
local _, currentTargetGuid = UnitExists("target")
|
||||
|
||||
-- first consider raid marks
|
||||
@@ -603,16 +614,16 @@ ui:SetScript("OnUpdate", function()
|
||||
if ui.maxBarsDisplayed then
|
||||
break
|
||||
end
|
||||
else
|
||||
shouldDisplayGuids[guid] = false
|
||||
end
|
||||
-- don't try to display this guid again
|
||||
shouldDisplayGuids[guid] = false
|
||||
end
|
||||
end
|
||||
|
||||
for guid, time in pairs(Cursive.core.guids) do
|
||||
-- calculate shouldDisplay
|
||||
local shouldDisplay = false
|
||||
if not shouldDisplayGuids[guid] then
|
||||
if shouldDisplayGuids[guid] == nil then
|
||||
shouldDisplay = Cursive:ShouldDisplayGuid(guid)
|
||||
shouldDisplayGuids[guid] = shouldDisplay
|
||||
|
||||
@@ -672,7 +683,7 @@ ui:SetScript("OnUpdate", function()
|
||||
break
|
||||
end
|
||||
|
||||
if not displayedGuids[guid] and shouldDisplayGuids[guid] then
|
||||
if not displayedGuids[guid] and shouldDisplayGuids[guid] == true then
|
||||
displayedGuids[guid] = true
|
||||
DisplayGuid(guid)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user