mapgen_rivers/init.lua
Gaël C 11e6e72324 Started refactoring code structure to support a separate mapgen thread
Probably not working for now (untested), still some things to do
Also making the code cleaner
2023-12-28 15:27:36 +01:00

42 lines
1.2 KiB
Lua

mapgen_rivers = {}
local modpath = minetest.get_modpath(minetest.get_current_modname()) .. '/'
mapgen_rivers.modpath = modpath
mapgen_rivers.world_data_path = minetest.get_worldpath() .. '/river_data/'
if minetest.get_mapgen_setting("mg_name") ~= "singlenode" then
minetest.set_mapgen_setting("mg_name", "singlenode", true)
minetest.log("warning", "[mapgen_rivers] Mapgen set to singlenode")
end
dofile(modpath .. 'settings.lua')
local sfile = io.open(mapgen_rivers.world_data_path .. 'size')
if sfile then
sfile:close()
else
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')
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')
return mapgen_rivers.grid
end
end,
}
setmetatable(mapgen_rivers, mt)