1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2024-12-26 19:00:24 +01:00

new flow logic: abms.lua: refactor ABM logic into new master ABM, make balance_pressure() take current pressure and return new pressure

This commit is contained in:
thetaepsilon-gamedev 2017-10-07 17:33:42 +01:00
parent 608a9a6980
commit 016f9de82f
3 changed files with 29 additions and 12 deletions

View File

@ -16,7 +16,7 @@ local flowlogic = pipeworks.flowlogic
-- register node list for the main logic function.
-- see flowlogic.run() in abms.lua.
--[[
local register_flowlogic_abm = function(nodename)
minetest.register_abm({
nodenames = { nodename },
@ -27,12 +27,13 @@ local register_flowlogic_abm = function(nodename)
end
})
end
]]
register.flowlogic = register_flowlogic_abm
-- register a node name for the pressure balancing ABM.
-- currently this only exists as a per-node function to allow nodes to be registered outside pipeworks.
--[[
local register_abm_balance = function(nodename)
minetest.register_abm({
nodenames = { nodename },
@ -44,6 +45,7 @@ local register_abm_balance = function(nodename)
})
end
register.balance = register_abm_balance
]]
-- 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).

View File

@ -65,17 +65,30 @@ local get_pressure_access = function(pos)
}
end
flowlogic.balance_pressure = function(pos, node)
-- debuglog("balance_pressure() "..node.name.." at "..pos.x.." "..pos.y.." "..pos.z)
-- check the pressure of all nearby nodes, and average it out.
-- for the moment, only balance neighbour nodes if it already has a pressure value.
-- XXX: maybe this could be used to add fluid behaviour to other mod's nodes too?
-- unconditionally include self in nodes to average over
local pressure = get_pressure_access(pos)
local currentpressure = pressure.get()
flowlogic.run = function(pos, node)
-- get the current pressure value.
local nodepressure = get_pressure_access(pos)
local currentpressure = nodepressure.get()
-- balance pressure with neighbours
currentpressure = flowlogic.balance_pressure(pos, node, currentpressure)
-- set the new pressure
nodepressure.set(currentpressure)
end
flowlogic.balance_pressure = function(pos, node, currentpressure)
-- debuglog("balance_pressure() "..node.name.." at "..pos.x.." "..pos.y.." "..pos.z)
-- check the pressure of all nearby flowable nodes, and average it out.
-- pressure handles to average over
local connections = { pressure }
local connections = {}
-- unconditionally include self in nodes to average over.
-- result of averaging will be returned as new pressure for main flow logic callback
local totalv = currentpressure
local totalc = 1
@ -99,6 +112,8 @@ flowlogic.balance_pressure = function(pos, node)
for _, target in ipairs(connections) do
target.set(average)
end
return average
end

View File

@ -36,7 +36,7 @@ register.simple = function(nodename)
pipeworks.flowables.list.simple[nodename] = true
table.insert(pipeworks.flowables.list.simple_nodenames, nodename)
if pipeworks.toggles.pressure_logic then
abmregister.balance(nodename)
abmregister.flowlogic(nodename)
end
regwarning("simple", nodename)
end