From 25319d805370888e8ef71e73b36db8c36b133cbf Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Mon, 8 Jun 2020 20:08:24 -0400 Subject: [PATCH] Remove all global refs from scanner, and return API --- init.lua | 4 ++-- map_api.lua | 6 +++--- scanner.lua | 10 +++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/init.lua b/init.lua index 19a99c3..e976181 100644 --- a/init.lua +++ b/init.lua @@ -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); diff --git a/map_api.lua b/map_api.lua index f2620a9..a4c0873 100644 --- a/map_api.lua +++ b/map_api.lua @@ -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 diff --git a/scanner.lua b/scanner.lua index 449eaa4..7e8746d 100644 --- a/scanner.lua +++ b/scanner.lua @@ -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;