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!
This commit is contained in:
Vanessa Dannenberg 2021-04-06 16:07:49 -04:00
parent 212024a9b4
commit e346fd599f
2 changed files with 20 additions and 5 deletions

View File

@ -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)

View File

@ -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)