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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ local on_digiline_receive = function (pos, node, channel, msg)
local setchan = minetest.get_meta(pos):get_string("channel")
if channel == setchan and msg == GET_COMMAND then
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

View File

@ -20,7 +20,7 @@ local on_digiline_receive = function (pos, node, channel, msg)
local setchan = minetest.get_meta(pos):get_string("channel")
if channel == setchan and msg == GET_COMMAND then
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

View File

@ -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}
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)
end
--Rules rotation Functions:
function digilines:rotate_rules_right(rules)
function digilines.rotate_rules_right(rules)
local nr={}
for i, rule in ipairs(rules) do
nr[i]={}
@ -18,7 +18,7 @@ function digilines:rotate_rules_right(rules)
return nr
end
function digilines:rotate_rules_left(rules)
function digilines.rotate_rules_left(rules)
local nr={}
for i, rule in ipairs(rules) do
nr[i]={}
@ -29,7 +29,7 @@ function digilines:rotate_rules_left(rules)
return nr
end
function digilines:rotate_rules_down(rules)
function digilines.rotate_rules_down(rules)
local nr={}
for i, rule in ipairs(rules) do
nr[i]={}
@ -40,7 +40,7 @@ function digilines:rotate_rules_down(rules)
return nr
end
function digilines:rotate_rules_up(rules)
function digilines.rotate_rules_up(rules)
local nr={}
for i, rule in ipairs(rules) do
nr[i]={}
@ -51,13 +51,13 @@ function digilines:rotate_rules_up(rules)
return nr
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
local newtable = {}
for idx, item in pairs(table) do
if type(item) == "table" then
newtable[idx] = digilines:tablecopy(item)
newtable[idx] = digilines.tablecopy(item)
else
newtable[idx] = item
end
@ -88,12 +88,12 @@ local vm_cache = nil
-- 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
-- scan is finished, to avoid using stale data in future.
function digiline:vm_begin()
function digilines.vm_begin()
vm_cache = {}
end
-- Ends a bulk-VoxelManipulator operation, freeing the cached data.
function digiline:vm_end()
function digilines.vm_end()
vm_cache = nil
end
@ -141,7 +141,7 @@ end
-- there.
--
-- 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
return vm_get_node(pos)
end

View File

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