From f82570f58027ec7659c4050124fdc15d1203dbd8 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 14:14:33 +0100 Subject: [PATCH 01/14] initial stub patches to re-implement new_flow_logic --- flowing_logic.lua | 8 ++++++++ pipes.lua | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/flowing_logic.lua b/flowing_logic.lua index 632baa6..0e62b46 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -132,3 +132,11 @@ pipeworks.fountainhead_check = function(pos, node) end end end + +local debuglog = function(msg) + print("## pipeworks: "..msg) +end + +pipeworks.balance_pressure = function(pos, node) + debuglog("balance_pressure() stub! "..node.name.." at "..pos.x.." "..pos.y.." "..pos.z) +end diff --git a/pipes.lua b/pipes.lua index 9771e3b..5a48801 100644 --- a/pipes.lua +++ b/pipes.lua @@ -227,3 +227,17 @@ minetest.register_abm({ end }) + +-- run pressure balancing ABM over all water-moving nodes +local pipes_all_nodenames = pipes_full_nodenames +for _, pipe in ipairs(pipes_empty_nodenames) do + table.insert(pipes_all_nodenames, pipe) +end +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 +}) From 64a5b18e8979c0e0e7d0bc06151f0a20b8447fe1 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 14:59:25 +0100 Subject: [PATCH 02/14] flowing_logic.lua: implement initital pressure balancing behaviour --- flowing_logic.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/flowing_logic.lua b/flowing_logic.lua index 0e62b46..ee34ed0 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -133,10 +133,52 @@ pipeworks.fountainhead_check = function(pos, node) end end -local debuglog = function(msg) - print("## pipeworks: "..msg) + + +-- 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 label_pressure = "pipeworks.water_pressure" +local label_haspressure = "pipeworks.is_pressure_node" pipeworks.balance_pressure = function(pos, node) - debuglog("balance_pressure() stub! "..node.name.." at "..pos.x.." "..pos.y.." "..pos.z) + -- 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 From 59ac9780939b9c130bb70034bccb04ff1e99136d Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 15:19:20 +0100 Subject: [PATCH 03/14] pipes.lua: place old ABM code registration behind if-guard for new flag --- init.lua | 3 +++ pipes.lua | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/init.lua b/init.lua index 2e05337..5094a13 100644 --- a/init.lua +++ b/init.lua @@ -111,6 +111,9 @@ dofile(pipeworks.modpath.."/filter-injector.lua") dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") +-- temporary flag to enable new flowing behaviour +pipeworks.enable_new_flow_logic = true + 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 diff --git a/pipes.lua b/pipes.lua index 5a48801..29f91d3 100644 --- a/pipes.lua +++ b/pipes.lua @@ -191,6 +191,13 @@ table.insert(pipes_full_nodenames,"pipeworks:valve_on_loaded") table.insert(pipes_full_nodenames,"pipeworks:entry_panel_loaded") table.insert(pipes_full_nodenames,"pipeworks:flow_sensor_loaded") + + + +if not pipeworks.enable_new_flow_logic then +-- sorry, no indents... it messes with the patchlogs too much + + minetest.register_abm({ nodenames = pipes_empty_nodenames, interval = 1, @@ -228,6 +235,9 @@ minetest.register_abm({ }) +else + + -- run pressure balancing ABM over all water-moving nodes local pipes_all_nodenames = pipes_full_nodenames for _, pipe in ipairs(pipes_empty_nodenames) do @@ -241,3 +251,7 @@ minetest.register_abm({ pipeworks.balance_pressure(pos, node) end }) + + + +end \ No newline at end of file From 6a0fe9f3c0797fb18f3613b35251536f84424d01 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 15:49:03 +0100 Subject: [PATCH 04/14] flowing_logic.lua: add new version of check_for_liquids() --- flowing_logic.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/flowing_logic.lua b/flowing_logic.lua index ee34ed0..1c02d36 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -149,6 +149,31 @@ local make_coords_offsets = function(pos, include_base) return coords 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. +pipeworks.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 + + + local label_pressure = "pipeworks.water_pressure" local label_haspressure = "pipeworks.is_pressure_node" pipeworks.balance_pressure = function(pos, node) From c5e5aa069fd45ba8d617bf4192f59699ddcdb186 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 16:02:30 +0100 Subject: [PATCH 05/14] flowing_logic.lua: add start of new pump handler code --- flowing_logic.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/flowing_logic.lua b/flowing_logic.lua index 1c02d36..0147283 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -135,6 +135,14 @@ end +-- 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 + + + -- borrowed from above: might be useable to replace the above coords tables local make_coords_offsets = function(pos, include_base) local coords = { @@ -155,6 +163,7 @@ end -- 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. pipeworks.check_for_liquids_v2 = function(pos, limit) if not limit then limit = 6 @@ -207,3 +216,14 @@ pipeworks.balance_pressure = function(pos, node) targetmeta:set_float(label_pressure, average) end end + +pipeworks.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 meta = minetest.get_meta(pos) + local currentpressure = meta:get_float(label_pressure) + local intake_limit = thresholds.pump_pressure - currentpressure + local actual_intake = pipeworks.check_for_liquids_v2(pos, limit) + local newpressure = actual_intake + currentpressure + meta:set_float(label_pressure, newpressure) +end From 67350b55bb00a8787ebfa3e5ab6763748cfd792d Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 16:20:07 +0100 Subject: [PATCH 06/14] pipes.lua: wire up pump intake ABM and add pumps to balancing logic --- pipes.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pipes.lua b/pipes.lua index 29f91d3..4b0b102 100644 --- a/pipes.lua +++ b/pipes.lua @@ -239,10 +239,19 @@ else -- 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 pipes_all_nodenames = pipes_full_nodenames for _, pipe in ipairs(pipes_empty_nodenames) do table.insert(pipes_all_nodenames, pipe) end +table.insert(pipes_all_nodenames, pump_off) +table.insert(pipes_all_nodenames, pump_on) + + + minetest.register_abm({ nodenames = pipes_all_nodenames, interval = 1, @@ -252,6 +261,16 @@ minetest.register_abm({ end }) +-- absorb water into pumps if it'll fit +minetest.register_abm({ + nodenames = { pump_on }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + pipeworks.run_pump_intake(pos, node) + end +}) -end \ No newline at end of file + +end From c3708b154c8b81d4ec65cbf736f55864519ef01f Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 16:32:22 +0100 Subject: [PATCH 07/14] flowing_logic.lua: fix pressure limit bug due to accessing non-existant variable --- flowing_logic.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flowing_logic.lua b/flowing_logic.lua index 0147283..62d75ab 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -159,6 +159,10 @@ 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. @@ -217,13 +221,16 @@ pipeworks.balance_pressure = function(pos, node) end end + + pipeworks.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 meta = minetest.get_meta(pos) local currentpressure = meta:get_float(label_pressure) local intake_limit = thresholds.pump_pressure - currentpressure - local actual_intake = pipeworks.check_for_liquids_v2(pos, limit) + local actual_intake = pipeworks.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 From d6dcd51302633e952b023526da0fe33d3759e2f8 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 16:42:15 +0100 Subject: [PATCH 08/14] devices.lua: replace calls to add_node() with swap_node() to preserve node metadata --- devices.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/devices.lua b/devices.lua index 0121e2f..3b7fc78 100644 --- a/devices.lua +++ b/devices.lua @@ -68,7 +68,7 @@ function pipeworks.rotate_on_place(itemstack, placer, pointed_thing) local placednode = string.gsub(itemstack:get_name(), "_loaded", "_empty") placednode = string.gsub(placednode, "_on", "_off") - minetest.add_node(pos1, {name = placednode, param2 = fdir }) + minetest.swap_node(pos1, {name = placednode, param2 = fdir }) pipeworks.scan_for_pipe_objects(pos1) if not pipeworks.expect_infinite_stacks then @@ -149,16 +149,17 @@ for s in ipairs(states) do drop = "pipeworks:pump_off", mesecons = {effector = { action_on = function (pos, node) - minetest.add_node(pos,{name="pipeworks:pump_on", param2 = node.param2}) + minetest.swap_node(pos,{name="pipeworks:pump_on", param2 = node.param2}) end, action_off = function (pos, node) - minetest.add_node(pos,{name="pipeworks:pump_off", param2 = node.param2}) + minetest.swap_node(pos,{name="pipeworks:pump_off", param2 = node.param2}) end }}, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local fdir = node.param2 - minetest.add_node(pos, { name = "pipeworks:pump_"..states[3-s], param2 = fdir }) + minetest.swap_node(pos, { name = "pipeworks:pump_"..states[3-s], param2 = fdir }) end, + -- FIXME - does this preserve metadata? need to look at this on_rotate = screwdriver.rotate_simple }) @@ -188,15 +189,15 @@ for s in ipairs(states) do drop = "pipeworks:valve_off_empty", mesecons = {effector = { action_on = function (pos, node) - minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2}) + minetest.swap_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2}) end, action_off = function (pos, node) - minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2}) + minetest.swap_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2}) end }}, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local fdir = node.param2 - minetest.add_node(pos, { name = "pipeworks:valve_"..states[3-s].."_empty", param2 = fdir }) + minetest.swap_node(pos, { name = "pipeworks:valve_"..states[3-s].."_empty", param2 = fdir }) end, on_rotate = pipeworks.fix_after_rotation }) @@ -228,15 +229,15 @@ minetest.register_node("pipeworks:valve_on_loaded", { drop = "pipeworks:valve_off_empty", mesecons = {effector = { action_on = function (pos, node) - minetest.add_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2}) + minetest.swap_node(pos,{name="pipeworks:valve_on_empty", param2 = node.param2}) end, action_off = function (pos, node) - minetest.add_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2}) + minetest.swap_node(pos,{name="pipeworks:valve_off_empty", param2 = node.param2}) end }}, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local fdir = node.param2 - minetest.add_node(pos, { name = "pipeworks:valve_off_empty", param2 = fdir }) + minetest.swap_node(pos, { name = "pipeworks:valve_off_empty", param2 = fdir }) end, on_rotate = pipeworks.fix_after_rotation }) From 69133818f7283ea3a8b14060b71df769cac9eb48 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 17:00:18 +0100 Subject: [PATCH 09/14] pipes.lua: split out new flow logic registration and make it respect feature toggles --- init.lua | 3 +++ pipes.lua | 40 +++------------------------------------- register_flow_logic.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 register_flow_logic.lua diff --git a/init.lua b/init.lua index 5094a13..6ceca65 100644 --- a/init.lua +++ b/init.lua @@ -117,6 +117,9 @@ pipeworks.enable_new_flow_logic = true 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 +if pipeworks.enable_new_flow_logic then dofile(pipeworks.modpath.."/register_flow_logic.lua") end + if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat-chests.lua") dofile(pipeworks.modpath.."/compat-furnaces.lua") diff --git a/pipes.lua b/pipes.lua index 4b0b102..54dfbd7 100644 --- a/pipes.lua +++ b/pipes.lua @@ -191,6 +191,9 @@ table.insert(pipes_full_nodenames,"pipeworks:valve_on_loaded") table.insert(pipes_full_nodenames,"pipeworks:entry_panel_loaded") table.insert(pipes_full_nodenames,"pipeworks:flow_sensor_loaded") +pipeworks.pipes_full_nodenames = pipes_full_nodenames +pipeworks.pipes_empty_nodenames = pipes_empty_nodenames + @@ -235,42 +238,5 @@ minetest.register_abm({ }) -else - - --- 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 pipes_all_nodenames = pipes_full_nodenames -for _, pipe in ipairs(pipes_empty_nodenames) do - table.insert(pipes_all_nodenames, pipe) -end -table.insert(pipes_all_nodenames, pump_off) -table.insert(pipes_all_nodenames, pump_on) - - - -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 -}) - --- absorb water into pumps if it'll fit -minetest.register_abm({ - nodenames = { pump_on }, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - pipeworks.run_pump_intake(pos, node) - end -}) - - end diff --git a/register_flow_logic.lua b/register_flow_logic.lua new file mode 100644 index 0000000..e027dae --- /dev/null +++ b/register_flow_logic.lua @@ -0,0 +1,40 @@ +-- register new flow logic ABMs + +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 pipes_all_nodenames = pipes_full_nodenames +for _, pipe in ipairs(pipes_empty_nodenames) do + table.insert(pipes_all_nodenames, pipe) +end +table.insert(pipes_all_nodenames, pump_off) +table.insert(pipes_all_nodenames, pump_on) + + +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 + +if pipeworks.enable_pipe_devices then + -- absorb water into pumps if it'll fit + minetest.register_abm({ + nodenames = { pump_on }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + pipeworks.run_pump_intake(pos, node) + end + }) +end From df8ef255a3a66c676fc74197fb034e5033aed763 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 17:25:16 +0100 Subject: [PATCH 10/14] flowing_logic.lua: add new spigot code + ABM registration --- flowing_logic.lua | 16 ++++++++++++++++ register_flow_logic.lua | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/flowing_logic.lua b/flowing_logic.lua index 62d75ab..50a4c99 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -234,3 +234,19 @@ pipeworks.run_pump_intake = function(pos, node) -- debuglog("oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake.." newpressure "..newpressure) meta:set_float(label_pressure, newpressure) end + + + +pipeworks.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/register_flow_logic.lua b/register_flow_logic.lua index e027dae..c6fc46f 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -7,13 +7,20 @@ local pipes_empty_nodenames = pipeworks.pipes_empty_nodenames -- 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 -table.insert(pipes_all_nodenames, pump_off) -table.insert(pipes_all_nodenames, pump_on) + +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 if pipeworks.enable_pipes then @@ -37,4 +44,14 @@ if pipeworks.enable_pipe_devices then 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. + 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 + }) end From 2d70d2b6576a2f8d795eb1ce166c58c7ada8802c Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 17:37:46 +0100 Subject: [PATCH 11/14] init.lua: turn off by-default new flow logic for now --- default_settings.lua | 2 ++ init.lua | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/default_settings.lua b/default_settings.lua index 91e511c..9aa4835 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -27,6 +27,8 @@ local settings = { drop_on_routing_fail = false, delete_item_on_clearobject = true, + + enable_new_flow_logic = false, } for name, value in pairs(settings) do diff --git a/init.lua b/init.lua index 6ceca65..80a83d3 100644 --- a/init.lua +++ b/init.lua @@ -14,14 +14,18 @@ pipeworks.worldpath = minetest.get_worldpath() pipeworks.modpath = minetest.get_modpath("pipeworks") dofile(pipeworks.modpath.."/default_settings.lua") - -- Read the external config file if it exists. + + 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!") +end -- Random variables @@ -111,9 +115,6 @@ dofile(pipeworks.modpath.."/filter-injector.lua") dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/wielder.lua") --- temporary flag to enable new flowing behaviour -pipeworks.enable_new_flow_logic = true - 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 From 3e827c23b9a9df72f55150ac38214444edd697f3 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 17:49:49 +0100 Subject: [PATCH 12/14] flowing_logic.lua: separate out new logic into seperate file --- flowing_logic.lua | 118 ------------------------------------------- new_flow_logic.lua | 121 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 118 deletions(-) create mode 100644 new_flow_logic.lua diff --git a/flowing_logic.lua b/flowing_logic.lua index 50a4c99..632baa6 100644 --- a/flowing_logic.lua +++ b/flowing_logic.lua @@ -132,121 +132,3 @@ pipeworks.fountainhead_check = function(pos, node) end end end - - - --- 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 - - - --- 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. -pipeworks.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 - - - -local label_pressure = "pipeworks.water_pressure" -local label_haspressure = "pipeworks.is_pressure_node" -pipeworks.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 - - - -pipeworks.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 meta = minetest.get_meta(pos) - local currentpressure = meta:get_float(label_pressure) - local intake_limit = thresholds.pump_pressure - currentpressure - local actual_intake = pipeworks.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 - - - -pipeworks.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.lua b/new_flow_logic.lua new file mode 100644 index 0000000..3fd1bb6 --- /dev/null +++ b/new_flow_logic.lua @@ -0,0 +1,121 @@ +-- reimplementation of new_flow_logic branch: processing functions +-- 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 + + + +-- 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. +pipeworks.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 + + + + +local label_pressure = "pipeworks.water_pressure" +local label_haspressure = "pipeworks.is_pressure_node" +pipeworks.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 + + + +pipeworks.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 meta = minetest.get_meta(pos) + local currentpressure = meta:get_float(label_pressure) + local intake_limit = thresholds.pump_pressure - currentpressure + local actual_intake = pipeworks.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 + + + +pipeworks.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 From 9d014824881c1f64c1846283f5e1af945cffc375 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 17:53:08 +0100 Subject: [PATCH 13/14] init.lua: add missing dofile for new flow logic --- init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 80a83d3..470db2e 100644 --- a/init.lua +++ b/init.lua @@ -119,7 +119,10 @@ 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 -if pipeworks.enable_new_flow_logic then dofile(pipeworks.modpath.."/register_flow_logic.lua") end +if pipeworks.enable_new_flow_logic then + dofile(pipeworks.modpath.."/new_flow_logic.lua") + dofile(pipeworks.modpath.."/register_flow_logic.lua") +end if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat-chests.lua") From 1666dfc2c7f26ac4cfe0ac01b4e164b7bae36681 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Wed, 27 Sep 2017 17:54:03 +0100 Subject: [PATCH 14/14] register_flow_logic.lua: add author notice --- register_flow_logic.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/register_flow_logic.lua b/register_flow_logic.lua index c6fc46f..c9df09c 100644 --- a/register_flow_logic.lua +++ b/register_flow_logic.lua @@ -1,4 +1,5 @@ -- 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