Skip to content

Commit

Permalink
Fix performance/lag when opening bag (#958)
Browse files Browse the repository at this point in the history
* Significantly increased bag rendering speed so that bags don't cause frame skips when opening
  • Loading branch information
Cidan authored May 21, 2023
1 parent 3ad760b commit 3cb25f6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
26 changes: 7 additions & 19 deletions widgets/ContainerFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function containerProto:OnCreate(name, isBank, bagObject)
self.added = {}
self.removed = {}
self.changed = {}
self.sameChanged = {}

self.itemGUIDtoItem = {}
---@type Frame|Grid
Expand Down Expand Up @@ -627,7 +626,7 @@ function containerProto:AddBottomWidget(widget, side, order, height, xOffset, yO
end

function containerProto:OnLayout()
self:Debug('OnLayout')
self:Debug('OnLayout Start')
local hlr, hrr = self.HeaderLeftRegion, self.HeaderRightRegion
local blr, brr = self.BottomLeftRegion, self.BottomRightRegion
local minWidth = max(
Expand All @@ -642,7 +641,7 @@ function containerProto:OnLayout()
if self.forceLayout then
self:FullUpdate()
end
self:Debug('OnLayout', self.ToSortSection:GetHeight())
self:Debug('OnLayout Height', self.ToSortSection:GetHeight())
self:SetSize(
BAG_INSET * 2 + max(minWidth, self.Content:GetWidth()),
addon.TOP_PADDING + BAG_INSET + bottomHeight + self.Content:GetHeight() + self.ToSortSection:GetHeight() + ITEM_SPACING
Expand Down Expand Up @@ -679,7 +678,7 @@ end
---@param bag number The id of the bag to update.
function containerProto:UpdateContent(bag)
self:Debug('UpdateContent', bag)
local added, removed, changed, sameChanged = self.added, self.removed, self.changed, self.sameChanged
local added, removed, changed = self.added, self.removed, self.changed
local content = self.content[bag]
local newSize = self:GetBagIds()[bag] and GetContainerNumSlots(bag) or 0
local _, bagFamily = GetContainerNumFreeSlots(bag)
Expand Down Expand Up @@ -780,7 +779,7 @@ function containerProto:UpdateContent(bag)
end

function containerProto:HasContentChanged()
return not not (next(self.added) or next(self.removed) or next(self.changed) or next(self.sameChanged))
return not not (next(self.added) or next(self.removed) or next(self.changed))
end

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -923,13 +922,12 @@ end

function containerProto:UpdateButtons()
if self.forceLayout then
return self:FullUpdate()
return
elseif not self:HasContentChanged() then
return
end
self:Debug('UpdateButtons')

local added, removed, changed, sameChanged = self.added, self.removed, self.changed, self.sameChanged
local added, removed, changed = self.added, self.removed, self.changed
self:SendMessage('AdiBags_PreContentUpdate', self, added, removed, changed)

for slotId in pairs(removed) do
Expand All @@ -949,20 +947,10 @@ function containerProto:UpdateButtons()
buttons[slotId]:FullUpdate()
end

if next(sameChanged) then
self:SendMessage('AdiBags_PreFilter', self)
for slotId, slotData in pairs(sameChanged) do
self:DispatchItem(slotData)
buttons[slotId]:FullUpdate()
end
self:SendMessage('AdiBags_PostFilter', self)
end

self:SendMessage('AdiBags_PostContentUpdate', self, added, removed, changed)
wipe(added)
wipe(removed)
wipe(changed)
wipe(sameChanged)

self:ResizeToSortSection()
end
Expand Down Expand Up @@ -1187,7 +1175,7 @@ function containerProto:LayoutSections(maxHeight, columnWidth, minWidth, section
contentHeight = max(contentHeight, heights[row] - yOffset)
x = x + thisColumnWidth + COLUMN_SPACING
end

return x - COLUMN_SPACING, contentHeight - ITEM_SPACING
end

Expand Down
30 changes: 22 additions & 8 deletions widgets/ItemButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function buttonProto:OnAcquire(container, bag, slot)
self.bag = bag
self.slot = slot
self.stack = nil
self.dirty = true
self:SetParent(addon.itemParentFrames[bag])
--TODO(lobato): Add this when (if?) Blizzard fixes taint for bags
--self:SetBagID(bag)
Expand All @@ -123,6 +124,7 @@ function buttonProto:OnRelease()
self.texture = nil
self.bagFamily = nil
self.stack = nil
self.dirty = false
addon:SendMessage('AdiBags_ButtonProtoRelease', self)
end

Expand Down Expand Up @@ -271,9 +273,9 @@ function buttonProto:OnShow()
self:RegisterEvent('INVENTORY_SEARCH_UPDATE', 'UpdateSearch')
end
self:RegisterEvent('UNIT_QUEST_LOG_CHANGED')
self:RegisterMessage('AdiBags_UpdateAllButtons', 'Update')
self:RegisterMessage('AdiBags_UpdateAllButtons', 'FullUpdate')
self:RegisterMessage('AdiBags_GlobalLockChanged', 'UpdateLock')
self:FullUpdate()
self:Update()
end

function buttonProto:OnHide()
Expand All @@ -296,10 +298,16 @@ end
--------------------------------------------------------------------------------

function buttonProto:CanUpdate()
if not self:IsVisible() or addon.holdYourBreath then
if self.dirty then
return true
end
return false
--[[
if not self:IsVisible() then
return false
end
return true
]]--
end

function buttonProto:FullUpdate()
Expand All @@ -308,7 +316,8 @@ function buttonProto:FullUpdate()
self.itemLink = GetContainerItemLink(bag, slot)
self.hasItem = not not self.itemId
self.texture = addon:GetContainerItemTexture(bag, slot)

self.dirty = true
addon:Debug("Full Update", self.itemLink)
-- TODO(lobato): Test if this is still needed
if self.bag == REAGENTBAG_CONTAINER then
self.bagFamily = 2048
Expand Down Expand Up @@ -341,6 +350,8 @@ end

function buttonProto:Update()
if not self:CanUpdate() then return end
self.dirty = false
addon:Debug("Update", self.itemLink, self.dirty)
self:UpdateIcon()
local tag = (not self.itemId or addon.db.profile.showBagType) and addon:GetFamilyTag(self.bagFamily)
if tag then
Expand Down Expand Up @@ -536,6 +547,7 @@ function stackProto:OnAcquire(container, key)
self.key = key
self.count = 0
self.dirtyCount = true
self.dirty = true
self:SetParent(container)
end

Expand All @@ -544,6 +556,7 @@ function stackProto:OnRelease()
self:SetSection(nil)
self.key = nil
self.container = nil
self.dirty = false
addon:SendMessage('AdiBags_ButtonProtoRelease', self)
wipe(self.slots)
end
Expand Down Expand Up @@ -666,16 +679,15 @@ function stackProto:SetVisibleSlot(slotId)
end

function stackProto:Update()
if not self:CanUpdate() then return end
self:UpdateVisibleSlot()
self:UpdateCount()
if self.button then
if self:UpdateCount() and self.button then
self.button.dirty = true
self.button:Update()
end
end

function stackProto:FullUpdate()
if not self:CanUpdate() then return end
self.dirty = false
self:UpdateVisibleSlot()
self:UpdateCount()
if self.button then
Expand All @@ -689,8 +701,10 @@ function stackProto:UpdateCount()

count = count + (addon:GetContainerItemStackCount(GetBagSlotFromId(slotId)) or 1)
end
local oldCount = self.count
self.count = count
self.dirtyCount = nil
return oldCount ~= count
end

function stackProto:AdiBags_PostContentUpdate()
Expand Down

0 comments on commit 3cb25f6

Please sign in to comment.