@@ -29,7 +29,7 @@ local function read_entities()
2929end
3030
3131local function write_entities ()
32- for _ , entity in pairs (luaentity .entities or {}) do
32+ for _ , entity in pairs (luaentity .entities or {}) do
3333 setmetatable (entity , nil )
3434 for _ , attached in pairs (entity ._attached_entities ) do
3535 if attached .entity then
5454local active_blocks = {} -- These only contain active blocks near players (i.e., not forceloaded ones)
5555local handle_active_blocks_step = 2
5656local handle_active_blocks_timer = 0
57- minetest .register_globalstep (function (dtime )
58- handle_active_blocks_timer = handle_active_blocks_timer + dtime
59- if handle_active_blocks_timer >= handle_active_blocks_step then
60- handle_active_blocks_timer = handle_active_blocks_timer - handle_active_blocks_step
61- local active_block_range = tonumber (minetest .setting_get (" active_block_range" )) or 2
62- local new_active_blocks = {}
63- for _ , player in ipairs (minetest .get_connected_players ()) do
64- local blockpos = get_blockpos (player :getpos ())
65- local minp = vector .subtract (blockpos , active_block_range )
66- local maxp = vector .add (blockpos , active_block_range )
57+ local function active_blocks_step ()
58+ local active_block_range = tonumber (minetest .setting_get (" active_block_range" )) or 2
59+ local new_active_blocks = {}
60+ for _ , player in ipairs (minetest .get_connected_players ()) do
61+ local blockpos = get_blockpos (player :getpos ())
62+ local minp = vector .subtract (blockpos , active_block_range )
63+ local maxp = vector .add (blockpos , active_block_range )
6764
68- for x = minp .x , maxp .x do
69- for y = minp .y , maxp .y do
70- for z = minp .z , maxp .z do
71- local pos = {x = x , y = y , z = z }
72- new_active_blocks [minetest .hash_node_position (pos )] = pos
73- end
74- end
75- end
65+ for x = minp .x , maxp .x do
66+ for y = minp .y , maxp .y do
67+ for z = minp .z , maxp .z do
68+ local pos = {x = x , y = y , z = z }
69+ new_active_blocks [minetest .hash_node_position (pos )] = pos
70+ end
71+ end
7672 end
77- active_blocks = new_active_blocks
78- -- todo: callbacks on block load/unload
7973 end
80- end )
74+ active_blocks = new_active_blocks
75+ -- todo: callbacks on block load/unload
76+
77+ minetest .after (handle_active_blocks_step , active_blocks_step )
78+ end
79+ minetest .after (0 , active_blocks_step )
8180
8281local function is_active (pos )
8382 return active_blocks [minetest .hash_node_position (get_blockpos (pos ))] ~= nil
0 commit comments