Remove all global refs from scanner, and return API

This commit is contained in:
Hugues Ross 2020-06-08 20:08:24 -04:00
parent 1f76359fbd
commit 25319d8053
3 changed files with 12 additions and 8 deletions

View File

@ -50,8 +50,8 @@ local marker_lookup = {};
local skin = loadfile(modpath .. "/skin_api.lua") ();
local gui = loadfile(modpath .. "/formspec.lua") ();
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
loadfile(modpath .. "/map_api.lua") (map_data, chunk, biome_lookup, marker_lookup);
local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk);
loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner, biome_lookup, marker_lookup);
local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin);
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, map_formspec);
loadfile(modpath .. "/commands.lua") (map_formspec);

View File

@ -1,4 +1,4 @@
local map_data, chunk, biome_lookup, marker_lookup = ...;
local map_data, chunk, scanner, biome_lookup, marker_lookup = ...;
function cartographer.create_map(x, z, w, h, filled, detail, scale)
local id = map_data.next_map_id;
@ -122,14 +122,14 @@ local function fill_loop()
y = pos.y,
z = pos.z + chunk.from(j),
}
cartographer.queue_region(adjusted_pos);
scanner.queue_region(adjusted_pos);
end
end
end
end
for _ = 1,10 do
cartographer.scan_regions();
scanner.scan_regions();
end
minetest.after(5, fill_loop);
end

View File

@ -145,6 +145,8 @@ local function on_generated(min, max, _)
end
end
minetest.register_on_generated(on_generated);
-- Is the scan of this position already handled?
-- x: The x position, in map coordinates
-- y: The y position, in world coordinates
@ -161,9 +163,11 @@ local function is_scan_handled(x, y, z)
return tile and ((not tile.manual_scan and tile.height > 0) or tile.height >= y);
end
local scanner = {};
-- Queue a tile for manual scanning
-- pos: The position as a table, in world coordinates
function cartographer.queue_region(pos)
function scanner.queue_region(pos)
local converted = {
x = chunk.from(chunk.to(pos.x)),
y = chunk.from(chunk.to(pos.y)),
@ -184,7 +188,7 @@ function cartographer.queue_region(pos)
end
-- Scan the next tile on the queue, and remove it
function cartographer.scan_regions()
function scanner.scan_regions()
local len = #scan_queue;
if len == 0 then
@ -215,4 +219,4 @@ function cartographer.scan_regions()
table.remove(scan_queue, 1);
end
minetest.register_on_generated(on_generated);
return scanner;