diff options
author | Christopher Head <chead@chead.ca> | 2017-02-19 15:15:00 -0800 |
---|---|---|
committer | Auke Kok <sofar+github@foo-projects.org> | 2017-02-28 22:13:19 -0800 |
commit | 84133a10df9f0c7d0d11e0ece8b5603e44208185 (patch) | |
tree | 9b968b71dfe2c5a2683d0abb57974126d138dcd1 | |
parent | 25ea72270dec5b0287b2a094d696bc807206b483 (diff) |
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.
-rw-r--r-- | init.lua | 2 | ||||
-rw-r--r-- | internal.lua | 2 |
2 files changed, 2 insertions, 2 deletions
@@ -9,7 +9,7 @@ dofile(modpath .. "/wire_std.lua") function digiline:receptor_send(pos, rules, channel, msg) 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 if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked) diff --git a/internal.lua b/internal.lua index 96f84e7..45cd5d7 100644 --- a/internal.lua +++ b/internal.lua @@ -105,7 +105,7 @@ function digiline:transmit(pos, channel, msg, checked) for _, rule in ipairs(rules) do local nextPos = digiline:addPosRule(curPos, rule) 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 checked[checkedID] = true queue_enqueue(queue, nextPos) |