Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #155 (option 2 used). Remove non-ActionQueue system. Enable overh…
…eat 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.
  • Loading branch information
Jeija committed Apr 20, 2014
1 parent 1f66687 commit 300abcb
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 117 deletions.
6 changes: 0 additions & 6 deletions mesecons/actionqueue.lua
Expand Up @@ -19,12 +19,6 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
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
-- Otherwise, add the action to the queue
if overwritecheck then -- check if old action has to be overwritten / removed:
Expand Down
26 changes: 11 additions & 15 deletions mesecons/init.lua
Expand Up @@ -79,14 +79,12 @@ 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
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
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

Expand All @@ -108,13 +106,11 @@ 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
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
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

Expand Down
8 changes: 2 additions & 6 deletions mesecons/internal.lua
Expand Up @@ -412,9 +412,7 @@ function mesecon:turnon(pos, rulename, recdepth)
end

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)
end
mesecon:turnon(pos, rulename, recdepth)
end)

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

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)
end
mesecon:turnoff(pos, rulename, recdepth)
end)


Expand Down
45 changes: 35 additions & 10 deletions mesecons/services.lua
@@ -1,3 +1,5 @@
-- Dig and place services

mesecon.on_placenode = function (pos, node)
-- Receptors: Send on signal when active
if mesecon:is_receptor_on(node.name) then
Expand Down Expand Up @@ -37,15 +39,38 @@ mesecon.on_dignode = function (pos, node)
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_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)
7 changes: 4 additions & 3 deletions mesecons/settings.lua
@@ -1,11 +1,12 @@
-- SETTINGS
BLINKY_PLANT_INTERVAL = 3
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
PRESSURE_PLATE_INTERVAL = 0.1
OBJECT_DETECTOR_RADIUS = 6
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
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
10 changes: 4 additions & 6 deletions mesecons_gates/init.lua
Expand Up @@ -47,9 +47,7 @@ function set_gate(pos, on)
gate = get_gate(pos)
local meta = minetest.get_meta(pos)
if on ~= gate_state(pos) then
yc_heat(meta)
--minetest.after(0.5, yc_cool, meta)
if yc_overheat(meta) then
if mesecon.do_overheat(pos) then
pop_gate(pos)
else
local node = minetest.get_node(pos)
Expand Down Expand Up @@ -78,7 +76,9 @@ end
function pop_gate(pos)
gate = get_gate(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")
end

Expand Down Expand Up @@ -153,7 +153,6 @@ for _, gate in ipairs(gates) do
walkable = true,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("heat", 0)
update_gate(pos)
end,
groups = groups,
Expand Down Expand Up @@ -221,4 +220,3 @@ minetest.register_craft({
{'mesecons:mesecon', '', ''},
},
})

58 changes: 24 additions & 34 deletions mesecons_luacontroller/init.lua
Expand Up @@ -122,30 +122,6 @@ end
-- 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)
mesecon:receptor_off(pos, mesecon.rules.flat)
end
Expand Down Expand Up @@ -232,6 +208,8 @@ local create_environment = function(pos, mem, event)
mem = mem,
tostring = tostring,
tonumber = tonumber,
heat = minetest.get_meta(pos):get_int("heat"),
heat_max = OVERHEAT_MAX,
string = {
byte = string.byte,
char = string.char,
Expand Down Expand Up @@ -299,11 +277,8 @@ local create_sandbox = function (code, env)
return f
end

local do_overheat = function (pos, meta)
-- Overheat protection
heat(meta)
--minetest.after(0.5, cool, meta)
if overheat(meta) then
local lc_overheat = function (pos, meta)
if mesecon.do_overheat(pos) then -- if too hot
local node = minetest.get_node(pos)
minetest.swap_node(pos, {name = BASENAME.."_burnt", param2 = node.param2})
minetest.after(0.2, overheat_off, pos) -- wait for pending operations
Expand Down Expand Up @@ -332,7 +307,7 @@ end

lc_update = function (pos, event)
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
local mem = load_memory(meta)
Expand Down Expand Up @@ -507,9 +482,9 @@ minetest.register_node(nodename, {
mesecons = mesecons,
digiline = digiline,
virtual_portstates = { a = a == 1, -- virtual portstates are
b = b == 1, -- the ports the the
c = c == 1, -- controller powers itself
d = d == 1},-- so those that light up
b = b == 1, -- the ports the the
c = c == 1, -- controller powers itself
d = d == 1},-- so those that light up
after_dig_node = function (pos, node)
mesecon:receptor_off(pos, output_rules)
end,
Expand All @@ -520,7 +495,21 @@ 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", {
drawtype = "nodebox",
tiles = {
Expand Down Expand Up @@ -553,6 +542,7 @@ minetest.register_node(BASENAME .. "_burnt", {
end,
sounds = default.node_sound_stone_defaults(),
virtual_portstates = {a = false, b = false, c = false, d = false},
mesecons = mesecons_burnt,
})

------------------------
Expand Down
42 changes: 5 additions & 37 deletions mesecons_microcontroller/init.lua
Expand Up @@ -93,7 +93,6 @@ minetest.register_node(nodename, {
"button[7.5,0.2;1.5,3;brsflop;RS-Flop]"..
"button_exit[3.5,1;2,3;program;Program]")
meta:set_string("infotext", "Unprogrammed Microcontroller")
meta:set_int("heat", 0)
local r = ""
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
meta:set_string("eeprom", r)
Expand Down Expand Up @@ -156,7 +155,6 @@ minetest.register_craft({
function yc_reset(pos)
yc_action(pos, {a=false, b=false, c=false, d=false})
local meta = minetest.get_meta(pos)
meta:set_int("heat", 0)
meta:set_int("afterid", 0)
local r = ""
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
Expand All @@ -165,11 +163,12 @@ end

function update_yc(pos)
local meta = minetest.get_meta(pos)
yc_heat(meta)
--minetest.after(0.5, yc_cool, meta)
if (yc_overheat(meta)) then

if (mesecon.do_overheat(pos)) then
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")
end

Expand Down Expand Up @@ -698,34 +697,3 @@ function yc_merge_portstates(Lreal, Lvirtual)
if Lvirtual.d or Lreal.d then L.d = true end
return L
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

0 comments on commit 300abcb

Please sign in to comment.