From 084bbc6c0b098235b6a402d04a3b57f69cede9ac Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 18 Oct 2017 09:32:33 +0100 Subject: 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. --- pressure_logic/abms.lua | 27 ++++++++++++++------------- 1 file 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 -- cgit v1.2.3