allow pipeworks to skip server steps when moving entities around.
This commit is contained in:
parent
3a77d1dd8e
commit
0639bb9706
@ -52,32 +52,27 @@ local function get_blockpos(pos)
|
||||
end
|
||||
|
||||
local active_blocks = {} -- These only contain active blocks near players (i.e., not forceloaded ones)
|
||||
local handle_active_blocks_step = 2
|
||||
local handle_active_blocks_timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
handle_active_blocks_timer = handle_active_blocks_timer + dtime
|
||||
if handle_active_blocks_timer >= handle_active_blocks_step then
|
||||
handle_active_blocks_timer = handle_active_blocks_timer - handle_active_blocks_step
|
||||
local active_block_range = tonumber(minetest.setting_get("active_block_range")) or 2
|
||||
local new_active_blocks = {}
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local blockpos = get_blockpos(player:getpos())
|
||||
local minp = vector.subtract(blockpos, active_block_range)
|
||||
local maxp = vector.add(blockpos, active_block_range)
|
||||
|
||||
for x = minp.x, maxp.x do
|
||||
for y = minp.y, maxp.y do
|
||||
for z = minp.z, maxp.z do
|
||||
local pos = {x = x, y = y, z = z}
|
||||
new_active_blocks[minetest.hash_node_position(pos)] = pos
|
||||
end
|
||||
end
|
||||
end
|
||||
local move_entities_globalstep_part1 = function(dtime)
|
||||
local active_block_range = tonumber(minetest.setting_get("active_block_range")) or 2
|
||||
local new_active_blocks = {}
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local blockpos = get_blockpos(player:getpos())
|
||||
local minp = vector.subtract(blockpos, active_block_range)
|
||||
local maxp = vector.add(blockpos, active_block_range)
|
||||
|
||||
for x = minp.x, maxp.x do
|
||||
for y = minp.y, maxp.y do
|
||||
for z = minp.z, maxp.z do
|
||||
local pos = {x = x, y = y, z = z}
|
||||
new_active_blocks[minetest.hash_node_position(pos)] = pos
|
||||
end
|
||||
end
|
||||
end
|
||||
active_blocks = new_active_blocks
|
||||
-- todo: callbacks on block load/unload
|
||||
end
|
||||
end)
|
||||
active_blocks = new_active_blocks
|
||||
-- todo: callbacks on block load/unload
|
||||
end
|
||||
|
||||
local function is_active(pos)
|
||||
return active_blocks[minetest.hash_node_position(get_blockpos(pos))] ~= nil
|
||||
@ -309,7 +304,7 @@ function luaentity.get_objects_inside_radius(pos, radius)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
local move_entities_globalstep_part2 = function(dtime)
|
||||
if not luaentity.entities then
|
||||
luaentity.entities = read_entities()
|
||||
end
|
||||
@ -348,4 +343,16 @@ minetest.register_globalstep(function(dtime)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local handle_active_blocks_step = 0.2
|
||||
local handle_active_blocks_timer = 0.1
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
handle_active_blocks_timer = handle_active_blocks_timer + dtime
|
||||
if handle_active_blocks_timer >= handle_active_blocks_step then
|
||||
handle_active_blocks_timer = handle_active_blocks_timer - handle_active_blocks_step
|
||||
move_entities_globalstep_part1(dtime)
|
||||
move_entities_globalstep_part2(dtime)
|
||||
end
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user