From caacc2a2613706c53b7ee27b04b5a4d7584a83f7 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 17:24:39 +0100 Subject: devices.lua: create local variables for device node names in preparation for flow logic registration --- devices.lua | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 3b7fc78..26df862 100644 --- a/devices.lua +++ b/devices.lua @@ -129,7 +129,8 @@ for s in ipairs(states) do dgroups = {snappy=3, pipe=1, not_in_creative_inventory=1} end - minetest.register_node("pipeworks:pump_"..states[s], { + local pumpname = "pipeworks:pump_"..states[s] + minetest.register_node(pumpname, { description = "Pump/Intake Module", drawtype = "mesh", mesh = "pipeworks_pump.obj", @@ -162,8 +163,9 @@ for s in ipairs(states) do -- FIXME - does this preserve metadata? need to look at this on_rotate = screwdriver.rotate_simple }) - - minetest.register_node("pipeworks:valve_"..states[s].."_empty", { + + local nodename_valve_empty = "pipeworks:valve_"..states[s].."_empty" + minetest.register_node(nodename_valve_empty, { description = "Valve", drawtype = "mesh", mesh = "pipeworks_valve_"..states[s]..".obj", @@ -203,7 +205,8 @@ for s in ipairs(states) do }) end -minetest.register_node("pipeworks:valve_on_loaded", { +local nodename_valve_loaded = "pipeworks:valve_on_loaded" +minetest.register_node(nodename_valve_loaded, { description = "Valve", drawtype = "mesh", mesh = "pipeworks_valve_on.obj", @@ -244,6 +247,7 @@ minetest.register_node("pipeworks:valve_on_loaded", { -- grating +-- FIXME: should this do anything useful in the new flow logic? minetest.register_node("pipeworks:grating", { description = "Decorative grating", tiles = { @@ -276,7 +280,8 @@ minetest.register_node("pipeworks:grating", { -- outlet spigot -minetest.register_node("pipeworks:spigot", { +local nodename_spigot_empty = "pipeworks:spigot" +minetest.register_node(nodename_spigot_empty, { description = "Spigot outlet", drawtype = "mesh", mesh = "pipeworks_spigot.obj", @@ -306,7 +311,8 @@ minetest.register_node("pipeworks:spigot", { on_rotate = pipeworks.fix_after_rotation }) -minetest.register_node("pipeworks:spigot_pouring", { +local nodename_spigot_loaded = "pipeworks:spigot_pouring" +minetest.register_node(nodename_spigot_loaded, { description = "Spigot outlet", drawtype = "mesh", mesh = "pipeworks_spigot_pouring.obj", @@ -360,7 +366,8 @@ local panel_cbox = { } } -minetest.register_node("pipeworks:entry_panel_empty", { +local nodename_panel_empty = "pipeworks:entry_panel_empty" +minetest.register_node(nodename_panel_empty, { description = "Airtight Pipe entry/exit", drawtype = "mesh", mesh = "pipeworks_entry_panel.obj", @@ -379,7 +386,8 @@ minetest.register_node("pipeworks:entry_panel_empty", { on_rotate = pipeworks.fix_after_rotation }) -minetest.register_node("pipeworks:entry_panel_loaded", { +local nodename_panel_loaded = "pipeworks:entry_panel_loaded" +minetest.register_node(nodename_panel_loaded, { description = "Airtight Pipe entry/exit", drawtype = "mesh", mesh = "pipeworks_entry_panel.obj", @@ -399,7 +407,8 @@ minetest.register_node("pipeworks:entry_panel_loaded", { on_rotate = pipeworks.fix_after_rotation }) -minetest.register_node("pipeworks:flow_sensor_empty", { +local nodename_sensor_empty = "pipeworks:flow_sensor_empty" +minetest.register_node(nodename_sensor_empty, { description = "Flow Sensor", drawtype = "mesh", mesh = "pipeworks_flow_sensor.obj", @@ -437,7 +446,8 @@ minetest.register_node("pipeworks:flow_sensor_empty", { on_rotate = pipeworks.fix_after_rotation }) -minetest.register_node("pipeworks:flow_sensor_loaded", { +local nodename_sensor_loaded = "pipeworks:flow_sensor_loaded" +minetest.register_node(nodename_sensor_loaded, { description = "Flow sensor (on)", drawtype = "mesh", mesh = "pipeworks_flow_sensor.obj", @@ -478,6 +488,7 @@ minetest.register_node("pipeworks:flow_sensor_loaded", { -- tanks +-- TODO: these don't currently do anything under the new flow logic. for fill = 0, 10 do local filldesc="empty" local sgroups = {snappy=3, pipe=1, tankfill=fill+1} @@ -548,7 +559,8 @@ end -- fountainhead -minetest.register_node("pipeworks:fountainhead", { +local nodename_fountain_empty = "pipeworks:fountainhead" +minetest.register_node(nodename_fountain_empty, { description = "Fountainhead", drawtype = "mesh", mesh = "pipeworks_fountainhead.obj", @@ -581,7 +593,8 @@ minetest.register_node("pipeworks:fountainhead", { on_rotate = false }) -minetest.register_node("pipeworks:fountainhead_pouring", { +local nodename_fountain_loaded = "pipeworks:fountainhead_pouring" +minetest.register_node(nodename_fountain_loaded, { description = "Fountainhead", drawtype = "mesh", mesh = "pipeworks_fountainhead.obj", -- cgit v1.2.3 From e6b55028fc9b6a50ecd6c28c2af1ee94e041edcd Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 17:36:03 +0100 Subject: move pump flow logic registration to devices.lua --- devices.lua | 5 +++++ new_flow_logic/register_local_pipes.lua | 6 +++--- pipes.lua | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 26df862..670ed6c 100644 --- a/devices.lua +++ b/devices.lua @@ -1,3 +1,4 @@ +local new_flow_logic_register = pipeworks.flowables.register -- rotation handlers @@ -163,6 +164,10 @@ for s in ipairs(states) do -- FIXME - does this preserve metadata? need to look at this on_rotate = screwdriver.rotate_simple }) + new_flow_logic_register.simple(pumpname) + if states[s] ~= "off" then + new_flow_logic_register.intake_simple(pumpname, 2) + end local nodename_valve_empty = "pipeworks:valve_"..states[s].."_empty" minetest.register_node(nodename_valve_empty, { diff --git a/new_flow_logic/register_local_pipes.lua b/new_flow_logic/register_local_pipes.lua index 5128d47..005a812 100644 --- a/new_flow_logic/register_local_pipes.lua +++ b/new_flow_logic/register_local_pipes.lua @@ -40,12 +40,12 @@ if pipeworks.enable_pipes then ]] if pipeworks.enable_pipe_devices then - register.simple(pump_off) - register.simple(pump_on) + --register.simple(pump_off) + --register.simple(pump_on) register.simple(spigot_on) register.simple(spigot_off) - register.intake_simple(pump_on, thresholds.pump_pressure) + --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) diff --git a/pipes.lua b/pipes.lua index 80fb0b3..d907160 100644 --- a/pipes.lua +++ b/pipes.lua @@ -195,6 +195,7 @@ local valve_on = "pipeworks:valve_on_empty" local valve_off = "pipeworks:valve_off_empty" local entry_panel_empty = "pipeworks:entry_panel_empty" local flow_sensor_empty = "pipeworks:flow_sensor_empty" +-- XXX: why aren't these in devices.lua!? table.insert(pipes_empty_nodenames, valve_on) table.insert(pipes_empty_nodenames, valve_off) table.insert(pipes_empty_nodenames, entry_panel_empty) -- cgit v1.2.3 From a1fc493de18bebd41e8d285ef610c0f8209fb609 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 18:05:44 +0100 Subject: migrate flowable registration for valve nodes to devices.lua --- devices.lua | 13 +++++++++++++ pipes.lua | 3 --- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 670ed6c..8b1725b 100644 --- a/devices.lua +++ b/devices.lua @@ -164,6 +164,7 @@ for s in ipairs(states) do -- FIXME - does this preserve metadata? need to look at this on_rotate = screwdriver.rotate_simple }) + -- FIXME: currently a simple flow device, but needs directionality checking new_flow_logic_register.simple(pumpname) if states[s] ~= "off" then new_flow_logic_register.intake_simple(pumpname, 2) @@ -208,6 +209,12 @@ for s in ipairs(states) do end, on_rotate = pipeworks.fix_after_rotation }) + -- only register flow logic for the "on" ABM. + -- this means that the off state automatically blocks flow by not participating in the balancing operation. + if states[s] ~= "off" then + -- FIXME: this still a simple device, directionality not honoured + new_flow_logic_register.simple(nodename_valve_empty) + end end local nodename_valve_loaded = "pipeworks:valve_on_loaded" @@ -249,6 +256,12 @@ minetest.register_node(nodename_valve_loaded, { end, on_rotate = pipeworks.fix_after_rotation }) +-- register this the same as the on-but-empty variant, so existing nodes of this type work also. +-- note that as new_flow_logic code does not distinguish empty/full in node states, +-- right-clicking a "loaded" valve (becoming an off valve) then turning it on again will yield a on-but-empty valve, +-- but the flow logic will still function. +-- thus under new_flow_logic this serves as a kind of migration. +new_flow_logic_register.simple(nodename_valve_loaded) -- grating diff --git a/pipes.lua b/pipes.lua index d907160..751d460 100644 --- a/pipes.lua +++ b/pipes.lua @@ -200,8 +200,6 @@ table.insert(pipes_empty_nodenames, valve_on) table.insert(pipes_empty_nodenames, valve_off) table.insert(pipes_empty_nodenames, entry_panel_empty) table.insert(pipes_empty_nodenames, flow_sensor_empty) -new_flow_logic_register.simple(valve_on) --- don't register valve_off, automatically makes it block flow in the new logic new_flow_logic_register.simple(entry_panel_empty) new_flow_logic_register.simple(flow_sensor_empty) @@ -211,7 +209,6 @@ local flow_sensor_loaded = "pipeworks:flow_sensor_loaded" table.insert(pipes_full_nodenames, valve_on_loaded) table.insert(pipes_full_nodenames, entry_panel_loaded) table.insert(pipes_full_nodenames, flow_sensor_loaded) -new_flow_logic_register.simple(valve_on_loaded) new_flow_logic_register.simple(entry_panel_loaded) new_flow_logic_register.simple(flow_sensor_loaded) -- cgit v1.2.3 From 13383770ef61d93899ad272586daeb0d8d3b4072 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 18:18:47 +0100 Subject: move spigot behaviour registration to devices.lua --- devices.lua | 9 +++++++++ new_flow_logic/register_local_pipes.lua | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 8b1725b..fd48033 100644 --- a/devices.lua +++ b/devices.lua @@ -372,6 +372,15 @@ minetest.register_node(nodename_spigot_loaded, { drop = "pipeworks:spigot", on_rotate = pipeworks.fix_after_rotation }) +-- new flow logic does not currently distinguish between these two visual states. +-- register both so existing flowing spigots continue to work (even if the visual doesn't match the spigot's behaviour). +new_flow_logic_register.simple(nodename_spigot_empty) +new_flow_logic_register.simple(nodename_spigot_loaded) +local spigot_min = 1 +new_flow_logic_register.output(nodename_spigot_empty, spigot_min, pipeworks.flowlogic.helpers.output_spigot) +new_flow_logic_register.output(nodename_spigot_loaded, spigot_min, pipeworks.flowlogic.helpers.output_spigot) + + -- sealed pipe entry/exit (horizontal pipe passing through a metal -- wall, for use in places where walls should look like they're airtight) diff --git a/new_flow_logic/register_local_pipes.lua b/new_flow_logic/register_local_pipes.lua index 005a812..0de0056 100644 --- a/new_flow_logic/register_local_pipes.lua +++ b/new_flow_logic/register_local_pipes.lua @@ -42,13 +42,13 @@ if pipeworks.enable_pipes then if pipeworks.enable_pipe_devices then --register.simple(pump_off) --register.simple(pump_on) - register.simple(spigot_on) - register.simple(spigot_off) + --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) + --register.output(spigot_off, thresholds.spigot_min, flowlogic.helpers.output_spigot) + --register.output(spigot_on, thresholds.spigot_min, flowlogic.helpers.output_spigot) end end -- cgit v1.2.3 From de44593b414cf024d70027297236f582309daa09 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 18:30:32 +0100 Subject: move flowable registration for airtight entry panel to devices.lua near node definition --- devices.lua | 6 ++++++ pipes.lua | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index fd48033..4344c83 100644 --- a/devices.lua +++ b/devices.lua @@ -433,6 +433,12 @@ minetest.register_node(nodename_panel_loaded, { drop = "pipeworks:entry_panel_empty", on_rotate = pipeworks.fix_after_rotation }) +-- FIXME requires-directionality +-- TODO: AFAIK the two panels have no visual difference, so are redundant under new flow logic - alias? +new_flow_logic_register.simple(nodename_panel_empty) +new_flow_logic_register.simple(nodename_panel_loaded) + + local nodename_sensor_empty = "pipeworks:flow_sensor_empty" minetest.register_node(nodename_sensor_empty, { diff --git a/pipes.lua b/pipes.lua index 751d460..46139ed 100644 --- a/pipes.lua +++ b/pipes.lua @@ -200,7 +200,6 @@ table.insert(pipes_empty_nodenames, valve_on) table.insert(pipes_empty_nodenames, valve_off) table.insert(pipes_empty_nodenames, entry_panel_empty) table.insert(pipes_empty_nodenames, flow_sensor_empty) -new_flow_logic_register.simple(entry_panel_empty) new_flow_logic_register.simple(flow_sensor_empty) local valve_on_loaded = "pipeworks:valve_on_loaded" @@ -209,7 +208,6 @@ local flow_sensor_loaded = "pipeworks:flow_sensor_loaded" table.insert(pipes_full_nodenames, valve_on_loaded) table.insert(pipes_full_nodenames, entry_panel_loaded) table.insert(pipes_full_nodenames, flow_sensor_loaded) -new_flow_logic_register.simple(entry_panel_loaded) new_flow_logic_register.simple(flow_sensor_loaded) pipeworks.pipes_full_nodenames = pipes_full_nodenames -- cgit v1.2.3 From df3d54f58a7b00880f6631e309fba08fb769cd33 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 18:34:55 +0100 Subject: move flowable registration for flow sensor to devices.lua near node definition --- devices.lua | 8 +++++++- pipes.lua | 5 +---- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 4344c83..f4f2150 100644 --- a/devices.lua +++ b/devices.lua @@ -518,10 +518,15 @@ minetest.register_node(nodename_sensor_loaded, { mesecons = pipereceptor_on, on_rotate = pipeworks.fix_after_rotation }) +-- FIXME requires-directionality +new_flow_logic_register.simple(nodename_sensor_empty) +new_flow_logic_register.simple(nodename_sensor_loaded) + + -- tanks --- TODO: these don't currently do anything under the new flow logic. +-- TODO flow-logic-stub: these don't currently do anything under the new flow logic. for fill = 0, 10 do local filldesc="empty" local sgroups = {snappy=3, pipe=1, tankfill=fill+1} @@ -592,6 +597,7 @@ end -- fountainhead +-- TODO flow-logic-stub: fountainheads currently non-functional under new flow logic local nodename_fountain_empty = "pipeworks:fountainhead" minetest.register_node(nodename_fountain_empty, { description = "Fountainhead", diff --git a/pipes.lua b/pipes.lua index 46139ed..c6ba09b 100644 --- a/pipes.lua +++ b/pipes.lua @@ -188,9 +188,8 @@ if REGISTER_COMPATIBILITY then }) end --- appropriate registration for both old and new flow logic follows --- FIXME/TODO: these aren't really "simple", they have directionality. + local valve_on = "pipeworks:valve_on_empty" local valve_off = "pipeworks:valve_off_empty" local entry_panel_empty = "pipeworks:entry_panel_empty" @@ -200,7 +199,6 @@ table.insert(pipes_empty_nodenames, valve_on) table.insert(pipes_empty_nodenames, valve_off) table.insert(pipes_empty_nodenames, entry_panel_empty) table.insert(pipes_empty_nodenames, flow_sensor_empty) -new_flow_logic_register.simple(flow_sensor_empty) local valve_on_loaded = "pipeworks:valve_on_loaded" local entry_panel_loaded = "pipeworks:entry_panel_loaded" @@ -208,7 +206,6 @@ local flow_sensor_loaded = "pipeworks:flow_sensor_loaded" table.insert(pipes_full_nodenames, valve_on_loaded) table.insert(pipes_full_nodenames, entry_panel_loaded) table.insert(pipes_full_nodenames, flow_sensor_loaded) -new_flow_logic_register.simple(flow_sensor_loaded) pipeworks.pipes_full_nodenames = pipes_full_nodenames pipeworks.pipes_empty_nodenames = pipes_empty_nodenames -- cgit v1.2.3 From 667eeb7d095f12d5c7e560d161697878ea485433 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 21:04:07 +0100 Subject: new flow logic: abms.lua: generalise spigot output code to support arbitary neighbour lists --- devices.lua | 5 +++-- new_flow_logic/abms.lua | 44 ++++++++++++++++---------------------------- 2 files changed, 19 insertions(+), 30 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index f4f2150..d12c84a 100644 --- a/devices.lua +++ b/devices.lua @@ -377,8 +377,9 @@ minetest.register_node(nodename_spigot_loaded, { new_flow_logic_register.simple(nodename_spigot_empty) new_flow_logic_register.simple(nodename_spigot_loaded) local spigot_min = 1 -new_flow_logic_register.output(nodename_spigot_empty, spigot_min, pipeworks.flowlogic.helpers.output_spigot) -new_flow_logic_register.output(nodename_spigot_loaded, spigot_min, pipeworks.flowlogic.helpers.output_spigot) +local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output({{x=0, y=-1, z=0}}) +new_flow_logic_register.output(nodename_spigot_empty, spigot_min, outputfn) +new_flow_logic_register.output(nodename_spigot_loaded, spigot_min, outputfn) diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua index afeb3b3..a07c390 100644 --- a/new_flow_logic/abms.lua +++ b/new_flow_logic/abms.lua @@ -111,19 +111,23 @@ end --- flowlogic output helper for spigots --- tries to place a water block in the world beneath the spigot. --- threshold checking is assumed to be handled by the node registration; --- see register_local_pipes.lua for the pipeworks default spigot. -flowlogic.helpers.output_spigot = function(pos, node, currentpressure) - local taken = 0 - 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"}) - taken = taken + 1 +-- flowlogic output helper implementation: +-- outputs water by trying to place water nodes nearby in the world. +-- neighbours is a list of node offsets to try placing water in. +-- this is a constructor function, returning another function which satisfies the output helper requirements. +flowlogic.helpers.make_neighbour_output = function(neighbours) + return function(pos, node, currentpressure) + local taken = 0 + for _, offset in pairs(neighbours) do + local npos = vector.add(pos, offset) + local name = minetest.get_node(npos).name + if (name == "air") or (name == "default:water_flowing") then + minetest.swap_node(npos, {name="default:water_source"}) + taken = taken + 1 + end + end + return taken end - return taken end @@ -145,19 +149,3 @@ flowlogic.run_output = function(pos, node, threshold, outputfn) meta:set_float(label_pressure, newpressure) end 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 -- cgit v1.2.3 From 76ebd0a0e1552e0b519716deca3d77e03d1b6b94 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 21:17:05 +0100 Subject: devices.lua: make fountains functional under new flow logic using new neighbour output helper --- devices.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index d12c84a..995f1da 100644 --- a/devices.lua +++ b/devices.lua @@ -598,7 +598,6 @@ end -- fountainhead --- TODO flow-logic-stub: fountainheads currently non-functional under new flow logic local nodename_fountain_empty = "pipeworks:fountainhead" minetest.register_node(nodename_fountain_empty, { description = "Fountainhead", @@ -668,6 +667,14 @@ minetest.register_node(nodename_fountain_loaded, { drop = "pipeworks:fountainhead", on_rotate = false }) +new_flow_logic_register.simple(nodename_fountain_empty) +new_flow_logic_register.simple(nodename_fountain_loaded) +local fountain_min = 1 +local fountainfn = pipeworks.flowlogic.helpers.make_neighbour_output({{x=0, y=1, z=0}}) +new_flow_logic_register.output(nodename_fountain_empty, fountain_min, fountainfn) +new_flow_logic_register.output(nodename_fountain_loaded, fountain_min, fountainfn) + + minetest.register_alias("pipeworks:valve_off_loaded", "pipeworks:valve_off_empty") minetest.register_alias("pipeworks:entry_panel", "pipeworks:entry_panel_empty") -- cgit v1.2.3 From 8e53526b545e2dc0a05066fb18f064a394e20740 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 1 Oct 2017 21:20:30 +0100 Subject: new flow logic: abms.lua: rename neighbour output helper to better indicate lack of rotation support --- devices.lua | 4 ++-- new_flow_logic/abms.lua | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 995f1da..1eb18be 100644 --- a/devices.lua +++ b/devices.lua @@ -377,7 +377,7 @@ minetest.register_node(nodename_spigot_loaded, { new_flow_logic_register.simple(nodename_spigot_empty) new_flow_logic_register.simple(nodename_spigot_loaded) local spigot_min = 1 -local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output({{x=0, y=-1, z=0}}) +local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed({{x=0, y=-1, z=0}}) new_flow_logic_register.output(nodename_spigot_empty, spigot_min, outputfn) new_flow_logic_register.output(nodename_spigot_loaded, spigot_min, outputfn) @@ -670,7 +670,7 @@ minetest.register_node(nodename_fountain_loaded, { new_flow_logic_register.simple(nodename_fountain_empty) new_flow_logic_register.simple(nodename_fountain_loaded) local fountain_min = 1 -local fountainfn = pipeworks.flowlogic.helpers.make_neighbour_output({{x=0, y=1, z=0}}) +local fountainfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed({{x=0, y=1, z=0}}) new_flow_logic_register.output(nodename_fountain_empty, fountain_min, fountainfn) new_flow_logic_register.output(nodename_fountain_loaded, fountain_min, fountainfn) diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua index a07c390..15adcef 100644 --- a/new_flow_logic/abms.lua +++ b/new_flow_logic/abms.lua @@ -115,7 +115,8 @@ end -- outputs water by trying to place water nodes nearby in the world. -- neighbours is a list of node offsets to try placing water in. -- this is a constructor function, returning another function which satisfies the output helper requirements. -flowlogic.helpers.make_neighbour_output = function(neighbours) +-- note that this does *not* take rotation into account. +flowlogic.helpers.make_neighbour_output_fixed = function(neighbours) return function(pos, node, currentpressure) local taken = 0 for _, offset in pairs(neighbours) do -- cgit v1.2.3 From 465e28cbd3e2d176a4ca0429711bc459fe37cf0d Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 12:16:36 +0100 Subject: devices.lua: factor out usage of flowlogic helper into dedicated registry function --- devices.lua | 12 ++++++------ new_flow_logic/flowable_node_registry_install.lua | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 1eb18be..61648da 100644 --- a/devices.lua +++ b/devices.lua @@ -377,9 +377,9 @@ minetest.register_node(nodename_spigot_loaded, { new_flow_logic_register.simple(nodename_spigot_empty) new_flow_logic_register.simple(nodename_spigot_loaded) local spigot_min = 1 -local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed({{x=0, y=-1, z=0}}) -new_flow_logic_register.output(nodename_spigot_empty, spigot_min, outputfn) -new_flow_logic_register.output(nodename_spigot_loaded, spigot_min, outputfn) +local spigot_neighbours={{x=0, y=-1, z=0}} +new_flow_logic_register.output_simple(nodename_spigot_empty, spigot_min, spigot_neighbours) +new_flow_logic_register.output_simple(nodename_spigot_loaded, spigot_min, spigot_neighbours) @@ -670,9 +670,9 @@ minetest.register_node(nodename_fountain_loaded, { new_flow_logic_register.simple(nodename_fountain_empty) new_flow_logic_register.simple(nodename_fountain_loaded) local fountain_min = 1 -local fountainfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed({{x=0, y=1, z=0}}) -new_flow_logic_register.output(nodename_fountain_empty, fountain_min, fountainfn) -new_flow_logic_register.output(nodename_fountain_loaded, fountain_min, fountainfn) +local fountain_neighbours={{x=0, y=1, z=0}} +new_flow_logic_register.output_simple(nodename_fountain_empty, fountain_min, fountain_neighbours) +new_flow_logic_register.output_simple(nodename_fountain_loaded, fountain_min, fountain_neighbours) diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 79f5997..3d9ce0a 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -77,3 +77,7 @@ end -- which tries to place water nodes around it. -- possibly this could be given a helper function to determine which faces a node should try, -- to allow things like rotation or other param values determining "direction" to be respected. +register.output_simple = function(nodename, threshold, neighbours) + local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed(neighbours) + register.output(nodename, threshold, outputfn) +end -- cgit v1.2.3 From 4f58a3039c55783978d5f85fbf59f06025884384 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 13:05:52 +0100 Subject: new flow logic: flowable_node_registry_install.lua: separate pressure threshold into upper and lower hysteresis values --- devices.lua | 14 ++++++++------ new_flow_logic/flowable_node_registry_install.lua | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 61648da..26b9275 100644 --- a/devices.lua +++ b/devices.lua @@ -376,10 +376,11 @@ minetest.register_node(nodename_spigot_loaded, { -- register both so existing flowing spigots continue to work (even if the visual doesn't match the spigot's behaviour). new_flow_logic_register.simple(nodename_spigot_empty) new_flow_logic_register.simple(nodename_spigot_loaded) -local spigot_min = 1 +local spigot_upper = 1.5 +local spigot_lower = 1.0 local spigot_neighbours={{x=0, y=-1, z=0}} -new_flow_logic_register.output_simple(nodename_spigot_empty, spigot_min, spigot_neighbours) -new_flow_logic_register.output_simple(nodename_spigot_loaded, spigot_min, spigot_neighbours) +new_flow_logic_register.output_simple(nodename_spigot_empty, spigot_upper, spigot_lower, spigot_neighbours) +new_flow_logic_register.output_simple(nodename_spigot_loaded, spigot_upper, spigot_lower, spigot_neighbours) @@ -669,10 +670,11 @@ minetest.register_node(nodename_fountain_loaded, { }) new_flow_logic_register.simple(nodename_fountain_empty) new_flow_logic_register.simple(nodename_fountain_loaded) -local fountain_min = 1 +local fountain_upper = 1.5 +local fountain_lower = 1.0 local fountain_neighbours={{x=0, y=1, z=0}} -new_flow_logic_register.output_simple(nodename_fountain_empty, fountain_min, fountain_neighbours) -new_flow_logic_register.output_simple(nodename_fountain_loaded, fountain_min, fountain_neighbours) +new_flow_logic_register.output_simple(nodename_fountain_empty, fountain_upper, fountain_lower, fountain_neighbours) +new_flow_logic_register.output_simple(nodename_fountain_loaded, fountain_upper, fountain_lower, fountain_neighbours) diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 3d9ce0a..7f414c4 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -62,12 +62,19 @@ end -- Register a node as an output. -- Expects node to already be a flowable. --- threshold and outputfn are currently as documented for register_abm_output() in abm_register.lua. -register.output = function(nodename, threshold, outputfn) +-- upper and lower thresholds have different meanings depending on whether finite liquid mode is in effect. +-- if not (the default unless auto-detected), +-- nodes above their upper threshold have their outputfn invoked (and pressure deducted), +-- nodes between upper and lower are left idle, +-- and nodes below lower have their cleanup fn invoked (to say remove water sources). +-- the upper and lower difference acts as a hysteresis to try and avoid "gaps" in the flow. +-- if finite mode is on, upper is ignored and lower is used to determine whether to run outputfn; +-- cleanupfn is ignored in this mode as finite mode assumes something causes water to move itself. +register.output = function(nodename, upper, lower, outputfn) checkbase(nodename) pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn } if pipeworks.toggles.pressure_logic then - abmregister.output(nodename, threshold, outputfn) + abmregister.output(nodename, lower, outputfn) end regwarning("output node", nodename) end @@ -77,7 +84,8 @@ end -- which tries to place water nodes around it. -- possibly this could be given a helper function to determine which faces a node should try, -- to allow things like rotation or other param values determining "direction" to be respected. -register.output_simple = function(nodename, threshold, neighbours) +-- for meanings of upper and lower, see register.output() above. +register.output_simple = function(nodename, upper, lower, neighbours) local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed(neighbours) - register.output(nodename, threshold, outputfn) + register.output(nodename, upper, lower, outputfn) end -- cgit v1.2.3 From ea92bfe4d321e11955c360fad527e08196fa5841 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sat, 7 Oct 2017 21:36:41 +0100 Subject: devices.lua: raise maximum pressure for pumps --- devices.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 26b9275..8ec3731 100644 --- a/devices.lua +++ b/devices.lua @@ -166,8 +166,9 @@ for s in ipairs(states) do }) -- FIXME: currently a simple flow device, but needs directionality checking new_flow_logic_register.simple(pumpname) + local pump_drive = 4 if states[s] ~= "off" then - new_flow_logic_register.intake_simple(pumpname, 2) + new_flow_logic_register.intake_simple(pumpname, pump_drive) end local nodename_valve_empty = "pipeworks:valve_"..states[s].."_empty" -- cgit v1.2.3 From 6a25e56336f98be7f91d328d6a75674450aa46a4 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 11:32:08 +0100 Subject: new flow logic: algorithmic and value tuning for non-finite mode --- devices.lua | 4 ++-- new_flow_logic/abms.lua | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 8ec3731..44c9d5e 100644 --- a/devices.lua +++ b/devices.lua @@ -377,7 +377,7 @@ minetest.register_node(nodename_spigot_loaded, { -- register both so existing flowing spigots continue to work (even if the visual doesn't match the spigot's behaviour). new_flow_logic_register.simple(nodename_spigot_empty) new_flow_logic_register.simple(nodename_spigot_loaded) -local spigot_upper = 1.5 +local spigot_upper = 1.0 local spigot_lower = 1.0 local spigot_neighbours={{x=0, y=-1, z=0}} new_flow_logic_register.output_simple(nodename_spigot_empty, spigot_upper, spigot_lower, spigot_neighbours) @@ -671,7 +671,7 @@ minetest.register_node(nodename_fountain_loaded, { }) new_flow_logic_register.simple(nodename_fountain_empty) new_flow_logic_register.simple(nodename_fountain_loaded) -local fountain_upper = 1.5 +local fountain_upper = 1.0 local fountain_lower = 1.0 local fountain_neighbours={{x=0, y=1, z=0}} new_flow_logic_register.output_simple(nodename_fountain_empty, fountain_upper, fountain_lower, fountain_neighbours) diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua index 9197d17..e83d50e 100644 --- a/new_flow_logic/abms.lua +++ b/new_flow_logic/abms.lua @@ -202,12 +202,13 @@ end -- removes water sources from neighbor positions when the output is "off" due to lack of pressure. flowlogic.helpers.make_neighbour_cleanup_fixed = function(neighbours) return function(pos, node, currentpressure) - -- FIXME - this would indiscriminately take blocks while under-pressure, not just one time? + --pipeworks.logger("neighbour_cleanup_fixed@"..formatvec(pos)) for _, offset in pairs(neighbours) do local npos = vector.add(pos, offset) local name = minetest.get_node(npos).name if (name == "default:water_source") then - minetest.remove_node(pos) + --pipeworks.logger("neighbour_cleanup_fixed removing "..formatvec(npos)) + minetest.remove_node(npos) end end end @@ -221,6 +222,7 @@ flowlogic.run_output = function(pos, node, currentpressure, oldpressure, outputd -- the outputfn is provided the current pressure and returns the pressure "taken". -- as an example, using this with the above spigot function, -- the spigot function tries to output a water source if it will fit in the world. + --pipeworks.logger("flowlogic.run_output() pos "..formatvec(pos).." old -> currentpressure "..tostring(oldpressure).." "..tostring(currentpressure).." finitemode "..tostring(finitemode)) local upper = outputdef.upper local lower = outputdef.lower local result = currentpressure @@ -232,7 +234,8 @@ flowlogic.run_output = function(pos, node, currentpressure, oldpressure, outputd if newpressure < 0 then newpressure = 0 end result = newpressure end - if (not finitemode) and (currentpressure < lower) and (oldpressure > lower) then + if (not finitemode) and (currentpressure < lower) and (oldpressure < lower) then + --pipeworks.logger("flowlogic.run_output() invoking cleanup currentpressure="..tostring(currentpressure)) outputdef.cleanupfn(pos, node, currentpressure) end return result -- cgit v1.2.3 From 32a24730f1ab8cd596ed2f4cf6eda1a58c877ecb Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 15:07:12 +0100 Subject: new flow logic: change simple transition set logic to take list of key-value pairs, add set registration for flow sensor pipe --- devices.lua | 3 +++ new_flow_logic/flowable_node_registry_install.lua | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 44c9d5e..196d660 100644 --- a/devices.lua +++ b/devices.lua @@ -524,6 +524,9 @@ minetest.register_node(nodename_sensor_loaded, { -- FIXME requires-directionality new_flow_logic_register.simple(nodename_sensor_empty) new_flow_logic_register.simple(nodename_sensor_loaded) +-- activate flow sensor at roughly half the pressure pumps drive pipes +local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 2.0 } } +new_flow_logic_register.transition_simple_set(sensor_pressure_set) diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index 63151f0..f019dc3 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -147,8 +147,11 @@ local simple_transitions = pipeworks.flowables.transitions.simple register.transition_simple_set = function(nodeset) local set = {} - for nodename, value in pairs(nodeset) do - if type(nodename) ~= "string" then simpleseterror("nodename key "..tostring(nodename).."was not a string!") end + for index, element in ipairs(nodeset) do + if type(element) ~= "table" then simpleseterror("element "..tostring(index).." in nodeset was not table!") end + local nodename = element[1] + local value = element[2] + if type(nodename) ~= "string" then simpleseterror("nodename "..tostring(nodename).."was not a string!") end if type(value) ~= "number" then simpleseterror("pressure value "..tostring(value).."was not a number!") end insert_transition_base(nodename) if simple_transitions[nodename] then duplicateerr("simple transition set", nodename) end @@ -159,7 +162,7 @@ register.transition_simple_set = function(nodeset) -- sort pressure values, smallest first local smallest_first = function(a, b) - return a.value < b.value + return a.threshold < b.threshold end table.sort(set, smallest_first) -- cgit v1.2.3 From ce0983d239c4c855b7f6fd9d96d352c03c5d88b0 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 16:41:00 +0100 Subject: devices.lua: adjust flow sensor threshold to more closely model classic mode --- devices.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 196d660..2a7afc9 100644 --- a/devices.lua +++ b/devices.lua @@ -525,7 +525,7 @@ minetest.register_node(nodename_sensor_loaded, { new_flow_logic_register.simple(nodename_sensor_empty) new_flow_logic_register.simple(nodename_sensor_loaded) -- activate flow sensor at roughly half the pressure pumps drive pipes -local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 2.0 } } +local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 1.0 } } new_flow_logic_register.transition_simple_set(sensor_pressure_set) -- cgit v1.2.3 From d5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Sun, 8 Oct 2017 17:38:28 +0100 Subject: new flow logic: implement post-transition hook with mesecons support, add mesecons transition rules for flow sensor --- devices.lua | 2 +- new_flow_logic/abms.lua | 24 +++++++++++++++++++++++ new_flow_logic/flowable_node_registry.lua | 1 + new_flow_logic/flowable_node_registry_install.lua | 12 +++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) (limited to 'devices.lua') diff --git a/devices.lua b/devices.lua index 2a7afc9..5203bf3 100644 --- a/devices.lua +++ b/devices.lua @@ -526,7 +526,7 @@ new_flow_logic_register.simple(nodename_sensor_empty) new_flow_logic_register.simple(nodename_sensor_loaded) -- activate flow sensor at roughly half the pressure pumps drive pipes local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 1.0 } } -new_flow_logic_register.transition_simple_set(sensor_pressure_set) +new_flow_logic_register.transition_simple_set(sensor_pressure_set, { mesecons=pipeworks.mesecons_rules }) diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua index 6abdd42..38ae4b6 100644 --- a/new_flow_logic/abms.lua +++ b/new_flow_logic/abms.lua @@ -111,6 +111,7 @@ flowlogic.run = function(pos, node) local newnode = flowlogic.run_transition(node, currentpressure) --pipeworks.logger("flowlogic.run()@"..formatvec(pos).." transition, new node name = "..dump(newnode).." pressure "..tostring(currentpressure)) minetest.swap_node(pos, newnode) + flowlogic.run_transition_post(pos, newnode) end -- set the new pressure @@ -289,3 +290,26 @@ flowlogic.run_transition = function(node, currentpressure) return result end + +-- post-update hook for run_transition +-- among other things, updates mesecons if present. +-- node here means the new node, returned from run_transition() above +flowlogic.run_transition_post = function(pos, node) + local mesecons_def = minetest.registered_nodes[node.name].mesecons + local mesecons_rules = pipeworks.flowables.transitions.mesecons[node.name] + if minetest.global_exists("mesecon") and (mesecons_def ~= nil) and mesecons_rules then + if type(mesecons_def) ~= "table" then + pipeworks.logger("flowlogic.run_transition_post() BUG mesecons def for "..node.name.."not a table: got "..tostring(mesecons_def)) + else + local receptor = mesecons_def.receptor + if receptor then + local state = receptor.state + if state == mesecon.state.on then + mesecon.receptor_on(pos, mesecons_rules) + elseif state == mesecon.state.off then + mesecon.receptor_off(pos, mesecons_rules) + end + end + end + end +end diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua index 7651928..2523803 100644 --- a/new_flow_logic/flowable_node_registry.lua +++ b/new_flow_logic/flowable_node_registry.lua @@ -32,6 +32,7 @@ pipeworks.flowables.outputs.list = {} pipeworks.flowables.transitions = {} pipeworks.flowables.transitions.list = {} -- master list pipeworks.flowables.transitions.simple = {} -- nodes that change based purely on pressure +pipeworks.flowables.transitions.mesecons = {} -- table of mesecons rules to apply on transition diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua index e4a5744..c8f6889 100644 --- a/new_flow_logic/flowable_node_registry_install.lua +++ b/new_flow_logic/flowable_node_registry_install.lua @@ -145,8 +145,9 @@ local simpleseterror = function(msg) end local simple_transitions = pipeworks.flowables.transitions.simple -register.transition_simple_set = function(nodeset) +register.transition_simple_set = function(nodeset, extras) local set = {} + if extras == nil then extras = {} end local length = #nodeset if length < 2 then simpleseterror("nodeset needs at least two elements!") end @@ -175,4 +176,13 @@ register.transition_simple_set = function(nodeset) --pipeworks.logger("register.transition_simple_set() after sort: nodename "..element.nodename.." value "..tostring(element.threshold)) simple_transitions[element.nodename] = set end + + -- handle extra options + -- if mesecons rules table was passed, set for each node + if extras.mesecons then + local mesecons_rules = pipeworks.flowables.transitions.mesecons + for _, element in ipairs(set) do + mesecons_rules[element.nodename] = extras.mesecons + end + end end -- cgit v1.2.3