mirror of
https://github.com/minetest-mods/technic.git
synced 2025-01-02 18:57:34 +01:00
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.
This commit is contained in:
parent
ec73a8508f
commit
c38da0945c
@ -36,3 +36,11 @@ function technic.function_exists(function_name)
|
|||||||
return type(resolve_name(function_name)) == 'function'
|
return type(resolve_name(function_name)) == 'function'
|
||||||
end
|
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
|
||||||
|
@ -108,23 +108,28 @@ local function quarry_run(pos, node)
|
|||||||
vector.multiply(pdir, rp)),
|
vector.multiply(pdir, rp)),
|
||||||
vector.multiply(qdir, rq))
|
vector.multiply(qdir, rq))
|
||||||
local can_dig = true
|
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
|
if can_dig and minetest.is_protected and minetest.is_protected(digpos, owner) then
|
||||||
can_dig = false
|
can_dig = false
|
||||||
end
|
end
|
||||||
local dignode
|
local dignode
|
||||||
if can_dig then
|
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}
|
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
|
if not dignodedef.diggable or (dignodedef.can_dig and not dignodedef.can_dig(digpos, nil)) then
|
||||||
can_dig = false
|
can_dig = false
|
||||||
end
|
end
|
||||||
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
|
nd = nd + 1
|
||||||
if can_dig then
|
if can_dig then
|
||||||
minetest.remove_node(digpos)
|
minetest.remove_node(digpos)
|
||||||
|
@ -82,15 +82,9 @@ local add_new_cable_node = function(nodes, pos)
|
|||||||
return true
|
return true
|
||||||
end
|
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
|
-- 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)
|
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 meta = minetest.get_meta(pos)
|
||||||
local name = minetest.get_node(pos).name
|
local name = minetest.get_node(pos).name
|
||||||
|
|
||||||
@ -219,7 +213,7 @@ minetest.register_abm({
|
|||||||
-- Run all the nodes
|
-- Run all the nodes
|
||||||
local function run_nodes(list)
|
local function run_nodes(list)
|
||||||
for _, pos2 in ipairs(list) do
|
for _, pos2 in ipairs(list) do
|
||||||
load_position(pos2)
|
technic.get_or_load_node(pos2)
|
||||||
local node2 = minetest.get_node(pos2)
|
local node2 = minetest.get_node(pos2)
|
||||||
local nodedef
|
local nodedef
|
||||||
if node2 and node2.name then
|
if node2 and node2.name then
|
||||||
|
Loading…
Reference in New Issue
Block a user