From d68d3d5852ae01048c6c2702ac25530d7fd293a0 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Tue, 17 Oct 2017 22:01:29 +0100 Subject: [PATCH] pressure logic: abms.lua: move neighbour candidates calculation to separate function --- pressure_logic/abms.lua | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/pressure_logic/abms.lua b/pressure_logic/abms.lua index c14c124..b79050b 100644 --- a/pressure_logic/abms.lua +++ b/pressure_logic/abms.lua @@ -130,17 +130,7 @@ end -flowlogic.balance_pressure = function(pos, node, currentpressure) - -- local dname = "flowlogic.balance_pressure()@"..formatvec(pos).." " - -- check the pressure of all nearby flowable nodes, and average it out. - - -- pressure handles to average over - local connections = {} - -- unconditionally include self in nodes to average over. - -- result of averaging will be returned as new pressure for main flow logic callback - local totalv = currentpressure - local totalc = 1 - +local get_neighbour_positions = function(pos, node) -- get list of node neighbours. -- if this node is directional and only flows on certain sides, -- invoke the callback to retrieve the set. @@ -158,6 +148,24 @@ flowlogic.balance_pressure = function(pos, node, currentpressure) end end + return candidates +end + + + +flowlogic.balance_pressure = function(pos, node, currentpressure) + -- local dname = "flowlogic.balance_pressure()@"..formatvec(pos).." " + -- check the pressure of all nearby flowable nodes, and average it out. + + -- pressure handles to average over + local connections = {} + -- unconditionally include self in nodes to average over. + -- result of averaging will be returned as new pressure for main flow logic callback + local totalv = currentpressure + local totalc = 1 + + local candidates = get_neighbour_positions(pos, node) + -- then handle neighbours, but if not a pressure node don't consider them at all for _, npos in ipairs(candidates) do local nodename = minetest.get_node(npos).name