aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--actionqueue.lua74
-rw-r--r--globalstep.lua43
-rw-r--r--init.lua3
3 files changed, 1 insertions, 119 deletions
diff --git a/actionqueue.lua b/actionqueue.lua
deleted file mode 100644
index 3f1862f..0000000
--- a/actionqueue.lua
+++ /dev/null
@@ -1,74 +0,0 @@
--- smarter mesecons actionqueue
--- TODO: create PR if ot works properly
-
-
--- execute the stored functions on a globalstep
--- if however, the pos of a function is not loaded (get_node_or_nil == nil), do NOT execute the function
--- this makes sure that resuming mesecons circuits when restarting minetest works fine
--- However, even that does not work in some cases, that's why we delay the time the globalsteps
--- start to be execute by 5 seconds
-local get_highest_priority = function (actions)
- local highestp = -1
- local highesti
- for i, ac in ipairs(actions) do
- if ac.priority > highestp then
- highestp = ac.priority
- highesti = i
- end
- end
-
- return highesti
-end
-
-local m_time = 0
-local resumetime = mesecon.setting("resumetime", 4)
-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
-
- if not mesecons_debug.enabled then
- return
- end
-
- local actions = mesecon.tablecopy(mesecon.queue.actions)
- local actions_now={}
-
- mesecon.queue.actions = {}
-
- -- sort actions into two categories:
- -- those toexecute now (actions_now) and those to execute later (mesecon.queue.actions)
- for _, ac in ipairs(actions) do
- if ac.time > 0 then
- ac.time = ac.time - dtime -- executed later
- table.insert(mesecon.queue.actions, ac)
- else
- table.insert(actions_now, ac)
- end
- end
-
- if #actions_now > 30000 then
- -- too much actions, purge them
- return
- end
-
- local t0 = minetest.get_us_time()
-
- while(#actions_now > 0) do -- execute highest priorities first, until all are executed
- local hp = get_highest_priority(actions_now)
- local action = actions_now[hp]
-
- local t1 = minetest.get_us_time()
- local diff = t1 - t0
- if diff > 75000 then
- -- execute remaining actions in next globalstep
- table.insert(mesecon.queue.actions, 1, action)
- else
- mesecon.queue:execute(action)
- table.remove(actions_now, hp)
- end
-
- end
-end)
-
diff --git a/globalstep.lua b/globalstep.lua
deleted file mode 100644
index cd0d95d..0000000
--- a/globalstep.lua
+++ /dev/null
@@ -1,43 +0,0 @@
-
--- globalstep on/off
-local i = 0
-for _, globalstep in ipairs(minetest.registered_globalsteps) do
- local info = minetest.callback_origins[globalstep]
- if not info then
- break
- end
-
- local modname = info.mod
-
- if modname == "mesecons" then
- i = i + 1
- -- 1 = execute globalstep
- -- 2 = cooldown globalstep
- if i == 1 then
- local fn = function(dtime)
- globalstep(dtime)
- end
-
- minetest.callback_origins[fn] = info
- minetest.registered_globalsteps[i] = fn
- end
- end
-end
-
--- execute()
-local old_execute = mesecon.queue.execute
-mesecon.queue.execute = function(...)
- if mesecons_debug.enabled then
- old_execute(...)
- end
-end
-
--- add_action()
-local old_add_action = mesecon.queue.add_action
-mesecon.queue.add_action = function(...)
- if mesecons_debug.enabled then
- old_add_action(...)
- end
-end
-
-
diff --git a/init.lua b/init.lua
index 8a3eb3a..6653914 100644
--- a/init.lua
+++ b/init.lua
@@ -10,7 +10,6 @@ dofile(MP.."/api_action_on.lua")
dofile(MP.."/api_nodetimer.lua")
dofile(MP.."/register.lua")
dofile(MP.."/flush.lua")
-dofile(MP.."/globalstep.lua")
-dofile(MP.."/actionqueue.lua")
+
print("[OK] mesecons_debug loaded")