From c3627551b091d27819c242da204ed1e9dd8f15f0 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 23:42:26 +0100 Subject: move all current new_flow_logic code to dedicated sub-directory --- new_flow_logic/flowable_node_registry.lua | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 new_flow_logic/flowable_node_registry.lua (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua new file mode 100644 index 0000000..def9649 --- /dev/null +++ b/new_flow_logic/flowable_node_registry.lua @@ -0,0 +1,59 @@ +-- registration code for nodes under new flow logic +-- written 2017 by thetaepsilon + +pipeworks.flowables = {} +pipeworks.flowables.list = {} +pipeworks.flowables.list.all = {} +-- pipeworks.flowables.list.nodenames = {} + +-- simple flowables - balance pressure in any direction +pipeworks.flowables.list.simple = {} +pipeworks.flowables.list.simple_nodenames = {} + +-- simple intakes - try to absorb any adjacent water nodes +pipeworks.flowables.inputs = {} +pipeworks.flowables.inputs.list = {} +pipeworks.flowables.inputs.nodenames = {} + +-- registration functions +pipeworks.flowables.register = {} +local register = pipeworks.flowables.register + +-- some sanity checking for passed args, as this could potentially be made an external API eventually +local checkexists = function(nodename) + if type(nodename) ~= "string" then error("pipeworks.flowables nodename must be a string!") end + return pipeworks.flowables.list.all[nodename] +end + +local insertbase = function(nodename) + if checkexists(nodename) then error("pipeworks.flowables duplicate registration!") end + pipeworks.flowables.list.all[nodename] = true + -- table.insert(pipeworks.flowables.list.nodenames, nodename) +end + +-- Register a node as a simple flowable. +-- Simple flowable nodes have no considerations for direction of flow; +-- A cluster of adjacent simple flowables will happily average out in any direction. +-- This does *not* register the ABM, as that is done in register_flow_logic.lua; +-- this is so that the new flow logic can remain optional during development. +register.simple = function(nodename) + insertbase(nodename) + pipeworks.flowables.list.simple[nodename] = true + table.insert(pipeworks.flowables.list.simple_nodenames, nodename) +end + +local checkbase = function(nodename) + if not checkexists(nodename) then error("pipeworks.flowables node doesn't exist as a flowable!") end +end + +-- Register a node as a simple intake. +-- See new_flow_logic for the details of this. +-- Expects node to be registered as a flowable (is present in flowables.list.all), +-- so that water can move out of it. +-- maxpressure is the maximum pipeline pressure that this node can drive. +-- possible WISHME here: technic-driven high-pressure pumps +register.intake_simple = function(nodename, maxpressure) + checkbase(nodename) + pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure } + table.insert(pipeworks.flowables.inputs.nodenames, nodename) +end -- cgit v1.2.3 From ec9cf1df5019c915cf7f5776c90cca760670569f Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 00:13:43 +0100 Subject: new_flow_logic/flowable_node_registry.lua: integrate existing ABM registration from register_local_pipes.lua --- new_flow_logic/flowable_node_registry.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index def9649..3cb2a67 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -1,6 +1,9 @@ -- registration code for nodes under new flow logic -- written 2017 by thetaepsilon +-- use for hooking up ABMs as nodes are registered +local abmregister = pipeworks.flowlogic.abmregister + pipeworks.flowables = {} pipeworks.flowables.list = {} pipeworks.flowables.list.all = {} @@ -34,12 +37,13 @@ end -- Register a node as a simple flowable. -- Simple flowable nodes have no considerations for direction of flow; -- A cluster of adjacent simple flowables will happily average out in any direction. --- This does *not* register the ABM, as that is done in register_flow_logic.lua; --- this is so that the new flow logic can remain optional during development. register.simple = function(nodename) insertbase(nodename) pipeworks.flowables.list.simple[nodename] = true table.insert(pipeworks.flowables.list.simple_nodenames, nodename) + if pipeworks.enable_new_flow_logic then + abmregister.balance(nodename) + end end local checkbase = function(nodename) @@ -56,4 +60,7 @@ register.intake_simple = function(nodename, maxpressure) checkbase(nodename) pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure } table.insert(pipeworks.flowables.inputs.nodenames, nodename) + if pipeworks.enable_new_flow_logic then + abmregister.input(nodename, maxpressure) + end end -- cgit v1.2.3 From 3486ee319ee4fafbf83c583dd9fedfaed92db7c4 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 00:44:14 +0100 Subject: abms.lua: refactor and generalise run_pump_intake() to allow passing custom intake functions --- new_flow_logic/flowable_node_registry.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index 3cb2a67..1465561 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -51,7 +51,6 @@ local checkbase = function(nodename) end -- Register a node as a simple intake. --- See new_flow_logic for the details of this. -- Expects node to be registered as a flowable (is present in flowables.list.all), -- so that water can move out of it. -- maxpressure is the maximum pipeline pressure that this node can drive. @@ -61,6 +60,6 @@ register.intake_simple = function(nodename, maxpressure) pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure } table.insert(pipeworks.flowables.inputs.nodenames, nodename) if pipeworks.enable_new_flow_logic then - abmregister.input(nodename, maxpressure) + abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2) end end -- cgit v1.2.3 From e615a1013b621daff64500fb74a6202fdca0093f Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 12:45:12 +0100 Subject: new flow logic: flowable_node_registry.lua: add output node registration --- new_flow_logic/flowable_node_registry.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index 1465561..f3548a4 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -18,6 +18,11 @@ pipeworks.flowables.inputs = {} pipeworks.flowables.inputs.list = {} pipeworks.flowables.inputs.nodenames = {} +-- outputs - takes pressure from pipes and update world to do something with it +pipeworks.flowables.outputs = {} +pipeworks.flowables.outputs.list = {} +-- not currently any nodenames arraylist for this one as it's not currently needed. + -- registration functions pipeworks.flowables.register = {} local register = pipeworks.flowables.register @@ -63,3 +68,20 @@ register.intake_simple = function(nodename, maxpressure) abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2) end end + +-- Register a node as an output. +-- Expects node to already be a flowable. +-- threshold and outputfn are currently as documented for register_abm_output() in abm_register.lua. +register.output = function(nodename, threshold, outputfn) + checkbase(nodename) + pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } + if pipeworks.enable_new_flow_logic then + abmregister.output(nodename, maxpressure, outputfn) + end +end + +-- TODOs here: +-- The spigot's output behaviour (and possibly the fountain) could be abstracted out into a "simple output" of sorts, +-- which tries to place water nodes around it. +-- possibly this could be given a helper function to determine which faces a node should try, +-- to allow things like rotation or other param values determining "direction" to be respected. -- cgit v1.2.3 From 3a1edac06ce193179b58ffcd055b492839d30018 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 13:00:41 +0100 Subject: new flow logic: register_local_pipes.lua: make spigots work again --- new_flow_logic/flowable_node_registry.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index f3548a4..f2ebdcb 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -76,7 +76,7 @@ register.output = function(nodename, threshold, outputfn) checkbase(nodename) pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } if pipeworks.enable_new_flow_logic then - abmregister.output(nodename, maxpressure, outputfn) + abmregister.output(nodename, threshold, outputfn) end end -- cgit v1.2.3 From f7b17197677ea3675eee6bc667370fe3e23ac099 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 15:18:00 +0100 Subject: new flow logic: node registry: split registration functions into seperate file to allow ABM code to inspect tables --- new_flow_logic/flowable_node_registry.lua | 73 +++---------------------------- 1 file changed, 7 insertions(+), 66 deletions(-) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index f2ebdcb..8fb925c 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -1,8 +1,12 @@ --- registration code for nodes under new flow logic +-- registry of flowable node behaviours in new flow logic -- written 2017 by thetaepsilon --- use for hooking up ABMs as nodes are registered -local abmregister = pipeworks.flowlogic.abmregister +-- the actual registration functions which edit these tables can be found in flowable_node_registry_install.lua +-- this is because the ABM code needs to inspect these tables, +-- but the registration code needs to reference said ABM code. +-- so those functions were split out to resolve a circular dependency. + + pipeworks.flowables = {} pipeworks.flowables.list = {} @@ -22,66 +26,3 @@ pipeworks.flowables.inputs.nodenames = {} pipeworks.flowables.outputs = {} pipeworks.flowables.outputs.list = {} -- not currently any nodenames arraylist for this one as it's not currently needed. - --- registration functions -pipeworks.flowables.register = {} -local register = pipeworks.flowables.register - --- some sanity checking for passed args, as this could potentially be made an external API eventually -local checkexists = function(nodename) - if type(nodename) ~= "string" then error("pipeworks.flowables nodename must be a string!") end - return pipeworks.flowables.list.all[nodename] -end - -local insertbase = function(nodename) - if checkexists(nodename) then error("pipeworks.flowables duplicate registration!") end - pipeworks.flowables.list.all[nodename] = true - -- table.insert(pipeworks.flowables.list.nodenames, nodename) -end - --- Register a node as a simple flowable. --- Simple flowable nodes have no considerations for direction of flow; --- A cluster of adjacent simple flowables will happily average out in any direction. -register.simple = function(nodename) - insertbase(nodename) - pipeworks.flowables.list.simple[nodename] = true - table.insert(pipeworks.flowables.list.simple_nodenames, nodename) - if pipeworks.enable_new_flow_logic then - abmregister.balance(nodename) - end -end - -local checkbase = function(nodename) - if not checkexists(nodename) then error("pipeworks.flowables node doesn't exist as a flowable!") end -end - --- Register a node as a simple intake. --- Expects node to be registered as a flowable (is present in flowables.list.all), --- so that water can move out of it. --- maxpressure is the maximum pipeline pressure that this node can drive. --- possible WISHME here: technic-driven high-pressure pumps -register.intake_simple = function(nodename, maxpressure) - checkbase(nodename) - pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure } - table.insert(pipeworks.flowables.inputs.nodenames, nodename) - if pipeworks.enable_new_flow_logic then - abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2) - end -end - --- Register a node as an output. --- Expects node to already be a flowable. --- threshold and outputfn are currently as documented for register_abm_output() in abm_register.lua. -register.output = function(nodename, threshold, outputfn) - checkbase(nodename) - pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } - if pipeworks.enable_new_flow_logic then - abmregister.output(nodename, threshold, outputfn) - end -end - --- TODOs here: --- The spigot's output behaviour (and possibly the fountain) could be abstracted out into a "simple output" of sorts, --- which tries to place water nodes around it. --- possibly this could be given a helper function to determine which faces a node should try, --- to allow things like rotation or other param values determining "direction" to be respected. -- cgit v1.2.3 From d9b616c5f05b1c512988fd5eef5f91aba5bf12cf Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 15:47:21 +0100 Subject: new flow logic: node registry: add initial stub for flow directionality check --- new_flow_logic/flowable_node_registry.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index 8fb925c..b0634d0 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -26,3 +26,16 @@ pipeworks.flowables.inputs.nodenames = {} pipeworks.flowables.outputs = {} pipeworks.flowables.outputs.list = {} -- not currently any nodenames arraylist for this one as it's not currently needed. + + + +-- 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 -- cgit v1.2.3 From e98e4e268b5faf898a0b8f580d7da2b46ead05c4 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 14:27:40 +0100 Subject: new flow logic: flowable node registry: add initial support for transition triggers --- new_flow_logic/flowable_node_registry.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index b0634d0..7651928 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -27,6 +27,12 @@ pipeworks.flowables.outputs = {} pipeworks.flowables.outputs.list = {} -- not currently any nodenames arraylist for this one as it's not currently needed. +-- nodes with registered node transitions +-- nodes will be switched depending on pressure level +pipeworks.flowables.transitions = {} +pipeworks.flowables.transitions.list = {} -- master list +pipeworks.flowables.transitions.simple = {} -- nodes that change based purely on pressure + -- checks if a given node can flow in a given direction. -- cgit v1.2.3 From d5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 17:38:28 +0100 Subject: new flow logic: implement post-transition hook with mesecons support, add mesecons transition rules for flow sensor --- new_flow_logic/flowable_node_registry.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'new_flow_logic/flowable_node_registry.lua') diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index 7651928..2523803 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -32,6 +32,7 @@ pipeworks.flowables.outputs.list = {} 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 -- cgit v1.2.3