Fix #155 (option 2 used). Remove non-ActionQueue system. Enable overheat for more than 20 actions per second on lua- / microcontrollers and gates.

Fix a bug where a burnt luacontroller didn't have the correct pin-states as the burnt controller does not register any changes from outside.
This commit is contained in:
Jeija 2014-04-20 21:44:58 +02:00
parent 1f66687580
commit 300abcb587
8 changed files with 85 additions and 117 deletions

View File

@ -19,12 +19,6 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil, owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
priority=priority} priority=priority}
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
if not MESECONS_GLOBALSTEP and action.time == 0 then
mesecon.queue:execute(action)
return
end
local toremove = nil local toremove = nil
-- Otherwise, add the action to the queue -- Otherwise, add the action to the queue
if overwritecheck then -- check if old action has to be overwritten / removed: if overwritecheck then -- check if old action has to be overwritten / removed:

View File

@ -79,7 +79,6 @@ 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,7 +87,6 @@ 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
@ -108,7 +106,6 @@ 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
@ -116,7 +113,6 @@ 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)

View File

@ -412,9 +412,7 @@ 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)
@ -455,9 +453,7 @@ 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)

View File

@ -1,3 +1,5 @@
-- Dig and place services
mesecon.on_placenode = function (pos, node) mesecon.on_placenode = function (pos, node)
-- Receptors: Send on signal when active -- Receptors: Send on signal when active
if mesecon:is_receptor_on(node.name) then if mesecon:is_receptor_on(node.name) then
@ -37,15 +39,38 @@ mesecon.on_dignode = function (pos, node)
end end
end end
minetest.register_abm({
nodenames = {"group:overheat"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
meta:set_int("heat",0)
end,
})
minetest.register_on_placenode(mesecon.on_placenode) minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode) minetest.register_on_dignode(mesecon.on_dignode)
-- Overheating service for fast circuits
-- returns true if heat is too high
mesecon.do_overheat = function(pos)
local meta = minetest.get_meta(pos)
local heat = meta:get_int("heat") or 0
heat = heat + 1
meta:set_int("heat", heat)
if heat < OVERHEAT_MAX then
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
else
return true
end
return false
end
mesecon.queue:add_function("cooldown", function (pos)
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
return -- node has been moved, this one does not use overheating - ignore
end
local meta = minetest.get_meta(pos)
local heat = meta:get_int("heat")
if (heat > 0) then
meta:set_int("heat", heat - 1)
end
end)

View File

@ -5,7 +5,8 @@ PRESSURE_PLATE_INTERVAL = 0.1
OBJECT_DETECTOR_RADIUS = 6 OBJECT_DETECTOR_RADIUS = 6
PISTON_MAXIMUM_PUSH = 15 PISTON_MAXIMUM_PUSH = 15
MOVESTONE_MAXIMUM_PUSH = 100 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 MESECONS_RESUMETIME = 4 -- time to wait when starting the server before
-- processing the ActionQueue, don't set this too low -- processing the ActionQueue, don't set this too low
OVERHEAT_MAX = 20 -- maximum heat of any component that directly sends an output
-- signal when the input changes (e.g. luacontroller, gates)
-- Unit: actions per second, checks are every 1 second

View File

@ -47,9 +47,7 @@ function set_gate(pos, on)
gate = get_gate(pos) gate = get_gate(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if on ~= gate_state(pos) then if on ~= gate_state(pos) then
yc_heat(meta) if mesecon.do_overheat(pos) then
--minetest.after(0.5, yc_cool, meta)
if yc_overheat(meta) then
pop_gate(pos) pop_gate(pos)
else else
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -78,7 +76,9 @@ end
function pop_gate(pos) function pop_gate(pos)
gate = get_gate(pos) gate = get_gate(pos)
minetest.remove_node(pos) minetest.remove_node(pos)
minetest.after(0.2, yc_overheat_off, pos) minetest.after(0.2, function (pos)
mesecon:receptor_off(pos, mesecon.rules.flat)
end , pos) -- wait for pending parsings
minetest.add_item(pos, "mesecons_gates:"..gate.."_off") minetest.add_item(pos, "mesecons_gates:"..gate.."_off")
end end
@ -153,7 +153,6 @@ for _, gate in ipairs(gates) do
walkable = true, walkable = true,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("heat", 0)
update_gate(pos) update_gate(pos)
end, end,
groups = groups, groups = groups,
@ -221,4 +220,3 @@ minetest.register_craft({
{'mesecons:mesecon', '', ''}, {'mesecons:mesecon', '', ''},
}, },
}) })

View File

@ -122,30 +122,6 @@ end
-- Overheat stuff -- -- Overheat stuff --
-------------------- --------------------
local heat = function (meta) -- warm up
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h + 1)
end
end
--local cool = function (meta) -- cool down after a while
-- h = meta:get_int("heat")
-- if h ~= nil then
-- meta:set_int("heat", h - 1)
-- end
--end
local overheat = function (meta) -- determine if too hot
h = meta:get_int("heat")
if h == nil then return true end -- if nil then overheat
if h > 40 then
return true
else
return false
end
end
local overheat_off = function(pos) local overheat_off = function(pos)
mesecon:receptor_off(pos, mesecon.rules.flat) mesecon:receptor_off(pos, mesecon.rules.flat)
end end
@ -232,6 +208,8 @@ local create_environment = function(pos, mem, event)
mem = mem, mem = mem,
tostring = tostring, tostring = tostring,
tonumber = tonumber, tonumber = tonumber,
heat = minetest.get_meta(pos):get_int("heat"),
heat_max = OVERHEAT_MAX,
string = { string = {
byte = string.byte, byte = string.byte,
char = string.char, char = string.char,
@ -299,11 +277,8 @@ local create_sandbox = function (code, env)
return f return f
end end
local do_overheat = function (pos, meta) local lc_overheat = function (pos, meta)
-- Overheat protection if mesecon.do_overheat(pos) then -- if too hot
heat(meta)
--minetest.after(0.5, cool, meta)
if overheat(meta) then
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = BASENAME.."_burnt", param2 = node.param2}) minetest.swap_node(pos, {name = BASENAME.."_burnt", param2 = node.param2})
minetest.after(0.2, overheat_off, pos) -- wait for pending operations minetest.after(0.2, overheat_off, pos) -- wait for pending operations
@ -332,7 +307,7 @@ end
lc_update = function (pos, event) lc_update = function (pos, event)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if do_overheat(pos, meta) then return end if lc_overheat(pos) then return end
-- load code & mem from memory -- load code & mem from memory
local mem = load_memory(meta) local mem = load_memory(meta)
@ -520,7 +495,21 @@ end
end end
end end
--overheated luacontroller ------------------------------
-- overheated luacontroller --
------------------------------
local mesecons_burnt = {
effector =
{
rules = mesecon.rules.flat,
action_change = function (pos, _, rulename, newstate)
-- only update portstates when changes are triggered
lc_update_real_portstates(pos, rulename, newstate)
end
}
}
minetest.register_node(BASENAME .. "_burnt", { minetest.register_node(BASENAME .. "_burnt", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = { tiles = {
@ -553,6 +542,7 @@ minetest.register_node(BASENAME .. "_burnt", {
end, end,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
virtual_portstates = {a = false, b = false, c = false, d = false}, virtual_portstates = {a = false, b = false, c = false, d = false},
mesecons = mesecons_burnt,
}) })
------------------------ ------------------------

View File

@ -93,7 +93,6 @@ minetest.register_node(nodename, {
"button[7.5,0.2;1.5,3;brsflop;RS-Flop]".. "button[7.5,0.2;1.5,3;brsflop;RS-Flop]"..
"button_exit[3.5,1;2,3;program;Program]") "button_exit[3.5,1;2,3;program;Program]")
meta:set_string("infotext", "Unprogrammed Microcontroller") meta:set_string("infotext", "Unprogrammed Microcontroller")
meta:set_int("heat", 0)
local r = "" local r = ""
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0" for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
meta:set_string("eeprom", r) meta:set_string("eeprom", r)
@ -156,7 +155,6 @@ minetest.register_craft({
function yc_reset(pos) function yc_reset(pos)
yc_action(pos, {a=false, b=false, c=false, d=false}) yc_action(pos, {a=false, b=false, c=false, d=false})
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("heat", 0)
meta:set_int("afterid", 0) meta:set_int("afterid", 0)
local r = "" local r = ""
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0" for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
@ -165,11 +163,12 @@ end
function update_yc(pos) function update_yc(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
yc_heat(meta)
--minetest.after(0.5, yc_cool, meta) if (mesecon.do_overheat(pos)) then
if (yc_overheat(meta)) then
minetest.remove_node(pos) minetest.remove_node(pos)
minetest.after(0.2, yc_overheat_off, pos) --wait for pending parsings minetest.after(0.2, function (pos)
mesecon:receptor_off(pos, mesecon.rules.flat)
end , pos) -- wait for pending parsings
minetest.add_item(pos, "mesecons_microcontroller:microcontroller0000") minetest.add_item(pos, "mesecons_microcontroller:microcontroller0000")
end end
@ -698,34 +697,3 @@ function yc_merge_portstates(Lreal, Lvirtual)
if Lvirtual.d or Lreal.d then L.d = true end if Lvirtual.d or Lreal.d then L.d = true end
return L return L
end end
--"Overheat" protection
function yc_heat(meta)
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h + 1)
end
end
--function yc_cool(meta)
-- h = meta:get_int("heat")
-- if h ~= nil then
-- meta:set_int("heat", h - 1)
-- end
--end
function yc_overheat(meta)
if MESECONS_GLOBALSTEP then return false end
h = meta:get_int("heat")
if h == nil then return true end -- if nil the overheat
if h>60 then
return true
else
return false
end
end
function yc_overheat_off(pos)
rules = mesecon:get_rules("mesecons_microcontroller:microcontroller1111")
mesecon:receptor_off(pos, rules)
end