Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/Classes/CalcsTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ end

-- Estimate the offensive and defensive power of all unallocated nodes
function CalcsTabClass:PowerBuilder()
--local timer_start = GetTime()
-- local timer_start = GetTime()
local useFullDPS = self.powerStat and self.powerStat.stat == "FullDPS"
local calcFunc, calcBase = self:GetMiscCalculator()
local cache = { }
Expand All @@ -494,18 +494,31 @@ function CalcsTabClass:PowerBuilder()
end

local start = GetTime()
local nodeIndex = 0
local total = 0

for nodeId, node in pairs(self.build.spec.nodes) do
wipeTable(node.power)
if node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
distanceMap[node.pathDist or 1000] = distanceMap[node.pathDist or 1000] or { }
distanceMap[node.pathDist or 1000][nodeId] = node
if not (self.nodePowerMaxDepth and self.nodePowerMaxDepth < node.pathDist) then
total = total + 1
end
end
end
for distance, nodes in pairs(distanceMap) do
t_insert(distanceList, { distance, nodes })
end
distanceMap = nil
table.sort(distanceList, function(a, b) return a[1] < b[1] end)
-- Count eligible cluster nodes
for _, node in pairs(self.build.spec.tree.clusterNodeMap) do
if not node.alloc and node.modKey ~= "" and not self.mainEnv.grantedPassives[node.id] then
total = total + 1
end
end

for _, data in ipairs(distanceList) do
local distance, nodes = data[1], data[2]
if self.nodePowerMaxDepth and self.nodePowerMaxDepth < distance then
Expand Down Expand Up @@ -559,7 +572,11 @@ function CalcsTabClass:PowerBuilder()
end
end
end
nodeIndex = nodeIndex + 1
if coroutine.running() and GetTime() - start > 100 then
if self.build.powerBuilderProgressCallback then
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
end
coroutine.yield()
start = GetTime()
end
Expand All @@ -581,15 +598,19 @@ function CalcsTabClass:PowerBuilder()
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
node.power.singleStat = self:CalculatePowerStat(self.powerStat, output, calcBase)
end
end
if coroutine.running() and GetTime() - start > 100 then
coroutine.yield()
start = GetTime()
nodeIndex = nodeIndex + 1
if coroutine.running() and GetTime() - start > 100 then
if self.build.powerBuilderProgressCallback then
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
end
coroutine.yield()
start = GetTime()
end
end
end
self.powerMax = newPowerMax
self.powerBuilderInitialized = true
--ConPrintf("Power Build time: %d ms", GetTime() - timer_start)
-- ConPrintf("Power Build time: %d ms", GetTime() - timer_start)
end

function CalcsTabClass:CalculatePowerStat(selection, original, modified)
Expand Down
46 changes: 46 additions & 0 deletions src/Classes/TreeTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ local s_gsub = string.gsub
local s_byte = string.byte
local dkjson = require "dkjson"

-- Helper function to find toast index by content pattern
-- TODO: remove this when when we can control toast notifications better
local function findToastIndex(pattern)
for i, msg in ipairs(main.toastMessages) do
if msg:match(pattern) then
return i
end
end
return nil
end

local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
self.ControlHost()

Expand Down Expand Up @@ -278,10 +289,45 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
end
end)
self.controls.powerReportList.shown = false
-- Progress callback from the CalcsTab power builder coroutine
self.powerBuilderToastActive = false
self.lastProgressToastUpdate = 0
self.build.powerBuilderProgressCallback = function(percent)
local now = GetTime()
if now - self.lastProgressToastUpdate < 100 then
return
end

local message = percent and string.format("Building Power Report... (%d%%)", percent) or "Building Power Report..."

self.controls.powerReportList.label = message
self.lastProgressToastUpdate = now
local toastIndex = findToastIndex("^Building Power Report")
if toastIndex then
main.toastMessages[toastIndex] = message
else
t_insert(main.toastMessages, message)
self.powerBuilderToastActive = true
end
end
-- Completion callback from the CalcsTab power builder coroutine
self.build.powerBuilderCallback = function()
local powerStat = self.build.calcsTab.powerStat or data.powerStatList[1]
local report = self:BuildPowerReportList(powerStat)
self.controls.powerReportList:SetReport(powerStat, report)
local toastIndex = findToastIndex("^Building Power Report")
if self.powerBuilderToastActive and toastIndex then
-- Remove the toast from the queue instead of triggering hide animation
-- This prevents issues when the toast is not currently displayed (queued behind another toast)
-- TODO: look into allowing toast notifications to stack and have UUID's we can control them better
if toastIndex == 1 then
main.toastMode = "HIDING"
main.toastStart = GetTime()
else
t_remove(main.toastMessages, toastIndex)
end
end
self.powerBuilderToastActive = false
end

self.controls.specConvertText = new("LabelControl", { "BOTTOMLEFT", self.controls.specSelect, "TOPLEFT" }, { 0, -14, 0, 16 }, "^7This is an older tree version, which may not be fully compatible with the current game version.")
Expand Down