From 6107fd1f664216c2a25ca40c517a784c3a4214a7 Mon Sep 17 00:00:00 2001 From: Zemtzov7 <72821250+zmv7@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:18:11 +0500 Subject: [PATCH 1/2] Set proper callback origin to globalstep_func --- mesecons/actionqueue.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mesecons/actionqueue.lua b/mesecons/actionqueue.lua index 72b464df..0fc27ec4 100644 --- a/mesecons/actionqueue.lua +++ b/mesecons/actionqueue.lua @@ -127,6 +127,10 @@ do end -- replace this globalstep function minetest.registered_globalsteps[globalstep_func_index] = globalstep_func + minetest.callback_origins[globalstep_func] = { + mod = minetest.get_current_modname() or "mesecons", + name = "register_globalstep" + } end) end From 5ffdd7a1669ff073a3946bcb671dea7878654ca2 Mon Sep 17 00:00:00 2001 From: zmv7 Date: Wed, 14 Aug 2024 19:38:20 +0500 Subject: [PATCH 2/2] Move the delay into the main globalstep_func --- mesecons/actionqueue.lua | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/mesecons/actionqueue.lua b/mesecons/actionqueue.lua index 0fc27ec4..b3118f06 100644 --- a/mesecons/actionqueue.lua +++ b/mesecons/actionqueue.lua @@ -70,7 +70,17 @@ end -- However, even that does not work in some cases, that's why we delay the time the globalsteps -- start to be execute by 4 seconds +local m_time = 0 +local resumetime = mesecon.setting("resumetime", 4) + local function globalstep_func(dtime) + -- don't even try if server has not been running for XY seconds; resumetime = time to wait + -- after starting the server before processing the ActionQueue, don't set this too low + if m_time < resumetime then + m_time = m_time + dtime + return + end + local actions = queue.actions -- split into two categories: -- actions_now: actions to execute now @@ -112,27 +122,7 @@ local function globalstep_func(dtime) end end --- delay the time the globalsteps start to be execute by 4 seconds -do - local m_time = 0 - local resumetime = mesecon.setting("resumetime", 4) - local globalstep_func_index = #minetest.registered_globalsteps + 1 - - minetest.register_globalstep(function(dtime) - m_time = m_time + dtime - -- don't even try if server has not been running for XY seconds; resumetime = time to wait - -- after starting the server before processing the ActionQueue, don't set this too low - if m_time < resumetime then - return - end - -- replace this globalstep function - minetest.registered_globalsteps[globalstep_func_index] = globalstep_func - minetest.callback_origins[globalstep_func] = { - mod = minetest.get_current_modname() or "mesecons", - name = "register_globalstep" - } - end) -end +minetest.register_globalstep(globalstep_func) function queue:execute(action) -- ignore if action queue function name doesn't exist,