summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.lua3
-rw-r--r--new_flow_logic/flowable_node_registry.lua73
-rw-r--r--new_flow_logic/flowable_node_registry_install.lua70
3 files changed, 79 insertions, 67 deletions
diff --git a/init.lua b/init.lua
index d6067e5..e91c4dc 100644
--- a/init.lua
+++ b/init.lua
@@ -118,9 +118,10 @@ dofile(pipeworks.modpath.."/wielder.lua")
local logicdir = "/new_flow_logic/"
-- note that even with these files the new flow logic is not yet default
+dofile(pipeworks.modpath..logicdir.."flowable_node_registry.lua")
dofile(pipeworks.modpath..logicdir.."abms.lua")
dofile(pipeworks.modpath..logicdir.."abm_register.lua")
-dofile(pipeworks.modpath..logicdir.."flowable_node_registry.lua")
+dofile(pipeworks.modpath..logicdir.."flowable_node_registry_install.lua")
if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end
if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube.lua") end
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.
diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua
new file mode 100644
index 0000000..06d69fd
--- /dev/null
+++ b/new_flow_logic/flowable_node_registry_install.lua
@@ -0,0 +1,70 @@
+-- flowable node registry: add entries and install ABMs if new flow logic is enabled
+-- written 2017 by thetaepsilon
+
+
+
+-- use for hooking up ABMs as nodes are registered
+local abmregister = pipeworks.flowlogic.abmregister
+
+-- 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.