Skip to content

Commit

Permalink
Added test function from cBlockArea and class cStopWatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Seadragon91 committed Oct 6, 2019
1 parent 77f40c9 commit ce54af7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Commands/Selection.lua
Expand Up @@ -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
Expand All @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions 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

0 comments on commit ce54af7

Please sign in to comment.