Move scan_queue to local scope

This commit is contained in:
Hugues Ross 2020-06-08 20:03:44 -04:00
parent b42c9d051f
commit 1d3c6dec97
2 changed files with 8 additions and 7 deletions

View File

@ -5,7 +5,6 @@ local modpath = minetest.get_modpath("cartographer");
-- The API object -- The API object
cartographer = { cartographer = {
scan_queue = {},
}; };
local map_data = { local map_data = {

View File

@ -2,6 +2,8 @@
-- map_data: The cartographer map data table -- map_data: The cartographer map data table
local map_data, chunk = ...; local map_data, chunk = ...;
local scan_queue = {};
-- Register a new tile in map data -- Register a new tile in map data
-- x: The x position in map coordinates -- x: The x position in map coordinates
-- y: The y position in map coordinates -- y: The y position in map coordinates
@ -172,24 +174,24 @@ function cartographer.queue_region(pos)
return; return;
end end
for _,queued_pos in ipairs(cartographer.scan_queue) do for _,queued_pos in ipairs(scan_queue) do
if vector.equals(converted, queued_pos) then if vector.equals(converted, queued_pos) then
return; return;
end end
end end
cartographer.scan_queue[#cartographer.scan_queue + 1] = converted; scan_queue[#scan_queue + 1] = converted;
end end
-- Scan the next tile on the queue, and remove it -- Scan the next tile on the queue, and remove it
function cartographer.scan_regions() function cartographer.scan_regions()
local len = #cartographer.scan_queue; local len = #scan_queue;
if len == 0 then if len == 0 then
return; return;
end end
local startpos = cartographer.scan_queue[1]; local startpos = scan_queue[1];
local chunk_x = chunk.to(startpos.x); local chunk_x = chunk.to(startpos.x);
local chunk_y = chunk.to(startpos.y); local chunk_y = chunk.to(startpos.y);
local chunk_z = chunk.to(startpos.z); local chunk_z = chunk.to(startpos.z);
@ -201,7 +203,7 @@ function cartographer.scan_regions()
}; };
if is_scan_handled(chunk_x, startpos.y, chunk_z) then if is_scan_handled(chunk_x, startpos.y, chunk_z) then
table.remove(cartographer.scan_queue, 1); table.remove(scan_queue, 1);
return; return;
end end
@ -210,7 +212,7 @@ function cartographer.scan_regions()
register_tile(chunk_x, chunk_z, biome, height, true) register_tile(chunk_x, chunk_z, biome, height, true)
end end
table.remove(cartographer.scan_queue, 1); table.remove(scan_queue, 1);
end end
minetest.register_on_generated(on_generated); minetest.register_on_generated(on_generated);