mirror of
https://github.com/brues-code/SuperCleveRoidMacros.git
synced 2026-09-16 03:38:00 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 004eebc9f7 | |||
| 63b484b1ea |
@@ -3904,6 +3904,17 @@ function CleveRoids.OnUpdate(self)
|
||||
-- PERFORMANCE: Single GetTime() call per frame
|
||||
local time = GetTime()
|
||||
|
||||
-- Coalesced macro/spell/action-bar rebuild (armed by UPDATE_MACROS,
|
||||
-- SPELLS_CHANGED and PLAYER_LOGIN). Debounced so the login burst -
|
||||
-- SPELLS_CHANGED fires several times as the spellbook populates - collapses
|
||||
-- into a single rebuild. Runs even before `ready` so spells/talents are
|
||||
-- indexed before the init timer's first action-bar pass; RebuildMacros
|
||||
-- itself skips the 120-slot action-bar rebuild until ready.
|
||||
if CR.macroRebuildTime and time >= CR.macroRebuildTime then
|
||||
CR.macroRebuildTime = nil
|
||||
CR.RebuildMacros()
|
||||
end
|
||||
|
||||
-- PERFORMANCE: Early exit if not ready (before any other checks)
|
||||
if not CR.ready then
|
||||
-- Handle initialization timer only when not ready
|
||||
@@ -3942,10 +3953,21 @@ function CleveRoids.OnUpdate(self)
|
||||
return
|
||||
end
|
||||
|
||||
-- PERFORMANCE: Delayed WDB warmup after login (ensures GetItemInfo works after WDB clear)
|
||||
if CR.wdbWarmupTime and time >= CR.wdbWarmupTime then
|
||||
CR.wdbWarmupTime = nil
|
||||
CR.DoWDBWarmup()
|
||||
-- Coalesced re-index after async item data arrives (GET_ITEM_INFO_RECEIVED).
|
||||
-- ClassicAPI warms the item cache asynchronously, so items that were still
|
||||
-- uncached during an earlier index pass land here once their
|
||||
-- SMSG_ITEM_QUERY_SINGLE response resolves. Bursts are debounced into one
|
||||
-- re-index via CR.itemInfoReindexTime (armed by the event handler).
|
||||
if CR.itemInfoReindexTime and time >= CR.itemInfoReindexTime then
|
||||
CR.itemInfoReindexTime = nil
|
||||
-- In combat: drop it; PLAYER_LEAVE_COMBAT does a full re-index once safe.
|
||||
if not UnitAffectingCombat("player") then
|
||||
CR.lastItemIndexTime = GetTime()
|
||||
CR.IndexItems()
|
||||
CR.Actions = {}
|
||||
CR.Macros = {}
|
||||
CR.IndexActionBars()
|
||||
end
|
||||
end
|
||||
|
||||
-- PERFORMANCE: Cache refresh rate calculation (avoid per-frame division)
|
||||
@@ -4824,6 +4846,7 @@ CleveRoids.Frame:RegisterEvent("UPDATE_MACROS")
|
||||
CleveRoids.Frame:RegisterEvent("SPELLS_CHANGED")
|
||||
CleveRoids.Frame:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
|
||||
CleveRoids.Frame:RegisterEvent("BAG_UPDATE_DELAYED")
|
||||
CleveRoids.Frame:RegisterEvent("GET_ITEM_INFO_RECEIVED")
|
||||
CleveRoids.Frame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
|
||||
CleveRoids.Frame:RegisterEvent("UNIT_PET")
|
||||
|
||||
@@ -4962,59 +4985,13 @@ function CleveRoids.Frame:PLAYER_LOGIN()
|
||||
CleveRoids.IndexPetSpells()
|
||||
CleveRoids.initializationTimer = GetTime() + 1.5
|
||||
|
||||
-- Guarantee a full index (talents + macros + action bars) even if
|
||||
-- UPDATE_MACROS / SPELLS_CHANGED happen not to fire before the init timer.
|
||||
-- Coalesces with those events' arming; RebuildMacros runs once for the burst.
|
||||
CleveRoids.macroRebuildTime = GetTime() + 0.3
|
||||
|
||||
-- PERFORMANCE: Initialize event-driven cache states
|
||||
CleveRoids._cachedPlayerInCombat = UnitAffectingCombat("player") and true or false
|
||||
|
||||
-- Schedule delayed WDB warmup (loads items into client cache via tooltip scan)
|
||||
-- This ensures GetItemInfo() works for all inventory items after a WDB clear
|
||||
CleveRoids.wdbWarmupTime = GetTime() + 3.0 -- 3 second delay after login
|
||||
end
|
||||
|
||||
-- PERFORMANCE: WDB warmup - tooltip scan all bag items to ensure they're cached
|
||||
-- This prevents GetItemInfo() returning nil for items after a WDB clear
|
||||
function CleveRoids.DoWDBWarmup()
|
||||
if CleveRoids.wdbWarmupDone then return end
|
||||
CleveRoids.wdbWarmupDone = true
|
||||
|
||||
-- Create a hidden tooltip for scanning if it doesn't exist
|
||||
local tip = CleveRoidsWDBTip
|
||||
if not tip then
|
||||
tip = CreateFrame("GameTooltip", "CleveRoidsWDBTip", UIParent, "GameTooltipTemplate")
|
||||
tip:SetOwner(WorldFrame, "ANCHOR_NONE")
|
||||
end
|
||||
|
||||
local scanned = 0
|
||||
|
||||
-- Scan all bag slots
|
||||
for bag = 0, 4 do
|
||||
local slots = GetContainerNumSlots(bag) or 0
|
||||
for slot = 1, slots do
|
||||
if C_Container.GetContainerItemID(bag, slot) then
|
||||
-- Tooltip scan loads the item into WDB
|
||||
tip:ClearLines()
|
||||
tip:SetBagItem(bag, slot)
|
||||
scanned = scanned + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Scan equipped items
|
||||
for slot = 1, 19 do
|
||||
if GetInventoryItemID("player", slot) then
|
||||
tip:ClearLines()
|
||||
tip:SetInventoryItem("player", slot)
|
||||
scanned = scanned + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Now trigger a full item index to populate the cache with valid data
|
||||
if CleveRoids.IndexItems then
|
||||
CleveRoids.IndexItems()
|
||||
end
|
||||
|
||||
if CleveRoids.debug then
|
||||
CleveRoids.Print("|cff88ff88[WDB Warmup]|r Scanned " .. scanned .. " items into cache")
|
||||
end
|
||||
end
|
||||
|
||||
function CleveRoids.Frame:ADDON_LOADED(addon)
|
||||
@@ -5651,35 +5628,44 @@ function CleveRoids.Frame:PLAYER_TARGET_CHANGED()
|
||||
end
|
||||
end
|
||||
|
||||
function CleveRoids.Frame:UPDATE_MACROS()
|
||||
-- Full rebuild of the macro/spell/talent/action-bar index. Invoked from the
|
||||
-- update loop when macroRebuildTime elapses (armed by UPDATE_MACROS /
|
||||
-- SPELLS_CHANGED / PLAYER_LOGIN), never inline from an event - so a burst of
|
||||
-- those events collapses into one rebuild.
|
||||
function CleveRoids.RebuildMacros()
|
||||
CleveRoids.currentSequence = nil
|
||||
-- Explicitly nil tables before re-assignment
|
||||
CleveRoids.ParsedMsg = nil;
|
||||
CleveRoids.ParsedMsg = {}
|
||||
|
||||
CleveRoids.Macros = nil;
|
||||
CleveRoids.Macros = {}
|
||||
|
||||
CleveRoids.Actions = nil;
|
||||
CleveRoids.Actions = {}
|
||||
|
||||
CleveRoids.Sequences = nil;
|
||||
CleveRoids.Sequences = {}
|
||||
|
||||
CleveRoids.IndexSpells()
|
||||
CleveRoids.IndexTalents()
|
||||
CleveRoids.IndexPetSpells()
|
||||
CleveRoids.IndexActionBars()
|
||||
|
||||
-- Action-bar indexing is wasted before `ready` (GetAction early-returns
|
||||
-- while not ready), and the +1.5s init timer rebuilds the bars once anyway.
|
||||
-- Skipping it here keeps the pre-ready login rebuilds from fanning 120 slot
|
||||
-- updates out to Blizzard/pfUI/Bongos buttons.
|
||||
if CleveRoids.ready then
|
||||
CleveRoids.IndexActionBars()
|
||||
end
|
||||
|
||||
if CleveRoidMacros.realtime == 0 then
|
||||
CleveRoids.QueueActionUpdate()
|
||||
end
|
||||
end
|
||||
|
||||
function CleveRoids.Frame:UPDATE_MACROS()
|
||||
-- Debounce: collapse bursts (login, rapid macro edits) into one rebuild.
|
||||
CleveRoids.macroRebuildTime = GetTime() + 0.3
|
||||
end
|
||||
|
||||
function CleveRoids.Frame:SPELLS_CHANGED()
|
||||
-- PERFORMANCE: Clear spell caches when spells change (learn new ranks, etc.)
|
||||
-- Clear spell caches immediately (cheap); defer the heavy rebuild.
|
||||
CleveRoids.spellIdCache = {}
|
||||
CleveRoids.spellNameCache = {}
|
||||
CleveRoids.Frame:UPDATE_MACROS()
|
||||
CleveRoids.macroRebuildTime = GetTime() + 0.3
|
||||
end
|
||||
|
||||
function CleveRoids.Frame:ACTIONBAR_SLOT_CHANGED()
|
||||
@@ -5690,6 +5676,23 @@ function CleveRoids.Frame:ACTIONBAR_SLOT_CHANGED()
|
||||
end
|
||||
end
|
||||
|
||||
-- ClassicAPI fires GET_ITEM_INFO_RECEIVED when an async item-cache fill lands
|
||||
-- (the hooked GetItemInfo auto-warms on a miss). It fires for EVERY fill in the
|
||||
-- game though - quest DB scans, AH sweeps, chat-link hovers, inspects - so we
|
||||
-- ignore anything not in pendingItemInfo (items we own that missed the last
|
||||
-- index pass). That check is O(1) and keeps unrelated bursts free.
|
||||
function CleveRoids.Frame:GET_ITEM_INFO_RECEIVED()
|
||||
local pending = CleveRoids.pendingItemInfo
|
||||
if not (pending and pending[arg1]) then return end
|
||||
-- Skip during combat; PLAYER_LEAVE_COMBAT re-indexes once it's safe.
|
||||
if UnitAffectingCombat("player") then return end
|
||||
-- Arm once per burst; the update loop clears it after re-indexing. Later
|
||||
-- arrivals re-arm it, guaranteeing the final resolved state is captured.
|
||||
if not CleveRoids.itemInfoReindexTime then
|
||||
CleveRoids.itemInfoReindexTime = GetTime() + 0.5
|
||||
end
|
||||
end
|
||||
|
||||
function CleveRoids.Frame:BAG_UPDATE_DELAYED()
|
||||
-- In combat: Skip expensive indexing but still queue icon update
|
||||
-- so conditionals like [inbag] re-evaluate (they use live bag APIs)
|
||||
@@ -5706,10 +5709,15 @@ function CleveRoids.Frame:BAG_UPDATE_DELAYED()
|
||||
CleveRoids.lastItemIndexTime = now
|
||||
CleveRoids.IndexItems()
|
||||
|
||||
-- Directly clear all relevant caches and force a UI refresh for all buttons.
|
||||
CleveRoids.Actions = {}
|
||||
CleveRoids.Macros = {}
|
||||
CleveRoids.IndexActionBars()
|
||||
-- Rebuild action bars so item-dependent macro resolution refreshes.
|
||||
-- Skipped before `ready` (GetAction early-returns; the +1.5s init timer
|
||||
-- builds the bars), which keeps bag-fill events during login from firing
|
||||
-- a full 120-slot rebuild each time.
|
||||
if CleveRoids.ready then
|
||||
CleveRoids.Actions = {}
|
||||
CleveRoids.Macros = {}
|
||||
CleveRoids.IndexActionBars()
|
||||
end
|
||||
end
|
||||
|
||||
-- Always queue icon update so conditionals like [inbag] re-evaluate
|
||||
|
||||
@@ -238,6 +238,14 @@ function CleveRoids.IndexItems()
|
||||
local items = {}
|
||||
local NUM_BAG_SLOTS = NUM_BAG_SLOTS -- Upvalue for bag constant
|
||||
|
||||
-- Rebuilt each pass: itemIDs the player owns that GetItemInfo couldn't
|
||||
-- resolve yet (cold cache under ClassicAPI's async warmup). The
|
||||
-- GET_ITEM_INFO_RECEIVED handler consults this so it only re-indexes for
|
||||
-- our own uncached items and ignores the flood of unrelated fills (quest
|
||||
-- DB scans, AH, chat-link hovers, inspects) in O(1).
|
||||
local pendingItemInfo = {}
|
||||
CleveRoids.pendingItemInfo = pendingItemInfo
|
||||
|
||||
-- PERFORMANCE: Local function references
|
||||
local GetContainerNumSlots = GetContainerNumSlots
|
||||
local GetContainerItemInfo = GetContainerItemInfo
|
||||
@@ -281,6 +289,9 @@ function CleveRoids.IndexItems()
|
||||
if lowerName ~= name then
|
||||
items[lowerName] = name
|
||||
end
|
||||
else
|
||||
-- Owned but not cached yet; wait for GET_ITEM_INFO_RECEIVED.
|
||||
pendingItemInfo[itemID] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -318,6 +329,9 @@ function CleveRoids.IndexItems()
|
||||
if lowerName ~= name then
|
||||
items[lowerName] = name
|
||||
end
|
||||
else
|
||||
-- Owned but not cached yet; wait for GET_ITEM_INFO_RECEIVED.
|
||||
pendingItemInfo[itemID] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user