Skip to content

Commit 7979297

Browse files
authored
Reduce performance issues with Time-Lost Jewels (#555)
* rewrite time lost logic to use parser and PassiveTreeView.lua on load instead of recreating the wheel with sd logic * updates, hash work, still broken * rework to use GlobalCache and actually have a working version? amaze * relax conditional * nil check, clean up * merge stats * update for weapon sets, if jewel is allocated WS1/WS2 * spellchecker * clean up * removing leftover code
1 parent cb707e0 commit 7979297

File tree

5 files changed

+563
-654
lines changed

5 files changed

+563
-654
lines changed

src/Classes/ItemsTab.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,9 @@ holding Shift will put it in the second.]])
707707
end
708708

709709
-- Adding Mod
710+
self.build.treeTab.skipTimeLostJewelProcessing = true
710711
self:AddModComparisonTooltip(tooltip, mod)
712+
self.build.treeTab.skipTimeLostJewelProcessing = false
711713
end
712714
end
713715
end

src/Classes/PassiveTreeView.lua

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ function PassiveTreeViewClass:AddNodeTooltip(tooltip, node, build, incSmallPassi
11371137
tooltip:AddSeparator(14)
11381138
end
11391139

1140-
local function addModInfoToTooltip(node, i, line)
1140+
local function addModInfoToTooltip(node, i, line, localSmallIncEffect)
11411141
if node.mods[i] then
11421142
if launch.devModeAlt and node.mods[i].list then
11431143
-- Modifier debugging info
@@ -1152,10 +1152,10 @@ function PassiveTreeViewClass:AddNodeTooltip(tooltip, node, build, incSmallPassi
11521152
line = line .. " " .. modStr
11531153
end
11541154
end
1155-
1155+
11561156
-- Apply Inc Node scaling from Hulking Form only visually
1157-
if incSmallPassiveSkillEffect > 0 and node.type == "Normal" and not node.isAttribute and not node.ascendancyName and node.mods[i].list then
1158-
local scale = 1 + incSmallPassiveSkillEffect / 100
1157+
if (incSmallPassiveSkillEffect + localSmallIncEffect) > 0 and node.type == "Normal" and not node.isAttribute and not node.ascendancyName and node.mods[i].list then
1158+
local scale = 1 + (incSmallPassiveSkillEffect + localSmallIncEffect) / 100
11591159
local scaledList = new("ModList")
11601160
scaledList:ScaleAddList(node.mods[i].list, scale)
11611161
local number = line:match("%d*%.?%d+")
@@ -1166,24 +1166,105 @@ function PassiveTreeViewClass:AddNodeTooltip(tooltip, node, build, incSmallPassi
11661166
elseif type(mod.value) == "table" then
11671167
newValue = mod.value.mod.value
11681168
end
1169-
line = line:gsub("%d*%.?%d+",math.abs(newValue))
1169+
line = line:gsub("%d*%.?%d+", math.abs(newValue))
11701170
end
11711171
-- line = line .. " ^8(Effect increased by "..incSmallPassiveSkillEffect.."%)"
11721172
end
1173-
1173+
11741174
tooltip:AddLine(16, ((node.mods[i].extra or not node.mods[i].list) and colorCodes.UNSUPPORTED or colorCodes.MAGIC)..line)
11751175
end
11761176
end
11771177

1178+
local function mergeStats(nodeSd, jewelSd, spec)
1179+
-- copy the original tree node so we ignore the mods being added from the jewel
1180+
local nodeSdCopy = copyTable(nodeSd)
1181+
local nodeNumber = 0
1182+
local nodeString = ""
1183+
local modToAddNumber = 0
1184+
local modToAddString = ""
1185+
1186+
-- loop the original node mods and compare to the jewel mod we want to add
1187+
-- if the strings without the numbers are identical, the mods should be identical
1188+
-- if so, update the node's version of the mod and do not add the jewel mods to the list
1189+
-- otherwise, add the jewel mod because it's unique/new to the node
1190+
for index, originalSd in ipairs(nodeSdCopy) do
1191+
nodeString = originalSd:gsub("(%d+)", function(number)
1192+
nodeNumber = number
1193+
return ""
1194+
end)
1195+
modToAddString = jewelSd:gsub("(%d+)", function(number)
1196+
modToAddNumber = number
1197+
return ""
1198+
end)
1199+
if nodeString == modToAddString then
1200+
nodeSd[index] = nodeSd[index]:gsub("(%d+)", (nodeNumber + modToAddNumber))
1201+
return
1202+
end
1203+
end
1204+
t_insert(nodeSd, jewelSd)
1205+
end
1206+
1207+
-- loop over mods generated in CalcSetup by rad.func calls and grab the lines added
1208+
-- processStats once on copied node to cleanly setup for the tooltip
1209+
local function processTimeLostModsAndGetLocalEffect(mNode, build)
1210+
local localSmallIncEffect = 0
1211+
local hasWSCondition = false
1212+
local newSd = copyTable(build.spec.tree.nodes[mNode.id].sd)
1213+
for _, mod in ipairs(mNode.finalModList) do
1214+
-- if the jewelMod has a WS Condition, only add the incEffect given it matches the activeWeaponSet
1215+
-- otherwise the mod came from a jewel that is allocMode 0, so it always applies
1216+
for _, modCriteria in ipairs(mod) do
1217+
if modCriteria.type == "Condition" and modCriteria.var and modCriteria.var:match("^WeaponSet") then
1218+
if (tonumber(modCriteria.var:match("(%d)")) == (build.itemsTab.activeItemSet.useSecondWeaponSet and 2 or 1)) then
1219+
if mod.name == "JewelSmallPassiveSkillEffect" then
1220+
localSmallIncEffect = mod.value
1221+
elseif mod.parsedLine then
1222+
mergeStats(newSd, mod.parsedLine, build.spec)
1223+
end
1224+
end
1225+
hasWSCondition = true
1226+
end
1227+
end
1228+
if not hasWSCondition then
1229+
if mod.name == "JewelSmallPassiveSkillEffect" then
1230+
localSmallIncEffect = mod.value
1231+
elseif mod.parsedLine then
1232+
mergeStats(newSd, mod.parsedLine, build.spec)
1233+
end
1234+
end
1235+
end
1236+
mNode.sd = copyTable(newSd)
1237+
build.spec.tree:ProcessStats(mNode)
1238+
return localSmallIncEffect
1239+
end
1240+
1241+
-- we only want to run the timeLost function on a node that can could be in a jewel socket radius of up to Large
1242+
-- essentially trying to avoid calling ProcessStats for a Normal/Notable node that can't possibly be affected
1243+
-- loops potentially every socket (24) until itemsTab is loaded or a jewel socket is hovered, then it will only loop the allocated sockets
1244+
local function isNodeInARadius(node)
1245+
local isInRadius = false
1246+
for id, socket in pairs(build.itemsTab.sockets) do
1247+
if build.itemsTab.activeSocketList and socket.inactive == false or socket.inactive == nil then
1248+
isInRadius = isInRadius or build.spec.nodes[id].nodesInRadius[3][node.id] ~= nil
1249+
if isInRadius then break end
1250+
end
1251+
end
1252+
return isInRadius
1253+
end
1254+
11781255
-- If so, check if the left hand tree is unallocated, but the right hand tree is allocated.
11791256
-- Then continue processing as normal
1180-
local mNode = node
1257+
local mNode = copyTableSafe(node, true, true)
11811258

11821259
-- This stanza actives for both Mastery and non Mastery tooltips. Proof: add '"Blah "..' to addModInfoToTooltip
11831260
if mNode.sd[1] and not mNode.allMasteryOptions then
11841261
tooltip:AddLine(16, "")
1262+
local localSmallIncEffect = 0
1263+
if not mNode.isAttribute and (mNode.type == "Normal" or mNode.type == "Notable") and isNodeInARadius(node) then
1264+
localSmallIncEffect = processTimeLostModsAndGetLocalEffect(mNode, build)
1265+
end
11851266
for i, line in ipairs(mNode.sd) do
1186-
addModInfoToTooltip(mNode, i, line)
1267+
addModInfoToTooltip(mNode, i, line, localSmallIncEffect)
11871268
end
11881269
end
11891270

0 commit comments

Comments
 (0)