From b2b29a1737c4bd86e397bb496d06aebd8129def7 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Thu, 19 Oct 2017 13:35:31 +0100 Subject: pressure logic: rewrite callbacks for horizontal rotation flowables to support singular and double-ended devices --- devices.lua | 12 +++--- pressure_logic/flowable_node_registry_install.lua | 51 +++++++++++++---------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/devices.lua b/devices.lua index 093137e..cb1a6d1 100644 --- a/devices.lua +++ b/devices.lua @@ -215,7 +215,7 @@ for s in ipairs(states) do -- 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 - new_flow_logic_register.directional_horizonal_rotate(nodename_valve_empty) + new_flow_logic_register.directional_horizonal_rotate(nodename_valve_empty, true) end end @@ -263,7 +263,7 @@ minetest.register_node(nodename_valve_loaded, { -- 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.directional_horizonal_rotate(nodename_valve_loaded) +new_flow_logic_register.directional_horizonal_rotate(nodename_valve_loaded, true) -- grating @@ -438,8 +438,8 @@ minetest.register_node(nodename_panel_loaded, { on_rotate = pipeworks.fix_after_rotation }) -- TODO: AFAIK the two panels have no visual difference, so are redundant under new flow logic - alias? -new_flow_logic_register.directional_horizonal_rotate(nodename_panel_empty) -new_flow_logic_register.directional_horizonal_rotate(nodename_panel_loaded) +new_flow_logic_register.directional_horizonal_rotate(nodename_panel_empty, true) +new_flow_logic_register.directional_horizonal_rotate(nodename_panel_loaded, true) @@ -521,8 +521,8 @@ minetest.register_node(nodename_sensor_loaded, { mesecons = pipereceptor_on, on_rotate = pipeworks.fix_after_rotation }) -new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_empty) -new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_loaded) +new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_empty, true) +new_flow_logic_register.directional_horizonal_rotate(nodename_sensor_loaded, true) -- 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, { mesecons=pipeworks.mesecons_rules }) diff --git a/pressure_logic/flowable_node_registry_install.lua b/pressure_logic/flowable_node_registry_install.lua index 7b14fd3..9bb9e9a 100644 --- a/pressure_logic/flowable_node_registry_install.lua +++ b/pressure_logic/flowable_node_registry_install.lua @@ -69,34 +69,39 @@ end -- register a node as a directional flowable whose accepting sides depends upon param2 rotation. -- used for entry panels, valves, flow sensors and spigots, -- whose facing axis is always upwards and can only rotate horizontally. -local iseastwest = function(node) - local data = node.param2 - local rotation = data % 4 - -- rotation 0 and 2 is the same axis, as is 1 and 3. - -- 0-3 starts at north and proceeds clockwise. - local axis = rotation % 2 - --pipeworks.logger("iseastwest() rotation="..tostring(rotation).." axis="..tostring(axis)) - return (axis == 1) -end -register.directional_horizonal_rotate = function(nodename) - local north = {x= 0,y= 0,z= 1} - local south = {x= 0,y= 0,z=-1} - local east = {x= 1,y= 0,z= 0} - local west = {x=-1,y= 0,z= 0} - local neighbourfn = function(node) - if iseastwest(node) then - return { east, west } +register.directional_horizonal_rotate = function(nodename, doubleended) + local rotations = { + {x= 0,y= 0,z= 1}, + {x= 1,y= 0,z= 0}, + {x= 0,y= 0,z=-1}, + {x=-1,y= 0,z= 0}, + } + local getends = function(node) + --local dname = "horizontal rotate getends() " + local param2 = node.param2 + -- the sole end of the spigot points in the direction the rotation bits suggest + -- also note to self: lua arrays start at one... + local mainend = (param2 % 4) + 1 + -- use modulus wrap-around to find other end for straight-run devices like the valve + local otherend = ((param2 + 2) % 4) + 1 + local mainrot = rotations[mainend] + --pipeworks.logger(dname.."mainrot: "..dump(mainrot)) + local result + if doubleended then + result = { mainrot, rotations[otherend] } else - return { north, south } + result = { mainrot } end + --pipeworks.logger(dname.."result: "..dump(result)) + return result + end + local neighbourfn = function(node) + return getends(node) end local directionfn = function(node, direction) local result = false - if iseastwest(node) then - --pipeworks.logger("horizontal rotate directionfn() eastwest=true") - result = vector.equals(direction, east) or vector.equals(direction, west) - else - result = vector.equals(direction, north) or vector.equals(direction, south) + for index, endvec in ipairs(getends(node)) do + if vector.equals(direction, endvec) then result = true end end return result end -- cgit v1.2.3 From b7714df9549be36920b1940f6dd2f627c36f160b Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Thu, 19 Oct 2017 13:41:37 +0100 Subject: devices.lua: convert spigot to single-ended horizontally rotating flowable --- devices.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devices.lua b/devices.lua index cb1a6d1..3ccbd09 100644 --- a/devices.lua +++ b/devices.lua @@ -376,8 +376,8 @@ minetest.register_node(nodename_spigot_loaded, { }) -- 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) +new_flow_logic_register.directional_horizonal_rotate(nodename_spigot_empty, false) +new_flow_logic_register.directional_horizonal_rotate(nodename_spigot_loaded, false) local spigot_upper = 1.0 local spigot_lower = 1.0 local spigot_neighbours={{x=0, y=-1, z=0}} -- cgit v1.2.3 From bd172a3ca1120581e35bfb558e6647da7540ac78 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Thu, 19 Oct 2017 13:43:11 +0100 Subject: todo: remove item for directionality code --- todo/pressure_logic.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/todo/pressure_logic.txt b/todo/pressure_logic.txt index 41ce2f8..60884e1 100644 --- a/todo/pressure_logic.txt +++ b/todo/pressure_logic.txt @@ -1,10 +1,3 @@ --- Directionality code (in progress) -The flowable node class for directional nodes now exists and is hooked up in the code for determining valid neighbours in the flowable node ABM routines. -Pumps have been converted to this as part of the testing. -However, currently only the "raw" registration for this is available, and the pump definition registers it's own callback routines. -Helpers need to be added to flowable_node_registry_install.lua to abstract away the expression of which nodes can flow which ways - valves, flow sensors, spigots and entry panels, for instance, all currently rotate the same way using an upwards facedir, so a helper for these nodes would prevent code duplication. - - -- (may not be possible) stop removing water nodes that were not placed by outputs when off In non-finite mode, spigots and fountainheads will vanish water sources in their output positions, even if those output nodes did not place them there. This is annoying though not game-breaking in non-finite mode, where water sources can at least be easily replenished. -- cgit v1.2.3 From 4d1c8d5529253e736422aacc75ce35d44a4b309e Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Thu, 19 Oct 2017 13:46:30 +0100 Subject: changelog: add entry for pressure logic directionality work --- changelog.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/changelog.txt b/changelog.txt index 9ea2dbb..d33ed87 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,15 @@ Changelog --------- + + +2017-10-19 (thetaepsilon) +Directional flowables are now implemented. +All devices for which it is relevant (valve, flow sensor etc.) have been converted so that they only flow on their connecting sides, so pressure propogation now works as expected for these devices when pressure logic is enabled. +Classic mode continues to be preserved by default as before. + + + 2017-10-14 (thetaepsilon, VanessaE) Node breakers have been updated to not have a tool by default, and determine if the node that they are trying to break can be dug with the tool in it's inventory slot. The crafting recipe for the node breakers has been updated, using a new gear crafting item that requires iron instead of mese, which should be a more accessible cost in most cases. -- cgit v1.2.3 From d4b32d5fa332fe2d3aec8a433bcde3abb80406ff Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Thu, 19 Oct 2017 21:41:04 +0100 Subject: default_settings.lua: document pressure logic settings --- default_settings.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/default_settings.lua b/default_settings.lua index 91e511c..5073b7d 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -29,6 +29,25 @@ local settings = { delete_item_on_clearobject = true, } +-- documentation for toggles controlling pressure logic features +-- do not edit this; +-- instead, copy the uncommented lines into pipeworks_settings.txt in your world directory. +--[[ +-- enable pressure logic mode instead of "classic" mode. +-- WARNING: this changes a few things, most noticeably how pumps work. +-- you'll want to make sure they're fed by an infinite spring. +pipeworks.toggles.pressure_logic = true + +-- force-enable finite water handling mode. +-- this changes the way that water node placement is handled; +-- volume will always be preserved, and water is assumed to move itself downwards. +-- nil (the default) means autodetect from installed finite liquid mods, true is force-on, false is force-off. +-- note that you should NOT normally explicitly set this to either true or false, +-- unless the mod you want this for is not covered by autodetect-finite-water.lua. +-- please file an issue if you need to use this for a finite water mod exists not covered there. +pipeworks.toggles.finite_water = nil +]] + for name, value in pairs(settings) do local setting_type = type(value) if setting_type == "boolean" then -- cgit v1.2.3 From 86fa342d85bb589e54ac8ec2b8c14d14c8843c09 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Thu, 19 Oct 2017 21:51:55 +0100 Subject: default_settings.lua: line wrap length fixes for pressure logic toggle documentation --- default_settings.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/default_settings.lua b/default_settings.lua index 5073b7d..c211153 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -29,9 +29,10 @@ local settings = { delete_item_on_clearobject = true, } --- documentation for toggles controlling pressure logic features --- do not edit this; --- instead, copy the uncommented lines into pipeworks_settings.txt in your world directory. +-- documentation for toggles controlling pressure logic features. +-- do not edit this file directly; +-- instead, create pipeworks_settings.txt in your world directory, +-- and copy the uncommented lines from the block comment below into it. --[[ -- enable pressure logic mode instead of "classic" mode. -- WARNING: this changes a few things, most noticeably how pumps work. @@ -40,11 +41,15 @@ pipeworks.toggles.pressure_logic = true -- force-enable finite water handling mode. -- this changes the way that water node placement is handled; --- volume will always be preserved, and water is assumed to move itself downwards. --- nil (the default) means autodetect from installed finite liquid mods, true is force-on, false is force-off. --- note that you should NOT normally explicitly set this to either true or false, --- unless the mod you want this for is not covered by autodetect-finite-water.lua. --- please file an issue if you need to use this for a finite water mod exists not covered there. +-- volume will always be preserved, +-- and water is assumed to move itself downwards. +-- nil (the default) means autodetect from installed finite liquid mods, +-- true is force-on, false is force-off. +-- note that you should NOT normally explicitly set this to true/false, +-- unless the mod you want this for is not covered by auto-detection +-- (please see autodetect-finite-water.lua). +-- please file an issue if you have a finite water mod not covered there, +-- and feel it necessary to explicitly set this toggle pipeworks.toggles.finite_water = nil ]] -- cgit v1.2.3 From 538e33c537c2c6347a7a2251392fedbf5ee07ba3 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Fri, 20 Oct 2017 21:34:08 +0100 Subject: init.lua: update pressure logic mode warning --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index f4276f8..9ce6a0f 100644 --- a/init.lua +++ b/init.lua @@ -26,7 +26,7 @@ if worldsettingsfile then dofile(worldsettingspath) end if pipeworks.toggles.pressure_logic then - minetest.log("warning", "pipeworks pressure-based logic is WIP and incomplete!") + minetest.log("warning", "pipeworks pressure logic mode comes with caveats and differences in behaviour, you have been warned!") end -- Random variables -- cgit v1.2.3 From 75978a020751ce5591d0fd0b8adeaa32422b2fe5 Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Fri, 20 Oct 2017 22:46:51 +0100 Subject: refactor pressure logic toggle to act as option enum --- default_settings.lua | 18 ++++++++++++------ init.lua | 6 +----- pipes.lua | 2 +- pressure_logic/abm_register.lua | 2 +- pressure_logic/flowable_node_registry_install.lua | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/default_settings.lua b/default_settings.lua index c211153..7d8bfd9 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -29,16 +29,22 @@ local settings = { delete_item_on_clearobject = true, } +pipeworks.toggles = {} -- documentation for toggles controlling pressure logic features. -- do not edit this file directly; -- instead, create pipeworks_settings.txt in your world directory, --- and copy the uncommented lines from the block comment below into it. +-- and copy the uncommented lines from the block comments below into it. +--[[ +-- flow logic implementation. +-- set to one of the following strings. +-- "classic": classic mode written by VanessaE +-- "pressure": pressure metadata based, written by thetaepsilon. +-- has caveats such as water speed issues though. +-- setting to nil inhibits all flow logic, useful for debugging ABM crashes, +-- or for rendering the pipes purely decorative. +]] +pipeworks.toggles.pipe_mode = "classic" --[[ --- enable pressure logic mode instead of "classic" mode. --- WARNING: this changes a few things, most noticeably how pumps work. --- you'll want to make sure they're fed by an infinite spring. -pipeworks.toggles.pressure_logic = true - -- force-enable finite water handling mode. -- this changes the way that water node placement is handled; -- volume will always be preserved, diff --git a/init.lua b/init.lua index 9ce6a0f..e908bcc 100644 --- a/init.lua +++ b/init.lua @@ -15,17 +15,13 @@ pipeworks.modpath = minetest.get_modpath("pipeworks") 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.toggles.pressure_logic then +if pipeworks.toggles.pipe_mode == "pressure" then minetest.log("warning", "pipeworks pressure logic mode comes with caveats and differences in behaviour, you have been warned!") end diff --git a/pipes.lua b/pipes.lua index 2acdfa9..602daab 100644 --- a/pipes.lua +++ b/pipes.lua @@ -213,7 +213,7 @@ pipeworks.pipes_empty_nodenames = pipes_empty_nodenames -if not pipeworks.toggles.pressure_logic then +if pipeworks.toggles.pipe_mode == "classic" then diff --git a/pressure_logic/abm_register.lua b/pressure_logic/abm_register.lua index a8e3abc..4019eef 100644 --- a/pressure_logic/abm_register.lua +++ b/pressure_logic/abm_register.lua @@ -10,7 +10,7 @@ local flowlogic = pipeworks.flowlogic -- see flowlogic.run() in abms.lua. local register_flowlogic_abm = function(nodename) - if pipeworks.toggles.pressure_logic then + if pipeworks.toggles.pipe_mode == "pressure" then minetest.register_abm({ label = "pipeworks new_flow_logic run", nodenames = { nodename }, diff --git a/pressure_logic/flowable_node_registry_install.lua b/pressure_logic/flowable_node_registry_install.lua index 9bb9e9a..5cf1941 100644 --- a/pressure_logic/flowable_node_registry_install.lua +++ b/pressure_logic/flowable_node_registry_install.lua @@ -20,14 +20,14 @@ 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) - if pipeworks.toggles.pressure_logic then + if pipeworks.toggles.pipe_mode == "pressure" then abmregister.flowlogic(nodename) end end local regwarning = function(kind, nodename) local tail = "" - if not pipeworks.toggles.pressure_logic then tail = " but pressure logic not enabled" end + if pipeworks.toggles.pipe_mode ~= "pressure" then tail = " but pressure logic not enabled" end --pipeworks.logger(kind.." flow logic registry requested for "..nodename..tail) end -- cgit v1.2.3