summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-07 17:55:14 +0100
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-07 17:55:14 +0100
commit65b3448796815718275ed3c16af4865e5e005454 (patch)
treef069b22becf461f133d1bc1eeb761ebf868e7c70
parent016f9de82f91b61a14ad1bc477ee18b501f77e39 (diff)
downloadpipeworks-65b3448796815718275ed3c16af4865e5e005454.tar
pipeworks-65b3448796815718275ed3c16af4865e5e005454.tar.gz
pipeworks-65b3448796815718275ed3c16af4865e5e005454.tar.bz2
pipeworks-65b3448796815718275ed3c16af4865e5e005454.tar.xz
pipeworks-65b3448796815718275ed3c16af4865e5e005454.zip
new flow logic: abms.lua: refactor flowlogic.run_output() into a processing stage of flowlogic.run()
-rw-r--r--new_flow_logic/abm_register.lua2
-rw-r--r--new_flow_logic/abms.lua31
-rw-r--r--new_flow_logic/flowable_node_registry_install.lua5
3 files changed, 24 insertions, 14 deletions
diff --git a/new_flow_logic/abm_register.lua b/new_flow_logic/abm_register.lua
index db6233f..1c7eede 100644
--- a/new_flow_logic/abm_register.lua
+++ b/new_flow_logic/abm_register.lua
@@ -66,6 +66,7 @@ register.input = register_abm_input
-- threshold determines the minimum pressure, over which outputfn is called.
-- outputfn is then given the current pressure, and returns the pressure relieved by the output process.
-- outputfn is expected to update environment, nearby world etc. as appropriate for the node.
+--[[
local register_abm_output = function(nodename, threshold, outputfn)
minetest.register_abm({
nodenames = { nodename },
@@ -77,6 +78,7 @@ local register_abm_output = function(nodename, threshold, outputfn)
})
end
register.output = register_abm_output
+]]
-- old spigot ABM code, not yet migrated
--[[
diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua
index 37b10bc..671a69d 100644
--- a/new_flow_logic/abms.lua
+++ b/new_flow_logic/abms.lua
@@ -68,6 +68,7 @@ end
flowlogic.run = function(pos, node)
+ local nodename = node.name
-- get the current pressure value.
local nodepressure = get_pressure_access(pos)
local currentpressure = nodepressure.get()
@@ -75,6 +76,18 @@ flowlogic.run = function(pos, node)
-- balance pressure with neighbours
currentpressure = flowlogic.balance_pressure(pos, node, currentpressure)
+ -- if node is an output: run output phase
+ local output = pipeworks.flowables.outputs.list[nodename]
+ if output then
+ currentpressure = flowlogic.run_output(
+ pos,
+ node,
+ currentpressure,
+ output.upper,
+ output.lower,
+ output.outputfn)
+ end
+
-- set the new pressure
nodepressure.set(currentpressure)
end
@@ -176,20 +189,18 @@ end
-flowlogic.run_output = function(pos, node, threshold, outputfn)
- -- callback for output devices.
- -- takes care of checking a minimum pressure value and updating the node metadata.
+flowlogic.run_output = function(pos, node, currentpressure, upper, lower, outputfn)
+ -- processing step for water output devices.
+ -- takes care of checking a minimum pressure value and updating the resulting pressure level
-- the outputfn is provided the current pressure and returns the pressure "taken".
-- as an example, using this with the above spigot function,
-- the spigot function tries to output a water source if it will fit in the world.
- local meta = minetest.get_meta(pos)
- -- sometimes I wonder if meta:get_* returning default values would ever be problematic.
- -- though here it doesn't matter, an uninit'd node returns 0, which is fine for a new, empty node.
- local currentpressure = meta:get_float(label_pressure)
- if currentpressure > threshold then
+ local result = currentpressure
+ if currentpressure > lower then
local takenpressure = outputfn(pos, node, currentpressure)
local newpressure = currentpressure - takenpressure
- if newpressure < 0 then currentpressure = 0 end
- meta:set_float(label_pressure, newpressure)
+ if newpressure < 0 then newpressure = 0 end
+ result = newpressure
end
+ return result
end
diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua
index d195c63..aed6fbd 100644
--- a/new_flow_logic/flowable_node_registry_install.lua
+++ b/new_flow_logic/flowable_node_registry_install.lua
@@ -75,10 +75,7 @@ register.output = function(nodename, upper, lower, outputfn)
error("pipeworks.flowables.outputs duplicate registration!")
end
checkbase(nodename)
- pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn }
- if pipeworks.toggles.pressure_logic then
- abmregister.output(nodename, lower, outputfn)
- end
+ pipeworks.flowables.outputs.list[nodename] = { upper=upper, lower=lower, outputfn=outputfn }
-- output ABM now part of main flow logic ABM to preserve ordering.
-- note that because outputs have to be a flowable first
-- (and the installation of the flow logic ABM is conditional),