Skip to content

Commit 9bea201

Browse files
authored
Merge pull request #674 from Xian55/feature/addon/1.7.65
Addon: [1.7.65] - Optimize for memory allocation. Core: AddonBits: SoftInteract_Enabled
2 parents 5be5cef + 23d6436 commit 9bea201

File tree

7 files changed

+194
-150
lines changed

7 files changed

+194
-150
lines changed

Addons/DataToColor/Collections.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ function struct:new(tickLifetime)
7171
end
7272

7373
function struct:set(key, value)
74-
self.table[key] = { value = value or key, dirty = 0 }
74+
local entry = self.table[key]
75+
if not entry then
76+
self.table[key] = { value = value or key, dirty = 0 }
77+
return
78+
end
79+
80+
entry.value = value or key
81+
entry.dirty = 0
7582
end
7683

7784
function struct:getTimed(globalTick)

Addons/DataToColor/Constants.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ DataToColor.C.unitParty = "party"
1717
DataToColor.C.unitRaid = "raid"
1818
DataToColor.C.unitPet = "pet"
1919

20+
DataToColor.C.unitPartyNames = {}
21+
DataToColor.C.unitPartyPetNames = {}
22+
2023
if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
2124
DataToColor.C.unitFocus = "party1"
2225
DataToColor.C.unitFocusTarget = "party1target"
@@ -77,10 +80,22 @@ DataToColor.C.GuidType = {
7780
["Vehicle"] = 4,
7881
}
7982

83+
DataToColor.C.unitClassification = {
84+
["normal"] = 1,
85+
["trivial"] = 2,
86+
["minus"] = 4,
87+
["rare"] = 8,
88+
["elite"] = 16,
89+
["rareelite"] = 32,
90+
["worldboss"] = 64
91+
}
92+
8093
-- Mirror timer labels
8194
DataToColor.C.MIRRORTIMER.BREATH = "BREATH"
8295

8396
DataToColor.C.ActionType.Spell = "spell"
8497
DataToColor.C.ActionType.Macro = "macro"
8598

86-
DataToColor.C.PET_MODE_DEFENSIVE = "PET_MODE_DEFENSIVE"
99+
DataToColor.C.PET_MODE_DEFENSIVE = "PET_MODE_DEFENSIVE"
100+
101+
DataToColor.C.CVarSoftTargetInteract = "SoftTargetInteract"

Addons/DataToColor/DataToColor.lua

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ local GetNumTalentTabs = GetNumTalentTabs
5555
local GetNumTalents = GetNumTalents
5656
local GetTalentInfo = GetTalentInfo
5757
local GetNumSpellTabs = GetNumSpellTabs
58+
local IsSpellKnown = IsSpellKnown
5859

5960
local GetPlayerFacing = GetPlayerFacing
6061
local UnitLevel = UnitLevel
62+
local UnitLevelSafe = DataToColor.UnitLevelSafe
6163
local UnitHealthMax = UnitHealthMax
6264
local UnitHealth = UnitHealth
6365
local UnitPowerMax = UnitPowerMax
@@ -199,6 +201,8 @@ DataToColor.customTrigger1 = {}
199201

200202
DataToColor.sessionKillCount = 0
201203

204+
local SpellQueueWindow = min(tonumber(GetCVar(DataToColor.C.SpellQueueWindow)) or 0, 999)
205+
202206
function DataToColor:RegisterSlashCommands()
203207
DataToColor:RegisterChatCommand('dc', 'StartSetup')
204208
DataToColor:RegisterChatCommand('dccpu', 'GetCPUImpact')
@@ -226,6 +230,7 @@ end
226230

227231
-- This function runs when addon is initialized/player logs in
228232
function DataToColor:OnInitialize()
233+
DataToColor:CreateConstants()
229234
DataToColor:SetupRequirements()
230235
DataToColor:CreateFrames()
231236
DataToColor:RegisterSlashCommands()
@@ -253,6 +258,13 @@ function DataToColor:SetupRequirements()
253258
SetCVar('Gamma', 1, '[]')
254259
end
255260

261+
function DataToColor:CreateConstants()
262+
for i = 1, 4 do
263+
DataToColor.C.unitPartyNames[i] = DataToColor.C.unitParty .. i
264+
DataToColor.C.unitPartyPetNames[i] = DataToColor.C.unitPartyNames[i] .. DataToColor.C.unitPet
265+
end
266+
end
267+
256268
function DataToColor:Reset()
257269
DataToColor.S.playerSpellBookName = {}
258270
DataToColor.S.playerSpellBookId = {}
@@ -366,17 +378,23 @@ end
366378
function DataToColor:BagSlotChanged(container, slot)
367379
local _, count, _, _, _, _, _, _, _, id = GetContainerItemInfo(container, slot)
368380

369-
if id == nil then
381+
if not id then
370382
count = 0
371383
id = 0
372384
end
373385

374386
local index = container * 1000 + slot
375-
if bagCache[index] == nil or bagCache[index].id ~= id or bagCache[index].count ~= count then
387+
local cache = bagCache[index]
388+
if cache then
389+
if cache.id ~= id or cache.count ~= count then
390+
cache.id = id
391+
cache.count = count
392+
return true
393+
end
394+
else
376395
bagCache[index] = { id = id, count = count }
377396
return true
378397
end
379-
380398
return false
381399
end
382400

@@ -398,14 +416,14 @@ end
398416

399417
function DataToColor:PopulateSpellBookInfo()
400418
local num, type = 1, 1
401-
if GetNumSpellTabs == nil then
419+
if not GetNumSpellTabs then
402420
while true do
403421
local name, _, id = GetSpellBookItemName(num, type)
404422
if not name then
405423
break
406424
end
407425

408-
if id ~= nil then
426+
if id then
409427
local texture = GetSpellBookItemTexture(num, type)
410428
DataToColor.S.playerSpellBookId[id] = true
411429
DataToColor.S.playerSpellBookName[texture] = name
@@ -419,15 +437,16 @@ function DataToColor:PopulateSpellBookInfo()
419437
end
420438
end
421439
else
440+
-- Cataclysm Classic
422441
for i = 1, GetNumSpellTabs() do
423442
local offset, numSlots = select(3, GetSpellTabInfo(i))
424-
for j = offset+1, offset+numSlots do
443+
for j = offset + 1, offset + numSlots do
425444
local name, _, id = GetSpellBookItemName(j, type)
426445
if not name then
427446
break
428447
end
429448

430-
if id ~= nil then
449+
if id and IsSpellKnown(id) then
431450
local texture = GetSpellBookItemTexture(j, type)
432451
DataToColor.S.playerSpellBookId[id] = true
433452
DataToColor.S.playerSpellBookName[texture] = name
@@ -656,19 +675,19 @@ function DataToColor:CreateFrames()
656675
Pixel(int, costMeta or 0, 35)
657676
Pixel(int, costValue or 0, 36)
658677

659-
local slot, expireTime = DataToColor.actionBarCooldownQueue:getTimed(globalTick)
660-
if slot then
661-
DataToColor.actionBarCooldownQueue:setDirtyAfterTime(slot, globalTick)
678+
local actionSlot, expireTime = DataToColor.actionBarCooldownQueue:getTimed(globalTick)
679+
if actionSlot then
680+
DataToColor.actionBarCooldownQueue:setDirtyAfterTime(actionSlot, globalTick)
662681

663682
local duration = max(0, floor((expireTime - GetTime()) * 10))
664683
--if duration > 0 then
665-
-- DataToColor:Print("actionBarCooldownQueue: ", slot, " ", duration, " ", expireTime - GetTime())
684+
-- DataToColor:Print("actionBarCooldownQueue: ", actionSlot, " ", duration, " ", expireTime - GetTime())
666685
--end
667-
Pixel(int, slot * 100000 + duration, 37)
686+
Pixel(int, actionSlot * 100000 + duration, 37)
668687

669688
if duration == 0 then
670-
DataToColor.actionBarCooldownQueue:removeWhenExpired(slot, globalTick)
671-
--DataToColor:Print("actionBarCooldownQueue: ", slot, " expired")
689+
DataToColor.actionBarCooldownQueue:removeWhenExpired(actionSlot, globalTick)
690+
--DataToColor:Print("actionBarCooldownQueue: ", actionSlot, " expired")
672691
end
673692
else
674693
Pixel(int, 0, 37)
@@ -681,11 +700,8 @@ function DataToColor:CreateFrames()
681700
Pixel(int, DataToColor:getAuraMaskForClass(UnitBuff, DataToColor.C.unitPlayer, DataToColor.S.playerBuffs), 41)
682701
Pixel(int, DataToColor:getAuraMaskForClass(UnitDebuff, DataToColor.C.unitTarget, DataToColor.S.targetDebuffs), 42)
683702

684-
local targetLevel = UnitLevel(DataToColor.C.unitTarget)
685-
if targetLevel == -1 then
686-
targetLevel = playerLevel + 10
687-
end
688-
Pixel(int, targetLevel * 100 + DataToColor.unitClassification[UnitClassification(DataToColor.C.unitTarget)], 43)
703+
local targetLevel = UnitLevelSafe(DataToColor.C.unitTarget, playerLevel)
704+
Pixel(int, targetLevel * 100 + DataToColor.C.unitClassification[UnitClassification(DataToColor.C.unitTarget)], 43)
689705

690706
-- Amount of money in coppers
691707
Pixel(int, GetMoney() % 1000000, 44) -- Represents amount of money held (in copper)
@@ -701,8 +717,8 @@ function DataToColor:CreateFrames()
701717
Pixel(int, DataToColor.uiErrorMessage, 52) -- Last UI Error message
702718
DataToColor.uiErrorMessage = 0
703719

704-
Pixel(int, DataToColor:CastingInfoSpellId(DataToColor.C.unitPlayer), 53) -- SpellId being cast
705-
Pixel(int, DataToColor:getAvgEquipmentDurability() * 100 + ((DataToColor.C.CHARACTER_CLASS_ID == 2 and UnitPower(DataToColor.C.unitPlayer, Enum.PowerType.HolyPower) or GetComboPoints(DataToColor.C.unitPlayer, DataToColor.C.unitTarget)) or 0), 54) -- for paladin holy power or combo points
720+
Pixel(int, DataToColor:CastingInfoSpellId(DataToColor.C.unitPlayer), 53) -- SpellId being cast
721+
Pixel(int, DataToColor:getAvgEquipmentDurability() * 100 + ((DataToColor.C.CHARACTER_CLASS_ID == 2 and UnitPower(DataToColor.C.unitPlayer, Enum.PowerType.HolyPower) or GetComboPoints(DataToColor.C.unitPlayer, DataToColor.C.unitTarget)) or 0), 54) -- for paladin holy power or combo points
706722

707723
local playerBuffCount = DataToColor:populateAuraTimer(UnitBuff, DataToColor.C.unitPlayer, DataToColor.playerBuffTime)
708724
local playerDebuffCount = DataToColor:populateAuraTimer(UnitDebuff, DataToColor.C.unitPlayer, nil)
@@ -853,11 +869,8 @@ function DataToColor:CreateFrames()
853869
Pixel(int, 0, 93)
854870
end
855871

856-
local mouseoverLevel = UnitLevel(DataToColor.C.unitmouseover)
857-
if mouseoverLevel == -1 then
858-
mouseoverLevel = playerLevel + 10
859-
end
860-
Pixel(int, mouseoverLevel * 100 + DataToColor.unitClassification[UnitClassification(DataToColor.C.unitmouseover)], 85)
872+
local mouseoverLevel = UnitLevelSafe(DataToColor.C.unitmouseover, playerLevel)
873+
Pixel(int, mouseoverLevel * 100 + DataToColor.C.unitClassification[UnitClassification(DataToColor.C.unitmouseover)], 85)
861874

862875
Pixel(int, DataToColor:NpcId(DataToColor.C.unitmouseover), 86)
863876
Pixel(int, DataToColor:getGuidFromUnit(DataToColor.C.unitmouseover), 87)
@@ -880,10 +893,9 @@ function DataToColor:CreateFrames()
880893
if globalTick % LATENCY_ITERATION_FRAME_CHANGE_RATE == 0 then
881894
local _, _, lagHome, lagWorld = GetNetStats()
882895

883-
local spellQueue = min(tonumber(GetCVar(DataToColor.C.SpellQueueWindow)) or 0, 999)
884896
local lag = min(max(lagHome, lagWorld), 9999)
885897

886-
Pixel(int, 10000 * spellQueue + lag, 96)
898+
Pixel(int, 10000 * SpellQueueWindow + lag, 96)
887899
end
888900

889901
-- Timers
@@ -895,7 +907,7 @@ function DataToColor:CreateFrames()
895907
Pixel(int, lootItemCount * 10 + DataToColor.lastLoot, 97)
896908

897909
local e = DataToColor.ChatQueue:peek()
898-
if e == nil then
910+
if not e then
899911
Pixel(int, 0, 98)
900912
Pixel(int, 0, 99)
901913
else
@@ -1049,7 +1061,7 @@ function DataToColor:sell(items)
10491061
end
10501062

10511063
local item = GetMerchantItemLink(1)
1052-
if item == nil then
1064+
if not item then
10531065
DataToColor:Print("Merchant is not open to sell to, please approach and open.")
10541066
return
10551067
end

Addons/DataToColor/DataToColor.toc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Title: DataToColor
44
## Author: FreeHongKongMMO
55
## Notes: Displays data as colors
6-
## Version: 1.7.64
6+
## Version: 1.7.65
77
## RequiredDeps:
88
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
99
## SavedVariables:

0 commit comments

Comments
 (0)