summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2015-01-24 04:30:48 +0100
committerest31 <MTest31@outlook.com>2015-01-24 19:40:02 +0100
commitc38da0945c58ee3d1979f73082532b48197e1d24 (patch)
tree2e5ed1cd8746011c2f911c255a80084c9fce638e
parentec73a8508fc8458e10be6a93bbc3be2eba26595f (diff)
Optimize quarry_run
Don't load the whole digging area when only a small piece is relevant. Also, move the (time expensive) check whether the air above a block is free to the last position, which spares unneccessary checks when multiple quarries are placed together, or a quarry has to loop over air for another reason.
-rw-r--r--technic/helpers.lua8
-rw-r--r--technic/machines/HV/quarry.lua19
-rw-r--r--technic/machines/switching_station.lua10
3 files changed, 22 insertions, 15 deletions
diff --git a/technic/helpers.lua b/technic/helpers.lua
index c07937a..d4306cf 100644
--- a/technic/helpers.lua
+++ b/technic/helpers.lua
@@ -36,3 +36,11 @@ function technic.function_exists(function_name)
return type(resolve_name(function_name)) == 'function'
end
+-- if the node is loaded, returns it. If it isn't loaded, load it and return nil.
+function technic.get_or_load_node(pos)
+ local node_or_nil = minetest.get_node_or_nil(pos)
+ if node_or_nil then return node_or_nil end
+ local vm = VoxelManip()
+ local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
+ return nil
+end
diff --git a/technic/machines/HV/quarry.lua b/technic/machines/HV/quarry.lua
index 4b845c5..f5280f2 100644
--- a/technic/machines/HV/quarry.lua
+++ b/technic/machines/HV/quarry.lua
@@ -108,23 +108,28 @@ local function quarry_run(pos, node)
vector.multiply(pdir, rp)),
vector.multiply(qdir, rq))
local can_dig = true
- for ay = startpos.y, digpos.y+1, -1 do
- if data[area:index(digpos.x, ay, digpos.z)] ~= c_air then
- can_dig = false
- break
- end
- end
if can_dig and minetest.is_protected and minetest.is_protected(digpos, owner) then
can_dig = false
end
local dignode
if can_dig then
- dignode = minetest.get_node(digpos)
+ dignode = technic.get_or_load_node(digpos) or minetest.get_node(digpos)
local dignodedef = minetest.registered_nodes[dignode.name] or {diggable=false}
if not dignodedef.diggable or (dignodedef.can_dig and not dignodedef.can_dig(digpos, nil)) then
can_dig = false
end
end
+
+ if can_dig then
+ for ay = startpos.y, digpos.y+1, -1 do
+ local checkpos = {x=digpos.x, y=ay, z=digpos.z}
+ local checknode = technic.get_or_load_node(checkpos) or minetest.get_node(checkpos)
+ if checknode.name ~= "air" then
+ can_dig = false
+ break
+ end
+ end
+ end
nd = nd + 1
if can_dig then
minetest.remove_node(digpos)
diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua
index 33dff2b..737970d 100644
--- a/technic/machines/switching_station.lua
+++ b/technic/machines/switching_station.lua
@@ -82,15 +82,9 @@ local add_new_cable_node = function(nodes, pos)
return true
end
-local load_position = function(pos)
- if minetest.get_node_or_nil(pos) then return end
- local vm = VoxelManip()
- local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
-end
-
-- Generic function to add found connected nodes to the right classification array
local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos)
- load_position(pos)
+ technic.get_or_load_node(pos)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
@@ -219,7 +213,7 @@ minetest.register_abm({
-- Run all the nodes
local function run_nodes(list)
for _, pos2 in ipairs(list) do
- load_position(pos2)
+ technic.get_or_load_node(pos2)
local node2 = minetest.get_node(pos2)
local nodedef
if node2 and node2.name then