Adapt to multithreading, now it is working!

This commit is contained in:
Gaël C 2024-01-05 00:02:30 +01:00
parent f26fd1cccb
commit e9fa7f9a5c

View File

@ -15,7 +15,7 @@ local elevation_chill = tonumber(settings:get('elevation_chill'))
local use_distort = settings:get_bool('distort')
local use_biomes = settings:get_bool('biomes')
local use_biomegen_mod = use_biomes and minetest.global_exists('biomegen')
use_biomes = use_biomes and minetest.global_exists('default') and not use_biomegen_mod
use_biomes = use_biomes and minetest.get_modpath("default") and not use_biomegen_mod
local noiseparams = {
distort_x = settings:get_np_group('np_distort_x'),
@ -77,7 +77,7 @@ local function init_mapgen(chulens)
end
end
local function generate(minp, maxp, seed)
local function generate(vm, minp, maxp, seed)
minetest.log("info", ("[mapgen_rivers] Generating from %s to %s"):format(minetest.pos_to_string(minp), minetest.pos_to_string(maxp)))
local chulens = {
@ -175,7 +175,7 @@ local function generate(minp, maxp, seed)
c_ice = minetest.get_content_id("default:ice")
end
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local emin, emax = vm:get_emerged_area()
vm:get_data(data)
local a = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
@ -276,7 +276,9 @@ local function generate(minp, maxp, seed)
vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
vm:update_liquids()
vm:write_to_map()
if mapgen_rivers.thread == "main" then
vm:write_to_map()
end
local t = os.clock()-t0
ngen = ngen + 1
@ -285,7 +287,15 @@ local function generate(minp, maxp, seed)
minetest.log("verbose", ("[mapgen_rivers] Done in %5.3f s"):format(t))
end
minetest.register_on_generated(generate)
if mapgen_rivers.thread == "main" then
minetest.register_on_generated(function(minp, maxp, seed)
local vm = minetest.get_mapgen_object("voxelmanip")
generate(vm, minp, maxp, seed)
end)
elseif mapgen_rivers.thread == "mapgen" then
minetest.register_on_generated(generate)
end
minetest.register_on_shutdown(function()
if ngen == 0 then
return