Skip to content

Commit

Permalink
Replaced TexturePool implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
d87 committed Jul 26, 2024
1 parent 9e4d428 commit 2669485
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ function Aptechka.Widget.FloatingIcon.Create(parent, popts, gopts)
f:SetSize(10, 10)
f:SetPoint(opts.point, parent, opts.point, opts.x, opts.y)

local iconPool = CreateTexturePool(f, "ARTWORK", 2)
local iconPool = helpers.CreateTexturePool(f, "ARTWORK", 2)
f.iconPool = iconPool
f.opts = opts
iconPool.creationFunc = FloatingIcon_CreationFunc
Expand Down Expand Up @@ -3241,7 +3241,7 @@ AptechkaDefaultConfig.GridSkin = function(self)
-- HEALTH LOST EFFECT
----------------------

local flashPool = CreateTexturePool(hp, "ARTWORK", -5)
local flashPool = helpers.CreateTexturePool(hp, "ARTWORK", -5)
flashPool.StopEffect = function(self, flash)
flash.ag:Finish()
end
Expand Down
74 changes: 74 additions & 0 deletions helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,77 @@ function helpers.ShakeAssignments(newOpts, defaultOpts)
end
end
end



local ObjectPool = {
-- creationFunc = function(self)
-- return self.parent:CreateMaskTexture()
-- end,
-- resetterFunc = function(self, mask)
-- mask:Hide()
-- mask:ClearAllPoints()
-- end,
AddObject = function(self, object)
local dummy = true
self.activeObjects[object] = dummy
self.activeObjectCount = self.activeObjectCount + 1
end,
ReclaimObject = function(self, object)
tinsert(self.inactiveObjects, object)
self.activeObjects[object] = nil
self.activeObjectCount = self.activeObjectCount - 1
end,
Release = function(self, object)
local active = self.activeObjects[object] ~= nil
if active then
self:resetterFunc(object)
self:ReclaimObject(object)
end
return active
end,
Acquire = function(self)
local object = tremove(self.inactiveObjects)
local new = object == nil
if new then
object = self:creationFunc()
self:resetterFunc(object, new)
end
self:AddObject(object)
return object, new
end,
ReleaseAll = function(self)
for obj in pairs(self.activeObjects) do
self:Release(obj);
end
end,
Init = function(self, parent)
self.activeObjects = {}
self.inactiveObjects = {}
self.activeObjectCount = 0
self.parent = parent
end
}

local function Pool_HideAndClearAnchors(framePool, frame)
frame:Hide();
frame:ClearAllPoints();
end
local TextureDefaultReset = Pool_HideAndClearAnchors
local TextureDefaultCreate = function(texturePool)
return texturePool.parent:CreateTexture(nil, texturePool.layer, texturePool.textureTemplate, texturePool.subLayer);
end
-- local FrameDefaultResetter = Pool_HideAndClearAnchors

function helpers.CreateTexturePool(parent, layer, subLayer, textureTemplate, resetterFunc)
local texturePool = setmetatable({}, { __index = ObjectPool })
texturePool:Init(parent)

texturePool.layer = layer;
texturePool.subLayer = subLayer;
texturePool.textureTemplate = textureTemplate;
texturePool.creationFunc = TextureDefaultCreate
texturePool.resetterFunc = TextureDefaultReset

return texturePool;
end

0 comments on commit 2669485

Please sign in to comment.