Hi all
I'm currently drawing "lines" in an addon. To do this I create a texture frame for every single line and rotate/scale the texture via SetTexCoord. That part is working as intended.
My problem with this is, I need a LOT of lines ... let's say 1000/minute. Fortunately these lines are not permanent visible. So I should be able to "reuse" the frames from lines that are not longer visible.
My approach to reuse the frames is to store every newly created frame into a table. If a frame is not longer visible I'll flag the frame in the table as "not in use". If I'll draw a new line I'll take the first frame from the table that is flagged as "not in use" and reuse it. Only if all existing frames are "in use" I'll create a new one.
My first try to do this was
Code:
local FrameStack = {}
function GetTexture()
local Texture = nil
table.foreach(
FrameStack,
function(index, value)
if value.InUse == false and Texture == nil then
value.InUse = true
Texture = value
end
end
)
if Texture == nil then
Texture = _G["TestParentFrame"]:CreateTexture(nil,"ARTWORK")
Texture:ClearAllPoints()
Texture.InUse = true
table.insert(FrameStack, Texture)
end
return Texture
end
This is working as intended. Unfortunately table.foreach is slow as hell if FrameStack has ... let's say 4.000 entries.
My sesond approach was
Code:
local FrameStack = {}
function GetTexture()
local Texture = nil
local x = 1
while not Texture do
if FrameStack[x] then
if FrameStack[x].InUse == false then
FrameStack[x].InUse = true
Texture = FrameStack[x]
else
x = x + 1
end
else
break
end
end
if Texture == nil then
Texture = _G["TestParentFrame"]:CreateTexture(nil,"ARTWORK")
Texture:ClearAllPoints()
Texture.InUse = true
table.insert(FrameStack, Texture)
end
return Texture
end
It's working too. But it's as slow as the first version.
So my question is, how can I do this job in a faster way?