Skip to content

Commit

Permalink
FIX: output reuse and acceleration without existing env
Browse files Browse the repository at this point in the history
  • Loading branch information
Paliak committed Aug 30, 2024
1 parent df71c74 commit 90baaff
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/Classes/CalcsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ function CalcsTabClass:PowerBuilder()
for nodeId, node in pairs(nodes) do
if not node.alloc and node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
if not cache[node.modKey] then
cache[node.modKey] = calcFunc({ addNodes = { [node] = true } }, { requirementsItems = true, requirementsGems = true, skills = true }, useFullDPS)
cache[node.modKey] = calcFunc({ addNodes = { [node] = true } }, useFullDPS)
end
local output = cache[node.modKey]
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
Expand All @@ -527,7 +527,7 @@ function CalcsTabClass:PowerBuilder()
pathNodes[node] = true
end
if node.pathDist > 1 then
node.power.pathPower = self:CalculatePowerStat(self.powerStat, calcFunc({ addNodes = pathNodes }, { requirementsItems = true, requirementsGems = true, skills = true }), calcBase)
node.power.pathPower = self:CalculatePowerStat(self.powerStat, calcFunc({ addNodes = pathNodes }, useFullDPS), calcBase)
end
end
elseif not self.powerStat or not self.powerStat.ignoreForNodes then
Expand All @@ -542,7 +542,7 @@ function CalcsTabClass:PowerBuilder()
end
elseif node.alloc and node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
if not cache[node.modKey.."_remove"] then
cache[node.modKey.."_remove"] = calcFunc({ removeNodes = { [node] = true } }, { requirementsItems = true, requirementsGems = true, skills = true })
cache[node.modKey.."_remove"] = calcFunc({ removeNodes = { [node] = true } }, useFullDPS)
end
local output = cache[node.modKey.."_remove"]
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
Expand All @@ -554,7 +554,7 @@ function CalcsTabClass:PowerBuilder()
pathNodes[node] = true
end
if #node.depends > 1 then
node.power.pathPower = self:CalculatePowerStat(self.powerStat, calcFunc({ removeNodes = pathNodes }, { requirementsItems = true, requirementsGems = true, skills = true }), calcBase)
node.power.pathPower = self:CalculatePowerStat(self.powerStat, calcFunc({ removeNodes = pathNodes }, useFullDPS), calcBase)
end
end
end
Expand All @@ -575,7 +575,7 @@ function CalcsTabClass:PowerBuilder()
wipeTable(node.power)
if not node.alloc and node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
if not cache[node.modKey] then
cache[node.modKey] = calcFunc({ addNodes = { [node] = true } }, { requirementsItems = true, requirementsGems = true, skills = true })
cache[node.modKey] = calcFunc({ addNodes = { [node] = true } }, useFullDPS)
end
local output = cache[node.modKey]
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/GemSelectControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function GemSelectClass:CalcOutputWithThisGem(calcFunc, gemData, qualityId, useF
-- Add hovered gem to tooltip
self:AddGemTooltip(gemInstance)
-- Calculate the impact of using this gem
local output = calcFunc({ }, { allocNodes = true, requirementsItems = true }, useFullDPS)
local output = calcFunc(nil, useFullDPS)
-- Put the original gem back into the list
if oldGem then
gemInstance.gemData = oldGem.gemData
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/ItemDBControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function ItemDBClass:ListBuilder()
item.measuredPower = 0
for slotName, slot in pairs(self.itemsTab.slots) do
if self.itemsTab:IsItemValidForSlot(item, slotName) and not slot.inactive and (not slot.weaponSet or slot.weaponSet == (self.itemsTab.activeItemSet.useSecondWeaponSet and 2 or 1)) then
local output = calcFunc(item.base.flask and { toggleFlask = item } or item.base.tincture and { toggleTincture = item } or { repSlotName = slotName, repItem = item }, { nodeAlloc = true, requirementsGems = true })
local output = calcFunc(item.base.flask and { toggleFlask = item } or item.base.tincture and { toggleTincture = item } or { repSlotName = slotName, repItem = item })
local measuredPower = output.Minion and output.Minion[self.sortMode] or output[self.sortMode] or 0
if self.sortDetail.transform then
measuredPower = self.sortDetail.transform(measuredPower)
Expand Down
16 changes: 8 additions & 8 deletions src/Classes/ItemsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,8 @@ function ItemsTabClass:AddModComparisonTooltip(tooltip, mod)
newItem:BuildAndParseRaw()

local calcFunc = self.build.calcsTab:GetMiscCalculator()
local outputBase = calcFunc({ repSlotName = slotName, repItem = self.displayItem }, {})
local outputNew = calcFunc({ repSlotName = slotName, repItem = newItem }, {})
local outputBase = calcFunc({ repSlotName = slotName, repItem = self.displayItem })
local outputNew = calcFunc({ repSlotName = slotName, repItem = newItem })
self.build:AddStatComparesToTooltip(tooltip, outputBase, outputNew, "\nAdding this mod will give: ")
end

Expand Down Expand Up @@ -2278,8 +2278,8 @@ function ItemsTabClass:AppendAnointTooltip(tooltip, node, actionText)
header = "^7"..actionText.." nothing will give you: "
end
local calcFunc = self.build.calcsTab:GetMiscCalculator()
local outputBase = calcFunc({ repSlotName = "Amulet", repItem = self.displayItem }, {})
local outputNew = calcFunc({ repSlotName = "Amulet", repItem = self:anointItem(node) }, {})
local outputBase = calcFunc({ repSlotName = "Amulet", repItem = self.displayItem })
local outputNew = calcFunc({ repSlotName = "Amulet", repItem = self:anointItem(node) })
local numChanges = self.build:AddStatComparesToTooltip(tooltip, outputBase, outputNew, header)
if node and numChanges == 0 then
tooltip:AddLine(14, "^7"..actionText.." "..node.dn.." changes nothing.")
Expand All @@ -2291,7 +2291,7 @@ end
---@param node table @The passive tree node that will be added
function ItemsTabClass:AppendAddedNotableTooltip(tooltip, node)
local calcFunc, calcBase = self.build.calcsTab:GetMiscCalculator()
local outputNew = calcFunc({ addNodes = { [node] = true } }, { requirementsItems = true, requirementsGems = true, skills = true })
local outputNew = calcFunc({ addNodes = { [node] = true } })
local numChanges = self.build:AddStatComparesToTooltip(tooltip, calcBase, outputNew, "^7Allocating "..node.dn.." will give you: ")
if numChanges == 0 then
tooltip:AddLine(14, "^7Allocating "..node.dn.." changes nothing.")
Expand Down Expand Up @@ -3618,7 +3618,7 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode)
tooltip:AddLine(14, stat)
end
end
local output = calcFunc({ toggleFlask = item }, {})
local output = calcFunc({ toggleFlask = item })
local header
if self.build.calcsTab.mainEnv.flasks[item] then
header = "^7Deactivating this flask will give you:"
Expand Down Expand Up @@ -3654,7 +3654,7 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode)
tooltip:AddLine(14, stat)
end
end
local output = calcFunc({ toggleTincture = item }, {})
local output = calcFunc({ toggleTincture = item })
local header
if self.build.calcsTab.mainEnv.tinctures[item] then
header = "^7Deactivating this tincture will give you:"
Expand Down Expand Up @@ -3701,7 +3701,7 @@ function ItemsTabClass:AddItemTooltip(tooltip, item, slot, dbMode)
for _, compareSlot in pairs(compareSlots) do
if not main.slotOnlyTooltips or (slot and (slot.nodeId == compareSlot.nodeId or slot.slotName == compareSlot.slotName)) or not slot or slot == compareSlot then
local selItem = self.items[compareSlot.selItemId]
local output = calcFunc({ repSlotName = compareSlot.slotName, repItem = item ~= selItem and item or nil}, {})
local output = calcFunc({ repSlotName = compareSlot.slotName, repItem = item ~= selItem and item or nil})
local header
if item == selItem then
header = "^7Removing this item from "..compareSlot.label.." will give you:"
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/NotableDBControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ function NotableDBClass:ListBuilder()
local start = GetTime()
local calcFunc = self.itemsTab.build.calcsTab:GetMiscCalculator()
local itemType = self.itemsTab.displayItem.base.type
local calcBase = calcFunc({ repSlotName = itemType, repItem = self.itemsTab:anointItem(nil) }, {})
local calcBase = calcFunc({ repSlotName = itemType, repItem = self.itemsTab:anointItem(nil) })
self.sortMaxPower = 0
for nodeIndex, node in ipairs(list) do
node.measuredPower = 0
if node.modKey ~= "" then
local output = calcFunc({ repSlotName = itemType, repItem = self.itemsTab:anointItem(node) }, {})
local output = calcFunc({ repSlotName = itemType, repItem = self.itemsTab:anointItem(node) })
node.measuredPower = self:CalculatePowerStat(self.sortDetail, output, calcBase)
if node.measuredPower == m_huge then
t_insert(infinites, node)
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/PassiveTreeView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ function PassiveTreeViewClass:AddNodeTooltip(tooltip, node, build)
-- Calculated the differences caused by allocating this node and all nodes along the path to it
if node.type == "Mastery" and node.allMasteryOptions then
pathNodes[node] = nil
nodeOutput = calcFunc({})
nodeOutput = calcFunc()
else
nodeOutput = calcFunc({ addNodes = { [node] = true } })
end
Expand Down
6 changes: 3 additions & 3 deletions src/Classes/SkillsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ function SkillsTabClass:CreateGemSlot(index)
local tempQual = self.displayGroup.gemList[index].qualityId
self.displayGroup.gemList[index].qualityId = hoveredQuality.type
self:ProcessSocketGroup(self.displayGroup)
local output = calcFunc({}, {})
local output = calcFunc()
self.displayGroup.gemList[index].qualityId = tempQual
tooltip:AddSeparator(10)
self.build:AddStatComparesToTooltip(tooltip, calcBase, output, "^7Switching to this quality variant will give you:")
Expand Down Expand Up @@ -824,7 +824,7 @@ function SkillsTabClass:CreateGemSlot(index)
if calcFunc then
local storedQuality = self.displayGroup.gemList[index].quality
self.displayGroup.gemList[index].quality = 20
local output = calcFunc({}, {})
local output = calcFunc()
self.displayGroup.gemList[index].quality = storedQuality
self.build:AddStatComparesToTooltip(tooltip, calcBase, output, "^7Setting to 20 quality will give you:")
end
Expand Down Expand Up @@ -866,7 +866,7 @@ function SkillsTabClass:CreateGemSlot(index)
local calcFunc, calcBase = self.build.calcsTab:GetMiscCalculator(self.build)
if calcFunc then
self.displayGroup.gemList[index].enabled = not self.displayGroup.gemList[index].enabled
local output = calcFunc({}, {})
local output = calcFunc()
self.displayGroup.gemList[index].enabled = not self.displayGroup.gemList[index].enabled
self.build:AddStatComparesToTooltip(tooltip, calcBase, output, self.displayGroup.gemList[index].enabled and "^7Disabling this gem will give you:" or "^7Enabling this gem will give you:")
end
Expand Down
8 changes: 4 additions & 4 deletions src/Classes/TradeQuery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,10 @@ function TradeQueryClass:GetResultEvaluation(row_idx, result_index, calcFunc, ba
for nodeName in (result.item_string.."\r\n"):gmatch("1 Added Passive Skill is (.-)\r?\n") do
t_insert(addedNodes, self.itemsTab.build.spec.tree.clusterNodeMap[nodeName])
end
local output12 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[1]] = true, [addedNodes[2]] = true } }, { requirementsItems = true, requirementsGems = true, skills = true }))
local output13 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[1]] = true, [addedNodes[3]] = true } }, { requirementsItems = true, requirementsGems = true, skills = true }))
local output23 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[2]] = true, [addedNodes[3]] = true } }, { requirementsItems = true, requirementsGems = true, skills = true }))
local output123 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[1]] = true, [addedNodes[2]] = true, [addedNodes[3]] = true } }), { requirementsItems = true, requirementsGems = true, skills = true })
local output12 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[1]] = true, [addedNodes[2]] = true } }))
local output13 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[1]] = true, [addedNodes[3]] = true } }))
local output23 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[2]] = true, [addedNodes[3]] = true } }))
local output123 = self:ReduceOutput(calcFunc({ addNodes = { [addedNodes[1]] = true, [addedNodes[2]] = true, [addedNodes[3]] = true } }))
-- Sometimes the third node is as powerful as a wet noodle, so use weight per point spent, including the jewel socket
local weight12 = self.tradeQueryGenerator.WeightedRatioOutputs(baseOutput, output12, self.statSortSelectionList) / 4
local weight13 = self.tradeQueryGenerator.WeightedRatioOutputs(baseOutput, output13, self.statSortSelectionList) / 4
Expand Down
8 changes: 4 additions & 4 deletions src/Classes/TradeQueryGenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ function TradeQueryGeneratorClass:GenerateModWeights(modsToTest)
logToFile("Failed to test %s mod: %s", self.calcContext.itemCategory, modLine)
end

local output = self.calcContext.calcFunc({ repSlotName = self.calcContext.slot.slotName, repItem = self.calcContext.testItem }, { nodeAlloc = true })
local output = self.calcContext.calcFunc({ repSlotName = self.calcContext.slot.slotName, repItem = self.calcContext.testItem })
local meanStatDiff = TradeQueryGeneratorClass.WeightedRatioOutputs(self.calcContext.baseOutput, output, self.calcContext.options.statWeights) * 1000 - (self.calcContext.baseStatValue or 0)
if meanStatDiff > 0.01 then
t_insert(self.modWeights, { tradeModId = entry.tradeMod.id, weight = meanStatDiff / modValue, meanStatDiff = meanStatDiff, invert = entry.sign == "-" and true or false })
Expand Down Expand Up @@ -620,7 +620,7 @@ function TradeQueryGeneratorClass:GeneratePassiveNodeWeights(nodesToTest)
local node = self.itemsTab.build.spec.tree.clusterNodeMap[nodeName] or self.itemsTab.build.spec.tree.notableMap[nodeName]

local baseOutput = self.calcContext.baseOutput
local output = self.calcContext.calcFunc({ addNodes = { [node] = true } }, { requirementsItems = true, requirementsGems = true, skills = true })
local output = self.calcContext.calcFunc({ addNodes = { [node] = true } })
local meanStatDiff = TradeQueryGeneratorClass.WeightedRatioOutputs(baseOutput, output, self.calcContext.options.statWeights) * 1000 - (self.calcContext.baseStatValue or 0)
if meanStatDiff > 0.01 then
t_insert(self.modWeights, { tradeModId = entry.tradeMod.id, weight = meanStatDiff, meanStatDiff = meanStatDiff, invert = false })
Expand Down Expand Up @@ -783,7 +783,7 @@ function TradeQueryGeneratorClass:StartQuery(slot, options)

-- Calculate base output with a blank item
local calcFunc, baseOutput = self.itemsTab.build.calcsTab:GetMiscCalculator()
local baseItemOutput = slot and calcFunc({ repSlotName = slot.slotName, repItem = testItem }, { nodeAlloc = true }) or baseOutput
local baseItemOutput = slot and calcFunc({ repSlotName = slot.slotName, repItem = testItem }) or baseOutput
-- make weights more human readable
local compStatValue = TradeQueryGeneratorClass.WeightedRatioOutputs(baseOutput, baseItemOutput, options.statWeights) * 1000

Expand Down Expand Up @@ -854,7 +854,7 @@ function TradeQueryGeneratorClass:FinishQuery()
end
self.calcContext.testItem:BuildAndParseRaw()

local originalOutput = originalItem and self.calcContext.calcFunc({ repSlotName = self.calcContext.slot.slotName, repItem = self.calcContext.testItem }, { nodeAlloc = true }) or self.calcContext.baseOutput
local originalOutput = originalItem and self.calcContext.calcFunc({ repSlotName = self.calcContext.slot.slotName, repItem = self.calcContext.testItem }) or self.calcContext.baseOutput
local currentStatDiff = TradeQueryGeneratorClass.WeightedRatioOutputs(self.calcContext.baseOutput, originalOutput, self.calcContext.options.statWeights) * 1000 - (self.calcContext.baseStatValue or 0)

-- Sort by mean Stat diff rather than weight to more accurately prioritize stats that can contribute more
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/TreeTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
if selIndex ~= self.activeSpec then
local calcFunc, calcBase = self.build.calcsTab:GetMiscCalculator()
if calcFunc then
local output = calcFunc({ spec = spec }, {})
local output = calcFunc({ spec = spec })
self.build:AddStatComparesToTooltip(tooltip, calcBase, output, "^7Switching to this tree will give you:")
end
if spec.curClassId == self.build.spec.curClassId then
Expand Down Expand Up @@ -1668,7 +1668,7 @@ function TreeTabClass:FindTimelessJewel()
local function generateFallbackWeights(nodes, selection)
local calcFunc, calcBase = self.build.calcsTab:GetMiscCalculator(self.build)
local newList = { }
local baseOutput = calcFunc({ })
local baseOutput = calcFunc()
if baseOutput.Minion then
baseOutput = baseOutput.Minion
end
Expand Down
4 changes: 2 additions & 2 deletions src/Modules/Calcs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function calcs.getMiscCalculator(build)
env.player.output.FullDPS = fullDPS.combinedDPS
env.player.output.FullDotDPS = fullDPS.TotalDotDPS
end
return function(override, accelerate, useFullDPS)
return function(override, useFullDPS)
local env, cachedPlayerDB, cachedEnemyDB, cachedMinionDB = calcs.initEnv(build, "CALCULATOR", override)
-- we need to preserve the override somewhere for use by possible trigger-based build-outs with overrides
env.override = override
Expand All @@ -139,7 +139,7 @@ function calcs.getMiscCalculator(build)
-- prevent upcoming calculation from using Cached Data and thus forcing it to re-calculate new FullDPS roll-up
-- without this, FullDPS increase/decrease when for node/item/gem comparison would be all 0 as it would be comparing
-- A with A (due to cache reuse) instead of A with B
local fullDPS = calcs.calcFullDPS(build, "CALCULATOR", override, { cachedPlayerDB = cachedPlayerDB, cachedEnemyDB = cachedEnemyDB, cachedMinionDB = cachedMinionDB, env = env, accelerate = accelerate })
local fullDPS = calcs.calcFullDPS(build, "CALCULATOR", override, { cachedPlayerDB = cachedPlayerDB, cachedEnemyDB = cachedEnemyDB, cachedMinionDB = cachedMinionDB, env = nil})
env.player.output.SkillDPS = fullDPS.skills
env.player.output.FullDPS = fullDPS.combinedDPS
env.player.output.FullDotDPS = fullDPS.TotalDotDPS
Expand Down

0 comments on commit 90baaff

Please sign in to comment.