mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-27 02:40:18 +01:00
Fix delayers and disable resuming if not using MESECONS_GLOBALSTEP
This commit is contained in:
parent
a6bd955449
commit
a632a8abc8
@ -20,7 +20,7 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
|
|||||||
priority=priority}
|
priority=priority}
|
||||||
|
|
||||||
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
|
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
|
||||||
if not MESECONS_GLOBALSTEP then
|
if not MESECONS_GLOBALSTEP and action.time == 0 then
|
||||||
mesecon.queue:execute(action)
|
mesecon.queue:execute(action)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -64,7 +64,7 @@ end
|
|||||||
local m_time = 0
|
local m_time = 0
|
||||||
minetest.register_globalstep(function (dtime)
|
minetest.register_globalstep(function (dtime)
|
||||||
m_time = m_time + dtime
|
m_time = m_time + dtime
|
||||||
if (m_time < 5) then return end -- don't even try if server has not been running for 2 seconds
|
if (m_time < MESECONS_RESUMETIME) then return end -- don't even try if server has not been running for XY seconds
|
||||||
local actions = mesecon:tablecopy(mesecon.queue.actions)
|
local actions = mesecon:tablecopy(mesecon.queue.actions)
|
||||||
local actions_now={}
|
local actions_now={}
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ mesecon.queue:add_function("receptor_on", function (pos, rules)
|
|||||||
rules = rules or mesecon.rules.default
|
rules = rules or mesecon.rules.default
|
||||||
|
|
||||||
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
|
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
|
||||||
|
if MESECONS_GLOBALSTEP then -- trying to enable resuming with globalstep disabled would cause an endless loop
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
-- if area is not loaded, keep trying
|
-- if area is not loaded, keep trying
|
||||||
@ -88,6 +89,7 @@ mesecon.queue:add_function("receptor_on", function (pos, rules)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- execute action
|
-- execute action
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
@ -107,6 +109,7 @@ mesecon.queue:add_function("receptor_off", function (pos, rules)
|
|||||||
rules = rules or mesecon.rules.default
|
rules = rules or mesecon.rules.default
|
||||||
|
|
||||||
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
|
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
|
||||||
|
if MESECONS_GLOBALSTEP then
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
if minetest.get_node_or_nil(np) == nil then
|
if minetest.get_node_or_nil(np) == nil then
|
||||||
@ -114,6 +117,7 @@ mesecon.queue:add_function("receptor_off", function (pos, rules)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
|
@ -412,7 +412,9 @@ function mesecon:turnon(pos, rulename, recdepth)
|
|||||||
end
|
end
|
||||||
|
|
||||||
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
|
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
|
||||||
|
if (MESECONS_GLOBALSTEP) then -- do not resume if we don't use globalstep - that would cause an endless loop
|
||||||
mesecon:turnon(pos, rulename, recdepth)
|
mesecon:turnon(pos, rulename, recdepth)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mesecon:turnoff(pos, rulename, recdepth)
|
function mesecon:turnoff(pos, rulename, recdepth)
|
||||||
@ -453,7 +455,9 @@ function mesecon:turnoff(pos, rulename, recdepth)
|
|||||||
end
|
end
|
||||||
|
|
||||||
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
|
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
|
||||||
|
if (MESECONS_GLOBALSTEP) then -- do not resume if we don't use globalstep - that would cause an endless loop
|
||||||
mesecon:turnoff(pos, rulename, recdepth)
|
mesecon:turnoff(pos, rulename, recdepth)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,3 +7,5 @@ PISTON_MAXIMUM_PUSH = 15
|
|||||||
MOVESTONE_MAXIMUM_PUSH = 100
|
MOVESTONE_MAXIMUM_PUSH = 100
|
||||||
MESECONS_GLOBALSTEP = true -- true = receptors/effectors won't be updated
|
MESECONS_GLOBALSTEP = true -- true = receptors/effectors won't be updated
|
||||||
-- until next globalstep, decreases server load
|
-- until next globalstep, decreases server load
|
||||||
|
MESECONS_RESUMETIME = 4 -- time to wait when starting the server before
|
||||||
|
-- processing the ActionQueue, don't set this too low
|
||||||
|
Loading…
Reference in New Issue
Block a user