diff options
author | root <root@linuxworks.belug.de> | 2017-10-22 21:09:00 +0200 |
---|---|---|
committer | root <root@linuxworks.belug.de> | 2017-10-22 21:09:00 +0200 |
commit | 31a6107b82ba1373289423b414b54b2818e61f3c (patch) | |
tree | b1ab231598b02f7342c95ded253c8f671c9b1bd1 | |
parent | 277154cf2daf870044c6f5bac90f338552fb75df (diff) | |
parent | 75978a020751ce5591d0fd0b8adeaa32422b2fe5 (diff) |
Merge branch 'master' of https://github.com/minetest-mods/pipeworks
-rw-r--r-- | changelog.txt | 9 | ||||
-rw-r--r-- | default_settings.lua | 30 | ||||
-rw-r--r-- | devices.lua | 16 | ||||
-rw-r--r-- | init.lua | 8 | ||||
-rw-r--r-- | pipes.lua | 2 | ||||
-rw-r--r-- | pressure_logic/abm_register.lua | 2 | ||||
-rw-r--r-- | pressure_logic/flowable_node_registry_install.lua | 55 | ||||
-rw-r--r-- | todo/pressure_logic.txt | 7 |
8 files changed, 81 insertions, 48 deletions
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. diff --git a/default_settings.lua b/default_settings.lua index 91e511c..7d8bfd9 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -29,6 +29,36 @@ 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 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" +--[[ +-- 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 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 +]] + for name, value in pairs(settings) do local setting_type = type(value) if setting_type == "boolean" then diff --git a/devices.lua b/devices.lua index 093137e..3ccbd09 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 @@ -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}} @@ -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 }) @@ -15,18 +15,14 @@ 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 - minetest.log("warning", "pipeworks pressure-based logic is WIP and incomplete!") +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 -- Random variables @@ -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 7b14fd3..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 @@ -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 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. |