diff options
author | thetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com> | 2017-10-07 17:33:42 +0100 |
---|---|---|
committer | thetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com> | 2017-10-07 17:33:42 +0100 |
commit | 016f9de82f91b61a14ad1bc477ee18b501f77e39 (patch) | |
tree | 1551627d147e32054e6eb1a4ff79fe990b06a24b /new_flow_logic/abms.lua | |
parent | 608a9a69808ee58d05dc115b37af1d53b00f0241 (diff) |
new flow logic: abms.lua: refactor ABM logic into new master ABM, make balance_pressure() take current pressure and return new pressure
Diffstat (limited to 'new_flow_logic/abms.lua')
-rw-r--r-- | new_flow_logic/abms.lua | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua index 9e5eb2d..37b10bc 100644 --- a/new_flow_logic/abms.lua +++ b/new_flow_logic/abms.lua @@ -65,17 +65,30 @@ local get_pressure_access = function(pos) } end -flowlogic.balance_pressure = function(pos, node) + + +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 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? + -- check the pressure of all nearby flowable nodes, and average it out. - -- unconditionally include self in nodes to average over - local pressure = get_pressure_access(pos) - local currentpressure = pressure.get() -- 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 |