From 40eeaac2ecb25dbc55f7315342e74723d6248534 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 20:16:00 +0100 Subject: internal refactoring of flowable node registration in preparation for enhanced flow checking logic --- register_flow_logic.lua | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'register_flow_logic.lua') diff --git a/register_flow_logic.lua b/register_flow_logic.lua index c9df09c..8580188 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -1,29 +1,11 @@ -- register new flow logic ABMs -- written 2017 by thetaepsilon -local pipes_full_nodenames = pipeworks.pipes_full_nodenames -local pipes_empty_nodenames = pipeworks.pipes_empty_nodenames - --- run pressure balancing ABM over all water-moving nodes --- FIXME: DRY principle, get this from elsewhere in the code -local pump_on = "pipeworks:pump_on" -local pump_off = "pipeworks:pump_off" -local spigot_off = "pipeworks:spigot" -local spigot_on = "pipeworks:spigot_pouring" - -local pipes_all_nodenames = pipes_full_nodenames -for _, pipe in ipairs(pipes_empty_nodenames) do - table.insert(pipes_all_nodenames, pipe) -end - -if pipeworks.enable_pipe_devices then - table.insert(pipes_all_nodenames, pump_off) - table.insert(pipes_all_nodenames, pump_on) - table.insert(pipes_all_nodenames, spigot_on) - table.insert(pipes_all_nodenames, spigot_off) -end +-- note that checking for feature toggles (because otherwise certain pipes aren't define) +-- is now done by flowable_nodes_add_pipes.lua +--[[ if pipeworks.enable_pipes then minetest.register_abm({ nodenames = pipes_all_nodenames, @@ -34,19 +16,32 @@ if pipeworks.enable_pipes then end }) end +]] +-- flowables.register.simple takes care of creating an array-like table of node names +minetest.register_abm({ + nodenames = pipeworks.flowables.list.simple_nodenames, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + pipeworks.balance_pressure(pos, node) + end +}) if pipeworks.enable_pipe_devices then -- absorb water into pumps if it'll fit minetest.register_abm({ - nodenames = { pump_on }, + nodenames = pipeworks.flowables.inputs.nodenames, interval = 1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) pipeworks.run_pump_intake(pos, node) end }) + -- output water from spigots -- add both "on/off" spigots so one can be used to indicate a certain level of fluid. + -- temp. disabled as the node names were moved to flowable_node_add_pipes.lua + --[[ minetest.register_abm({ nodenames = { spigot_on, spigot_off }, interval = 1, @@ -55,4 +50,5 @@ if pipeworks.enable_pipe_devices then pipeworks.run_spigot_output(pos, node) end }) + ]] end -- cgit v1.2.3 From 0251baf692741c5cf3173ff9415c94dbbc3719f3 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 20:47:00 +0100 Subject: new_flow_logic.lua: move logic functions inside pipeworks.flowlogic sub-table --- register_flow_logic.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'register_flow_logic.lua') diff --git a/register_flow_logic.lua b/register_flow_logic.lua index 8580188..3a8df8e 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -23,7 +23,7 @@ minetest.register_abm({ interval = 1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.balance_pressure(pos, node) + pipeworks.flowlogic.balance_pressure(pos, node) end }) @@ -34,7 +34,7 @@ if pipeworks.enable_pipe_devices then interval = 1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.run_pump_intake(pos, node) + pipeworks.flowlogic.run_pump_intake(pos, node) end }) -- cgit v1.2.3 From 8dfbcad949b7751d4ddb56f033d82c0432d2e112 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 22:41:38 +0100 Subject: register_flow_logic.lua: begin refactoring abm registration to allow use by other mods --- register_flow_logic.lua | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'register_flow_logic.lua') diff --git a/register_flow_logic.lua b/register_flow_logic.lua index 3a8df8e..f82b8a9 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -17,15 +17,20 @@ if pipeworks.enable_pipes then }) end ]] --- flowables.register.simple takes care of creating an array-like table of node names -minetest.register_abm({ - nodenames = pipeworks.flowables.list.simple_nodenames, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.flowlogic.balance_pressure(pos, node) - end -}) + +local register_abm_balance = function(nodename) + minetest.register_abm({ + nodenames = { nodename }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + pipeworks.flowlogic.balance_pressure(pos, node) + end + }) +end +for nodename, _ in pairs(pipeworks.flowables.list.simple) do + register_abm_balance(nodename) +end if pipeworks.enable_pipe_devices then -- absorb water into pumps if it'll fit -- cgit v1.2.3 From aaef5eb22b439c3e410942c39726e58c0c041c40 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 22:56:12 +0100 Subject: register_flow_logic.lua: factor out per-node input ABM registration --- register_flow_logic.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'register_flow_logic.lua') diff --git a/register_flow_logic.lua b/register_flow_logic.lua index f82b8a9..60fc820 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -32,16 +32,22 @@ for nodename, _ in pairs(pipeworks.flowables.list.simple) do register_abm_balance(nodename) end -if pipeworks.enable_pipe_devices then - -- absorb water into pumps if it'll fit +local register_abm_input = function(nodename, properties) minetest.register_abm({ - nodenames = pipeworks.flowables.inputs.nodenames, + nodenames = { nodename }, interval = 1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) pipeworks.flowlogic.run_pump_intake(pos, node) end }) +end + +if pipeworks.enable_pipe_devices then + -- absorb water into pumps if it'll fit + for nodename, properties in pairs(pipeworks.flowables.inputs.list) do + register_abm_input(nodename, properties) + end -- output water from spigots -- add both "on/off" spigots so one can be used to indicate a certain level of fluid. -- cgit v1.2.3 From afcec82ae336cba3e874f6afd1b4e46e04245f7d Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 23:02:11 +0100 Subject: register_flow_logic.lua: expose ABM registration functions --- register_flow_logic.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'register_flow_logic.lua') diff --git a/register_flow_logic.lua b/register_flow_logic.lua index 60fc820..f3e8fbd 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -3,6 +3,11 @@ +local register = {} +pipeworks.flowlogic.abmregister = register + + + -- note that checking for feature toggles (because otherwise certain pipes aren't define) -- is now done by flowable_nodes_add_pipes.lua --[[ @@ -28,6 +33,7 @@ local register_abm_balance = function(nodename) end }) end +register.balance = register_abm_balance for nodename, _ in pairs(pipeworks.flowables.list.simple) do register_abm_balance(nodename) end @@ -42,6 +48,7 @@ local register_abm_input = function(nodename, properties) end }) end +register.input = register_abm_input if pipeworks.enable_pipe_devices then -- absorb water into pumps if it'll fit -- cgit v1.2.3 From d69941a0ae763d6681ede2185ad88e25b11fead5 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 23:22:04 +0100 Subject: temporarily move ABM registration out of register_flow_logic.lua to allow refactoring it into flowable registry --- register_flow_logic.lua | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'register_flow_logic.lua') diff --git a/register_flow_logic.lua b/register_flow_logic.lua index f3e8fbd..e7bed6a 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -8,21 +8,8 @@ pipeworks.flowlogic.abmregister = register --- note that checking for feature toggles (because otherwise certain pipes aren't define) --- is now done by flowable_nodes_add_pipes.lua ---[[ -if pipeworks.enable_pipes then - minetest.register_abm({ - nodenames = pipes_all_nodenames, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.balance_pressure(pos, node) - end - }) -end -]] - +-- register a node name for the pressure balancing ABM. +-- currently this only exists as a per-node function to allow nodes to be registered outside pipeworks. local register_abm_balance = function(nodename) minetest.register_abm({ nodenames = { nodename }, @@ -34,11 +21,10 @@ local register_abm_balance = function(nodename) }) end register.balance = register_abm_balance -for nodename, _ in pairs(pipeworks.flowables.list.simple) do - register_abm_balance(nodename) -end -local register_abm_input = function(nodename, properties) +-- register a node for the pump ABM. +-- maxpressure is the maximum pressure that this pump can drive. +local register_abm_input = function(nodename, maxpressure) minetest.register_abm({ nodenames = { nodename }, interval = 1, @@ -50,16 +36,8 @@ local register_abm_input = function(nodename, properties) end register.input = register_abm_input -if pipeworks.enable_pipe_devices then - -- absorb water into pumps if it'll fit - for nodename, properties in pairs(pipeworks.flowables.inputs.list) do - register_abm_input(nodename, properties) - end - - -- output water from spigots - -- add both "on/off" spigots so one can be used to indicate a certain level of fluid. - -- temp. disabled as the node names were moved to flowable_node_add_pipes.lua - --[[ +-- old spigot ABM code, not yet migrated +--[[ minetest.register_abm({ nodenames = { spigot_on, spigot_off }, interval = 1, @@ -68,5 +46,4 @@ if pipeworks.enable_pipe_devices then pipeworks.run_spigot_output(pos, node) end }) - ]] -end +]] -- cgit v1.2.3 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 --- register_flow_logic.lua | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 register_flow_logic.lua (limited to 'register_flow_logic.lua') diff --git a/register_flow_logic.lua b/register_flow_logic.lua deleted file mode 100644 index e7bed6a..0000000 --- a/register_flow_logic.lua +++ /dev/null @@ -1,49 +0,0 @@ --- register new flow logic ABMs --- written 2017 by thetaepsilon - - - -local register = {} -pipeworks.flowlogic.abmregister = register - - - --- register a node name for the pressure balancing ABM. --- currently this only exists as a per-node function to allow nodes to be registered outside pipeworks. -local register_abm_balance = function(nodename) - minetest.register_abm({ - nodenames = { nodename }, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.flowlogic.balance_pressure(pos, node) - end - }) -end -register.balance = register_abm_balance - --- register a node for the pump ABM. --- maxpressure is the maximum pressure that this pump can drive. -local register_abm_input = function(nodename, maxpressure) - minetest.register_abm({ - nodenames = { nodename }, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.flowlogic.run_pump_intake(pos, node) - end - }) -end -register.input = register_abm_input - --- old spigot ABM code, not yet migrated ---[[ - minetest.register_abm({ - nodenames = { spigot_on, spigot_off }, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.run_spigot_output(pos, node) - end - }) -]] -- cgit v1.2.3