1
0
mirror of https://github.com/mt-mods/biome_lib.git synced 2024-12-23 09:20:18 +01:00

Allow old blocks to time-out after a while

(default 5 minutes).

Rationale: if a block is old enough, there's a very high probability
that the engine's done screwing around with its neighbors, so it's safe
to process.
This commit is contained in:
Vanessa Dannenberg 2021-04-07 07:10:10 -04:00
parent 0a34e3c7af
commit dd650da443
2 changed files with 9 additions and 3 deletions

View File

@ -76,6 +76,9 @@ local rr = tonumber(minetest.settings:get("biome_lib_queue_run_ratio")) or -100
biome_lib.queue_run_ratio = 100 - rr
biome_lib.entries_per_step = math.max(-rr, 1)
-- timer runs in microseconds, but I want the user to supply a time in seconds
biome_lib.block_timeout = (tonumber(minetest.settings:get("biome_lib_block_timeout")) or 300) * 1000000
local time_speed = tonumber(minetest.settings:get("time_speed"))
biome_lib.plantlife_seed_diff = 329 -- needs to be global so other mods can see it
@ -477,10 +480,12 @@ function biome_lib.generate_block(shutting_down)
local pos_hash = minetest.hash_node_position(minp)
if not biome_lib.pos_hash then -- we need to read the maplock and get the surfaces list
local now = minetest.get_us_time()
biome_lib.pos_hash = {}
minetest.load_area(minp)
if not confirm_block_surroundings(minp)
and not shutting_down then -- if any neighbors appear not to be loaded, skip this block for now
and not shutting_down
and (blocklog[1][4] + biome_lib.block_timeout) > now then -- if any neighbors appear not to be loaded and the block hasn't expired yet, defer it
if biome_lib.run_block_recheck_list then
biome_lib.block_log[#biome_lib.block_log + 1] = table.copy(biome_lib.block_recheck_list[1])

View File

@ -56,6 +56,7 @@ end
-- split into individual mapblocks to reduce lag
minetest.register_on_generated(function(minp, maxp, blockseed)
local timestamp = minetest.get_us_time()
for x = 0, 4 do
local minx = minp.x + x*16
for y = 0, 4 do
@ -65,8 +66,8 @@ minetest.register_on_generated(function(minp, maxp, blockseed)
local bmin = {x=minx, y=miny, z=minz}
local bmax = {x=minx + 15, y=miny + 15, z=minz + 15}
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, true }
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, false }
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, true, timestamp }
biome_lib.block_log[#biome_lib.block_log + 1] = { bmin, bmax, false, timestamp }
end
end
end