summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-18 09:32:33 +0100
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-18 09:32:33 +0100
commit084bbc6c0b098235b6a402d04a3b57f69cede9ac (patch)
tree74e707a56a9d053331177f180fb8db80b6c02399
parenta69c5e24a9771dc1818a01092730104c62703908 (diff)
downloadpipeworks-084bbc6c0b098235b6a402d04a3b57f69cede9ac.tar
pipeworks-084bbc6c0b098235b6a402d04a3b57f69cede9ac.tar.gz
pipeworks-084bbc6c0b098235b6a402d04a3b57f69cede9ac.tar.bz2
pipeworks-084bbc6c0b098235b6a402d04a3b57f69cede9ac.tar.xz
pipeworks-084bbc6c0b098235b6a402d04a3b57f69cede9ac.zip
pressure logic: abms.lua: get_neighbour_positions: move calculation of absolute world position to neighbour probing for-loop
This allows the raw offset to be visible inside that for-loop, which will be needed for calling the directionfn for directional neighbours to determine if they can flow in the given direction.
-rw-r--r--pressure_logic/abms.lua27
1 files changed, 14 insertions, 13 deletions
diff --git a/pressure_logic/abms.lua b/pressure_logic/abms.lua
index d6152dc..bed96b8 100644
--- a/pressure_logic/abms.lua
+++ b/pressure_logic/abms.lua
@@ -23,16 +23,6 @@ local make_coords_offsets = function(pos, include_base)
return coords
end
--- create positions from list of offsets
--- see in use of directional flow logic below
-local apply_coords_offsets = function(pos, offsets)
- local result = {}
- for index, offset in ipairs(offsets) do
- table.insert(result, vector.add(pos, offset))
- end
- return result
-end
-
-- local debuglog = function(msg) print("## "..msg) end
@@ -41,6 +31,8 @@ end
local formatvec = function(vec) local sep="," return "("..tostring(vec.x)..sep..tostring(vec.y)..sep..tostring(vec.z)..")" end
+
+
-- new version of liquid check
-- accepts a limit parameter to only delete water blocks that the receptacle can accept,
-- and returns it so that the receptacle can update it's pressure values.
@@ -130,6 +122,14 @@ end
+local simple_neighbour_offsets = {
+ {x=0, y=-1,z= 0},
+ {x=0, y= 1,z= 0},
+ {x=-1,y= 0,z= 0},
+ {x= 1,y= 0,z= 0},
+ {x= 0,y= 0,z=-1},
+ {x= 0,y= 0,z= 1},
+}
local get_neighbour_positions = function(pos, node)
-- get list of node neighbours.
-- if this node is directional and only flows on certain sides,
@@ -137,14 +137,14 @@ local get_neighbour_positions = function(pos, node)
-- for simple flowables this is just an auto-gen'd list of all six possible neighbours.
local candidates = {}
if pipeworks.flowables.list.simple[node.name] then
- candidates = make_coords_offsets(pos, false)
+ candidates = simple_neighbour_offsets
else
-- directional flowables: call the callback to get the list
local directional = pipeworks.flowables.list.directional[node.name]
if directional then
--pipeworks.logger(dname.."invoking neighbourfn")
local offsets = directional.neighbourfn(node)
- candidates = apply_coords_offsets(pos, offsets)
+ candidates = offsets
end
end
@@ -152,7 +152,8 @@ local get_neighbour_positions = function(pos, node)
-- for now, just check if it's in the simple table.
-- TODO: will need to add a single-face direction checking function for directional nodes
local connections = {}
- for index, npos in ipairs(candidates) do
+ for index, offset in ipairs(candidates) do
+ local npos = vector.add(pos, offset)
local nodename = minetest.get_node(npos).name
local is_simple = (pipeworks.flowables.list.simple[nodename])
if is_simple then