forked from mtcontrib/pipeworks
internal refactoring of flowable node registration in preparation for enhanced flow checking logic
This commit is contained in:
parent
10221c6c15
commit
40eeaac2ec
59
flowable_node_registry.lua
Normal file
59
flowable_node_registry.lua
Normal file
@ -0,0 +1,59 @@
|
||||
-- registration code for nodes under new flow logic
|
||||
-- written 2017 by thetaepsilon
|
||||
|
||||
pipeworks.flowables = {}
|
||||
pipeworks.flowables.list = {}
|
||||
pipeworks.flowables.list.all = {}
|
||||
-- pipeworks.flowables.list.nodenames = {}
|
||||
|
||||
-- simple flowables - balance pressure in any direction
|
||||
pipeworks.flowables.list.simple = {}
|
||||
pipeworks.flowables.list.simple_nodenames = {}
|
||||
|
||||
-- simple intakes - try to absorb any adjacent water nodes
|
||||
pipeworks.flowables.inputs = {}
|
||||
pipeworks.flowables.inputs.list = {}
|
||||
pipeworks.flowables.inputs.nodenames = {}
|
||||
|
||||
-- registration functions
|
||||
pipeworks.flowables.register = {}
|
||||
local register = pipeworks.flowables.register
|
||||
|
||||
-- some sanity checking for passed args, as this could potentially be made an external API eventually
|
||||
local checkexists = function(nodename)
|
||||
if type(nodename) ~= "string" then error("pipeworks.flowables nodename must be a string!") end
|
||||
return pipeworks.flowables.list.all[nodename]
|
||||
end
|
||||
|
||||
local insertbase = function(nodename)
|
||||
if checkexists(nodename) then error("pipeworks.flowables duplicate registration!") end
|
||||
pipeworks.flowables.list.all[nodename] = true
|
||||
-- table.insert(pipeworks.flowables.list.nodenames, nodename)
|
||||
end
|
||||
|
||||
-- Register a node as a simple flowable.
|
||||
-- Simple flowable nodes have no considerations for direction of flow;
|
||||
-- A cluster of adjacent simple flowables will happily average out in any direction.
|
||||
-- This does *not* register the ABM, as that is done in register_flow_logic.lua;
|
||||
-- this is so that the new flow logic can remain optional during development.
|
||||
register.simple = function(nodename)
|
||||
insertbase(nodename)
|
||||
pipeworks.flowables.list.simple[nodename] = true
|
||||
table.insert(pipeworks.flowables.list.simple_nodenames, nodename)
|
||||
end
|
||||
|
||||
local checkbase = function(nodename)
|
||||
if not checkexists(nodename) then error("pipeworks.flowables node doesn't exist as a flowable!") end
|
||||
end
|
||||
|
||||
-- Register a node as a simple intake.
|
||||
-- See new_flow_logic for the details of this.
|
||||
-- Expects node to be registered as a flowable (is present in flowables.list.all),
|
||||
-- so that water can move out of it.
|
||||
-- maxpressure is the maximum pipeline pressure that this node can drive.
|
||||
-- possible WISHME here: technic-driven high-pressure pumps
|
||||
register.intake_simple = function(nodename, maxpressure)
|
||||
checkbase(nodename)
|
||||
pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure }
|
||||
table.insert(pipeworks.flowables.inputs.nodenames, nodename)
|
||||
end
|
45
flowable_nodes_add_pipes.lua
Normal file
45
flowable_nodes_add_pipes.lua
Normal file
@ -0,0 +1,45 @@
|
||||
-- conditional registration of pipe nodes for the new pipe logic, depending on enable flags.
|
||||
-- otherwise register_flow_logic.lua would be attempting to register ABMs for non-existant nodes.
|
||||
-- written 2017 by thetaepsilon
|
||||
|
||||
|
||||
|
||||
-- global values and thresholds for water behaviour
|
||||
-- TODO: add some way of setting this per-world
|
||||
local thresholds = {}
|
||||
-- limit on pump pressure - will not absorb more than can be taken
|
||||
thresholds.pump_pressure = 2
|
||||
|
||||
|
||||
|
||||
local pipes_full_nodenames = pipeworks.pipes_full_nodenames
|
||||
local pipes_empty_nodenames = pipeworks.pipes_empty_nodenames
|
||||
|
||||
local register = pipeworks.flowables.register
|
||||
|
||||
|
||||
|
||||
-- FIXME: DRY principle for names, move this to devices.lua?
|
||||
-- FIXME: all devices still considered simple
|
||||
local pump_on = "pipeworks:pump_on"
|
||||
local pump_off = "pipeworks:pump_off"
|
||||
local spigot_off = "pipeworks:spigot"
|
||||
local spigot_on = "pipeworks:spigot_pouring"
|
||||
|
||||
if pipeworks.enable_pipes then
|
||||
for _, pipe in ipairs(pipes_full_nodenames) do
|
||||
register.simple(pipe)
|
||||
end
|
||||
for _, pipe in ipairs(pipes_empty_nodenames) do
|
||||
register.simple(pipe)
|
||||
end
|
||||
|
||||
if pipeworks.enable_pipe_devices then
|
||||
register.simple(pump_off)
|
||||
register.simple(pump_on)
|
||||
register.simple(spigot_on)
|
||||
register.simple(spigot_off)
|
||||
|
||||
register.intake_simple(pump_on, thresholds.pump_pressure)
|
||||
end
|
||||
end
|
6
init.lua
6
init.lua
@ -115,12 +115,16 @@ dofile(pipeworks.modpath.."/filter-injector.lua")
|
||||
dofile(pipeworks.modpath.."/trashcan.lua")
|
||||
dofile(pipeworks.modpath.."/wielder.lua")
|
||||
|
||||
-- note that pipes still don't appear until registered in the files below this one, so can still be turned off
|
||||
dofile(pipeworks.modpath.."/flowable_node_registry.lua")
|
||||
|
||||
if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end
|
||||
if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube.lua") end
|
||||
if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end
|
||||
-- individual enable flags also checked in register_flow_logic.lua
|
||||
-- individual enable flags also checked in flowable_nodes_add_pipes.lua
|
||||
if pipeworks.enable_new_flow_logic then
|
||||
dofile(pipeworks.modpath.."/new_flow_logic.lua")
|
||||
dofile(pipeworks.modpath.."/flowable_nodes_add_pipes.lua")
|
||||
dofile(pipeworks.modpath.."/register_flow_logic.lua")
|
||||
end
|
||||
|
||||
|
@ -3,14 +3,6 @@
|
||||
|
||||
|
||||
|
||||
-- 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 = {
|
||||
@ -95,9 +87,14 @@ 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 properties = pipeworks.flowables.inputs.list[node.name]
|
||||
local maxpressure = properties.maxpressure
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local currentpressure = meta:get_float(label_pressure)
|
||||
local intake_limit = thresholds.pump_pressure - currentpressure
|
||||
|
||||
local intake_limit = maxpressure - 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)
|
||||
|
@ -1,29 +1,11 @@
|
||||
-- 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
|
||||
|
||||
-- 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 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
|
||||
|
||||
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
|
||||
|
||||
|
||||
-- note that checking for feature toggles (because otherwise certain pipes aren't define)
|
||||
-- is now done by flowable_nodes_add_pipes.lua
|
||||
--[[
|
||||
if pipeworks.enable_pipes then
|
||||
minetest.register_abm({
|
||||
nodenames = pipes_all_nodenames,
|
||||
@ -34,19 +16,32 @@ if pipeworks.enable_pipes then
|
||||
end
|
||||
})
|
||||
end
|
||||
]]
|
||||
-- flowables.register.simple takes care of creating an array-like table of node names
|
||||
minetest.register_abm({
|
||||
nodenames = pipeworks.flowables.list.simple_nodenames,
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
pipeworks.balance_pressure(pos, node)
|
||||
end
|
||||
})
|
||||
|
||||
if pipeworks.enable_pipe_devices then
|
||||
-- absorb water into pumps if it'll fit
|
||||
minetest.register_abm({
|
||||
nodenames = { pump_on },
|
||||
nodenames = pipeworks.flowables.inputs.nodenames,
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
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.
|
||||
-- temp. disabled as the node names were moved to flowable_node_add_pipes.lua
|
||||
--[[
|
||||
minetest.register_abm({
|
||||
nodenames = { spigot_on, spigot_off },
|
||||
interval = 1,
|
||||
@ -55,4 +50,5 @@ if pipeworks.enable_pipe_devices then
|
||||
pipeworks.run_spigot_output(pos, node)
|
||||
end
|
||||
})
|
||||
]]
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user