Skip to content
Permalink
Browse files
Fix delayers and disable resuming if not using MESECONS_GLOBALSTEP
  • Loading branch information
Jeija committed Jan 19, 2014
1 parent a6bd955 commit a632a8abc80155118708108d846f52bbc230f257
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
@@ -20,7 +20,7 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
priority=priority}

-- 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)
return
end
@@ -64,7 +64,7 @@ end
local m_time = 0
minetest.register_globalstep(function (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_now={}

@@ -80,12 +80,14 @@ mesecon.queue:add_function("receptor_on", function (pos, rules)
rules = rules or mesecon.rules.default

-- 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
local np = mesecon:addPosRule(pos, rule)
-- if area is not loaded, keep trying
if minetest.get_node_or_nil(np) == nil then
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
return
if MESECONS_GLOBALSTEP then -- trying to enable resuming with globalstep disabled would cause an endless loop
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule)
-- if area is not loaded, keep trying
if minetest.get_node_or_nil(np) == nil then
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
return
end
end
end

@@ -107,11 +109,13 @@ mesecon.queue:add_function("receptor_off", function (pos, rules)
rules = rules or mesecon.rules.default

-- 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
local np = mesecon:addPosRule(pos, rule)
if minetest.get_node_or_nil(np) == nil then
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
return
if MESECONS_GLOBALSTEP then
for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule)
if minetest.get_node_or_nil(np) == nil then
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
return
end
end
end

@@ -412,7 +412,9 @@ function mesecon:turnon(pos, rulename, recdepth)
end

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)

function mesecon:turnoff(pos, rulename, recdepth)
@@ -453,7 +455,9 @@ function mesecon:turnoff(pos, rulename, recdepth)
end

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)


@@ -7,3 +7,5 @@ PISTON_MAXIMUM_PUSH = 15
MOVESTONE_MAXIMUM_PUSH = 100
MESECONS_GLOBALSTEP = true -- true = receptors/effectors won't be updated
-- 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

0 comments on commit a632a8a

Please sign in to comment.