Added global noise/ map functionality, allowing generators to

register their 2D noises with multi_map globally and retrieve
them during map generation. multi_map takes care of reusing last
cached map in case the same layer is used for performance/ memory
reasons. In addition, it prepares an array of parameters so that
the noises can be used in any layer (truly availble globally) with
seeds different for each layer (but based on the seed passed
during registration via random seeding). Placeholder for global
3D maps added, but not implemented yet.
This commit is contained in:
evrooije 2018-07-23 01:04:07 +02:00
parent 44b8ee2807
commit aa9c3c4921
2 changed files with 78 additions and 52 deletions

View File

@ -92,6 +92,47 @@ function multi_map.register_fallback_generator(...)
multi_map.fallback_generator = { generator = generator, arguments = arguments }
end
multi_map.global_2d_maps = {}
multi_map.global_2d_params = {}
multi_map.global_2d_map_arrays = {}
local last_used_layer = -1
function multi_map.register_global_2dmap(name, params)
math.randomseed(params.seed)
multi_map.global_2d_params[name] = {}
multi_map.global_2d_map_arrays[name] = {}
for i = 0, multi_map.number_of_layers -1 do
local new_params = {
offset = params.offset,
scale = params.scale,
spread = {x=params.spread.x, y=params.spread.y, z=params.spread.z},
seed = math.random(-1000000000000, 1000000000000),
octaves = params.octaves,
persist = params.persist
}
multi_map.global_2d_params[name][i] = new_params
end
end
function multi_map.get_global_2dmap_flat(name, chulenxz, minposxz, current_layer)
if not current_layer then
if multi_map.current_layer ~= last_used_layer then
multi_map.global_2d_maps[name] = minetest.get_perlin_map(multi_map.global_2d_params[name][multi_map.current_layer], chulenxz)
end
return multi_map.global_2d_maps[name]:get2dMap_flat(minposxz, multi_map.global_2d_map_arrays[name][multi_map.current_layer])
else
if current_layer ~= last_used_layer then
multi_map.global_2d_maps[name] = minetest.get_perlin_map(multi_map.global_2d_params[name][current_layer], chulenxz)
end
return multi_map.global_2d_maps[name]:get2dMap_flat(minposxz, multi_map.global_2d_map_arrays[name][current_layer])
end
end
function multi_map.register_global_3dnoise()
end
-- Register a generator for all if position is left out or one layer if position is specified
-- position = the optional layer for which call this generator
-- generator = the function to call

View File

@ -3,61 +3,52 @@ local layers = {}
mmgen_testauri.water_height = 0
mmgen_testauri.seed = 835726
math.randomseed(mmgen_testauri.seed)
for i = 0, multi_map.number_of_layers -1 do
local height_map_seed = math.random(-1000000000000, 1000000000000)
local terrain_type_seed = math.random(-1000000000000, 1000000000000)
local mountain_peak_seed = math.random(-1000000000000, 1000000000000)
layers[i] = {
height_map_params = {
offset = 0,
scale = 50,
spread = {x=2048, y=2048, z=2048},
seed = height_map_seed,
octaves = 7,
persist = 0.7
},
terrain_type_params = {
offset = 2.5,
scale = 2.5,
spread = {x=1024, y=1024, z=1024},
seed = terrain_type_seed,
octaves = 6,
persist = 0.6
},
mountain_peak_params = {
offset = -75,
scale = 125,
spread = {x=256, y=256, z=256},
seed = mountain_peak_seed,
octaves = 7,
persist = 0.6
},
multi_map.register_global_2dmap(
"height_map",
{
offset = 0,
scale = 50,
spread = {x=2048, y=2048, z=2048},
seed = 6897925,
octaves = 7,
persist = 0.7
}
end
)
multi_map.register_global_2dmap(
"terrain_type",
{
offset = 2.5,
scale = 2.5,
spread = {x=1024, y=1024, z=1024},
seed = 9414432,
octaves = 6,
persist = 0.6
}
)
multi_map.register_global_2dmap(
"mountain_peak",
{
offset = -75,
scale = 125,
spread = {x=256, y=256, z=256},
seed = 21341535,
octaves = 7,
persist = 0.6
}
)
mmgen_testauri.cave_seed = 6568239
mmgen_testauri.lake_seed = 6568239
local last_layer
-- Base terrain is the lower frequency, lower amplitude noise
-- Terrain type is a multiplier that can dampen terrain to make
-- flat plains, hills or mountains
-- Mountain peak generates peaks when greater than zero, making
-- jagged and rugged peaks on the surface or mountain tops
local height_map
local terrain_type_map
local mountain_peak_map
local lake_map
local height_map_2dmap = {}
local terrain_type_2dmap = {}
local mountain_peak_2dmap = {}
local lake_3dmap = {}
local cave_map
@ -114,18 +105,12 @@ function mmgen_testauri.generate(current_layer, vm, area, vm_data, minp, maxp, o
local ystridevm = sidelen + 32
local zstridevm = ystridevm ^ 2
if last_layer ~= current_layer then
height_map = minetest.get_perlin_map(layers[current_layer].height_map_params, chulenxz)
terrain_type_map = minetest.get_perlin_map(layers[current_layer].terrain_type_params, chulenxz)
mountain_peak_map = minetest.get_perlin_map(layers[current_layer].mountain_peak_params, chulenxz)
end
cave_map = cave_map or minetest.get_perlin_map(cave_params, chulenxyz)
-- perlin_worm_start_map = perlin_worm_start_map or minetest.get_perlin_map(perlin_worm_start_params, chulenxyz)
height_map:get2dMap_flat(minposxz, height_map_2dmap)
terrain_type_map:get2dMap_flat(minposxz, terrain_type_2dmap)
mountain_peak_map:get2dMap_flat(minposxz, mountain_peak_2dmap)
local height_map_2dmap = multi_map.get_global_2dmap_flat("height_map", chulenxz, minposxz)
local terrain_type_2dmap = multi_map.get_global_2dmap_flat("terrain_type", chulenxz, minposxz)
local mountain_peak_2dmap = multi_map.get_global_2dmap_flat("mountain_peak", chulenxz, minposxz)
cave_map:get3dMap_flat(minposxyz, cave_3dmap)
-- perlin_worm_start_map:get3dMap_flat(minposxyz, perlin_worm_start_3dmap)