From 0a4d15d26ecc33315a5d088eace532ca3e539bbb Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Tue, 17 Oct 2017 23:14:26 +0100 Subject: [PATCH] pressure logic: flowable node registry: add directionfn to directional flowable entries --- pressure_logic/flowable_node_registry.lua | 23 ++++++++----------- .../flowable_node_registry_install.lua | 7 ++++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pressure_logic/flowable_node_registry.lua b/pressure_logic/flowable_node_registry.lua index c60a39e..6d7bf17 100644 --- a/pressure_logic/flowable_node_registry.lua +++ b/pressure_logic/flowable_node_registry.lua @@ -23,6 +23,16 @@ pipeworks.flowables.list.simple_nodenames = {} -- called to determine which nodes to consider as neighbours. -- can be used to e.g. inspect the node's param values for facedir etc. -- returns: array of vector offsets to look for possible neighbours in +-- directionfn: function(node, vector): +-- can this node flow in this direction? +-- called in the context of another node to check the matching entry returned by neighbourfn. +-- for every offset vector returned by neighbourfn, +-- the node at that absolute position is checked. +-- if that node is also a directional flowable, +-- then that node's vector is passed to that node's directionfn +-- (inverted, so that directionfn sees a vector pointing out from it back to the origin node). +-- if directionfn agrees that the neighbour node can currently flow in that direction, +-- the neighbour is to participate in pressure balancing. pipeworks.flowables.list.directional = {} -- simple intakes - try to absorb any adjacent water nodes @@ -41,16 +51,3 @@ pipeworks.flowables.transitions = {} pipeworks.flowables.transitions.list = {} -- master list pipeworks.flowables.transitions.simple = {} -- nodes that change based purely on pressure pipeworks.flowables.transitions.mesecons = {} -- table of mesecons rules to apply on transition - - - --- checks if a given node can flow in a given direction. --- used to implement directional devices such as pumps, --- which only visually connect in a certain direction. --- node is the usual name + param structure. --- direction is an x/y/z vector of the flow direction; --- this function answers the question "can this node flow in this direction?" -pipeworks.flowables.flow_check = function(node, direction) - minetest.log("warning", "pipeworks.flowables.flow_check() stub!") - return true -end diff --git a/pressure_logic/flowable_node_registry_install.lua b/pressure_logic/flowable_node_registry_install.lua index a49c31a..3cd9c4d 100644 --- a/pressure_logic/flowable_node_registry_install.lua +++ b/pressure_logic/flowable_node_registry_install.lua @@ -43,9 +43,12 @@ end -- Register a node as a directional flowable: -- has a helper function which determines which nodes to consider valid neighbours. -register.directional = function(nodename, neighbourfn) +register.directional = function(nodename, neighbourfn, directionfn) insertbase(nodename) - pipeworks.flowables.list.directional[nodename] = { neighbourfn = neighbourfn } + pipeworks.flowables.list.directional[nodename] = { + neighbourfn = neighbourfn, + directionfn = directionfn + } regwarning("directional", nodename) end