Change to ..

This commit is contained in:
Diego Martínez 2017-03-01 07:26:20 -03:00 committed by Auke Kok
parent 6a2fa5a3e4
commit f5e6a7d181
7 changed files with 72 additions and 72 deletions

@ -11,12 +11,12 @@ dofile(modpath .. "/internal.lua")
dofile(modpath .. "/wires_common.lua") dofile(modpath .. "/wires_common.lua")
dofile(modpath .. "/wire_std.lua") dofile(modpath .. "/wire_std.lua")
function digilines:receptor_send(pos, rules, channel, msg) function digilines.receptor_send(pos, rules, channel, msg)
local checked = {} local checked = {}
checked[minetest.hash_node_position(pos)] = true -- exclude itself checked[minetest.hash_node_position(pos)] = true -- exclude itself
for _,rule in ipairs(rules) do for _,rule in ipairs(rules) do
if digilines:rules_link(pos, digilines:addPosRule(pos, rule)) then if digilines.rules_link(pos, digilines.addPosRule(pos, rule)) then
digilines:transmit(digilines:addPosRule(pos, rule), channel, msg, checked) digilines.transmit(digilines.addPosRule(pos, rule), channel, msg, checked)
end end
end end
end end

@ -1,9 +1,9 @@
function digilines:getspec(node) function digilines.getspec(node)
if not minetest.registered_nodes[node.name] then return false end if not minetest.registered_nodes[node.name] then return false end
return minetest.registered_nodes[node.name].digiline return minetest.registered_nodes[node.name].digiline
end end
function digilines:importrules(spec, node) function digilines.importrules(spec, node)
if type(spec) == 'function' then if type(spec) == 'function' then
return spec(node) return spec(node)
elseif spec then elseif spec then
@ -13,43 +13,43 @@ function digilines:importrules(spec, node)
end end
end end
function digiline:getAnyInputRules(pos) function digilines.getAnyInputRules(pos)
local node = digiline:get_node_force(pos) local node = digilines.get_node_force(pos)
local spec = digiline:getspec(node) local spec = digilines.getspec(node)
if not spec then return end if not spec then return end
if spec.wire then if spec.wire then
return digilines:importrules(spec.wire.rules, node) return digilines.importrules(spec.wire.rules, node)
end end
if spec.effector then if spec.effector then
return digilines:importrules(spec.effector.rules, node) return digilines.importrules(spec.effector.rules, node)
end end
end end
function digiline:getAnyOutputRules(pos) function digilines.getAnyOutputRules(pos)
local node = digiline:get_node_force(pos) local node = digilines.get_node_force(pos)
local spec = digiline:getspec(node) local spec = digilines.getspec(node)
if not spec then return end if not spec then return end
if spec.wire then if spec.wire then
return digilines:importrules(spec.wire.rules, node) return digilines.importrules(spec.wire.rules, node)
end end
if spec.receptor then if spec.receptor then
return digilines:importrules(spec.receptor.rules, node) return digilines.importrules(spec.receptor.rules, node)
end end
end end
function digilines:rules_link(output, input) function digilines.rules_link(output, input)
local outputrules = digilines:getAnyOutputRules(output) local outputrules = digilines.getAnyOutputRules(output)
local inputrules = digilines:getAnyInputRules (input) local inputrules = digilines.getAnyInputRules (input)
if not outputrules or not inputrules then return false end if not outputrules or not inputrules then return false end
for _, orule in ipairs(outputrules) do for _, orule in ipairs(outputrules) do
if digilines:cmpPos(digilines:addPosRule(output, orule), input) then if digilines.cmpPos(digilines.addPosRule(output, orule), input) then
for _, irule in ipairs(inputrules) do for _, irule in ipairs(inputrules) do
if digilines:cmpPos(digilines:addPosRule(input, irule), output) then if digilines.cmpPos(digilines.addPosRule(input, irule), output) then
return true return true
end end
end end
@ -58,9 +58,9 @@ function digilines:rules_link(output, input)
return false return false
end end
function digilines:rules_link_anydir(output, input) function digilines.rules_link_anydir(output, input)
return digilines:rules_link(output, input) return digilines.rules_link(output, input)
or digilines:rules_link(input, output) or digilines.rules_link(input, output)
end end
local function queue_new() local function queue_new()
@ -85,14 +85,14 @@ local function queue_dequeue(queue)
return object return object
end end
function digiline:transmit(pos, channel, msg, checked) function digilines.transmit(pos, channel, msg, checked)
digiline:vm_begin() digilines.vm_begin()
local queue = queue_new() local queue = queue_new()
queue_enqueue(queue, pos) queue_enqueue(queue, pos)
while not queue_empty(queue) do while not queue_empty(queue) do
local curPos = queue_dequeue(queue) local curPos = queue_dequeue(queue)
local node = digiline:get_node_force(curPos) local node = digilines.get_node_force(curPos)
local spec = digiline:getspec(node) local spec = digilines.getspec(node)
if spec then if spec then
-- Effector actions --> Receive -- Effector actions --> Receive
if spec.effector then if spec.effector then
@ -101,10 +101,10 @@ function digiline:transmit(pos, channel, msg, checked)
-- Cable actions --> Transmit -- Cable actions --> Transmit
if spec.wire then if spec.wire then
local rules = digiline:importrules(spec.wire.rules, node) local rules = digilines.importrules(spec.wire.rules, node)
for _, rule in ipairs(rules) do for _, rule in ipairs(rules) do
local nextPos = digiline:addPosRule(curPos, rule) local nextPos = digilines.addPosRule(curPos, rule)
if digiline:rules_link(curPos, nextPos) then if digilines.rules_link(curPos, nextPos) then
local checkedID = minetest.hash_node_position(nextPos) local checkedID = minetest.hash_node_position(nextPos)
if not checked[checkedID] then if not checked[checkedID] then
checked[checkedID] = true checked[checkedID] = true
@ -115,5 +115,5 @@ function digiline:transmit(pos, channel, msg, checked)
end end
end end
end end
digiline:vm_end() digilines.vm_end()
end end

@ -2,7 +2,7 @@ local function sendMessage(pos, msg, channel)
if channel == nil then if channel == nil then
channel = minetest.get_meta(pos):get_string("channel") channel = minetest.get_meta(pos):get_string("channel")
end end
digilines:receptor_send(pos,digilines.rules.default,channel,msg) digilines.receptor_send(pos,digilines.rules.default,channel,msg)
end end
local function maybeString(stack) local function maybeString(stack)

@ -25,7 +25,7 @@ local on_digiline_receive = function (pos, node, channel, msg)
local setchan = minetest.get_meta(pos):get_string("channel") local setchan = minetest.get_meta(pos):get_string("channel")
if channel == setchan and msg == GET_COMMAND then if channel == setchan and msg == GET_COMMAND then
local lightval = minetest.get_node_light(pos) local lightval = minetest.get_node_light(pos)
digilines:receptor_send(pos, digilines.rules.default, channel, lightval) digilines.receptor_send(pos, digilines.rules.default, channel, lightval)
end end
end end

@ -20,7 +20,7 @@ local on_digiline_receive = function (pos, node, channel, msg)
local setchan = minetest.get_meta(pos):get_string("channel") local setchan = minetest.get_meta(pos):get_string("channel")
if channel == setchan and msg == GET_COMMAND then if channel == setchan and msg == GET_COMMAND then
local timeofday = minetest.get_timeofday() local timeofday = minetest.get_timeofday()
digilines:receptor_send(pos, digilines.rules.default, channel, timeofday) digilines.receptor_send(pos, digilines.rules.default, channel, timeofday)
end end
end end

@ -1,13 +1,13 @@
function digilines:addPosRule(p, r) function digilines.addPosRule(p, r)
return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z} return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
end end
function digilines:cmpPos(p1, p2) function digilines.cmpPos(p1, p2)
return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z) return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z)
end end
--Rules rotation Functions: --Rules rotation Functions:
function digilines:rotate_rules_right(rules) function digilines.rotate_rules_right(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -18,7 +18,7 @@ function digilines:rotate_rules_right(rules)
return nr return nr
end end
function digilines:rotate_rules_left(rules) function digilines.rotate_rules_left(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -29,7 +29,7 @@ function digilines:rotate_rules_left(rules)
return nr return nr
end end
function digilines:rotate_rules_down(rules) function digilines.rotate_rules_down(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -40,7 +40,7 @@ function digilines:rotate_rules_down(rules)
return nr return nr
end end
function digilines:rotate_rules_up(rules) function digilines.rotate_rules_up(rules)
local nr={} local nr={}
for i, rule in ipairs(rules) do for i, rule in ipairs(rules) do
nr[i]={} nr[i]={}
@ -51,13 +51,13 @@ function digilines:rotate_rules_up(rules)
return nr return nr
end end
function digilines:tablecopy(table) -- deep table copy function digilines.tablecopy(table) -- deep table copy
if type(table) ~= "table" then return table end -- no need to copy if type(table) ~= "table" then return table end -- no need to copy
local newtable = {} local newtable = {}
for idx, item in pairs(table) do for idx, item in pairs(table) do
if type(item) == "table" then if type(item) == "table" then
newtable[idx] = digilines:tablecopy(item) newtable[idx] = digilines.tablecopy(item)
else else
newtable[idx] = item newtable[idx] = item
end end
@ -88,12 +88,12 @@ local vm_cache = nil
-- directly on VM-loaded arrays, which should be faster for reading many nodes -- directly on VM-loaded arrays, which should be faster for reading many nodes
-- in rapid succession. However, the cache must be flushed with vm_end once the -- in rapid succession. However, the cache must be flushed with vm_end once the
-- scan is finished, to avoid using stale data in future. -- scan is finished, to avoid using stale data in future.
function digiline:vm_begin() function digilines.vm_begin()
vm_cache = {} vm_cache = {}
end end
-- Ends a bulk-VoxelManipulator operation, freeing the cached data. -- Ends a bulk-VoxelManipulator operation, freeing the cached data.
function digiline:vm_end() function digilines.vm_end()
vm_cache = nil vm_cache = nil
end end
@ -141,7 +141,7 @@ end
-- there. -- there.
-- --
-- Inside a bulk-VoxelManipulator operation, the operations VM cache is used. -- Inside a bulk-VoxelManipulator operation, the operations VM cache is used.
function digiline:get_node_force(pos) function digilines.get_node_force(pos)
if vm_cache then if vm_cache then
return vm_get_node(pos) return vm_get_node(pos)
end end

@ -1,17 +1,17 @@
minetest.register_on_placenode(function(pos, node) minetest.register_on_placenode(function(pos, node)
if minetest.registered_nodes[node.name].digiline then if minetest.registered_nodes[node.name].digiline then
digilines:update_autoconnect(pos) digilines.update_autoconnect(pos)
end end
end) end)
minetest.register_on_dignode(function(pos, node) minetest.register_on_dignode(function(pos, node)
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].digiline then if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].digiline then
-- need to make sure that node exists (unknown nodes!) -- need to make sure that node exists (unknown nodes!)
digilines:update_autoconnect(pos) digilines.update_autoconnect(pos)
end end
end) end)
function digilines:update_autoconnect(pos, secondcall) function digilines.update_autoconnect(pos, secondcall)
local xppos = {x=pos.x+1, y=pos.y, z=pos.z} local xppos = {x=pos.x+1, y=pos.y, z=pos.z}
local zppos = {x=pos.x, y=pos.y, z=pos.z+1} local zppos = {x=pos.x, y=pos.y, z=pos.z+1}
local xmpos = {x=pos.x-1, y=pos.y, z=pos.z} local xmpos = {x=pos.x-1, y=pos.y, z=pos.z}
@ -26,20 +26,20 @@ function digilines:update_autoconnect(pos, secondcall)
local zmypos = {x=pos.x, y=pos.y+1, z=pos.z-1} local zmypos = {x=pos.x, y=pos.y+1, z=pos.z-1}
if secondcall == nil then if secondcall == nil then
digilines:update_autoconnect(xppos, true) digilines.update_autoconnect(xppos, true)
digilines:update_autoconnect(zppos, true) digilines.update_autoconnect(zppos, true)
digilines:update_autoconnect(xmpos, true) digilines.update_autoconnect(xmpos, true)
digilines:update_autoconnect(zmpos, true) digilines.update_autoconnect(zmpos, true)
digilines:update_autoconnect(xpypos, true) digilines.update_autoconnect(xpypos, true)
digilines:update_autoconnect(zpypos, true) digilines.update_autoconnect(zpypos, true)
digilines:update_autoconnect(xmypos, true) digilines.update_autoconnect(xmypos, true)
digilines:update_autoconnect(zmypos, true) digilines.update_autoconnect(zmypos, true)
digilines:update_autoconnect(xpympos, true) digilines.update_autoconnect(xpympos, true)
digilines:update_autoconnect(zpympos, true) digilines.update_autoconnect(zpympos, true)
digilines:update_autoconnect(xmympos, true) digilines.update_autoconnect(xmympos, true)
digilines:update_autoconnect(zmympos, true) digilines.update_autoconnect(zmympos, true)
end end
local def = minetest.registered_nodes[minetest.get_node(pos).name] local def = minetest.registered_nodes[minetest.get_node(pos).name]
@ -49,20 +49,20 @@ function digilines:update_autoconnect(pos, secondcall)
return nil return nil
end end
local zmg = digilines:rules_link_anydir(pos, zmpos) local zmg = digilines.rules_link_anydir(pos, zmpos)
local zmymg = digilines:rules_link_anydir(pos, zmympos) local zmymg = digilines.rules_link_anydir(pos, zmympos)
local xmg = digilines:rules_link_anydir(pos, xmpos) local xmg = digilines.rules_link_anydir(pos, xmpos)
local xmymg = digilines:rules_link_anydir(pos, xmympos) local xmymg = digilines.rules_link_anydir(pos, xmympos)
local zpg = digilines:rules_link_anydir(pos, zppos) local zpg = digilines.rules_link_anydir(pos, zppos)
local zpymg = digilines:rules_link_anydir(pos, zpympos) local zpymg = digilines.rules_link_anydir(pos, zpympos)
local xpg = digilines:rules_link_anydir(pos, xppos) local xpg = digilines.rules_link_anydir(pos, xppos)
local xpymg = digilines:rules_link_anydir(pos, xpympos) local xpymg = digilines.rules_link_anydir(pos, xpympos)
local xpyg = digilines:rules_link_anydir(pos, xpypos) local xpyg = digilines.rules_link_anydir(pos, xpypos)
local zpyg = digilines:rules_link_anydir(pos, zpypos) local zpyg = digilines.rules_link_anydir(pos, zpypos)
local xmyg = digilines:rules_link_anydir(pos, xmypos) local xmyg = digilines.rules_link_anydir(pos, xmypos)
local zmyg = digilines:rules_link_anydir(pos, zmypos) local zmyg = digilines.rules_link_anydir(pos, zmypos)
local zm, xm, zp, xp, xpy, zpy, xmy, zmy local zm, xm, zp, xp, xpy, zpy, xmy, zmy
if zmg or zmymg then zm = 1 else zm = 0 end if zmg or zmymg then zm = 1 else zm = 0 end