mirror of
https://github.com/minetest-mods/digilines.git
synced 2024-12-24 17:50:20 +01:00
Use minetest.hash_node_position
for searches.
Previously, Digilines used concatenations of X/Y/Z coordinates into strings as keys to check for repeatedly visiting the same node during a graph search. Replace them with integer keys generated by `minetest.hash_node_position`, which should be more efficient.
This commit is contained in:
parent
25ea72270d
commit
84133a10df
2
init.lua
2
init.lua
@ -9,7 +9,7 @@ dofile(modpath .. "/wire_std.lua")
|
|||||||
|
|
||||||
function digiline:receptor_send(pos, rules, channel, msg)
|
function digiline:receptor_send(pos, rules, channel, msg)
|
||||||
local checked = {}
|
local checked = {}
|
||||||
checked[tostring(pos.x).."_"..tostring(pos.y).."_"..tostring(pos.z)] = 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 digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then
|
if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then
|
||||||
digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked)
|
digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked)
|
||||||
|
@ -105,7 +105,7 @@ function digiline:transmit(pos, channel, msg, checked)
|
|||||||
for _, rule in ipairs(rules) do
|
for _, rule in ipairs(rules) do
|
||||||
local nextPos = digiline:addPosRule(curPos, rule)
|
local nextPos = digiline:addPosRule(curPos, rule)
|
||||||
if digiline:rules_link(curPos, nextPos) then
|
if digiline:rules_link(curPos, nextPos) then
|
||||||
local checkedID = tostring(nextPos.x) .. "_" .. tostring(nextPos.y) .. "_" .. tostring(nextPos.z)
|
local checkedID = minetest.hash_node_position(nextPos)
|
||||||
if not checked[checkedID] then
|
if not checked[checkedID] then
|
||||||
checked[checkedID] = true
|
checked[checkedID] = true
|
||||||
queue_enqueue(queue, nextPos)
|
queue_enqueue(queue, nextPos)
|
||||||
|
Loading…
Reference in New Issue
Block a user