summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeija <jeija@mesecons.net>2014-01-11 16:46:27 +0100
committerJeija <jeija@mesecons.net>2014-01-11 16:46:27 +0100
commit1083539e9b82c729687f012e741614d1fc216757 (patch)
tree19daf44da46c8c9227952e550082c401b5866f85
parent6afded8284e42c8b976d8685f537d8d54264277a (diff)
downloadmesecons-1083539e9b82c729687f012e741614d1fc216757.tar
mesecons-1083539e9b82c729687f012e741614d1fc216757.tar.gz
mesecons-1083539e9b82c729687f012e741614d1fc216757.tar.bz2
mesecons-1083539e9b82c729687f012e741614d1fc216757.tar.xz
mesecons-1083539e9b82c729687f012e741614d1fc216757.zip
Resume turnon/off calls as soon as area is loaded in case turnon/off calls end in unloaded territory
-rw-r--r--mesecons/actionqueue.lua8
-rw-r--r--mesecons/internal.lua48
2 files changed, 46 insertions, 10 deletions
diff --git a/mesecons/actionqueue.lua b/mesecons/actionqueue.lua
index 1c02b46..66e9fd7 100644
--- a/mesecons/actionqueue.lua
+++ b/mesecons/actionqueue.lua
@@ -20,24 +20,28 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
priority=priority}
- --print(dump(action))
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
if not MESECONS_GLOBALSTEP then
mesecon.queue:execute(action)
return
end
+ local toremove = nil
-- Otherwise, add the action to the queue
if overwritecheck then -- check if old action has to be overwritten / removed:
for i, ac in ipairs(mesecon.queue.actions) do
if(mesecon:cmpPos(pos, ac.pos)
and mesecon:cmpAny(overwritecheck, ac.owcheck)) then
- table.remove(mesecon.queue.actions, i)
+ toremove = i
break
end
end
end
+ if (toremove ~= nil) then
+ table.remove(mesecon.queue.actions, i)
+ end
+
table.insert(mesecon.queue.actions, action)
end
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index f713a7c..8e58d73 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -368,6 +368,12 @@ end
function mesecon:turnon(pos, rulename, recdepth)
recdepth = recdepth or 2
local node = minetest.get_node(pos)
+
+ if(node.name == "ignore") then
+ -- try turning on later again
+ mesecon.queue:add_action(
+ pos, "turnon", {rulename, recdepth + 1}, nil, rulename)
+ end
if mesecon:is_conductor_off(node, rulename) then
local rules = mesecon:conductor_get_rules(node)
@@ -385,10 +391,16 @@ function mesecon:turnon(pos, rulename, recdepth)
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
local np = mesecon:addPosRule(pos, rule)
- local rulenames = mesecon:rules_link_rule_all(pos, rule)
-
- for _, rulename in ipairs(rulenames) do
- mesecon:turnon(np, rulename, recdepth + 1)
+ if(minetest.get_node(np).name == "ignore") then
+ -- try turning on later again
+ mesecon.queue:add_action(
+ np, "turnon", {rulename, recdepth + 1}, nil, rulename)
+ else
+ local rulenames = mesecon:rules_link_rule_all(pos, rule)
+
+ for _, rulename in ipairs(rulenames) do
+ mesecon:turnon(np, rulename, recdepth + 1)
+ end
end
end
elseif mesecon:is_effector(node.name) then
@@ -399,20 +411,36 @@ function mesecon:turnon(pos, rulename, recdepth)
end
end
+mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
+ mesecon:turnon(pos, rulename, recdepth)
+end)
+
function mesecon:turnoff(pos, rulename, recdepth)
recdepth = recdepth or 0
local node = minetest.get_node(pos)
+ if(node.name == "ignore") then
+ -- try turning on later again
+ mesecon.queue:add_action(
+ pos, "turnoff", {rulename, recdepth + 1}, nil, rulename)
+ end
+
if mesecon:is_conductor_on(node, rulename) then
local rules = mesecon:conductor_get_rules(node)
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node, rulename), param2 = node.param2})
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
local np = mesecon:addPosRule(pos, rule)
- local rulenames = mesecon:rules_link_rule_all(pos, rule)
-
- for _, rulename in ipairs(rulenames) do
- mesecon:turnoff(np, rulename, recdepth + 1)
+ if(minetest.get_node(np).name == "ignore") then
+ -- try turning on later again
+ mesecon.queue:add_action(
+ np, "turnoff", {rulename, recdepth + 1}, nil, rulename)
+ else
+ local rulenames = mesecon:rules_link_rule_all(pos, rule)
+
+ for _, rulename in ipairs(rulenames) do
+ mesecon:turnoff(np, rulename, recdepth + 1)
+ end
end
end
elseif mesecon:is_effector(node.name) then
@@ -424,6 +452,10 @@ function mesecon:turnoff(pos, rulename, recdepth)
end
end
+mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
+ mesecon:turnoff(pos, rulename, recdepth)
+end)
+
function mesecon:connected_to_receptor(pos, rulename)
local node = minetest.get_node(pos)