Skip to content

Commit

Permalink
add benchmark test for autoTransformItems
Browse files Browse the repository at this point in the history
  • Loading branch information
pennaor committed Jun 15, 2024
1 parent 4ba4b7b commit 2060f22
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,36 @@ local function addItemsToAutoTransform(data)
end
end

local function addSpikesTest()
local load = 25
local centerX = 32636
local centerY = 31996
local centerZ = 7
local tiles = {}
for x = -load, load do
for y = -load, load do
local position = Position(centerX + x, centerY + y, centerZ)
local tile = position:getTile()
if tile and tile:getGround() then
tiles[#tiles+1] = tile
end
end
end
local count = 0
for _, tile in ipairs(tiles) do
if tile:addItem(2147) then
autoTransformItems({ 2147, 2148 }, tile:getPosition(), math.random(3), onTransformIntoSpikes)
count = count + 1
end
end
logger.info("[addSpikesTest]: added {} items to auto transform", count)
end

local addItemsToAutoTransformEvent = GlobalEvent("addItemsToAutoTransform.onStartup")
function addItemsToAutoTransformEvent.onStartup()
addItemsToAutoTransform(slitsBlades)
addItemsToAutoTransform(holesSpikes)
addSpikesTest()
end

addItemsToAutoTransformEvent:register()
2 changes: 2 additions & 0 deletions data/scripts/globalevents/auto_transform_items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ end
local autoTransformItemsEvent = GlobalEvent("autoTransformItems.onThink")

function autoTransformItemsEvent.onThink(interval, lastExecution)
local start = os.clock()
for defaultIntervalMs, data in pairs(itemsToTransform) do
data.currentMs = data.currentMs + interval
if data.currentMs >= defaultIntervalMs then
Expand Down Expand Up @@ -82,6 +83,7 @@ function autoTransformItemsEvent.onThink(interval, lastExecution)
end
end
end
logger.info("[autoTransformItems] elapsed time: {} secs", os.clock() - start)
return true
end

Expand Down

0 comments on commit 2060f22

Please sign in to comment.