diff --git a/Commands/Selection.lua b/Commands/Selection.lua index 51e5f8b..2ff26da 100755 --- a/Commands/Selection.lua +++ b/Commands/Selection.lua @@ -105,6 +105,8 @@ function HandleDistrCommand(a_Split, a_Player) local TotalCount = Area:GetVolume() local BlockCounts = {} + local sw = cStopWatch.new() + sw:Start() for X = 0, SizeX do for Y = 0, SizeY do for Z = 0, SizeZ do @@ -113,6 +115,27 @@ function HandleDistrCommand(a_Split, a_Player) end end end + a_Player:SendMessage("Current: " .. tostring(sw:GetElapsedMilliseconds())) + BlockCounts = {} + + sw = cStopWatch.new() + sw:Start() + local blocksCounted = Area:CountAllNonAirBlocksAndMetas() + local nonAirBlocks = 0 + for idMeta, amount in pairs(blocksCounted) do + local tbIdMeta = StringSplit(idMeta, "-") + local BlockType = tonumber(tbIdMeta[1]) + -- local meta = tonumber(tbIdMeta[2]) + if BlockCounts[BlockType] == nil then + BlockCounts[BlockType] = amount + nonAirBlocks = nonAirBlocks + amount + else + BlockCounts[BlockType] = BlockCounts[BlockType] + amount + nonAirBlocks = nonAirBlocks + amount + end + end + BlockCounts[0] = TotalCount - nonAirBlocks + a_Player:SendMessage("New: " .. tostring(sw:GetElapsedMilliseconds())) -- Generate the output. -- Sort records by count. diff --git a/Commands/StopWatch.lua b/Commands/StopWatch.lua new file mode 100644 index 0000000..62c61ad --- /dev/null +++ b/Commands/StopWatch.lua @@ -0,0 +1,33 @@ +cStopWatch = {} +cStopWatch.__index = cStopWatch + +function cStopWatch.new() + local self = setmetatable({}, cStopWatch) + return self +end + + +function cStopWatch:Start() + self.m_IsRunning = true + self.m_Start = cRoot:Get():GetCurrentTimeInMillseconds() +end + + + +function cStopWatch:Stop() + self.m_IsRunning = false + self.m_Stop = cRoot:Get():GetCurrentTimeInMillseconds() +end + + + +function cStopWatch:GetElapsedMilliseconds() + if self.m_Start == nil then + return 0 + end + if self.m_IsRunning then + return cRoot:Get():GetCurrentTimeInMillseconds() - self.m_Start + else + return self.m_Stop - self.m_Start + end +end