Skip to content

Commit 300abcb

Browse files
author
Jeija
committedApr 20, 2014
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.
1 parent 1f66687 commit 300abcb

File tree

8 files changed

+85
-117
lines changed

8 files changed

+85
-117
lines changed
 

‎mesecons/actionqueue.lua

-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
1919
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
2020
priority=priority}
2121

22-
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
23-
if not MESECONS_GLOBALSTEP and action.time == 0 then
24-
mesecon.queue:execute(action)
25-
return
26-
end
27-
2822
local toremove = nil
2923
-- Otherwise, add the action to the queue
3024
if overwritecheck then -- check if old action has to be overwritten / removed:

‎mesecons/init.lua

+11-15
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,12 @@ mesecon.queue:add_function("receptor_on", function (pos, rules)
7979
rules = rules or mesecon.rules.default
8080

8181
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
82-
if MESECONS_GLOBALSTEP then -- trying to enable resuming with globalstep disabled would cause an endless loop
83-
for _, rule in ipairs(mesecon:flattenrules(rules)) do
84-
local np = mesecon:addPosRule(pos, rule)
85-
-- if area is not loaded, keep trying
86-
if minetest.get_node_or_nil(np) == nil then
87-
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
88-
return
89-
end
82+
for _, rule in ipairs(mesecon:flattenrules(rules)) do
83+
local np = mesecon:addPosRule(pos, rule)
84+
-- if area is not loaded, keep trying
85+
if minetest.get_node_or_nil(np) == nil then
86+
mesecon.queue:add_action(pos, "receptor_on", {rules}, nil, rules)
87+
return
9088
end
9189
end
9290

@@ -108,13 +106,11 @@ mesecon.queue:add_function("receptor_off", function (pos, rules)
108106
rules = rules or mesecon.rules.default
109107

110108
-- if area (any of the rule targets) is not loaded, keep trying and call this again later
111-
if MESECONS_GLOBALSTEP then
112-
for _, rule in ipairs(mesecon:flattenrules(rules)) do
113-
local np = mesecon:addPosRule(pos, rule)
114-
if minetest.get_node_or_nil(np) == nil then
115-
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
116-
return
117-
end
109+
for _, rule in ipairs(mesecon:flattenrules(rules)) do
110+
local np = mesecon:addPosRule(pos, rule)
111+
if minetest.get_node_or_nil(np) == nil then
112+
mesecon.queue:add_action(pos, "receptor_off", {rules}, nil, rules)
113+
return
118114
end
119115
end
120116

‎mesecons/internal.lua

+2-6
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ function mesecon:turnon(pos, rulename, recdepth)
412412
end
413413

414414
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
415-
if (MESECONS_GLOBALSTEP) then -- do not resume if we don't use globalstep - that would cause an endless loop
416-
mesecon:turnon(pos, rulename, recdepth)
417-
end
415+
mesecon:turnon(pos, rulename, recdepth)
418416
end)
419417

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

457455
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
458-
if (MESECONS_GLOBALSTEP) then -- do not resume if we don't use globalstep - that would cause an endless loop
459-
mesecon:turnoff(pos, rulename, recdepth)
460-
end
456+
mesecon:turnoff(pos, rulename, recdepth)
461457
end)
462458

463459

‎mesecons/services.lua

+35-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- Dig and place services
2+
13
mesecon.on_placenode = function (pos, node)
24
-- Receptors: Send on signal when active
35
if mesecon:is_receptor_on(node.name) then
@@ -37,15 +39,38 @@ mesecon.on_dignode = function (pos, node)
3739
end
3840
end
3941

40-
minetest.register_abm({
41-
nodenames = {"group:overheat"},
42-
interval = 1.0,
43-
chance = 1,
44-
action = function(pos, node, active_object_count, active_object_count_wider)
45-
local meta = minetest.get_meta(pos)
46-
meta:set_int("heat",0)
47-
end,
48-
})
49-
5042
minetest.register_on_placenode(mesecon.on_placenode)
5143
minetest.register_on_dignode(mesecon.on_dignode)
44+
45+
-- Overheating service for fast circuits
46+
47+
-- returns true if heat is too high
48+
mesecon.do_overheat = function(pos)
49+
local meta = minetest.get_meta(pos)
50+
local heat = meta:get_int("heat") or 0
51+
52+
heat = heat + 1
53+
meta:set_int("heat", heat)
54+
55+
if heat < OVERHEAT_MAX then
56+
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
57+
else
58+
return true
59+
end
60+
61+
return false
62+
end
63+
64+
65+
mesecon.queue:add_function("cooldown", function (pos)
66+
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
67+
return -- node has been moved, this one does not use overheating - ignore
68+
end
69+
70+
local meta = minetest.get_meta(pos)
71+
local heat = meta:get_int("heat")
72+
73+
if (heat > 0) then
74+
meta:set_int("heat", heat - 1)
75+
end
76+
end)

‎mesecons/settings.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
-- SETTINGS
22
BLINKY_PLANT_INTERVAL = 3
3-
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
3+
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
44
PRESSURE_PLATE_INTERVAL = 0.1
55
OBJECT_DETECTOR_RADIUS = 6
66
PISTON_MAXIMUM_PUSH = 15
77
MOVESTONE_MAXIMUM_PUSH = 100
8-
MESECONS_GLOBALSTEP = true -- true = receptors/effectors won't be updated
9-
-- until next globalstep, decreases server load
108
MESECONS_RESUMETIME = 4 -- time to wait when starting the server before
119
-- processing the ActionQueue, don't set this too low
10+
OVERHEAT_MAX = 20 -- maximum heat of any component that directly sends an output
11+
-- signal when the input changes (e.g. luacontroller, gates)
12+
-- Unit: actions per second, checks are every 1 second

‎mesecons_gates/init.lua

+4-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ function set_gate(pos, on)
4747
gate = get_gate(pos)
4848
local meta = minetest.get_meta(pos)
4949
if on ~= gate_state(pos) then
50-
yc_heat(meta)
51-
--minetest.after(0.5, yc_cool, meta)
52-
if yc_overheat(meta) then
50+
if mesecon.do_overheat(pos) then
5351
pop_gate(pos)
5452
else
5553
local node = minetest.get_node(pos)
@@ -78,7 +76,9 @@ end
7876
function pop_gate(pos)
7977
gate = get_gate(pos)
8078
minetest.remove_node(pos)
81-
minetest.after(0.2, yc_overheat_off, pos)
79+
minetest.after(0.2, function (pos)
80+
mesecon:receptor_off(pos, mesecon.rules.flat)
81+
end , pos) -- wait for pending parsings
8282
minetest.add_item(pos, "mesecons_gates:"..gate.."_off")
8383
end
8484

@@ -153,7 +153,6 @@ for _, gate in ipairs(gates) do
153153
walkable = true,
154154
on_construct = function(pos)
155155
local meta = minetest.get_meta(pos)
156-
meta:set_int("heat", 0)
157156
update_gate(pos)
158157
end,
159158
groups = groups,
@@ -221,4 +220,3 @@ minetest.register_craft({
221220
{'mesecons:mesecon', '', ''},
222221
},
223222
})
224-

‎mesecons_luacontroller/init.lua

+24-34
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,6 @@ end
122122
-- Overheat stuff --
123123
--------------------
124124

125-
local heat = function (meta) -- warm up
126-
h = meta:get_int("heat")
127-
if h ~= nil then
128-
meta:set_int("heat", h + 1)
129-
end
130-
end
131-
132-
--local cool = function (meta) -- cool down after a while
133-
-- h = meta:get_int("heat")
134-
-- if h ~= nil then
135-
-- meta:set_int("heat", h - 1)
136-
-- end
137-
--end
138-
139-
local overheat = function (meta) -- determine if too hot
140-
h = meta:get_int("heat")
141-
if h == nil then return true end -- if nil then overheat
142-
if h > 40 then
143-
return true
144-
else
145-
return false
146-
end
147-
end
148-
149125
local overheat_off = function(pos)
150126
mesecon:receptor_off(pos, mesecon.rules.flat)
151127
end
@@ -232,6 +208,8 @@ local create_environment = function(pos, mem, event)
232208
mem = mem,
233209
tostring = tostring,
234210
tonumber = tonumber,
211+
heat = minetest.get_meta(pos):get_int("heat"),
212+
heat_max = OVERHEAT_MAX,
235213
string = {
236214
byte = string.byte,
237215
char = string.char,
@@ -299,11 +277,8 @@ local create_sandbox = function (code, env)
299277
return f
300278
end
301279

302-
local do_overheat = function (pos, meta)
303-
-- Overheat protection
304-
heat(meta)
305-
--minetest.after(0.5, cool, meta)
306-
if overheat(meta) then
280+
local lc_overheat = function (pos, meta)
281+
if mesecon.do_overheat(pos) then -- if too hot
307282
local node = minetest.get_node(pos)
308283
minetest.swap_node(pos, {name = BASENAME.."_burnt", param2 = node.param2})
309284
minetest.after(0.2, overheat_off, pos) -- wait for pending operations
@@ -332,7 +307,7 @@ end
332307

333308
lc_update = function (pos, event)
334309
local meta = minetest.get_meta(pos)
335-
if do_overheat(pos, meta) then return end
310+
if lc_overheat(pos) then return end
336311

337312
-- load code & mem from memory
338313
local mem = load_memory(meta)
@@ -507,9 +482,9 @@ minetest.register_node(nodename, {
507482
mesecons = mesecons,
508483
digiline = digiline,
509484
virtual_portstates = { a = a == 1, -- virtual portstates are
510-
b = b == 1, -- the ports the the
511-
c = c == 1, -- controller powers itself
512-
d = d == 1},-- so those that light up
485+
b = b == 1, -- the ports the the
486+
c = c == 1, -- controller powers itself
487+
d = d == 1},-- so those that light up
513488
after_dig_node = function (pos, node)
514489
mesecon:receptor_off(pos, output_rules)
515490
end,
@@ -520,7 +495,21 @@ end
520495
end
521496
end
522497

523-
--overheated luacontroller
498+
------------------------------
499+
-- overheated luacontroller --
500+
------------------------------
501+
502+
local mesecons_burnt = {
503+
effector =
504+
{
505+
rules = mesecon.rules.flat,
506+
action_change = function (pos, _, rulename, newstate)
507+
-- only update portstates when changes are triggered
508+
lc_update_real_portstates(pos, rulename, newstate)
509+
end
510+
}
511+
}
512+
524513
minetest.register_node(BASENAME .. "_burnt", {
525514
drawtype = "nodebox",
526515
tiles = {
@@ -553,6 +542,7 @@ minetest.register_node(BASENAME .. "_burnt", {
553542
end,
554543
sounds = default.node_sound_stone_defaults(),
555544
virtual_portstates = {a = false, b = false, c = false, d = false},
545+
mesecons = mesecons_burnt,
556546
})
557547

558548
------------------------

‎mesecons_microcontroller/init.lua

+5-37
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ minetest.register_node(nodename, {
9393
"button[7.5,0.2;1.5,3;brsflop;RS-Flop]"..
9494
"button_exit[3.5,1;2,3;program;Program]")
9595
meta:set_string("infotext", "Unprogrammed Microcontroller")
96-
meta:set_int("heat", 0)
9796
local r = ""
9897
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
9998
meta:set_string("eeprom", r)
@@ -156,7 +155,6 @@ minetest.register_craft({
156155
function yc_reset(pos)
157156
yc_action(pos, {a=false, b=false, c=false, d=false})
158157
local meta = minetest.get_meta(pos)
159-
meta:set_int("heat", 0)
160158
meta:set_int("afterid", 0)
161159
local r = ""
162160
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
@@ -165,11 +163,12 @@ end
165163

166164
function update_yc(pos)
167165
local meta = minetest.get_meta(pos)
168-
yc_heat(meta)
169-
--minetest.after(0.5, yc_cool, meta)
170-
if (yc_overheat(meta)) then
166+
167+
if (mesecon.do_overheat(pos)) then
171168
minetest.remove_node(pos)
172-
minetest.after(0.2, yc_overheat_off, pos) --wait for pending parsings
169+
minetest.after(0.2, function (pos)
170+
mesecon:receptor_off(pos, mesecon.rules.flat)
171+
end , pos) -- wait for pending parsings
173172
minetest.add_item(pos, "mesecons_microcontroller:microcontroller0000")
174173
end
175174

@@ -698,34 +697,3 @@ function yc_merge_portstates(Lreal, Lvirtual)
698697
if Lvirtual.d or Lreal.d then L.d = true end
699698
return L
700699
end
701-
702-
--"Overheat" protection
703-
function yc_heat(meta)
704-
h = meta:get_int("heat")
705-
if h ~= nil then
706-
meta:set_int("heat", h + 1)
707-
end
708-
end
709-
710-
--function yc_cool(meta)
711-
-- h = meta:get_int("heat")
712-
-- if h ~= nil then
713-
-- meta:set_int("heat", h - 1)
714-
-- end
715-
--end
716-
717-
function yc_overheat(meta)
718-
if MESECONS_GLOBALSTEP then return false end
719-
h = meta:get_int("heat")
720-
if h == nil then return true end -- if nil the overheat
721-
if h>60 then
722-
return true
723-
else
724-
return false
725-
end
726-
end
727-
728-
function yc_overheat_off(pos)
729-
rules = mesecon:get_rules("mesecons_microcontroller:microcontroller1111")
730-
mesecon:receptor_off(pos, rules)
731-
end

0 commit comments

Comments
 (0)
Please sign in to comment.