diff options
author | Vanessa Ezekowitz <vanessaezekowitz@gmail.com> | 2017-03-31 18:27:44 -0400 |
---|---|---|
committer | Vanessa Ezekowitz <vanessaezekowitz@gmail.com> | 2017-03-31 18:27:44 -0400 |
commit | 0639bb970666cfc9ec56f848c6334263fccaaa9f (patch) | |
tree | cf21a9bc1d6aa7febd3285c524ca7b98c4377f12 | |
parent | 3a77d1dd8e8929ff07fd1bdaf0a180c03ee128e4 (diff) | |
download | pipeworks-0639bb970666cfc9ec56f848c6334263fccaaa9f.tar pipeworks-0639bb970666cfc9ec56f848c6334263fccaaa9f.tar.gz pipeworks-0639bb970666cfc9ec56f848c6334263fccaaa9f.tar.bz2 pipeworks-0639bb970666cfc9ec56f848c6334263fccaaa9f.tar.xz pipeworks-0639bb970666cfc9ec56f848c6334263fccaaa9f.zip |
allow pipeworks to skip server steps when moving entities around.
-rw-r--r-- | luaentity.lua | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/luaentity.lua b/luaentity.lua index 665e055..50004ed 100644 --- a/luaentity.lua +++ b/luaentity.lua @@ -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) |