summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md28
-rw-r--r--mesecons/init.lua47
-rw-r--r--mesecons/internal.lua111
-rw-r--r--mesecons/services.lua15
-rw-r--r--mesecons/settings.lua2
-rw-r--r--mesecons_gates/init.lua6
-rw-r--r--mesecons_luacontroller/init.lua60
-rw-r--r--mesecons_microcontroller/init.lua21
-rw-r--r--mesecons_pistons/init.lua10
-rw-r--r--mesecons_pistons/sounds/piston_extend.oggbin0 -> 7060 bytes
-rw-r--r--mesecons_pistons/sounds/piston_retract.oggbin0 -> 7092 bytes
11 files changed, 242 insertions, 58 deletions
diff --git a/README.md b/README.md
index 37b6c22..32b4a12 100644
--- a/README.md
+++ b/README.md
@@ -51,19 +51,21 @@ Who wrote it anyways?
---------------------
These awesome people made Mesecons possible!
-| Contributor | Contribution |
-| --------------- | ---------------------------------- |
-| Jat15 | Various tweaks. |
-| Jeija | **Main developer! Everything.** |
-| Jordach | Noteblock sounds. |
-| khonkhortistan | Coding, recipes, textures. |
-| Kotolegokot | Nodeboxes for items. |
-| minerd247 | Textures. |
-| RealBadAngel | Fixes, improvements. |
-| sfan5 | Coding, recipes, textures. |
-| Uberi/Temperest | Coding, textures, documentation. |
-| VanessaE | Coding, recipes, textures, design. |
-| Whiskers75 | Logic gates implementation. |
+| Contributor | Contribution |
+| --------------- | -------------------------------- |
+| Jat15 | Various tweaks. |
+| Jeija | **Main developer! Everything.** |
+| Jordach | Noteblock sounds. |
+| khonkhortistan | Code, recipes, textures. |
+| Kotolegokot | Nodeboxes for items. |
+| minerd247 | Textures. |
+| Nore/Novatux | Code. |
+| RealBadAngel | Fixes, improvements. |
+| sfan5 | Code, recipes, textures. |
+| suzenako | Piston sounds. |
+| Uberi/Temperest | Code, textures, documentation. |
+| VanessaE | Code, recipes, textures, design. |
+| Whiskers75 | Logic gates implementation. |
There are also a whole bunch of other people helping with everything from code to testing and feedback. Mesecons would also not be possible without their help!
diff --git a/mesecons/init.lua b/mesecons/init.lua
index 7f6fe5d..635725f 100644
--- a/mesecons/init.lua
+++ b/mesecons/init.lua
@@ -49,6 +49,31 @@ mesecon.receptors={} -- saves all information about receptors | DEPRECATED
mesecon.effectors={} -- saves all information about effectors | DEPRECATED
mesecon.conductors={} -- saves all information about conductors | DEPRECATED
+
+local wpath = minetest.get_worldpath()
+local function read_file(fn)
+ local f = io.open(fn, "r")
+ if f==nil then return {} end
+ local t = f:read("*all")
+ f:close()
+ if t=="" or t==nil then return {} end
+ return minetest.deserialize(t)
+end
+
+local function write_file(fn, tbl)
+ local f = io.open(fn, "w")
+ f:write(minetest.serialize(tbl))
+ f:close()
+end
+
+mesecon.to_update = read_file(wpath.."/mesecon_to_update")
+mesecon.r_to_update = read_file(wpath.."/mesecon_r_to_update")
+
+minetest.register_on_shutdown(function()
+ write_file(wpath.."/mesecon_to_update",mesecon.to_update)
+ write_file(wpath.."/mesecon_r_to_update",mesecon.r_to_update)
+end)
+
-- Settings
dofile(minetest.get_modpath("mesecons").."/settings.lua")
@@ -76,7 +101,7 @@ dofile(minetest.get_modpath("mesecons").."/legacy.lua");
-- API
-- these are the only functions you need to remember
-function mesecon:receptor_on(pos, rules)
+function mesecon:receptor_on_i(pos, rules)
rules = rules or mesecon.rules.default
for _, rule in ipairs(rules) do
@@ -88,7 +113,16 @@ function mesecon:receptor_on(pos, rules)
end
end
-function mesecon:receptor_off(pos, rules)
+function mesecon:receptor_on(pos, rules)
+ if MESECONS_GLOBALSTEP then
+ rules = rules or mesecon.rules.default
+ mesecon.r_to_update[#mesecon.r_to_update+1]={pos=pos, rules=rules, action="on"}
+ else
+ mesecon:receptor_on_i(pos, rules)
+ end
+end
+
+function mesecon:receptor_off_i(pos, rules)
rules = rules or mesecon.rules.default
for _, rule in ipairs(rules) do
@@ -104,6 +138,15 @@ function mesecon:receptor_off(pos, rules)
end
end
+function mesecon:receptor_off(pos, rules)
+ if MESECONS_GLOBALSTEP then
+ rules = rules or mesecon.rules.default
+ mesecon.r_to_update[#mesecon.r_to_update+1]={pos=pos, rules=rules, action="off"}
+ else
+ mesecon:receptor_off_i(pos, rules)
+ end
+end
+
print("[OK] Mesecons")
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index 5e243cf..30991cd 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -180,24 +180,115 @@ end
--Signals
function mesecon:activate(pos, node, rulename)
- local effector = mesecon:get_effector(node.name)
- if effector and effector.action_on then
- effector.action_on (pos, node, rulename)
+ if MESECONS_GLOBALSTEP then
+ if rulename == nil then
+ for _,rule in ipairs(mesecon:effector_get_rules(node)) do
+ mesecon:activate(pos, node, rule)
+ end
+ return
+ end
+ add_action(pos, "on", rulename)
+ else
+ local effector = mesecon:get_effector(node.name)
+ if effector and effector.action_on then
+ effector.action_on (pos, node, rulename)
+ end
end
end
function mesecon:deactivate(pos, node, rulename)
- local effector = mesecon:get_effector(node.name)
- if effector and effector.action_off then
- effector.action_off (pos, node, rulename)
+ if MESECONS_GLOBALSTEP then
+ if rulename == nil then
+ for _,rule in ipairs(mesecon:effector_get_rules(node)) do
+ mesecon:deactivate(pos, node, rule)
+ end
+ return
+ end
+ add_action(pos, "off", rulename)
+ else
+ local effector = mesecon:get_effector(node.name)
+ if effector and effector.action_off then
+ effector.action_off (pos, node, rulename)
+ end
end
end
function mesecon:changesignal(pos, node, rulename, newstate)
- local effector = mesecon:get_effector(node.name)
- if effector and effector.action_change then
- effector.action_change (pos, node, rulename, newstate)
+
+ newstate = newstate or "on"
+ --rulename = rulename or mesecon.rules.default
+ if MESECONS_GLOBALSTEP then
+ if rulename == nil then
+ for _,rule in ipairs(mesecon:effector_get_rules(node)) do
+ mesecon:changesignal(pos, node, rule, newstate)
+ end
+ return
+ end
+ add_action(pos, "c"..newstate, rulename)
+ else
+ local effector = mesecon:get_effector(node.name)
+ if effector and effector.action_change then
+ effector.action_change (pos, node, rulename, newstate)
+ end
+ end
+end
+
+function execute_actions(dtime)
+ local nactions = mesecon.to_update
+ mesecon.to_update = {}
+ for _,i in ipairs(nactions) do
+ node = minetest.env:get_node(i.pos)
+ if node.name=="ignore" then
+ add_action(i.pos, i.action, i.rname)
+ else
+ effector = mesecon:get_effector(node.name)
+ if i.action == "on" then
+ if effector and effector.action_on then
+ effector.action_on(i.pos, node, i.rname)
+ end
+ elseif i.action == "off" then
+ if effector and effector.action_off then
+ effector.action_off(i.pos, node, i.rname)
+ end
+ elseif i.action == "con" then
+ if effector and effector.action_change then
+ effector.action_change(i.pos, node, i.rname, "on")
+ end
+ elseif i.action == "coff" then
+ if effector and effector.action_change then
+ effector.action_change(i.pos, node, i.rname, "off")
+ end
+ end
+ end
+ end
+ local nactions = mesecon.r_to_update
+ mesecon.r_to_update = {}
+ for _,i in ipairs(nactions) do
+ if i.action == "on" then
+ mesecon:receptor_on_i(i.pos, i.rules)
+ else
+ mesecon:receptor_off_i(i.pos,i.rules)
+ end
+ end
+end
+
+minetest.register_globalstep(execute_actions)
+
+function add_action(pos, action, rname)
+ for _,i in ipairs(mesecon.to_update) do
+ if i.pos.x == pos.x and i.pos.y == pos.y and i.pos.z == pos.z and i.rname.x == rname.x and i.rname.y == rname.y and i.rname.z == rname.z then
+ if (i.action == "on" and action == "on") or (i.action == "off" and action == "off") then
+ --nothing
+ elseif i.action == "coff" and action == "on" then i.action = "on"
+ elseif i.action == "con" and action == "off" then i.action = "off"
+ else
+ if action == "on" or action == "con" then i.action = "con" end
+ if action == "off" or action == "coff" then i.action = "coff" end
+ end
+ break
+ end
end
+ mesecon.to_update[#mesecon.to_update+1] = {pos = pos, action = action, rname = rname}
end
--Rules
@@ -396,7 +487,7 @@ function mesecon:rules_link(output, input, dug_outputrules) --output/input are p
for _, inputrule in ipairs(inputrules) do
-- Check if input accepts from output
if mesecon:cmpPos(mesecon:addPosRule(input, inputrule), output) then
- return true, inputrule.name
+ return true, inputrule
end
end
end
diff --git a/mesecons/services.lua b/mesecons/services.lua
index a2f9d01..34413d1 100644
--- a/mesecons/services.lua
+++ b/mesecons/services.lua
@@ -1,5 +1,4 @@
-mesecon.on_placenode = function (pos)
- local node = minetest.env:get_node(pos)
+mesecon.on_placenode = function (pos, node)
if mesecon:is_receptor_on(node.name) then
mesecon:receptor_on(pos, mesecon:receptor_get_rules(node))
elseif mesecon:is_powered(pos) then
@@ -7,7 +6,7 @@ mesecon.on_placenode = function (pos)
mesecon:turnon (pos)
mesecon:receptor_on (pos, mesecon:conductor_get_rules(node))
else
- mesecon:changesignal(pos, node)
+ mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "on")
mesecon:activate(pos, node)
end
elseif mesecon:is_conductor_on(node.name) then
@@ -25,5 +24,15 @@ 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.env:get_meta(pos)
+ meta:set_int("heat",0)
+ end,
+})
+
minetest.register_on_placenode(mesecon.on_placenode)
minetest.register_on_dignode(mesecon.on_dignode)
diff --git a/mesecons/settings.lua b/mesecons/settings.lua
index eaed9de..e35bb1e 100644
--- a/mesecons/settings.lua
+++ b/mesecons/settings.lua
@@ -5,3 +5,5 @@ 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
diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua
index 162c7d8..37b046f 100644
--- a/mesecons_gates/init.lua
+++ b/mesecons_gates/init.lua
@@ -47,7 +47,7 @@ function set_gate(pos, on)
local meta = minetest.env:get_meta(pos)
if on ~= gate_state(pos) then
yc_heat(meta)
- minetest.after(0.5, yc_cool, meta)
+ --minetest.after(0.5, yc_cool, meta)
if yc_overheat(meta) then
pop_gate(pos)
else
@@ -112,13 +112,13 @@ for _, gate in ipairs(gates) do
drop = nodename.."_off"
nodename = nodename.."_"..onoff
description = "You hacker you!"
- groups = {dig_immediate=2, not_in_creative_inventory=1}
+ groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1}
else
onoff = "off"
drop = nil
nodename = nodename.."_"..onoff
description = gate.name.." Gate"
- groups = {dig_immediate=2}
+ groups = {dig_immediate=2, overheat = 1}
end
tiles = "jeija_microcontroller_bottom.png^"..
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua
index 2166754..c8cb6ca 100644
--- a/mesecons_luacontroller/init.lua
+++ b/mesecons_luacontroller/init.lua
@@ -100,17 +100,17 @@ local heat = function (meta) -- warm up
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 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 > 20 then
+ if h > 40 then
return true
else
return false
@@ -127,7 +127,7 @@ end
local code_prohibited = function(code)
-- Clean code
- local prohibited = {"while", "for", "repeat", "until", "function"}
+ local prohibited = {"while", "for", "repeat", "until", "function", "goto"}
for _, p in ipairs(prohibited) do
if string.find(code, p) then
return "Prohibited command: "..p
@@ -135,10 +135,34 @@ local code_prohibited = function(code)
end
end
-local safeprint = function(param)
+local safe_print = function(param)
print(dump(param))
end
+deep_copy = function(original, visited) --deep copy that removes functions
+ visited = visited or {}
+ if visited[original] ~= nil then --already visited this node
+ return visited[original]
+ end
+ if type(original) == 'table' then --nested table
+ local copy = {}
+ visited[original] = copy
+ for key, value in next, original, nil do
+ copy[deep_copy(key, visited)] = deep_copy(value, visited)
+ end
+ setmetatable(copy, deep_copy(getmetatable(original), visited))
+ return copy
+ elseif type(original) == 'function' then --ignore functions
+ return nil
+ else --by-value type
+ return original
+ end
+end
+
+local safe_serialize = function(value)
+ return minetest.serialize(deep_copy(value))
+end
+
local interrupt = function(params)
lc_update(params.pos, {type="interrupt", iid = params.iid})
end
@@ -150,15 +174,16 @@ local getinterrupt = function(pos)
local meta = minetest.env:get_meta(pos)
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
local found = false
+ local search = safe_serialize(iid)
for _, i in ipairs(interrupts) do
- if minetest.serialize(i) == minetest.serialize(iid) then
+ if safe_serialize(i) == search then
found = true
break
end
end
if not found then
table.insert(interrupts, iid)
- meta:set_string("lc_interrupts", minetest.serialize(interrupts))
+ meta:set_string("lc_interrupts", safe_serialize(interrupts))
end
minetest.after(time, interrupt, {pos=pos, iid = iid})
end
@@ -181,7 +206,7 @@ local create_environment = function(pos, mem, event)
local rports = get_real_portstates(pos)
return {
- print = safeprint,
+ print = safe_print,
pin = merge_portstates(vports, rports),
port = vports,
interrupt = getinterrupt(pos),
@@ -258,7 +283,7 @@ end
local do_overheat = function (pos, meta)
-- Overheat protection
heat(meta)
- minetest.after(0.5, cool, meta)
+ --minetest.after(0.5, cool, meta)
if overheat(meta) then
mesecon:swap_node(pos, BASENAME.."_burnt")
minetest.env:get_meta(pos):set_string("lc_interrupts", "")
@@ -272,15 +297,16 @@ local load_memory = function(meta)
end
local save_memory = function(meta, mem)
- meta:set_string("lc_memory", minetest.serialize(mem))
+ meta:set_string("lc_memory", safe_serialize(mem))
end
local interrupt_allow = function (meta, event)
if event.type ~= "interrupt" then return true end
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
+ local search = safe_serialize(event.iid)
for _, i in ipairs(interrupts) do
- if minetest.serialize(i) == minetest.serialize(event.iid) then
+ if safe_serialize(i) == search then
return true
end
end
@@ -414,9 +440,9 @@ if d == 1 then
end
if a + b + c + d ~= 0 then
- groups = {dig_immediate=2, not_in_creative_inventory=1}
+ groups = {dig_immediate=2, not_in_creative_inventory=1, overheat = 1}
else
- groups = {dig_immediate=2}
+ groups = {dig_immediate=2, overheat = 1}
end
output_rules[cid] = {}
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua
index 0f6a7cd..8be9ffa 100644
--- a/mesecons_microcontroller/init.lua
+++ b/mesecons_microcontroller/init.lua
@@ -19,9 +19,9 @@ if tostring(d) == "1" then
top = top.."^jeija_microcontroller_LED_D.png"
end
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
- groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
+ groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, overheat = 1}
else
- groups = {dig_immediate=2, mesecon = 3}
+ groups = {dig_immediate=2, mesecon = 3, overheat = 1}
end
local rules={}
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
@@ -162,7 +162,7 @@ end
function update_yc(pos)
local meta = minetest.env:get_meta(pos)
yc_heat(meta)
- minetest.after(0.5, yc_cool, meta)
+ --minetest.after(0.5, yc_cool, meta)
if (yc_overheat(meta)) then
minetest.env:remove_node(pos)
minetest.after(0.2, yc_overheat_off, pos) --wait for pending parsings
@@ -674,17 +674,18 @@ function yc_heat(meta)
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_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>30 then
+ if h>60 then
return true
else
return false
diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua
index 26f2040..f044d5a 100644
--- a/mesecons_pistons/init.lua
+++ b/mesecons_pistons/init.lua
@@ -63,6 +63,11 @@ local piston_remove_pusher = function (pos, node)
if pushername == pistonspec.pusher then --make sure there actually is a pusher (for compatibility reasons mainly)
minetest.env:remove_node(pusherpos)
+ minetest.sound_play("piston_retract", {
+ pos = pos,
+ max_hear_distance = 20,
+ gain = 0.3,
+ })
nodeupdate(pusherpos)
end
end
@@ -76,6 +81,11 @@ local piston_on = function (pos, node)
if success then
minetest.env:add_node(pos, {param2 = node.param2, name = pistonspec.onname})
minetest.env:add_node(np, {param2 = node.param2, name = pistonspec.pusher})
+ minetest.sound_play("piston_extend", {
+ pos = pos,
+ max_hear_distance = 20,
+ gain = 0.3,
+ })
mesecon:mvps_process_stack (stack)
mesecon:mvps_move_objects (np, dir, oldstack)
end
diff --git a/mesecons_pistons/sounds/piston_extend.ogg b/mesecons_pistons/sounds/piston_extend.ogg
new file mode 100644
index 0000000..e234ad9
--- /dev/null
+++ b/mesecons_pistons/sounds/piston_extend.ogg
Binary files differ
diff --git a/mesecons_pistons/sounds/piston_retract.ogg b/mesecons_pistons/sounds/piston_retract.ogg
new file mode 100644
index 0000000..feb9f04
--- /dev/null
+++ b/mesecons_pistons/sounds/piston_retract.ogg
Binary files differ