From e346fd599f3877a89618c7b811fea3ae6d7e0117 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Tue, 6 Apr 2021 16:07:49 -0400 Subject: [PATCH] rather than rearranging the block log to deal with blocks that can't be populated yet, move those blocks to a separate list, and replay that list whenever new mapblocks come in. That way the main block list can run dry and allow the block populate routines to go idle. Thanks to Warr1024 for the idea! --- init.lua | 19 ++++++++++++++----- search_functions.lua | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index fe3d8f1..028370f 100644 --- a/init.lua +++ b/init.lua @@ -439,6 +439,8 @@ local function confirm_block_surroundings(p) return true end +biome_lib.block_recheck_list = {} + function biome_lib.generate_block(shutting_down) if not biome_lib.block_log[1] then return end -- the block log is empty @@ -450,11 +452,11 @@ function biome_lib.generate_block(shutting_down) if not biome_lib.pos_hash then -- we need to read the maplock and get the surfaces list biome_lib.pos_hash = {} if not confirm_block_surroundings(minp) and not shutting_down then -- if any neighbors appear not to be loaded, move this block to the end of the queue - biome_lib.block_log[#biome_lib.block_log + 1] = biome_lib.block_log[1] + biome_lib.block_recheck_list[#biome_lib.block_recheck_list + 1] = table.copy(biome_lib.block_log[1]) table.remove(biome_lib.block_log, 1) biome_lib.pos_hash = nil biome_lib:dbg("Mapblock at "..minetest.pos_to_string(minp).. - " had a neighbor not fully emerged, moved it to the end of the queue.") + " had a neighbor not fully emerged, moved it to the \"check-later\" list.") return else biome_lib.pos_hash.surface_node_list = airflag @@ -523,15 +525,22 @@ end) -- to prevent unpopulated map areas minetest.register_on_shutdown(function() - if #biome_lib.block_log == 0 then + if #biome_lib.block_log + #biome_lib.block_recheck_list == 0 then return end print("[biome_lib] Stand by, playing out the rest of the mapblock log") - print("(there are "..#biome_lib.block_log.." entries)...") + print("(there are "..(#biome_lib.block_log + #biome_lib.block_recheck_list).." entries)...") while #biome_lib.block_log > 0 do biome_lib.generate_block(true) end + + if #biome_lib.block_recheck_list > 0 then + biome_lib.block_log = table.copy(biome_lib.block_recheck_list) + while #biome_lib.block_log > 0 do + biome_lib.generate_block(true) + end + end end) -- The spawning ABM @@ -729,7 +738,7 @@ if DEBUG then function biome_lib.show_pending_block_count() if biome_lib.last_count ~= #biome_lib.block_log then - biome_lib:dbg("Pending block count: "..#biome_lib.block_log) + biome_lib:dbg("Pending block count: "..(#biome_lib.block_log + #biome_lib.block_recheck_list)) biome_lib.last_count = #biome_lib.block_log end minetest.after(1, biome_lib.show_pending_block_count) diff --git a/search_functions.lua b/search_functions.lua index 3f9d414..db6fdad 100644 --- a/search_functions.lua +++ b/search_functions.lua @@ -70,4 +70,10 @@ minetest.register_on_generated(function(minp, maxp, blockseed) end end end + if #biome_lib.block_recheck_list > 0 then + for i = 1, #biome_lib.block_recheck_list do + biome_lib.block_log[#biome_lib.block_log + 1] = table.copy(biome_lib.block_recheck_list[i]) + end + end + biome_lib.block_recheck_list = {} end)