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 --- init.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 470db2e..a64be4e 100644 --- a/init.lua +++ b/init.lua @@ -115,12 +115,16 @@ dofile(pipeworks.modpath.."/filter-injector.lua") dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") +-- note that pipes still don't appear until registered in the files below this one, so can still be turned off +dofile(pipeworks.modpath.."/flowable_node_registry.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 if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end --- individual enable flags also checked in register_flow_logic.lua +-- individual enable flags also checked in flowable_nodes_add_pipes.lua if pipeworks.enable_new_flow_logic then dofile(pipeworks.modpath.."/new_flow_logic.lua") + dofile(pipeworks.modpath.."/flowable_nodes_add_pipes.lua") dofile(pipeworks.modpath.."/register_flow_logic.lua") end -- 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 --- flowable_nodes_add_pipes.lua | 8 ++++++++ init.lua | 2 +- register_flow_logic.lua | 39 ++++++++------------------------------- 3 files changed, 17 insertions(+), 32 deletions(-) (limited to 'init.lua') diff --git a/flowable_nodes_add_pipes.lua b/flowable_nodes_add_pipes.lua index e681619..6fe8b7e 100644 --- a/flowable_nodes_add_pipes.lua +++ b/flowable_nodes_add_pipes.lua @@ -16,6 +16,7 @@ local pipes_full_nodenames = pipeworks.pipes_full_nodenames local pipes_empty_nodenames = pipeworks.pipes_empty_nodenames local register = pipeworks.flowables.register +local abmregister = pipeworks.flowlogic.abmregister @@ -29,9 +30,11 @@ local spigot_on = "pipeworks:spigot_pouring" if pipeworks.enable_pipes then for _, pipe in ipairs(pipes_full_nodenames) do register.simple(pipe) + abmregister.balance(pipe) end for _, pipe in ipairs(pipes_empty_nodenames) do register.simple(pipe) + abmregister.balance(pipe) end if pipeworks.enable_pipe_devices then @@ -39,7 +42,12 @@ if pipeworks.enable_pipes then register.simple(pump_on) register.simple(spigot_on) register.simple(spigot_off) + abmregister.balance(pump_off) + abmregister.balance(pump_on) + abmregister.balance(spigot_on) + abmregister.balance(spigot_off) register.intake_simple(pump_on, thresholds.pump_pressure) + abmregister.input(pump_on, thresholds.pump_pressure) end end diff --git a/init.lua b/init.lua index a64be4e..d70e4f4 100644 --- a/init.lua +++ b/init.lua @@ -124,8 +124,8 @@ if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") -- individual enable flags also checked in flowable_nodes_add_pipes.lua if pipeworks.enable_new_flow_logic then dofile(pipeworks.modpath.."/new_flow_logic.lua") - dofile(pipeworks.modpath.."/flowable_nodes_add_pipes.lua") dofile(pipeworks.modpath.."/register_flow_logic.lua") + dofile(pipeworks.modpath.."/flowable_nodes_add_pipes.lua") end if pipeworks.enable_redefines then 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 --- flowable_node_registry.lua | 59 -------------- flowable_nodes_add_pipes.lua | 53 ------------- init.lua | 11 +-- new_flow_logic.lua | 123 ------------------------------ new_flow_logic/abm_register.lua | 49 ++++++++++++ new_flow_logic/abms.lua | 123 ++++++++++++++++++++++++++++++ new_flow_logic/flowable_node_registry.lua | 59 ++++++++++++++ new_flow_logic/register_local_pipes.lua | 53 +++++++++++++ register_flow_logic.lua | 49 ------------ 9 files changed, 290 insertions(+), 289 deletions(-) delete mode 100644 flowable_node_registry.lua delete mode 100644 flowable_nodes_add_pipes.lua delete mode 100644 new_flow_logic.lua create mode 100644 new_flow_logic/abm_register.lua create mode 100644 new_flow_logic/abms.lua create mode 100644 new_flow_logic/flowable_node_registry.lua create mode 100644 new_flow_logic/register_local_pipes.lua delete mode 100644 register_flow_logic.lua (limited to 'init.lua') diff --git a/flowable_node_registry.lua b/flowable_node_registry.lua deleted file mode 100644 index def9649..0000000 --- a/flowable_node_registry.lua +++ /dev/null @@ -1,59 +0,0 @@ --- 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 diff --git a/flowable_nodes_add_pipes.lua b/flowable_nodes_add_pipes.lua deleted file mode 100644 index 6fe8b7e..0000000 --- a/flowable_nodes_add_pipes.lua +++ /dev/null @@ -1,53 +0,0 @@ --- conditional registration of pipe nodes for the new pipe logic, depending on enable flags. --- otherwise register_flow_logic.lua would be attempting to register ABMs for non-existant nodes. --- written 2017 by thetaepsilon - - - --- global values and thresholds for water behaviour --- TODO: add some way of setting this per-world -local thresholds = {} --- limit on pump pressure - will not absorb more than can be taken -thresholds.pump_pressure = 2 - - - -local pipes_full_nodenames = pipeworks.pipes_full_nodenames -local pipes_empty_nodenames = pipeworks.pipes_empty_nodenames - -local register = pipeworks.flowables.register -local abmregister = pipeworks.flowlogic.abmregister - - - --- FIXME: DRY principle for names, move this to devices.lua? --- FIXME: all devices still considered simple -local pump_on = "pipeworks:pump_on" -local pump_off = "pipeworks:pump_off" -local spigot_off = "pipeworks:spigot" -local spigot_on = "pipeworks:spigot_pouring" - -if pipeworks.enable_pipes then - for _, pipe in ipairs(pipes_full_nodenames) do - register.simple(pipe) - abmregister.balance(pipe) - end - for _, pipe in ipairs(pipes_empty_nodenames) do - register.simple(pipe) - abmregister.balance(pipe) - end - - if pipeworks.enable_pipe_devices then - register.simple(pump_off) - register.simple(pump_on) - register.simple(spigot_on) - register.simple(spigot_off) - abmregister.balance(pump_off) - abmregister.balance(pump_on) - abmregister.balance(spigot_on) - abmregister.balance(spigot_off) - - register.intake_simple(pump_on, thresholds.pump_pressure) - abmregister.input(pump_on, thresholds.pump_pressure) - end -end diff --git a/init.lua b/init.lua index d70e4f4..a081759 100644 --- a/init.lua +++ b/init.lua @@ -115,17 +115,18 @@ dofile(pipeworks.modpath.."/filter-injector.lua") dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") +local logicdir = "/new_flow_logic/" -- note that pipes still don't appear until registered in the files below this one, so can still be turned off -dofile(pipeworks.modpath.."/flowable_node_registry.lua") +dofile(pipeworks.modpath..logicdir.."flowable_node_registry.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 if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end --- individual enable flags also checked in flowable_nodes_add_pipes.lua +-- individual enable flags also checked in register_local_pipes.lua if pipeworks.enable_new_flow_logic then - dofile(pipeworks.modpath.."/new_flow_logic.lua") - dofile(pipeworks.modpath.."/register_flow_logic.lua") - dofile(pipeworks.modpath.."/flowable_nodes_add_pipes.lua") + dofile(pipeworks.modpath..logicdir.."abms.lua") + dofile(pipeworks.modpath..logicdir.."abm_register.lua") + dofile(pipeworks.modpath..logicdir.."register_local_pipes.lua") end if pipeworks.enable_redefines then diff --git a/new_flow_logic.lua b/new_flow_logic.lua deleted file mode 100644 index 7360668..0000000 --- a/new_flow_logic.lua +++ /dev/null @@ -1,123 +0,0 @@ --- reimplementation of new_flow_logic branch: processing functions --- written 2017 by thetaepsilon - - - -local flowlogic = {} -pipeworks.flowlogic = flowlogic - - - --- borrowed from above: might be useable to replace the above coords tables -local make_coords_offsets = function(pos, include_base) - local coords = { - {x=pos.x,y=pos.y-1,z=pos.z}, - {x=pos.x,y=pos.y+1,z=pos.z}, - {x=pos.x-1,y=pos.y,z=pos.z}, - {x=pos.x+1,y=pos.y,z=pos.z}, - {x=pos.x,y=pos.y,z=pos.z-1}, - {x=pos.x,y=pos.y,z=pos.z+1}, - } - if include_base then table.insert(coords, pos) end - return coords -end - - - --- local debuglog = function(msg) print("## "..msg) end - - - --- new version of liquid check --- accepts a limit parameter to only delete water blocks that the receptacle can accept, --- and returns it so that the receptacle can update it's pressure values. --- this should ensure that water blocks aren't vanished from existance. --- will take care of zero or negative-valued limits. -local check_for_liquids_v2 = function(pos, limit) - if not limit then - limit = 6 - end - local coords = make_coords_offsets(pos, false) - local total = 0 - for index, tpos in ipairs(coords) do - if total >= limit then break end - local name = minetest.get_node(tpos).name - if name == "default:water_source" then - minetest.remove_node(tpos) - total = total + 1 - end - end - return total -end -flowlogic.check_for_liquids_v2 = check_for_liquids_v2 - - - -local label_pressure = "pipeworks.water_pressure" -local label_haspressure = "pipeworks.is_pressure_node" -flowlogic.balance_pressure = function(pos, node) - -- debuglog("balance_pressure() "..node.name.." at "..pos.x.." "..pos.y.." "..pos.z) - -- check the pressure of all nearby nodes, and average it out. - -- for the moment, only balance neighbour nodes if it already has a pressure value. - -- XXX: maybe this could be used to add fluid behaviour to other mod's nodes too? - - -- unconditionally include self in nodes to average over - local meta = minetest.get_meta(pos) - local currentpressure = meta:get_float(label_pressure) - meta:set_int(label_haspressure, 1) - local connections = { meta } - local totalv = currentpressure - local totalc = 1 - - -- then handle neighbours, but if not a pressure node don't consider them at all - for _, npos in ipairs(make_coords_offsets(pos, false)) do - local neighbour = minetest.get_meta(npos) - local haspressure = (neighbour:get_int(label_haspressure) ~= 0) - if haspressure then - local n = neighbour:get_float(label_pressure) - table.insert(connections, neighbour) - totalv = totalv + n - totalc = totalc + 1 - end - end - - local average = totalv / totalc - for _, targetmeta in ipairs(connections) do - targetmeta:set_float(label_pressure, average) - end -end - - - -flowlogic.run_pump_intake = function(pos, node) - -- try to absorb nearby water nodes, but only up to limit. - -- NB: check_for_liquids_v2 handles zero or negative from the following subtraction - - local properties = pipeworks.flowables.inputs.list[node.name] - local maxpressure = properties.maxpressure - - local meta = minetest.get_meta(pos) - local currentpressure = meta:get_float(label_pressure) - - local intake_limit = maxpressure - currentpressure - local actual_intake = check_for_liquids_v2(pos, intake_limit) - local newpressure = actual_intake + currentpressure - -- debuglog("oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake.." newpressure "..newpressure) - meta:set_float(label_pressure, newpressure) -end - - - -flowlogic.run_spigot_output = function(pos, node) - -- try to output a water source node if there's enough pressure and space below. - local meta = minetest.get_meta(pos) - local currentpressure = meta:get_float(label_pressure) - if currentpressure > 1 then - local below = {x=pos.x, y=pos.y-1, z=pos.z} - local name = minetest.get_node(below).name - if (name == "air") or (name == "default:water_flowing") then - minetest.set_node(below, {name="default:water_source"}) - meta:set_float(label_pressure, currentpressure - 1) - end - end -end diff --git a/new_flow_logic/abm_register.lua b/new_flow_logic/abm_register.lua new file mode 100644 index 0000000..e7bed6a --- /dev/null +++ b/new_flow_logic/abm_register.lua @@ -0,0 +1,49 @@ +-- 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 + }) +]] diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua new file mode 100644 index 0000000..7360668 --- /dev/null +++ b/new_flow_logic/abms.lua @@ -0,0 +1,123 @@ +-- reimplementation of new_flow_logic branch: processing functions +-- written 2017 by thetaepsilon + + + +local flowlogic = {} +pipeworks.flowlogic = flowlogic + + + +-- borrowed from above: might be useable to replace the above coords tables +local make_coords_offsets = function(pos, include_base) + local coords = { + {x=pos.x,y=pos.y-1,z=pos.z}, + {x=pos.x,y=pos.y+1,z=pos.z}, + {x=pos.x-1,y=pos.y,z=pos.z}, + {x=pos.x+1,y=pos.y,z=pos.z}, + {x=pos.x,y=pos.y,z=pos.z-1}, + {x=pos.x,y=pos.y,z=pos.z+1}, + } + if include_base then table.insert(coords, pos) end + return coords +end + + + +-- local debuglog = function(msg) print("## "..msg) end + + + +-- new version of liquid check +-- accepts a limit parameter to only delete water blocks that the receptacle can accept, +-- and returns it so that the receptacle can update it's pressure values. +-- this should ensure that water blocks aren't vanished from existance. +-- will take care of zero or negative-valued limits. +local check_for_liquids_v2 = function(pos, limit) + if not limit then + limit = 6 + end + local coords = make_coords_offsets(pos, false) + local total = 0 + for index, tpos in ipairs(coords) do + if total >= limit then break end + local name = minetest.get_node(tpos).name + if name == "default:water_source" then + minetest.remove_node(tpos) + total = total + 1 + end + end + return total +end +flowlogic.check_for_liquids_v2 = check_for_liquids_v2 + + + +local label_pressure = "pipeworks.water_pressure" +local label_haspressure = "pipeworks.is_pressure_node" +flowlogic.balance_pressure = function(pos, node) + -- debuglog("balance_pressure() "..node.name.." at "..pos.x.." "..pos.y.." "..pos.z) + -- check the pressure of all nearby nodes, and average it out. + -- for the moment, only balance neighbour nodes if it already has a pressure value. + -- XXX: maybe this could be used to add fluid behaviour to other mod's nodes too? + + -- unconditionally include self in nodes to average over + local meta = minetest.get_meta(pos) + local currentpressure = meta:get_float(label_pressure) + meta:set_int(label_haspressure, 1) + local connections = { meta } + local totalv = currentpressure + local totalc = 1 + + -- then handle neighbours, but if not a pressure node don't consider them at all + for _, npos in ipairs(make_coords_offsets(pos, false)) do + local neighbour = minetest.get_meta(npos) + local haspressure = (neighbour:get_int(label_haspressure) ~= 0) + if haspressure then + local n = neighbour:get_float(label_pressure) + table.insert(connections, neighbour) + totalv = totalv + n + totalc = totalc + 1 + end + end + + local average = totalv / totalc + for _, targetmeta in ipairs(connections) do + targetmeta:set_float(label_pressure, average) + end +end + + + +flowlogic.run_pump_intake = function(pos, node) + -- try to absorb nearby water nodes, but only up to limit. + -- NB: check_for_liquids_v2 handles zero or negative from the following subtraction + + local properties = pipeworks.flowables.inputs.list[node.name] + local maxpressure = properties.maxpressure + + local meta = minetest.get_meta(pos) + local currentpressure = meta:get_float(label_pressure) + + local intake_limit = maxpressure - currentpressure + local actual_intake = check_for_liquids_v2(pos, intake_limit) + local newpressure = actual_intake + currentpressure + -- debuglog("oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake.." newpressure "..newpressure) + meta:set_float(label_pressure, newpressure) +end + + + +flowlogic.run_spigot_output = function(pos, node) + -- try to output a water source node if there's enough pressure and space below. + local meta = minetest.get_meta(pos) + local currentpressure = meta:get_float(label_pressure) + if currentpressure > 1 then + local below = {x=pos.x, y=pos.y-1, z=pos.z} + local name = minetest.get_node(below).name + if (name == "air") or (name == "default:water_flowing") then + minetest.set_node(below, {name="default:water_source"}) + meta:set_float(label_pressure, currentpressure - 1) + end + end +end 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 diff --git a/new_flow_logic/register_local_pipes.lua b/new_flow_logic/register_local_pipes.lua new file mode 100644 index 0000000..6fe8b7e --- /dev/null +++ b/new_flow_logic/register_local_pipes.lua @@ -0,0 +1,53 @@ +-- conditional registration of pipe nodes for the new pipe logic, depending on enable flags. +-- otherwise register_flow_logic.lua would be attempting to register ABMs for non-existant nodes. +-- written 2017 by thetaepsilon + + + +-- global values and thresholds for water behaviour +-- TODO: add some way of setting this per-world +local thresholds = {} +-- limit on pump pressure - will not absorb more than can be taken +thresholds.pump_pressure = 2 + + + +local pipes_full_nodenames = pipeworks.pipes_full_nodenames +local pipes_empty_nodenames = pipeworks.pipes_empty_nodenames + +local register = pipeworks.flowables.register +local abmregister = pipeworks.flowlogic.abmregister + + + +-- FIXME: DRY principle for names, move this to devices.lua? +-- FIXME: all devices still considered simple +local pump_on = "pipeworks:pump_on" +local pump_off = "pipeworks:pump_off" +local spigot_off = "pipeworks:spigot" +local spigot_on = "pipeworks:spigot_pouring" + +if pipeworks.enable_pipes then + for _, pipe in ipairs(pipes_full_nodenames) do + register.simple(pipe) + abmregister.balance(pipe) + end + for _, pipe in ipairs(pipes_empty_nodenames) do + register.simple(pipe) + abmregister.balance(pipe) + end + + if pipeworks.enable_pipe_devices then + register.simple(pump_off) + register.simple(pump_on) + register.simple(spigot_on) + register.simple(spigot_off) + abmregister.balance(pump_off) + abmregister.balance(pump_on) + abmregister.balance(spigot_on) + abmregister.balance(spigot_off) + + register.intake_simple(pump_on, thresholds.pump_pressure) + abmregister.input(pump_on, thresholds.pump_pressure) + end +end 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 From 21892456f529e099a0c1d47ae780101d172f818a Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 30 Sep 2017 23:55:16 +0100 Subject: init.lua: move non-destructive new_flow_logic code outside if-guard --- init.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index a081759..d6067e5 100644 --- a/init.lua +++ b/init.lua @@ -116,7 +116,10 @@ dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") local logicdir = "/new_flow_logic/" --- note that pipes still don't appear until registered in the files below this one, so can still be turned off + +-- note that even with these files the new flow logic is not yet default +dofile(pipeworks.modpath..logicdir.."abms.lua") +dofile(pipeworks.modpath..logicdir.."abm_register.lua") dofile(pipeworks.modpath..logicdir.."flowable_node_registry.lua") if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end @@ -124,8 +127,6 @@ if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end -- individual enable flags also checked in register_local_pipes.lua if pipeworks.enable_new_flow_logic then - dofile(pipeworks.modpath..logicdir.."abms.lua") - dofile(pipeworks.modpath..logicdir.."abm_register.lua") dofile(pipeworks.modpath..logicdir.."register_local_pipes.lua") 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 --- init.lua | 3 +- new_flow_logic/flowable_node_registry.lua | 73 +++-------------------- new_flow_logic/flowable_node_registry_install.lua | 70 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 67 deletions(-) create mode 100644 new_flow_logic/flowable_node_registry_install.lua (limited to 'init.lua') 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. -- 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 --- init.lua | 4 ++++ new_flow_logic/flowable_node_registry_install.lua | 9 +++++++++ 2 files changed, 13 insertions(+) (limited to 'init.lua') diff --git a/init.lua b/init.lua index e91c4dc..e8a8d2f 100644 --- a/init.lua +++ b/init.lua @@ -94,6 +94,10 @@ function pipeworks.replace_name(tbl,tr,name) return ntbl end +pipeworks.logger = function(msg) + print("[pipeworks] "..msg) +end + ------------------------------------------- -- Load the various other parts of the mod 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 396a4fdacdd6f80e3bba55cd6c26a2ae321179d1 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 18:23:58 +0100 Subject: remove register_local_pipes.lua as node registration has been moved to more appropriate files --- init.lua | 8 ++--- new_flow_logic/register_local_pipes.lua | 54 --------------------------------- todo/new_flow_logic.txt | 4 --- 3 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 new_flow_logic/register_local_pipes.lua (limited to 'init.lua') diff --git a/init.lua b/init.lua index e8a8d2f..2a95be6 100644 --- a/init.lua +++ b/init.lua @@ -121,7 +121,9 @@ dofile(pipeworks.modpath.."/wielder.lua") local logicdir = "/new_flow_logic/" --- note that even with these files the new flow logic is not yet default +-- note that even with these files the new flow logic is not yet default. +-- registration will take place but no actual ABMs/node logic will be installed, +-- unless pipeworks.enable_new_flow_logic has been set. dofile(pipeworks.modpath..logicdir.."flowable_node_registry.lua") dofile(pipeworks.modpath..logicdir.."abms.lua") dofile(pipeworks.modpath..logicdir.."abm_register.lua") @@ -130,10 +132,6 @@ 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 if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end --- individual enable flags also checked in register_local_pipes.lua -if pipeworks.enable_new_flow_logic then - dofile(pipeworks.modpath..logicdir.."register_local_pipes.lua") -end if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat-chests.lua") diff --git a/new_flow_logic/register_local_pipes.lua b/new_flow_logic/register_local_pipes.lua deleted file mode 100644 index 0de0056..0000000 --- a/new_flow_logic/register_local_pipes.lua +++ /dev/null @@ -1,54 +0,0 @@ --- registration of pipework's own pipes. --- written 2017 by thetaepsilon - - - --- global values and thresholds for water behaviour --- TODO: add some way of setting this per-world -local thresholds = {} --- limit on pump pressure - will not absorb more than can be taken -thresholds.pump_pressure = 2 --- activation threshold for spigot --- should not be below 1, as spigot helper code indiscriminately places a water source node if run. -thresholds.spigot_min = 1 - - - -local pipes_full_nodenames = pipeworks.pipes_full_nodenames -local pipes_empty_nodenames = pipeworks.pipes_empty_nodenames - -local register = pipeworks.flowables.register -local flowlogic = pipeworks.flowlogic - - - --- FIXME: DRY principle for names, move this to devices.lua? --- FIXME: all devices still considered simple -local pump_on = "pipeworks:pump_on" -local pump_off = "pipeworks:pump_off" -local spigot_off = "pipeworks:spigot" -local spigot_on = "pipeworks:spigot_pouring" - -if pipeworks.enable_pipes then - --[[ - for _, pipe in ipairs(pipes_full_nodenames) do - register.simple(pipe) - end - for _, pipe in ipairs(pipes_empty_nodenames) do - register.simple(pipe) - end - ]] - - if pipeworks.enable_pipe_devices then - --register.simple(pump_off) - --register.simple(pump_on) - --register.simple(spigot_on) - --register.simple(spigot_off) - - --register.intake_simple(pump_on, thresholds.pump_pressure) - -- TODO: the code doesn't currently care if the spigot is the visually flowing node or not. - -- So some mechanism to register on/off states would be nice - --register.output(spigot_off, thresholds.spigot_min, flowlogic.helpers.output_spigot) - --register.output(spigot_on, thresholds.spigot_min, flowlogic.helpers.output_spigot) - end -end diff --git a/todo/new_flow_logic.txt b/todo/new_flow_logic.txt index acd6d1a..46f6c22 100644 --- a/todo/new_flow_logic.txt +++ b/todo/new_flow_logic.txt @@ -1,6 +1,2 @@ --- Per-world configuration of pump thresholds -This should be relatively trivial to do, just a case of adding another property to the pipeworks global that can be set per-world with pipeworks_settings.txt. -This does not appear to be that big a deal right now, as the internal threshold can always be changed. - -- Internal code to the effect of "is_node_flowable()" This is basically to implement valves - currently the flow logic will happily balance pipes with neighbour nodes that just happen to have the pressure property in their metadata. -- 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 --- init.lua | 8 +++++--- new_flow_logic/flowable_node_registry_install.lua | 8 ++++---- pipes.lua | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 2a95be6..8bae8e8 100644 --- a/init.lua +++ b/init.lua @@ -17,14 +17,16 @@ dofile(pipeworks.modpath.."/default_settings.lua") -- Read the external config file if it exists. +-- please add any new feature toggles to be a flag in this table... +pipeworks.toggles = {} local worldsettingspath = pipeworks.worldpath.."/pipeworks_settings.txt" local worldsettingsfile = io.open(worldsettingspath, "r") if worldsettingsfile then worldsettingsfile:close() dofile(worldsettingspath) end -if pipeworks.enable_new_flow_logic then - minetest.log("warning", "pipeworks new_flow_logic is WIP and incomplete!") +if pipeworks.toggles.pressure_logic then + minetest.log("warning", "pipeworks pressure-based logic is WIP and incomplete!") end -- Random variables @@ -123,7 +125,7 @@ local logicdir = "/new_flow_logic/" -- note that even with these files the new flow logic is not yet default. -- registration will take place but no actual ABMs/node logic will be installed, --- unless pipeworks.enable_new_flow_logic has been set. +-- unless the toggle flag is specifically enabled in the per-world settings flag. dofile(pipeworks.modpath..logicdir.."flowable_node_registry.lua") dofile(pipeworks.modpath..logicdir.."abms.lua") dofile(pipeworks.modpath..logicdir.."abm_register.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) diff --git a/pipes.lua b/pipes.lua index c6ba09b..2acdfa9 100644 --- a/pipes.lua +++ b/pipes.lua @@ -213,7 +213,7 @@ pipeworks.pipes_empty_nodenames = pipes_empty_nodenames -if not pipeworks.enable_new_flow_logic then +if not pipeworks.toggles.pressure_logic then -- cgit v1.2.3 From 750612181a67b9bf4ad4bd01c2d90472e8a41a6d Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Tue, 3 Oct 2017 20:53:49 +0100 Subject: add finite water feature toggle and auto-detect code --- autodetect-finite-water.lua | 9 +++++++++ init.lua | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 autodetect-finite-water.lua (limited to 'init.lua') diff --git a/autodetect-finite-water.lua b/autodetect-finite-water.lua new file mode 100644 index 0000000..d218e80 --- /dev/null +++ b/autodetect-finite-water.lua @@ -0,0 +1,9 @@ +-- enable finite liquid in the presence of dynamic liquid to preserve water volume. +local enable = false + +if minetest.get_modpath("dynamic_liquid") then + pipeworks.logger("detected mod dynamic_liquid, enabling finite liquid flag") + enable = true +end + +pipeworks.toggles.finite_water = enable diff --git a/init.lua b/init.lua index 8bae8e8..8974005 100644 --- a/init.lua +++ b/init.lua @@ -103,6 +103,11 @@ end ------------------------------------------- -- Load the various other parts of the mod +-- early auto-detection for finite water mode if not explicitly disabled +if pipeworks.toggles.finite_water == nil then + dofile(pipeworks.modpath.."/autodetect-finite-water.lua") +end + dofile(pipeworks.modpath.."/common.lua") dofile(pipeworks.modpath.."/models.lua") dofile(pipeworks.modpath.."/autoplace_pipes.lua") -- cgit v1.2.3