aboutsummaryrefslogtreecommitdiff
path: root/util/helper_mod
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-07-04 01:06:57 +0200
committerGitHub <noreply@github.com>2022-07-04 01:06:57 +0200
commit0e63f18a73754ebf68ebf286a95af222ab058538 (patch)
tree5fd649939acf0dee5761cc8bf5b8b91dd821b3c5 /util/helper_mod
parentfc3460470aec8d73317d2b35edf195bfeec2852c (diff)
downloadminetest-0e63f18a73754ebf68ebf286a95af222ab058538.tar.gz
minetest-0e63f18a73754ebf68ebf286a95af222ab058538.tar.bz2
minetest-0e63f18a73754ebf68ebf286a95af222ab058538.zip
Add utility script to stress-test mapgen
Diffstat (limited to 'util/helper_mod')
-rw-r--r--util/helper_mod/init.lua51
-rw-r--r--util/helper_mod/mod.conf3
2 files changed, 54 insertions, 0 deletions
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