This commit is contained in:
Gaël C 2024-01-04 23:28:33 +01:00
parent e5b8f2b3b8
commit f26fd1cccb
7 changed files with 31 additions and 22 deletions

View File

@ -5,31 +5,37 @@ if minetest.get_mapgen_setting("mg_name") ~= "singlenode" then
minetest.log("warning", "[mapgen_rivers] Mapgen set to singlenode")
end
dofile(modpath .. 'settings.lua')
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath .. '/settings.lua')
local sfile = io.open(minetest.get_worldpath() .. '/river_data/size')
if sfile then
sfile:close()
else
dofile(modpath .. 'pregenerate.lua')
dofile(modpath .. '/pregenerate.lua')
collectgarbage()
end
mapgen_rivers.use_mapgen_thread = minetest.settings:get_bool("mapgen_rivers_use_mapgen_thread")
mapgen_rivers.thread = 'main'
if mapgen_rivers.use_mapgen_thread and minetest.register_mapgen_dofile then
minetest.register_mapgen_dofile(modpath .. 'mapgen.lua')
else
minetest.log("warning", "[mapgen_rivers] Mapgen thread not available on this Minetest version.")
mapgen_rivers.use_mapgen_thread = false
dofile(modpath .. 'mapgen.lua')
if mapgen_rivers.use_mapgen_thread then
if minetest.register_mapgen_dofile then
minetest.register_mapgen_dofile(modpath .. '/mapgen.lua')
else
minetest.log("warning", "[mapgen_rivers] Mapgen thread not available on this Minetest version.")
mapgen_rivers.use_mapgen_thread = false
end
end
if not mapgen_rivers.use_mapgen_thread then
dofile(modpath .. '/mapgen.lua')
end
-- Setup a metatable to load grid on request if not present
local mt = {
__index = function(_, field)
if field == 'grid' then
dofile(modpath .. 'load_grid.lua')
dofile(modpath .. '/load_grid.lua')
return mapgen_rivers.grid
end
end,

View File

@ -12,7 +12,7 @@ else
use_interactive_loader = not minetest.settings:get_bool("mapgen_rivers_load_all")
end
if mapgen_rivers.use_interactive_loader then
if use_interactive_loader then
local loader_mt = {
__index = function(loader, i)
local file = loader.file
@ -61,6 +61,7 @@ else
for i=1, size do
local i0 = (i-1)*bytes+1
local i1 = i*bytes
local elements = {data:byte(i0, i1)}
local n = sbyte(data, i0)
if signed and n >= 128 then
@ -85,7 +86,7 @@ else
end
end
local sfile = io.open(world_data_path..'size', 'r')
local sfile = io.open(datapath..'size', 'r')
assert(sfile)
local X, Z = tonumber(sfile:read('*l')), tonumber(sfile:read('*l'))
sfile:close()
@ -96,7 +97,7 @@ end
mapgen_rivers.grid = {
size = {x=X, y=Z},
dem = load_map('dem', 2, true X*Z),
dem = load_map('dem', 2, true, X*Z),
lakes = load_map('lakes', 2, true, X*Z),
dirs = load_map('dirs', 1, false, X*Z),
rivers = load_map('rivers', 4, false, X*Z),

View File

@ -10,7 +10,7 @@ end
local settings = mapgen_rivers.settings
local sea_level = tonumber(settings:get('sea_level'))
local sea_level = tonumber(minetest.get_mapgen_setting("water_level"))
local elevation_chill = tonumber(settings:get('elevation_chill'))
local use_distort = settings:get_bool('distort')
local use_biomes = settings:get_bool('biomes')
@ -24,9 +24,9 @@ local noiseparams = {
}
if use_biomes then
noiseparams.heat = minetest.get_mapgen_setting_noiseparams("np_heat")
noiseparams.heat = minetest.get_mapgen_setting_noiseparams("mg_biome_np_heat")
noiseparams.heat.offset = noiseparams.heat.offset + sea_level / elevation_chill
noiseparams.heat_blend = minetest.get_mapgen_setting_noiseparams("np_heat_blend")
noiseparams.heat_blend = minetest.get_mapgen_setting_noiseparams("mg_biome_np_heat_blend")
end
if use_biomegen_mod then

View File

@ -39,7 +39,7 @@ local function get_temperature(x, y, z)
end
local glaciers = settings:get_bool('glaciers')
local glacier_factor = tonumber(settings:get('glacier_factor')
local glacier_factor = tonumber(settings:get('glacier_factor'))
local init = false

View File

@ -23,8 +23,10 @@ local niter = math.ceil(time/time_step)
time_step = time / niter
-- Setup the model
local grid = mapgen_rivers.grid
local size = grid.size
local size = {
x = tonumber(mapgen_rivers.settings:get("grid_x_size")),
y = tonumber(mapgen_rivers.settings:get("grid_z_size")),
}
local seed = tonumber(minetest.get_mapgen_setting("seed"))
np_base.seed = (np_base.seed or 0) + seed
@ -69,7 +71,7 @@ for i=1, size.x*size.y do
end
-- Write the results in the world directory
local datapath = minetest.get_worldpath .. "/river_data/"
local datapath = minetest.get_worldpath() .. "/river_data/"
minetest.mkdir(datapath)
local function write_map(filename, data, bytes)
@ -118,7 +120,7 @@ end
if not use_interactive_loader then
mapgen_rivers.grid = {
size = {x=size_x, y=size_y},
size = size,
dem = model.dem,
lakes = model.lakes,
dirs = model.dirs,

View File

@ -43,7 +43,7 @@ local function verify_setting(name, dtype, default)
v = mtsettings:get(mtname)
end
settings:set_bool(name, v)
elseif dtype = "noise" then
elseif dtype == "noise" then
if mthas then
v = mtsettings:get_np_group(mtname)
end

View File

@ -123,7 +123,7 @@ end
local modpath = ""
if minetest then
modpath = minetest.get_modpath(minetest.get_current_modname()) .. "terrainlib_lua/"
modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/terrainlib_lua/"
end
local rivermapper = dofile(modpath .. "rivermapper.lua")