diff --git a/src/Classes/CalcsTab.lua b/src/Classes/CalcsTab.lua index 094c7c155b..fe751b4674 100644 --- a/src/Classes/CalcsTab.lua +++ b/src/Classes/CalcsTab.lua @@ -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 = { } @@ -494,11 +494,17 @@ 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 @@ -506,6 +512,13 @@ function CalcsTabClass:PowerBuilder() 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 @@ -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 @@ -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) diff --git a/src/Classes/TreeTab.lua b/src/Classes/TreeTab.lua index c19edf0223..28bafbc548 100644 --- a/src/Classes/TreeTab.lua +++ b/src/Classes/TreeTab.lua @@ -278,10 +278,38 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build) end end) self.controls.powerReportList.shown = false + -- Progress callback from the CalcsTab power builder coroutine + self.powerBuilderToastIndex = nil + 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 Tree... (%d%%)", percent) or "Building Tree..." + + self.controls.powerReportList.label = message + self.lastProgressToastUpdate = now + if self.powerBuilderToastIndex then + if main.toastMessages[self.powerBuilderToastIndex] and main.toastMessages[self.powerBuilderToastIndex]:match("^Building Tree") then + main.toastMessages[self.powerBuilderToastIndex] = message + end + else + t_insert(main.toastMessages, message) + self.powerBuilderToastIndex = 1 + 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) + if self.powerBuilderToastIndex and main.toastMessages[self.powerBuilderToastIndex] and main.toastMessages[self.powerBuilderToastIndex]:match("^Building Tree") then + main.toastMode = "HIDING" + main.toastStart = GetTime() + end + self.powerBuilderToastIndex = nil 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.")