From 2060f22f13c829c752b843c46eaaa959af55889f Mon Sep 17 00:00:00 2001 From: Aluisio Penna Ordones Date: Sat, 15 Jun 2024 15:37:13 -0300 Subject: [PATCH] add benchmark test for autoTransformItems --- .../others/additems_to_auto_transform.lua | 26 +++++++++++++++++++ .../globalevents/auto_transform_items.lua | 2 ++ 2 files changed, 28 insertions(+) diff --git a/data-otservbr-global/scripts/globalevents/others/additems_to_auto_transform.lua b/data-otservbr-global/scripts/globalevents/others/additems_to_auto_transform.lua index 058f7c3ede3..6afcdddf6b3 100644 --- a/data-otservbr-global/scripts/globalevents/others/additems_to_auto_transform.lua +++ b/data-otservbr-global/scripts/globalevents/others/additems_to_auto_transform.lua @@ -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() diff --git a/data/scripts/globalevents/auto_transform_items.lua b/data/scripts/globalevents/auto_transform_items.lua index 45c08655968..2a085f7eca5 100644 --- a/data/scripts/globalevents/auto_transform_items.lua +++ b/data/scripts/globalevents/auto_transform_items.lua @@ -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 @@ -82,6 +83,7 @@ function autoTransformItemsEvent.onThink(interval, lastExecution) end end end + logger.info("[autoTransformItems] elapsed time: {} secs", os.clock() - start) return true end