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_install.lua | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 new_flow_logic/flowable_node_registry_install.lua (limited to 'new_flow_logic/flowable_node_registry_install.lua') 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. -- cgit v1.2.3 From f3cd1b61d771824ed9f42b32caa95ae08538bb64 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 16:17:35 +0100 Subject: new flow logic: flowable_node_registry_install.lua: add registration tracing --- new_flow_logic/flowable_node_registry_install.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 06d69fd..f83f8ad 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -22,6 +22,12 @@ local insertbase = function(nodename) -- table.insert(pipeworks.flowables.list.nodenames, nodename) end +local regwarning = function(kind, nodename) + local tail = "" + if pipeworks.enable_new_flow_logic then tail = " but new_flow_logic not enabled" end + pipeworks.logger("[pipeworks] "..kind.." flow logic registry requested for "..nodename..tail) +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. @@ -32,6 +38,7 @@ register.simple = function(nodename) if pipeworks.enable_new_flow_logic then abmregister.balance(nodename) end + regwarning("simple", nodename) end local checkbase = function(nodename) @@ -50,6 +57,7 @@ register.intake_simple = function(nodename, maxpressure) if pipeworks.enable_new_flow_logic then abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2) end + regwarning("simple intake", nodename) end -- Register a node as an output. @@ -61,6 +69,7 @@ register.output = function(nodename, threshold, outputfn) if pipeworks.enable_new_flow_logic then abmregister.output(nodename, threshold, outputfn) end + regwarning("output node", nodename) end -- TODOs here: -- cgit v1.2.3 From 0fb0eab7235db267aece1cecee7c1d6a1a5b42a1 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 16:54:24 +0100 Subject: move pipe node registration for new flow logic closer to their definition in pipes.lua --- new_flow_logic/flowable_node_registry_install.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index f83f8ad..ac305dc 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -24,8 +24,8 @@ end local regwarning = function(kind, nodename) local tail = "" - if pipeworks.enable_new_flow_logic then tail = " but new_flow_logic not enabled" end - pipeworks.logger("[pipeworks] "..kind.." flow logic registry requested for "..nodename..tail) + if not pipeworks.enable_new_flow_logic then tail = " but new_flow_logic not enabled" end + pipeworks.logger(kind.." flow logic registry requested for "..nodename..tail) end -- Register a node as a simple flowable. -- cgit v1.2.3 From 894ea5174fb8c3be9038698cb119b24acbec8cea Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Tue, 3 Oct 2017 20:38:56 +0100 Subject: move new flow logic flag to dedicated toggles table --- new_flow_logic/flowable_node_registry_install.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index ac305dc..defe877 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -24,7 +24,7 @@ end local regwarning = function(kind, nodename) local tail = "" - if not pipeworks.enable_new_flow_logic then tail = " but new_flow_logic not enabled" end + if not pipeworks.toggles.pressure_logic then tail = " but pressure logic not enabled" end pipeworks.logger(kind.." flow logic registry requested for "..nodename..tail) end @@ -35,7 +35,7 @@ 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 + if pipeworks.toggles.pressure_logic then abmregister.balance(nodename) end regwarning("simple", nodename) @@ -54,7 +54,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 + if pipeworks.toggles.pressure_logic then abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2) end regwarning("simple intake", nodename) @@ -66,7 +66,7 @@ end register.output = function(nodename, threshold, outputfn) checkbase(nodename) pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } - if pipeworks.enable_new_flow_logic then + if pipeworks.toggles.pressure_logic then abmregister.output(nodename, threshold, outputfn) end regwarning("output node", nodename) -- cgit v1.2.3 From 7eb5dc6aca664bbca5c81203f5d72d9abc39578c Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 4 Oct 2017 18:54:51 +0100 Subject: flowable_node_registry_install.lua: silence registration debugging by default --- new_flow_logic/flowable_node_registry_install.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index defe877..79f5997 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -25,7 +25,7 @@ end local regwarning = function(kind, nodename) local tail = "" if not pipeworks.toggles.pressure_logic then tail = " but pressure logic not enabled" end - pipeworks.logger(kind.." flow logic registry requested for "..nodename..tail) + --pipeworks.logger(kind.." flow logic registry requested for "..nodename..tail) end -- Register a node as a simple flowable. -- cgit v1.2.3 From 465e28cbd3e2d176a4ca0429711bc459fe37cf0d Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 12:16:36 +0100 Subject: devices.lua: factor out usage of flowlogic helper into dedicated registry function --- new_flow_logic/flowable_node_registry_install.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 79f5997..3d9ce0a 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -77,3 +77,7 @@ end -- 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. +register.output_simple = function(nodename, threshold, neighbours) + local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed(neighbours) + register.output(nodename, threshold, outputfn) +end -- cgit v1.2.3 From 4f58a3039c55783978d5f85fbf59f06025884384 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 13:05:52 +0100 Subject: new flow logic: flowable_node_registry_install.lua: separate pressure threshold into upper and lower hysteresis values --- new_flow_logic/flowable_node_registry_install.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 3d9ce0a..7f414c4 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -62,12 +62,19 @@ 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) +-- upper and lower thresholds have different meanings depending on whether finite liquid mode is in effect. +-- if not (the default unless auto-detected), +-- nodes above their upper threshold have their outputfn invoked (and pressure deducted), +-- nodes between upper and lower are left idle, +-- and nodes below lower have their cleanup fn invoked (to say remove water sources). +-- the upper and lower difference acts as a hysteresis to try and avoid "gaps" in the flow. +-- if finite mode is on, upper is ignored and lower is used to determine whether to run outputfn; +-- cleanupfn is ignored in this mode as finite mode assumes something causes water to move itself. +register.output = function(nodename, upper, lower, outputfn) checkbase(nodename) pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } if pipeworks.toggles.pressure_logic then - abmregister.output(nodename, threshold, outputfn) + abmregister.output(nodename, lower, outputfn) end regwarning("output node", nodename) end @@ -77,7 +84,8 @@ end -- 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. -register.output_simple = function(nodename, threshold, neighbours) +-- for meanings of upper and lower, see register.output() above. +register.output_simple = function(nodename, upper, lower, neighbours) local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed(neighbours) - register.output(nodename, threshold, outputfn) + register.output(nodename, upper, lower, outputfn) end -- cgit v1.2.3 From 31a67cf4f98f0c9850998799956063401efceef5 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 13:15:42 +0100 Subject: new flow logic: flowable_node_registry_install.lua: add proper documentation for register.output_simple() --- new_flow_logic/flowable_node_registry_install.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 7f414c4..650d1da 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -79,12 +79,17 @@ register.output = function(nodename, upper, lower, outputfn) regwarning("output node", nodename) 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. +-- register a simple output: +-- drains pressure by attempting to place water in nearby nodes, +-- which can be set by passing a list of offset vectors. +-- will attempt to drain as many whole nodes as there are positions in the offset list. -- for meanings of upper and lower, see register.output() above. +-- non-finite mode: +-- above upper pressure: places water sources as appropriate, keeps draining pressure. +-- below lower presssure: removes it's neighbour water sources. +-- finite mode: +-- same as for above pressure in non-finite mode, +-- but only drains pressure when water source nodes are actually placed. register.output_simple = function(nodename, upper, lower, neighbours) local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed(neighbours) register.output(nodename, upper, lower, outputfn) -- cgit v1.2.3 From 1669cfd4510a2dbb2ca3c754b414ae8c976ceca1 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 15:42:00 +0100 Subject: new flow logic: flowable_node_registry_install.lua: add duplicate registration guard for register.output() --- new_flow_logic/flowable_node_registry_install.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 650d1da..07001ef 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -71,6 +71,9 @@ end -- if finite mode is on, upper is ignored and lower is used to determine whether to run outputfn; -- cleanupfn is ignored in this mode as finite mode assumes something causes water to move itself. register.output = function(nodename, upper, lower, outputfn) + if pipeworks.flowables.outputs.list[nodename] then + error("pipeworks.flowables.outputs duplicate registration!") + end checkbase(nodename) pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } if pipeworks.toggles.pressure_logic then -- cgit v1.2.3 From 34cfee8a2faaa9366b1a9ae5035eedee3620aa56 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 16:12:36 +0100 Subject: new flow logic: start adding replacement ABM logic --- new_flow_logic/flowable_node_registry_install.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 07001ef..5ebae61 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -79,6 +79,10 @@ register.output = function(nodename, upper, lower, outputfn) if pipeworks.toggles.pressure_logic then abmregister.output(nodename, lower, outputfn) end + -- output ABM now part of main flow logic ABM to preserve ordering. + -- note that because outputs have to be a flowable first + -- (and the installation of the flow logic ABM is conditional), + -- registered output nodes for new_flow_logic is also still conditional on the enable flag. regwarning("output node", nodename) end -- cgit v1.2.3 From 016f9de82f91b61a14ad1bc477ee18b501f77e39 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 17:33:42 +0100 Subject: new flow logic: abms.lua: refactor ABM logic into new master ABM, make balance_pressure() take current pressure and return new pressure --- new_flow_logic/flowable_node_registry_install.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 5ebae61..d195c63 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -36,7 +36,7 @@ register.simple = function(nodename) pipeworks.flowables.list.simple[nodename] = true table.insert(pipeworks.flowables.list.simple_nodenames, nodename) if pipeworks.toggles.pressure_logic then - abmregister.balance(nodename) + abmregister.flowlogic(nodename) end regwarning("simple", nodename) end -- cgit v1.2.3 From 65b3448796815718275ed3c16af4865e5e005454 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 17:55:14 +0100 Subject: new flow logic: abms.lua: refactor flowlogic.run_output() into a processing stage of flowlogic.run() --- new_flow_logic/flowable_node_registry_install.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index d195c63..aed6fbd 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -75,10 +75,7 @@ register.output = function(nodename, upper, lower, outputfn) error("pipeworks.flowables.outputs duplicate registration!") end checkbase(nodename) - pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } - if pipeworks.toggles.pressure_logic then - abmregister.output(nodename, lower, outputfn) - end + pipeworks.flowables.outputs.list[nodename] = { upper=upper, lower=lower, outputfn=outputfn } -- output ABM now part of main flow logic ABM to preserve ordering. -- note that because outputs have to be a flowable first -- (and the installation of the flow logic ABM is conditional), -- cgit v1.2.3 From be1a6d53aa94f812dc661b4b08c5d0e2ebf97623 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 18:07:55 +0100 Subject: new flow logic: flowable_node_registry_install.lua: factor out register.intake_simple into generic registration and helper wrapper --- new_flow_logic/flowable_node_registry_install.lua | 32 ++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index aed6fbd..35dbe97 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -45,21 +45,41 @@ 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. +local duplicateerr = function(kind, nodename) error(kind.." duplicate registration for "..nodename) end + + + +-- Registers a node as a fluid intake. +-- intakefn is used to determine the water that can be taken in a node-specific way. -- 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. +-- maxpressure is the maximum pipeline pressure that this node can drive; +-- if the input's node exceeds this the callback is not run. -- possible WISHME here: technic-driven high-pressure pumps -register.intake_simple = function(nodename, maxpressure) +register.intake = function(nodename, maxpressure, intakefn) + -- check for duplicate registration of this node + local list = pipeworks.flowables.inputs.list checkbase(nodename) - pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure } + if list[nodename] then duplicateerr("pipeworks.flowables.inputs", nodename) end + list[nodename] = { maxpressure=maxpressure, intakefn=intakefn } table.insert(pipeworks.flowables.inputs.nodenames, nodename) if pipeworks.toggles.pressure_logic then - abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2) + abmregister.input(nodename, maxpressure, intakefn) end - regwarning("simple intake", nodename) + regwarning("intake", nodename) end + + +-- Register a node as a simple intake: +-- tries to absorb water source nodes from it's surroundings. +-- may exceed limit slightly due to needing to absorb whole nodes. +register.intake_simple = function(nodename, maxpressure) + register.intake(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2) +end + + + -- Register a node as an output. -- Expects node to already be a flowable. -- upper and lower thresholds have different meanings depending on whether finite liquid mode is in effect. -- cgit v1.2.3 From 9c770532e6e3cb1157e467015a97aef97a8a8893 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 19:19:09 +0100 Subject: new flow logic: abms.lua: refactor run_input to run as part of master run() ABM --- new_flow_logic/flowable_node_registry_install.lua | 4 ---- 1 file changed, 4 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 35dbe97..6da87dc 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -62,10 +62,6 @@ register.intake = function(nodename, maxpressure, intakefn) checkbase(nodename) if list[nodename] then duplicateerr("pipeworks.flowables.inputs", nodename) end list[nodename] = { maxpressure=maxpressure, intakefn=intakefn } - table.insert(pipeworks.flowables.inputs.nodenames, nodename) - if pipeworks.toggles.pressure_logic then - abmregister.input(nodename, maxpressure, intakefn) - end regwarning("intake", nodename) end -- cgit v1.2.3 From 453a114cd022a4d7b0a028f9e4a9785e20e6e368 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 21:55:49 +0100 Subject: new flow logic: flowable_node_registry_install.lua: add cleanupfn argument to register.output() --- new_flow_logic/flowable_node_registry_install.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 6da87dc..0be9fc0 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -86,12 +86,17 @@ end -- the upper and lower difference acts as a hysteresis to try and avoid "gaps" in the flow. -- if finite mode is on, upper is ignored and lower is used to determine whether to run outputfn; -- cleanupfn is ignored in this mode as finite mode assumes something causes water to move itself. -register.output = function(nodename, upper, lower, outputfn) +register.output = function(nodename, upper, lower, outputfn, cleanupfn) if pipeworks.flowables.outputs.list[nodename] then error("pipeworks.flowables.outputs duplicate registration!") end checkbase(nodename) - pipeworks.flowables.outputs.list[nodename] = { upper=upper, lower=lower, outputfn=outputfn } + pipeworks.flowables.outputs.list[nodename] = { + upper=upper, + lower=lower, + outputfn=outputfn, + cleanupfn=cleanupfn, + } -- output ABM now part of main flow logic ABM to preserve ordering. -- note that because outputs have to be a flowable first -- (and the installation of the flow logic ABM is conditional), @@ -112,5 +117,6 @@ end -- but only drains pressure when water source nodes are actually placed. register.output_simple = function(nodename, upper, lower, neighbours) local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed(neighbours) - register.output(nodename, upper, lower, outputfn) + local cleanupfn = pipeworks.flowlogic.helpers.make_neighbour_cleanup_fixed(neighbours) + register.output(nodename, upper, lower, outputfn, cleanupfn) 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_install.lua | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 0be9fc0..63151f0 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -120,3 +120,53 @@ register.output_simple = function(nodename, upper, lower, neighbours) local cleanupfn = pipeworks.flowlogic.helpers.make_neighbour_cleanup_fixed(neighbours) register.output(nodename, upper, lower, outputfn, cleanupfn) end + + + +-- common base checking for transition nodes +-- ensures the node has only been registered once as a transition. +local transition_list = pipeworks.flowables.transitions.list +local insert_transition_base = function(nodename) + checkbase(nodename) + if transition_list[nodename] then duplicateerr("base transition", nodename) end + transition_list[nodename] = true +end + + + +-- register a simple transition set. +-- expects a table with nodenames as keys and threshold pressures as values. +-- internally, the table is sorted by value, and when one of these nodes needs to transition, +-- the table is searched starting from the lowest (even if it's value is non-zero), +-- until a value is found which is higher than or equal to the current node pressure. +-- ex. nodeset = { ["mod:level_0"] = 0, ["mod:level_1"] = 1, --[[ ... ]] } +local simpleseterror = function(msg) + error("register.transition_simple_set(): "..msg) +end +local simple_transitions = pipeworks.flowables.transitions.simple + +register.transition_simple_set = function(nodeset) + local set = {} + for nodename, value in pairs(nodeset) do + if type(nodename) ~= "string" then simpleseterror("nodename key "..tostring(nodename).."was not a string!") end + if type(value) ~= "number" then simpleseterror("pressure value "..tostring(value).."was not a number!") end + insert_transition_base(nodename) + if simple_transitions[nodename] then duplicateerr("simple transition set", nodename) end + -- assigning set to table is done separately below + + table.insert(set, { nodename=nodename, threshold=value }) + end + + -- sort pressure values, smallest first + local smallest_first = function(a, b) + return a.value < b.value + end + table.sort(set, smallest_first) + + -- individual registration of each node, all sharing this set, + -- so each node in the set will transition to the correct target node. + for _, element in ipairs(set) do + --pipeworks.logger("register.transition_simple_set() after sort: nodename "..element.nodename.." value "..tostring(element.threshold)) + simple_transitions[element.nodename] = set + end +end -- cgit v1.2.3 From 32a24730f1ab8cd596ed2f4cf6eda1a58c877ecb Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 15:07:12 +0100 Subject: new flow logic: change simple transition set logic to take list of key-value pairs, add set registration for flow sensor pipe --- new_flow_logic/flowable_node_registry_install.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 63151f0..f019dc3 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -147,8 +147,11 @@ local simple_transitions = pipeworks.flowables.transitions.simple register.transition_simple_set = function(nodeset) local set = {} - for nodename, value in pairs(nodeset) do - if type(nodename) ~= "string" then simpleseterror("nodename key "..tostring(nodename).."was not a string!") end + for index, element in ipairs(nodeset) do + if type(element) ~= "table" then simpleseterror("element "..tostring(index).." in nodeset was not table!") end + local nodename = element[1] + local value = element[2] + if type(nodename) ~= "string" then simpleseterror("nodename "..tostring(nodename).."was not a string!") end if type(value) ~= "number" then simpleseterror("pressure value "..tostring(value).."was not a number!") end insert_transition_base(nodename) if simple_transitions[nodename] then duplicateerr("simple transition set", nodename) end @@ -159,7 +162,7 @@ register.transition_simple_set = function(nodeset) -- sort pressure values, smallest first local smallest_first = function(a, b) - return a.value < b.value + return a.threshold < b.threshold end table.sort(set, smallest_first) -- cgit v1.2.3 From c2553928f2e1063ca8011b0f9b024b819995cab5 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 16:20:30 +0100 Subject: new flow logic: flowable_node_registry_install.lua: add set size checking guard --- new_flow_logic/flowable_node_registry_install.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index f019dc3..e4a5744 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -147,6 +147,9 @@ local simple_transitions = pipeworks.flowables.transitions.simple register.transition_simple_set = function(nodeset) local set = {} + + local length = #nodeset + if length < 2 then simpleseterror("nodeset needs at least two elements!") end for index, element in ipairs(nodeset) do if type(element) ~= "table" then simpleseterror("element "..tostring(index).." in nodeset was not table!") end local nodename = element[1] -- 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_install.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'new_flow_logic/flowable_node_registry_install.lua') diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index e4a5744..c8f6889 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -145,8 +145,9 @@ local simpleseterror = function(msg) end local simple_transitions = pipeworks.flowables.transitions.simple -register.transition_simple_set = function(nodeset) +register.transition_simple_set = function(nodeset, extras) local set = {} + if extras == nil then extras = {} end local length = #nodeset if length < 2 then simpleseterror("nodeset needs at least two elements!") end @@ -175,4 +176,13 @@ register.transition_simple_set = function(nodeset) --pipeworks.logger("register.transition_simple_set() after sort: nodename "..element.nodename.." value "..tostring(element.threshold)) simple_transitions[element.nodename] = set end + + -- handle extra options + -- if mesecons rules table was passed, set for each node + if extras.mesecons then + local mesecons_rules = pipeworks.flowables.transitions.mesecons + for _, element in ipairs(set) do + mesecons_rules[element.nodename] = extras.mesecons + end + end end -- cgit v1.2.3