From 0e63f18a73754ebf68ebf286a95af222ab058538 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 4 Jul 2022 01:06:57 +0200 Subject: Add utility script to stress-test mapgen --- util/helper_mod/init.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ util/helper_mod/mod.conf | 3 +++ 2 files changed, 54 insertions(+) create mode 100644 util/helper_mod/init.lua create mode 100644 util/helper_mod/mod.conf (limited to 'util/helper_mod') diff --git a/util/helper_mod/init.lua b/util/helper_mod/init.lua new file mode 100644 index 000000000..4da832ed7 --- /dev/null +++ b/util/helper_mod/init.lua @@ -0,0 +1,51 @@ +local mode = core.settings:get("helper_mode") + +if mode == "devtest" then + + -- Provide feedback to script by creating files in world path + core.after(0, function() + io.close(io.open(core.get_worldpath() .. "/startup", "w")) + end) + local function callback(test_ok) + if not test_ok then + io.close(io.open(core.get_worldpath() .. "/test_failure", "w")) + end + io.close(io.open(core.get_worldpath() .. "/done", "w")) + core.request_shutdown("", false, 2) + end + -- If tests are enabled exit when they're done, otherwise exit on player join + if core.settings:get_bool("devtest_unittests_autostart") and core.global_exists("unittests") then + unittests.on_finished = callback + else + core.register_on_joinplayer(function() callback(true) end) + end + +elseif mode == "mapgen" then + + -- Stress-test mapgen by constantly generating new area + local csize = tonumber(core.settings:get("chunksize")) * core.MAP_BLOCKSIZE + local MINP, MAXP = vector.new(0, -csize, 0), vector.new(csize*3, csize*2, csize) + local DIR = "x" + local pstart = vector.new(0, 0, 0) + local next_, callback + next_ = function(arg) + print("emerging " .. core.pos_to_string(pstart)) + core.emerge_area( + vector.add(pstart, MINP), vector.add(pstart, MAXP), + callback, arg + ) + end + local trig = {} + callback = function(blockpos, action, calls_rem, n) + if action == core.EMERGE_CANCELLED or action == core.EMERGE_ERRORED then + return + end + if calls_rem <= 20 and not trig[n] then + trig[n] = true + pstart[DIR] = pstart[DIR] + (MAXP[DIR] - MINP[DIR]) + next_(n + 1) + end + end + core.after(0, next_, 1) + +end diff --git a/util/helper_mod/mod.conf b/util/helper_mod/mod.conf new file mode 100644 index 000000000..efdd9eaf3 --- /dev/null +++ b/util/helper_mod/mod.conf @@ -0,0 +1,3 @@ +name = helper_mod +description = Helper used by various test scripts +optional_depends = unittests -- cgit v1.2.3