From 266948566e3656a233c8e08221fce5cdfd27e811 Mon Sep 17 00:00:00 2001 From: d87 Date: Fri, 26 Jul 2024 08:00:28 +0700 Subject: [PATCH] Replaced TexturePool implementation --- frame.lua | 4 +-- helpers.lua | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/frame.lua b/frame.lua index 46e03b0..711f97d 100644 --- a/frame.lua +++ b/frame.lua @@ -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 @@ -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 diff --git a/helpers.lua b/helpers.lua index 8503b7f..6ae9152 100644 --- a/helpers.lua +++ b/helpers.lua @@ -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 \ No newline at end of file