forked from mtcontrib/pipeworks
new flow logic: abms.lua: refactor run_input to run as part of master run() ABM
This commit is contained in:
parent
be1a6d53aa
commit
9c770532e6
|
@ -50,6 +50,7 @@ register.balance = register_abm_balance
|
||||||
-- register a node for the input ABM.
|
-- register a node for the input ABM.
|
||||||
-- intakefn is run on the node to determine how much water can be taken (and update it's environment accordingly).
|
-- intakefn is run on the node to determine how much water can be taken (and update it's environment accordingly).
|
||||||
-- maxpressure is the maximum pressure that this input can drive, beyond which pressure will not be raised.
|
-- maxpressure is the maximum pressure that this input can drive, beyond which pressure will not be raised.
|
||||||
|
--[[
|
||||||
local register_abm_input = function(nodename, maxpressure, intakefn)
|
local register_abm_input = function(nodename, maxpressure, intakefn)
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = { nodename },
|
nodenames = { nodename },
|
||||||
|
@ -61,6 +62,7 @@ local register_abm_input = function(nodename, maxpressure, intakefn)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
register.input = register_abm_input
|
register.input = register_abm_input
|
||||||
|
]]
|
||||||
|
|
||||||
-- register a node for the output ABM.
|
-- register a node for the output ABM.
|
||||||
-- threshold determines the minimum pressure, over which outputfn is called.
|
-- threshold determines the minimum pressure, over which outputfn is called.
|
||||||
|
|
|
@ -66,6 +66,14 @@ local get_pressure_access = function(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- logging is unreliable when something is crashing...
|
||||||
|
local nilexplode = function(caller, label, value)
|
||||||
|
if value == nil then
|
||||||
|
error(caller..": "..label.." was nil")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
flowlogic.run = function(pos, node)
|
flowlogic.run = function(pos, node)
|
||||||
local nodename = node.name
|
local nodename = node.name
|
||||||
|
@ -73,6 +81,14 @@ flowlogic.run = function(pos, node)
|
||||||
local nodepressure = get_pressure_access(pos)
|
local nodepressure = get_pressure_access(pos)
|
||||||
local currentpressure = nodepressure.get()
|
local currentpressure = nodepressure.get()
|
||||||
|
|
||||||
|
-- if node is an input: run intake phase
|
||||||
|
local inputdef = pipeworks.flowables.inputs.list[nodename]
|
||||||
|
if inputdef then
|
||||||
|
currentpressure = flowlogic.run_input(pos, node, currentpressure, inputdef)
|
||||||
|
--debuglog("post-intake currentpressure is "..currentpressure)
|
||||||
|
--nilexplode("run()", "currentpressure", currentpressure)
|
||||||
|
end
|
||||||
|
|
||||||
-- balance pressure with neighbours
|
-- balance pressure with neighbours
|
||||||
currentpressure = flowlogic.balance_pressure(pos, node, currentpressure)
|
currentpressure = flowlogic.balance_pressure(pos, node, currentpressure)
|
||||||
|
|
||||||
|
@ -131,23 +147,22 @@ end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
flowlogic.run_input = function(pos, node, maxpressure, intakefn)
|
flowlogic.run_input = function(pos, node, currentpressure, inputdef)
|
||||||
-- intakefn allows a given input node to define it's own intake logic.
|
-- intakefn allows a given input node to define it's own intake logic.
|
||||||
-- this function will calculate the maximum amount of water that can be taken in;
|
-- this function will calculate the maximum amount of water that can be taken in;
|
||||||
-- the intakefn will be given this and is expected to return the actual absorption amount.
|
-- the intakefn will be given this and is expected to return the actual absorption amount.
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local maxpressure = inputdef.maxpressure
|
||||||
local currentpressure = meta:get_float(label_pressure)
|
|
||||||
local intake_limit = maxpressure - currentpressure
|
local intake_limit = maxpressure - currentpressure
|
||||||
if intake_limit <= 0 then return end
|
if intake_limit <= 0 then return currentpressure end
|
||||||
|
|
||||||
local actual_intake = intakefn(pos, intake_limit)
|
local actual_intake = inputdef.intakefn(pos, intake_limit)
|
||||||
--pipeworks.logger("run_input@"..formatvec(pos).." oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake)
|
--pipeworks.logger("run_input@"..formatvec(pos).." oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake)
|
||||||
if actual_intake <= 0 then return end
|
if actual_intake <= 0 then return currentpressure end
|
||||||
|
|
||||||
local newpressure = actual_intake + currentpressure
|
local newpressure = actual_intake + currentpressure
|
||||||
-- debuglog("oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake.." newpressure "..newpressure)
|
--debuglog("run_input() end, oldpressure "..currentpressure.." intake_limit "..intake_limit.." actual_intake "..actual_intake.." newpressure "..newpressure)
|
||||||
meta:set_float(label_pressure, newpressure)
|
return newpressure
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -62,10 +62,6 @@ register.intake = function(nodename, maxpressure, intakefn)
|
||||||
checkbase(nodename)
|
checkbase(nodename)
|
||||||
if list[nodename] then duplicateerr("pipeworks.flowables.inputs", nodename) end
|
if list[nodename] then duplicateerr("pipeworks.flowables.inputs", nodename) end
|
||||||
list[nodename] = { maxpressure=maxpressure, intakefn=intakefn }
|
list[nodename] = { maxpressure=maxpressure, intakefn=intakefn }
|
||||||
table.insert(pipeworks.flowables.inputs.nodenames, nodename)
|
|
||||||
if pipeworks.toggles.pressure_logic then
|
|
||||||
abmregister.input(nodename, maxpressure, intakefn)
|
|
||||||
end
|
|
||||||
regwarning("intake", nodename)
|
regwarning("intake", nodename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user