]> git.lizzy.rs Git - minetest.git/blob - util/helper_mod/init.lua
Expose dtime_s to LBM handler
[minetest.git] / util / helper_mod / init.lua
1 local mode = core.settings:get("helper_mode")
2
3 if mode == "devtest" then
4
5         -- Provide feedback to script by creating files in world path
6         core.after(0, function()
7                 io.close(io.open(core.get_worldpath() .. "/startup", "w"))
8         end)
9         local function callback(test_ok)
10                 if not test_ok then
11                         io.close(io.open(core.get_worldpath() .. "/test_failure", "w"))
12                 end
13                 io.close(io.open(core.get_worldpath() .. "/done", "w"))
14                 core.request_shutdown("", false, 2)
15         end
16         -- If tests are enabled exit when they're done, otherwise exit on player join
17         if core.settings:get_bool("devtest_unittests_autostart") and core.global_exists("unittests") then
18                 unittests.on_finished = callback
19         else
20                 core.register_on_joinplayer(function() callback(true) end)
21         end
22
23 elseif mode == "mapgen" then
24
25         -- Stress-test mapgen by constantly generating new area
26         local csize = tonumber(core.settings:get("chunksize")) * core.MAP_BLOCKSIZE
27         local MINP, MAXP = vector.new(0, -csize, 0), vector.new(csize*3, csize*2, csize)
28         local DIR = "x"
29         local pstart = vector.new(0, 0, 0)
30         local next_, callback
31         next_ = function(arg)
32                 print("emerging " .. core.pos_to_string(pstart))
33                 core.emerge_area(
34                         vector.add(pstart, MINP), vector.add(pstart, MAXP),
35                         callback, arg
36                 )
37         end
38         local trig = {}
39         callback = function(blockpos, action, calls_rem, n)
40                 if action == core.EMERGE_CANCELLED or action == core.EMERGE_ERRORED then
41                         return
42                 end
43                 if calls_rem <= 20 and not trig[n] then
44                         trig[n] = true
45                         pstart[DIR] = pstart[DIR] + (MAXP[DIR] - MINP[DIR])
46                         next_(n + 1)
47                 end
48         end
49         core.after(0, next_, 1)
50
51 end