forked from Mirrorlandia_minetest/mesecons
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,12 +80,14 @@ 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
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
if MESECONS_GLOBALSTEP then -- trying to enable resuming with globalstep disabled would cause an endless loop
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
-- if area is not loaded, keep trying
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
if minetest.get_node_or_nil(np) == nil then
|
-- if area is not loaded, keep trying
|
||||||
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
|
if minetest.get_node_or_nil(np) == nil then
|
||||||
return
|
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -107,11 +109,13 @@ 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
|
||||||
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
if MESECONS_GLOBALSTEP then
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
for _, rule in ipairs(mesecon:flattenrules(rules)) do
|
||||||
if minetest.get_node_or_nil(np) == nil then
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
|
if minetest.get_node_or_nil(np) == nil then
|
||||||
return
|
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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)
|
||||||
mesecon:turnon(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)
|
||||||
|
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)
|
||||||
mesecon:turnoff(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)
|
||||||
|
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