From f24fdc5b146eb0006d3803dc10d2ce05e94588b3 Mon Sep 17 00:00:00 2001 From: Shad MOrdre Date: Sat, 4 Apr 2020 10:38:42 -0700 Subject: [PATCH] Add files via upload Removed hardcoded references to lib_materials. This version works with default mod from MTG. Cleaned extraneous code, refactored on_generated call to be faster, use less resources. More to do. --- lib_mg_continental_voxel.lua | 956 ++++++++++++++++++++++++++++++----- mod.conf | 2 +- 2 files changed, 820 insertions(+), 138 deletions(-) diff --git a/lib_mg_continental_voxel.lua b/lib_mg_continental_voxel.lua index e669139..a345361 100644 --- a/lib_mg_continental_voxel.lua +++ b/lib_mg_continental_voxel.lua @@ -8,24 +8,15 @@ minetest.set_mapgen_setting('flags','nolight',true) local mg_map_view = false -local c_desertsandstone = minetest.get_content_id("lib_materials:stone_sandstone_desert") -local c_sandstone = minetest.get_content_id("lib_materials:stone_sandstone") -local c_desertstone = minetest.get_content_id("lib_materials:stone_desert") -local c_stone = minetest.get_content_id("lib_materials:stone") -local c_desertsand = minetest.get_content_id("lib_materials:sand_desert") -local c_sand = minetest.get_content_id("lib_materials:sand") -local c_brick = minetest.get_content_id("lib_materials:stone_brick") -local c_block = minetest.get_content_id("lib_materials:stone_block") -local c_desertstoneblock= minetest.get_content_id("lib_materials:stone_desert_block") -local c_desertstonebrick= minetest.get_content_id("lib_materials:stone_desert_brick") -local c_obsidian = minetest.get_content_id("lib_materials:stone_obsidian") -local c_dirt = minetest.get_content_id("lib_materials:dirt") -local c_dirtgrass = minetest.get_content_id("lib_materials:dirt_with_grass") -local c_dirtdrygrass = minetest.get_content_id("lib_materials:dirt_with_grass_dry") -local c_top = minetest.get_content_id("lib_materials:dirt_with_litter_coniferous") -local c_snow = minetest.get_content_id("lib_materials:dirt_with_snow") -local c_water = minetest.get_content_id("lib_materials:liquid_water_source") -local c_tree = minetest.get_content_id("lib_ecology:tree_default_trunk") + +local c_stone = minetest.get_content_id("default:stone") --minetest.get_content_id("lib_materials:stone") +local c_dirt = minetest.get_content_id("default:dirt") --minetest.get_content_id("lib_materials:dirt") +local c_dirtgrass = minetest.get_content_id("default:dirt_with_grass") --minetest.get_content_id("lib_materials:dirt_with_grass") +local c_coniferous --= minetest.get_content_id("default:coniferous_litter") --minetest.get_content_id("lib_materials:dirt_with_grass") +local c_rainforest --= minetest.get_content_id("default:rainforest_litter") --minetest.get_content_id("lib_materials:dirt_with_grass") +local c_sand --= minetest.get_content_id("default:sand") --minetest.get_content_id("lib_materials:dirt_with_grass") +local c_top = minetest.get_content_id("default:dirt_with_grass") --minetest.get_content_id("lib_materials:dirt_with_litter_coniferous") +local c_water = minetest.get_content_id("default:water_source") --minetest.get_content_id("lib_materials:liquid_water_source") local c_air = minetest.get_content_id("air") local c_ignore = minetest.get_content_id("ignore") @@ -34,7 +25,7 @@ local top_depth = 1 local map_world_size if mg_map_view == false then - map_world_size = 20000 + map_world_size = 10000 else map_world_size = 1000 end @@ -58,12 +49,10 @@ local sqrt = math.sqrt local floor = math.floor local convex = false -local mult = lib_materials.mapgen_scale_factor or 4 +local mult = 1 --lib_materials.mapgen_scale_factor or 4 local mg_golden_ratio = ((1 + (5^0.5)) * 0.5) -lib_mg_continental.half_map_chunk_size = 40 - -- local np_terrain = { offset = -4, @@ -91,17 +80,17 @@ local np_terrain = { scale = 50, seed = 5934, spread = {x = 2400, y = 2400, z = 2400}, - octaves = 5, + octaves = 8, persist = 0.2, lacunarity = 2.11, --flags = "defaults" } local np_cliffs = { - offset = -4, - scale = 0.72, - spread = {x = 180*mult, y =180*mult, z = 180*mult}, + offset = -0.4, + scale = 1, + spread = {x = 600, y =600, z = 600}, seed = 78901, - octaves = 5, + octaves = 8, persist = 0.2, lacunarity = 2.11, -- flags = "absvalue" @@ -182,56 +171,708 @@ local nbase_humiditymap = nil local nobj_humidityblend = nil local nbase_humidityblend = nil +local mg_custom_data = {} + lib_mg_continental.heightmap = {} lib_mg_continental.biomemap = {} -lib_mg_continental.hills_offset = 64*mult -lib_mg_continental.hills_thresh = math.floor((np_terrain.scale)*0.5) -lib_mg_continental.shelf_thresh = math.floor((np_terrain.scale)*0.5) -lib_mg_continental.cliffs_thresh = math.floor((np_terrain.scale)*0.5) +local hills_offset = 64*mult +local hills_thresh = math.floor((np_terrain.scale)*0.5) +local shelf_thresh = math.floor((np_terrain.scale)*0.5) +local cliffs_thresh = math.floor((np_terrain.scale)*0.5) + +local function max_height(noiseprm) + local height = 0 -- 30 18 + local scale = noiseprm.scale -- 18 10.8 + for i=1,noiseprm.octaves do -- 10.8 6.48 + height=height + scale -- 6.48 3.88 + scale = scale * noiseprm.persist -- 3.88 2.328 + end -- ----- ------ + return height+noiseprm.offset -- 41.496 + (-4) +end -- 37.496 + +local function min_height(noiseprm) + local height = 0 + local scale = noiseprm.scale + for i=1,noiseprm.octaves do + height=height - scale + scale = scale * noiseprm.persist + end + return height+noiseprm.offset +end + +local base_min = min_height(np_terrain) +local base_max = max_height(np_terrain) +local base_rng = base_max-base_min +local easing_factor = 1/(base_max*base_max*4) + +local function get_terrain_height_shelf(theight) + -- parabolic gradient + if theight > 0 and theight < shelf_thresh then + theight = theight * (theight*theight/(shelf_thresh*shelf_thresh)*0.5 + 0.5) + end + + return theight +end + +local function get_terrain_height_hills_adjustable_shelf(theight,hheight,cheight,shlf_thresh) + -- parabolic gradient + if theight > 0 and theight < shlf_thresh then + theight = theight * (theight*theight/(shlf_thresh*shlf_thresh)*0.5 + 0.5) + end + -- hills + if theight > hills_thresh then + theight = theight + math.max((theight-hills_thresh) * hheight,0) + -- cliffs + elseif theight > 1 and theight < hills_thresh then + local clifh = math.max(math.min(cheight,1),0) + if clifh > 0 then + clifh = -1*(clifh-1)*(clifh-1) + 1 + theight = theight + (hills_thresh-theight) * clifh * ((theight<2) and theight-1 or 1) + end + end + return theight +end + +local function get_distance(a,b) --get_distance(a,b) + return (max(abs(a.x-b.x), abs(a.y-b.y))) --returns the chebyshev distance between two points +end + +local function get_avg_distance(a,b) --get_avg_distance(a,b) + return ((abs(a.x-b.x) + abs(a.y-b.y)) * 0.5) --returns the average distance between two points +end + +local function get_manhattan_distance(a,b) --get_manhattan_distance(a,b) + return (abs(a.x-b.x) + abs(a.y-b.y)) --returns the manhattan distance between two points +end + +local function get_euclid_distance(a,b) + local dx = a.x - b.x + local dy = a.y - b.y + return (dx*dx+dy*dy)^0.5 +end + +local function get_midpoint(a,b) --get_midpoint(a,b) + return ((a.x+b.x)/2), ((a.y+b.y)/2) --returns the midpoint between two points +end + +-- +-- save list of generated lib_mg_continental +-- +function lib_mg_continental.save(pobj, pfilename) + local file = io.open(lib_mg_continental.path_world.."/"..pfilename.."", "w") + if file then + file:write(minetest.serialize(pobj)) + file:close() + end +end +-- +-- load list of generated lib_mg_continental +-- +function lib_mg_continental.load(pfilename) + local file = io.open(lib_mg_continental.path_world.."/"..pfilename.."", "r") + if file then + local table = minetest.deserialize(file:read("*all")) + if type(table) == "table" then + return table + end + end + --return {} + return nil +end + +-- +-- save .csv file format +-- +function lib_mg_continental.save_csv(pobj, pfilename) + local file = io.open(lib_mg_continental.path_world.."/"..pfilename.."", "w") + if file then + file:write(pobj) + file:close() + end +end + +function lib_mg_continental.load_csv(separator, path) + local file = io.open(lib_mg_continental.path_world.."/"..path, "r") + if file then + local t = {} + for line in file:lines() do + if line:sub(1,1) ~= "#" and line:find("[^%"..separator.."% ]") then + table.insert(t, line:split(separator, true)) + end + end + if type(t) == "table" then + return t + end + end + --return {} + return nil +end -- Create a table of biome ids, so I can use the biomemap. -if not lib_mg_continental.biome_ids then +--if not lib_mg_continental.biome_ids then --local get_cid = minetest.get_content_id lib_mg_continental.biome_info = {} for name, desc in pairs(minetest.registered_biomes) do - local b_cid = minetest.get_biome_id(name) + if desc then - local b_top = minetest.get_content_id(desc.node_top) - local b_top_depth = desc.depth_top or "" - local b_filler = minetest.get_content_id(desc.node_filler) - local b_filler_depth = desc.depth_filler or "" - local b_stone = minetest.get_content_id(desc.node_stone) - local b_water_top = minetest.get_content_id(desc.node_water_top) - local b_water_top_depth = desc.depth_water_top or "" - local b_water = minetest.get_content_id(desc.node_water) - local b_river = minetest.get_content_id(desc.node_river_water) - local b_riverbed = minetest.get_content_id(desc.node_riverbed) - local b_riverbed_depth = desc.depth_riverbed or "" - local b_cave_liquid = minetest.get_content_id(desc.node_cave_liquid) - local b_dungeon = minetest.get_content_id(desc.node_dungeon) - local b_dungeon_alt = minetest.get_content_id(desc.node_dungeon_alt) - local b_dungeon_stair = minetest.get_content_id(desc.node_dungeon_stair) - local b_node_dust = minetest.get_content_id(desc.node_dust) - local b_miny = desc.y_min or "" - local b_maxy = desc.y_max or "" - local b_heat = desc.heat_point or "" - local b_humid = desc.humidity_point or "" + local b_cid = minetest.get_biome_id(name) - lib_mg_continental.biome_info[desc.name] = name .. "|" .. b_cid .. "|" .. b_top .. "|" .. b_top_depth .. "|" .. b_filler .. "|" .. b_filler_depth .. "|" .. b_stone .. "|" .. b_water_top - .. "|" .. b_water_top_depth .. "|" .. b_water .. "|" .. b_river .. "|" .. b_riverbed .. "|" .. b_riverbed_depth .. "|" .. b_cave_liquid .. "|" .. b_dungeon - .. "|" .. b_dungeon_alt .. "|" .. b_dungeon_stair .. "|" .. b_node_dust .. "|" .. b_miny .. "|" .. b_maxy .. "|" .. b_heat .. "|" .. b_humid .. "\n" + local b_top, b_top_depth, b_filler, b_filler_depth, b_stone, b_water_top, b_water_top_depth, b_water, b_river, b_riverbed, b_riverbed_depth + local b_cave_liquid, b_dungeon, b_dungeon_alt, b_dungeon_stair, b_node_dust, b_miny, b_maxy, b_heat, b_humid + + local r_biome = name .. "|" .. b_cid .. "|" + + if desc.node_top and desc.node_top ~= "" then + b_top = minetest.get_content_id(desc.node_top) + else + b_top = minetest.get_content_id("default:dirt_with_grass") + end + r_biome = r_biome .. b_top .. "|" + + if desc.depth_top and desc.depth_top ~= "" then + b_top_depth = desc.depth_top or "" + else + b_top_depth = "1" + end + r_biome = r_biome .. b_top_depth .. "|" + + if desc.node_filler and desc.node_filler ~= "" then + b_filler = minetest.get_content_id(desc.node_filler) + else + b_filler = minetest.get_content_id("default:dirt") + end + r_biome = r_biome .. b_filler .. "|" + + if desc.depth_filler and desc.depth_filler ~= "" then + b_filler_depth = desc.depth_filler + else + b_filler_depth = "4" + end + r_biome = r_biome .. b_filler_depth .. "|" + + if desc.node_stone and desc.node_stone ~= "" then + b_stone = minetest.get_content_id(desc.node_stone) + else + b_stone = minetest.get_content_id("default:stone") + end + r_biome = r_biome .. b_stone .. "|" + + if desc.node_water_top and desc.node_water_top ~= "" then + b_water_top = minetest.get_content_id(desc.node_water_top) + else + b_water_top = minetest.get_content_id("default:water_source") + end + r_biome = r_biome .. b_water_top .. "|" + + if desc.depth_water_top and desc.depth_water_top ~= "" then + b_water_top_depth = desc.depth_water_top + else + b_water_top_depth = "1" + end + r_biome = r_biome .. b_water_top_depth .. "|" + + if desc.node_water and desc.node_water ~= "" then + b_water = minetest.get_content_id(desc.node_water) + else + b_water = minetest.get_content_id("default:water_source") + end + r_biome = r_biome .. b_water .. "|" + + if desc.node_river_water and desc.node_river_water ~= "" then + b_river = minetest.get_content_id(desc.node_river_water) + else + b_river = minetest.get_content_id("default:river_water_source") + end + r_biome = r_biome .. b_river .. "|" + + if desc.node_riverbed and desc.node_riverbed ~= "" then + b_riverbed = minetest.get_content_id(desc.node_riverbed) + else + b_riverbed = minetest.get_content_id("default:gravel") + end + r_biome = r_biome .. b_riverbed .. "|" + + if desc.depth_riverbed and desc.depth_riverbed ~= "" then + b_riverbed_depth = desc.depth_riverbed or "" + else + b_riverbed_depth = "2" + end + r_biome = r_biome .. b_riverbed_depth .. "|" + + if desc.node_cave_liquid and desc.node_cave_liquid ~= "" then + b_cave_liquid = minetest.get_content_id(desc.node_cave_liquid) + else + b_cave_liquid = minetest.get_content_id("default:lava_source") + end + r_biome = r_biome .. b_cave_liquid .. "|" + + if desc.node_dungeon and desc.node_dungeon ~= "" then + b_dungeon = minetest.get_content_id(desc.node_dungeon) + else + b_dungeon = minetest.get_content_id("default:mossycobble") + end + r_biome = r_biome .. b_dungeon .. "|" + + if desc.node_dungeon_alt and desc.node_dungeon_alt ~= "" then + b_dungeon_alt = minetest.get_content_id(desc.node_dungeon_alt) + else + b_dungeon_alt = minetest.get_content_id("default:stonebrick") + end + r_biome = r_biome .. b_dungeon_alt .. "|" + + if desc.node_dungeon_stair and desc.node_dungeon_stair ~= "" then + b_dungeon_stair = minetest.get_content_id(desc.node_dungeon_stair) + else + b_dungeon_stair = minetest.get_content_id("stairs:stair_cobble") + end + r_biome = r_biome .. b_dungeon_stair .. "|" + + if desc.node_dust and desc.node_dust ~= "" then + b_node_dust = minetest.get_content_id(desc.node_dust) + else + b_node_dust = minetest.get_content_id("default:snow") + end + r_biome = r_biome .. b_node_dust .. "|" + + if desc.y_min and desc.y_min ~= "" then + b_miny = desc.y_min or "" + else + b_miny = "-31000" + end + r_biome = r_biome .. b_miny .. "|" + + if desc.y_max and desc.y_max ~= "" then + b_maxy = desc.y_max or "" + else + b_maxy = "31000" + end + r_biome = r_biome .. b_maxy .. "|" + + if desc.heat_point and desc.heat_point ~= "" then + b_heat = desc.heat_point or "" + else + b_heat = "50" + end + r_biome = r_biome .. b_heat .. "|" + + if desc.humidity_point and desc.humidity_point ~= "" then + b_humid = desc.humidity_point + else + b_humid = "50" + end + r_biome = r_biome .. b_humid .. "|" + + --lib_mg_continental.biome_info[desc.name] = r_biome + lib_mg_continental.biome_info[b_cid] = r_biome + + end +-- end +--end + + +local function make_voronoi(cells, size) + + if not cells or not size then + return + end + + -- Start time of voronoi generation. + local t0 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Random Points generation start") + + --Prevents points from too near edges, ideally creating more evenly sized cells. + --Minumum: 50 + local size_offset = 125 + local size_half = size / 2 + + local t_map_cell = {} + + if cells > 0 then + local temp_points = "#Index|Pos.Z|Pos.X\n" + v_points = {} + for i_c = 1, cells do + local t_pt = {x = (math.random(1 + size_offset, size - size_offset) - size_half), z = (math.random(1 + size_offset, size - size_offset) - size_half)} + v_points[i_c] = t_pt + temp_points = temp_points .. i_c .. "|" .. t_pt.z .. "|" .. t_pt.x .. "\n" + end + lib_mg_continental.save_csv(temp_points, "lib_mg_continental_data_points.txt") + minetest.log("[lib_mg_continental_voronoi] Voronoi Cell Point List:\n" .. temp_points .. "") + elseif cells == 0 then + v_points = {} + for i, point in ipairs(mg_custom_data.base_points) do + local idx, p_z, p_x = unpack(point) + local t_pt = {x = tonumber(p_x), z = tonumber(p_z)} + v_points[tonumber(idx)] = t_pt + end + minetest.log("[lib_mg_continental_voronoi] Voronoi Cell Point List loaded from file.") + else + + end + + -- Random Points generation finished. Check the timer to know the elapsed time. + local t1 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Random Points generation time " .. (t1-t0) .. " ms") + minetest.log("[lib_mg_continental_voronoi] Cell Data (Cells, Neighbors, Midpoints) generation start") + + local temp_cells = "#Index|LinkIdx|Pos.Z|Pos.X|ClosestIndex|ClosestPosZ|ClosestPosX\n" + local temp_neighbors = "#CellIndex|LinkIdx|CellPosZ|CellPosX|ClosestNeighborIndex|ClosestNeighborPosZ|ClosestNeighborPosX|ClosestNeighborDist|ClosestNeighborEDist|ClosestNeighborMDist|ClosestNeighborADist|NeighborMidPosZ|NeighborMidPosX\n" + local temp_midpoints = "#LinkIdx|Pos.Z|Pos.X|DistBetweenCells|Cell1Idx|Cell1Dist|Cell2Idx|Cell2Dist|\n" + + for i, pos in pairs(v_points) do + + local closest_neighbor_idx = 0 + local closest_neighbor_pos_x = 0 + local closest_neighbor_pos_z = 0 + local closest_dist = 0 --chebyshev + local closest_edist = 0 --euclidean + local closest_adist = 0 --average + local closest_mdist = 0 --manhattan + local e_dist + local m_dist + local a_dist + local s_dist + local t_dist + --local t_point_x, t_point_z + + for k, pt in pairs(v_points) do + if i ~= k then + local neighbor_add = false + e_dist = get_euclid_distance({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) + --t_dist = get_euclidean2_distance({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) + t_dist = get_distance({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) + m_dist = get_manhattan_distance({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) + a_dist = get_avg_distance({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) + if s_dist then + if s_dist > t_dist then + s_dist = t_dist + closest_neighbor_idx = k + closest_neighbor_pos_x = pt.x + closest_neighbor_pos_z = pt.z + closest_dist = t_dist + closest_edist = e_dist + closest_mdist = m_dist + closest_adist = a_dist + neighbor_add = true + elseif s_dist == t_dist then + s_dist = t_dist + closest_neighbor_idx = 0 + closest_neighbor_pos_x = pt.x + closest_neighbor_pos_z = pt.z + closest_dist = t_dist + end + else + s_dist = t_dist + closest_neighbor_idx = k + closest_neighbor_pos_x = pt.x + closest_neighbor_pos_z = pt.z + + end + + local m_point_x, m_point_z = get_midpoint({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) + temp_midpoints = temp_midpoints .. i .. "-" .. k .. "|" .. m_point_z .. "|" .. m_point_x .. "|" .. get_distance({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) .. "|" .. i .. "|" .. get_distance({x=m_point_x,y=m_point_z}, {x=pos.x,y=pos.z}) .. "|" .. k .. "|" .. get_distance({x=pt.x,y=pt.z}, {x=m_point_x,y=m_point_z}) .. "\n" + + if neighbor_add == true then + local t_point_x, t_point_z = get_midpoint({x=pt.x,y=pt.z}, {x=pos.x,y=pos.z}) + temp_neighbors = temp_neighbors .. i .. "|" .. i .. "-" .. closest_neighbor_idx .. "|" .. pos.z .. "|" .. pos.x .. "|" .. closest_neighbor_idx .. "|" .. closest_neighbor_pos_z .. "|" .. closest_neighbor_pos_x .. "|" .. s_dist .. "|" .. e_dist .. "|" .. m_dist .. "|" .. a_dist .. "|" .. t_point_z .. "|" .. t_point_x .. "\n" + end + + end + + end + + t_map_cell[i] = { + link_idx = i .. "-" .. closest_neighbor_idx, + z = pos.z, + x = pos.x, + closest_idx = closest_neighbor_idx, + closestposz = closest_neighbor_pos_z, + closestposx = closest_neighbor_pos_x, + } + temp_cells = temp_cells .. i .. "|" .. i .. "-" .. closest_neighbor_idx .. "|" .. pos.z .. "|" .. pos.x .. "|" .. closest_neighbor_idx .. "|" .. closest_neighbor_pos_z .. "|" .. closest_neighbor_pos_x .. "\n" + + end + + -- Random cell generation finished. Check the timer to know the elapsed time. + local t2 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Cell Data (Cells, Neighbors, Midpoints) generation time " .. (t2-t1) .. " ms") + + lib_mg_continental.save_csv(temp_cells, "lib_mg_continental_data_cells.txt") + lib_mg_continental.save_csv(temp_neighbors, "lib_mg_continental_data_neighbors.txt") + lib_mg_continental.save_csv(temp_midpoints, "lib_mg_continental_data_midpoints.txt") + + -- Random cell generation finished. Check the timer to know the elapsed time. + local t3 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Cell Data save time " .. (t3-t2) .. " ms") + + -- Print generation time of this mapchunk. + local chugent = math.ceil((os.clock() - t0) * 1000) + minetest.log("[lib_mg_continental_voronoi] Voronoi Data generation time " .. chugent .. " ms") + + --return t_map_cell + return t_map_cell, temp_midpoints, temp_neighbors --, temp_points + end -dofile(lib_mg_continental.path_mod.."/lib_mg_continental_functions_io.lua") -dofile(lib_mg_continental.path_mod.."/lib_mg_continental_functions_utils.lua") -dofile(lib_mg_continental.path_mod.."/lib_mg_continental_functions_voronoi.lua") +local function make_edge_map(size) + -- Start time of voronoi generation. + local t0 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Edge Map generation start") + + local t_map_edge = {} + + local temp_edges = "#ID|Index|Pos.Z|Pos.X|Cell1 Index|Cell1 Distance|Cell1 EDistance|Cell1 MDistance|Cell1 ADistance|Cell Index|Cell2 Distance|Cell2 EDistance|Cell2 MDistance|Cell2 ADistance\n" + + local idx = 1 + for i_z = (1-(size/2)), (size-(size/2)) do + t_map_edge[i_z] = {} + for i_x = (1-(size/2)), (size-(size/2)) do + local closest_cell_idx = 0 + local closest_cell_dist + local closest_cell_edist = 0 + local closest_cell_mdist = 0 + local closest_cell_adist = 0 + local last_closest_idx = 0 + local last_dist + local this_dist + local last_edist + local last_mdist + local last_adist + local e_dist + local m_dist + local a_dist + + for i, pos in pairs(v_points) do + + local edge_add = false + + e_dist = get_euclid_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + --this_dist = get_euclidean2_distance({{x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + this_dist = get_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + m_dist = get_manhattan_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + a_dist = get_avg_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + + if last_dist then + if last_dist > this_dist then + + closest_cell_idx = i + closest_cell_dist = this_dist + closest_cell_edist = e_dist + last_dist = this_dist + last_edist = e_dist + last_mdist = m_dist + last_adist = a_dist + last_closest_idx = i + + elseif last_dist == this_dist then + + closest_cell_idx = 0 + edge_add = true + end + else + closest_cell_idx = i + closest_cell_dist = this_dist + closest_cell_edist = e_dist + last_dist = this_dist + last_edist = e_dist + last_mdist = m_dist + last_adist = a_dist + last_closest_idx = i + end + + if edge_add == true then + t_map_edge[i_z][i_x] = { + index = idx, + cells_index = "" .. i .. "-" .. last_closest_idx .. "", + cell1_index = i, + cell1_distance = this_dist, + cell1_edistance = e_dist, + cell1_mdistance = m_dist, + cell1_adistance = a_dist, + cell2_index = last_closest_idx, + cell2_distance = last_dist, + cell2_edistance = last_edist, + cell2_mdistance = last_mdist, + cell2_adistance = last_adist, + } + temp_edges = temp_edges .. i_z .. "|" .. i_x .. "|" .. idx .. "|" .. i .. "-" .. last_closest_idx .. "|" .. i .. "|" .. this_dist .. "|" .. e_dist .. "|" .. m_dist .. "|" .. a_dist .. "|" .. last_closest_idx .. "|" .. last_dist .. "|" .. last_edist .. "|" .. last_mdist .. "|" .. last_adist .. "\n" + end + end + + idx = idx + 1 + end + + end + + local t1 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Edge Map generation time " .. (t1-t0) .. " ms") + + lib_mg_continental.save_csv(temp_edges, "lib_mg_continental_data_edges.txt") + + local t2 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Edge Map save time " .. (t2-t1) .. " ms") + + -- Print generation time of this mapchunk. + local chugent = math.ceil((os.clock() - t0) * 1000) + minetest.log("[lib_mg_continental_voronoi] Edge Map Total generation time " .. chugent .. " ms") + + return t_map_edge + +end + +local function make_voronoi_maps(size) + + -- Start time of voronoi generation. + local t0 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Voronoi and Edges Maps generation start") + + local t_map_voronoi = {} + local t_map_edge = {} + + local temp_voronoi = "#Index|Pos.Z|Pos.X|ClosestIndex|ClosestDistance\n" + local temp_edges = "#ID|Index|Pos.Z|Pos.X|Cell1 Index|Cell1 Distance|Cell1 EDistance|Cell1 MDistance|Cell1 ADistance|Cell Index|Cell2 Distance|Cell2 EDistance|Cell2 MDistance|Cell2 ADistance\n" + + local idx = 1 + for i_z = (1-(size/2)), (size-(size/2)) do + t_map_voronoi[i_z] = {} + t_map_edge[i_z] = {} + for i_x = (1-(size/2)), (size-(size/2)) do + local closest_cell_idx = 0 + local closest_cell_dist + local closest_cell_edist = 0 + local closest_cell_mdist = 0 + local closest_cell_adist = 0 + local last_closest_idx = 0 + local last_dist + local this_dist + local last_edist + local last_mdist + local last_adist + local e_dist + local m_dist + local a_dist + + for i, pos in pairs(v_points) do + + local edge_add = false + + e_dist = get_euclid_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + --this_dist = get_euclidean2_distance({{x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + this_dist = get_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + m_dist = get_manhattan_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + a_dist = get_avg_distance({x=i_x,y=i_z}, {x=pos.x,y=pos.z}) + + if last_dist then + if last_dist > this_dist then + + closest_cell_idx = i + closest_cell_dist = this_dist + closest_cell_edist = e_dist + last_dist = this_dist + last_edist = e_dist + last_mdist = m_dist + last_adist = a_dist + last_closest_idx = i + + elseif last_dist == this_dist then + + closest_cell_idx = 0 + edge_add = true + end + else + closest_cell_idx = i + closest_cell_dist = this_dist + closest_cell_edist = e_dist + last_dist = this_dist + last_edist = e_dist + last_mdist = m_dist + last_adist = a_dist + last_closest_idx = i + end + + if edge_add == true then + t_map_edge[i_z][i_x] = { + index = "" .. i .. "-" .. last_closest_idx .. "", + z = i_z, + x = i_x, + cell1_index = i, + cell1_distance = this_dist, + cell1_edistance = e_dist, + cell1_mdistance = m_dist, + cell1_adistance = a_dist, + cell2_index = last_closest_idx, + cell2_distance = last_dist, + cell2_edistance = last_edist, + cell2_mdistance = last_mdist, + cell2_adistance = last_adist, + } + temp_edges = temp_edges .. idx .. "|" .. i .. "-" .. last_closest_idx .. "|" .. i_z .. "|" .. i_x .. "|" .. i .. "|" .. this_dist .. "|" .. e_dist .. "|" .. m_dist .. "|" .. a_dist .. "|" .. last_closest_idx .. "|" .. last_dist .. "|" .. last_edist .. "|" .. last_mdist .. "|" .. last_adist .. "\n" + end + end + + t_map_voronoi[i_z][i_x] = { + closest_idx = closest_cell_idx, + closest_dist = closest_cell_dist, + closest_edist = closest_cell_edist, + closest_mdist = closest_cell_mdist, + closest_adist = closest_cell_adist, + } + --temp_voronoi = temp_voronoi .. i_z .. "|" .. i_x .. "|" .. closest_cell_idx .. "|" .. closest_cell_dist .. "\n" + idx = idx + 1 + end + + end + + local t1 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Voronoi and Edges Maps generation time " .. (t1-t0) .. " ms") + + --lib_mg_continental.save_csv(temp_voronoi, "lib_mg_continental_data_voronoi.txt") + lib_mg_continental.save_csv(temp_edges, "lib_mg_continental_data_edges.txt") + + local t2 = os.clock() + minetest.log("[lib_mg_continental_voronoi] Voronoi and Edges Maps save time " .. (t2-t1) .. " ms") + + -- Print generation time of this mapchunk. + local chugent = math.ceil((os.clock() - t0) * 1000) + minetest.log("[lib_mg_continental_voronoi] Voronoi and Edges Maps Total generation time " .. chugent .. " ms") + + return t_map_voronoi, t_map_edge + --return t_map_voronoi, temp_edges + +end + +minetest.log("[lib_mg_continental_mg_dev_voronoi] Custom Data Load / Gen Start") +mg_custom_data.base_points = lib_mg_continental.load_csv("|", "lib_mg_continental_data_points.txt") +mg_custom_data.base_cells = lib_mg_continental.load_csv("|", "lib_mg_continental_data_cells.txt") +mg_custom_data.base_cellmap = lib_mg_continental.load("lib_mg_continental_data_cellmap.txt") +mg_custom_data.base_midpoints = lib_mg_continental.load_csv("|", "lib_mg_continental_data_midpoints.txt") +mg_custom_data.base_tectonicmap = lib_mg_continental.load("lib_mg_continental_data_tectonicmap.txt") +mg_custom_data.base_edgemap = lib_mg_continental.load("lib_mg_continental_data_edgemap.txt") +--mg_custom_data.base_edgemap = lib_mg_continental.load_csv("|", "lib_mg_continental_data_edges.txt") + +if not (mg_custom_data.base_cellmap) then + if (mg_custom_data.base_midpoints == nil) then + if (mg_custom_data.base_points == nil) then + mg_custom_data.base_cellmap, mg_custom_data.base_midpoints, mg_custom_data.base_neighbors = make_voronoi(voronoi_cells, map_scale) + lib_mg_continental.save(mg_custom_data.base_cellmap, "lib_mg_continental_data_cellmap.txt") + else + mg_custom_data.base_cellmap, mg_custom_data.base_midpoints, mg_custom_data.base_neighbors = make_voronoi(0, map_scale) + lib_mg_continental.save(mg_custom_data.base_cellmap, "lib_mg_continental_data_cellmap.txt") + end + end +end +if not (mg_custom_data.base_tectonicmap) or not (mg_custom_data.base_edgemap) then + mg_custom_data.base_tectonicmap, mg_custom_data.base_edgemap = make_voronoi_maps(map_scale) + lib_mg_continental.save(mg_custom_data.base_tectonicmap, "lib_mg_continental_data_tectonicmap.txt") + lib_mg_continental.save(mg_custom_data.base_edgemap, "lib_mg_continental_data_edgemap.txt") +end +minetest.log("[lib_mg_continental_voronoi] Custom Data Load / Gen End") local mapgen_times = { liquid_lighting = {}, @@ -293,13 +934,7 @@ minetest.register_on_generated(function(minp, maxp, seed) local t1 = os.clock() local write = false - - local center_of_chunk = { - x=maxp.x-lib_mg_continental.half_map_chunk_size, - y=maxp.y-lib_mg_continental.half_map_chunk_size, - z=maxp.z-lib_mg_continental.half_map_chunk_size - } - + -- 2D Generation loop. local index2d = 0 for z = minp.z, maxp.z do @@ -318,7 +953,7 @@ minetest.register_on_generated(function(minp, maxp, seed) --local ntectonic_mist --local ntectonic_aist - if mg_map_view == false then +-- if mg_map_view == false then s_z, s_z_r = math.modf(z / map_tectonic_scale) s_x, s_x_r = math.modf(x / map_tectonic_scale) if s_z_r >= 5 then @@ -327,28 +962,35 @@ minetest.register_on_generated(function(minp, maxp, seed) if s_x_r >= 5 then s_x = s_x + 1 end - ntectonic_idx = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_idx - ntectonic_dist = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_dist - ntectonic_edist = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_edist - --ntectonic_mdist = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_mdist - --ntectonic_adist = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_adist - else + local t_tect_map = mg_custom_data.base_tectonicmap[s_z][s_x] + ntectonic_idx = t_tect_map.closest_idx + ntectonic_dist = t_tect_map.closest_dist + ntectonic_edist = t_tect_map.closest_edist + + --ntectonic_idx = mg_custom_data.base_tectonicmap[s_z][s_x].closest_idx + --ntectonic_dist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_dist + --ntectonic_edist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_edist + --ntectonic_mdist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_mdist + --ntectonic_adist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_adist +-- else +--[[ s_z = z s_x = x if ((z > -500) and (z < 500)) and ((x > -500) and (x < 500)) then - ntectonic_idx = lib_mg_continental.mg_custom_data.base_tectonicmap[z][x].closest_idx - ntectonic_dist = lib_mg_continental.mg_custom_data.base_tectonicmap[z][x].closest_dist - ntectonic_edist = lib_mg_continental.mg_custom_data.base_tectonicmap[z][x].closest_edist - --ntectonic_mdist = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_mdist - --ntectonic_adist = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_adist + ntectonic_idx = mg_custom_data.base_tectonicmap[z][x].closest_idx + ntectonic_dist = mg_custom_data.base_tectonicmap[z][x].closest_dist + ntectonic_edist = mg_custom_data.base_tectonicmap[z][x].closest_edist + --ntectonic_mdist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_mdist + --ntectonic_adist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_adist else ntectonic_idx = -1234 ntectonic_dist = -2 ntectonic_edist = -2 end - end +--]] +-- end --- +--[[ if mg_map_view == false then if ntectonic_idx <= 0 then @@ -359,18 +1001,18 @@ minetest.register_on_generated(function(minp, maxp, seed) local cell2_pos_x local cell2_pos_z - cell1_idx = lib_mg_continental.mg_custom_data.base_edgemap[s_z][s_x].cell1_index - cell2_idx = lib_mg_continental.mg_custom_data.base_edgemap[s_z][s_x].cell2_index + cell1_idx = mg_custom_data.base_edgemap[s_z][s_x].cell1_index + cell2_idx = mg_custom_data.base_edgemap[s_z][s_x].cell2_index - cell1_pos_x = lib_mg_continental.mg_custom_data.base_cellmap[cell1_idx].x * map_tectonic_scale - cell1_pos_z = lib_mg_continental.mg_custom_data.base_cellmap[cell1_idx].z * map_tectonic_scale - cell2_pos_x = lib_mg_continental.mg_custom_data.base_cellmap[cell2_idx].x * map_tectonic_scale - cell2_pos_z = lib_mg_continental.mg_custom_data.base_cellmap[cell2_idx].z * map_tectonic_scale + cell1_pos_x = mg_custom_data.base_cellmap[cell1_idx].x * map_tectonic_scale + cell1_pos_z = mg_custom_data.base_cellmap[cell1_idx].z * map_tectonic_scale + cell2_pos_x = mg_custom_data.base_cellmap[cell2_idx].x * map_tectonic_scale + cell2_pos_z = mg_custom_data.base_cellmap[cell2_idx].z * map_tectonic_scale - local cell1_dist = lib_mg_continental.get_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) - local cell1_edist = lib_mg_continental.get_euclid_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) - local cell2_dist = lib_mg_continental.get_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) - local cell2_edist = lib_mg_continental.get_euclid_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) + local cell1_dist = get_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) + local cell1_edist = get_euclid_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) + local cell2_dist = get_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) + local cell2_edist = get_euclid_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) if cell1_dist == cell2_dist then ntectonic_idx = 0 @@ -398,8 +1040,8 @@ minetest.register_on_generated(function(minp, maxp, seed) --end end end --- end +--]] local ntectonic_rdist = (ntectonic_dist + ntectonic_edist) * 0.5 --ridges @@ -412,16 +1054,16 @@ minetest.register_on_generated(function(minp, maxp, seed) local nterrain = isln_terrain[z-minp.z+1][x-minp.x+1] local cheight = isln_cliffs[z-minp.z+1][x-minp.x+1] - local ncontinental = lib_mg_continental.get_terrain_height_shelf(ntectonic_edist) * -0.1 - local nmountain = (lib_mg_continental.get_terrain_height_shelf(ntectonic_rdist) * 0.1) - 2 + local ncontinental = get_terrain_height_shelf(ntectonic_edist) * -0.1 + local nmountain = (get_terrain_height_shelf(ntectonic_rdist) * 0.1) - 2 if mg_map_view == false then - theight = lib_mg_continental.get_terrain_height_hills_adjustable_shelf(nterrain + (math.max(ncontinental,nmountain)*0.5),(math.max(ncontinental,nmountain)*0.1),cheight,(ntect_rdist + (ntect_rdist / mg_golden_ratio))) - 2 + theight = get_terrain_height_hills_adjustable_shelf(nterrain + (math.max(ncontinental,nmountain)*0.5),(math.max(ncontinental,nmountain)*0.1),cheight,(ntect_rdist + (ntect_rdist / mg_golden_ratio))) - 2 else - theight = lib_mg_continental.get_terrain_height_hills_adjustable_shelf(nterrain + (nmountain * 0.1),(nmountain * 0.1),cheight,(ntect_rdist + (ntect_rdist / mg_golden_ratio)) * 0.1) + 3 + theight = get_terrain_height_hills_adjustable_shelf(nterrain + (nmountain * 0.1),(nmountain * 0.1),cheight,(ntect_rdist + (ntect_rdist / mg_golden_ratio)) * 0.1) + 3 end - lib_mg_continental.heightmap[index2d] = theight + lib_mg_continental.heightmap[index2d] = theight - 1 end end @@ -440,11 +1082,11 @@ minetest.register_on_generated(function(minp, maxp, seed) if y <= theight + 1 then +--[[ local t_heat, t_humid, t_altitude, t_name local nheat = nbase_heatmap[index2d] + nbase_heatblend[index2d] local nhumid = nbase_humiditymap[index2d] + nbase_humidityblend[index2d] - if nheat < 12.5 then t_heat = "cold" elseif nheat >= 12.5 and nheat < 37.5 then @@ -518,31 +1160,58 @@ minetest.register_on_generated(function(minp, maxp, seed) else end - +--]] local b_name, b_cid, b_top, b_top_d, b_fill, b_fill_d, b_stone, b_water_top, b_water_top_d, b_water, b_river, b_riverbed, b_riverbed_d local b_caveliquid, b_dungeon, b_dungeonalt, b_dungeonstair, b_dust, b_ymin, b_ymax, b_heat, b_humid - if t_name == "" then - t_name = minetest.get_biome_name(minetest.get_biome_data({x,y,z}).biome) - end - - local fill_depth = 1 - local top_depth = 1 + --if t_name == "" then + -- t_name = minetest.get_biome_name(minetest.get_biome_data({x,y,z}).biome) + --end + --local t_name = minetest.get_biome_name(minetest.get_biome_data({x,y,z}).biome) + --local t_name = minetest.get_biome_data({x,y,z}).biome + + local fill_depth + local top_depth if t_name and t_name ~= "" then - - b_name, b_cid, b_top, b_top_d, b_fill, b_fill_d, b_stone, b_water_top, b_water_top_d, b_water, b_river, b_riverbed, b_riverbed_d, b_caveliquid, b_dungeon, b_dungeonalt, b_dungeonstair, b_dust, b_ymin, b_ymax, b_heat, b_humid = unpack(lib_mg_continental.biome_info[t_name]:split("|", false)) - - c_stone = b_stone - c_dirt = b_fill - fill_depth = b_fill_d or 6 - c_top = b_top - top_depth = b_top_d or 1 + + --local t_biome_cid = minetest.get_biome_data({x,y,z}).biome + --local t_biome_name = minetest.get_biome_name(t_biome_cid) + --local t_biome_def = minetest.registered_biomes[t_biome_name] + + --minetest.log("lib_mg_continental: BIOME:" .. t_biome_name .. ";") + --print("lib_mg_continental: BIOME:" .. t_biome_name .. "") + --minetest.log("lib_mg_continental: STONE:" .. desc.node_stone .. ";") + --print("lib_mg_continental: STONE:" .. desc.node_stone .. "") + + --b_name, b_cid, b_top, b_top_d, b_fill, b_fill_d, b_stone, b_water_top, b_water_top_d, b_water, b_river, b_riverbed, b_riverbed_d, b_caveliquid, b_dungeon, b_dungeonalt, b_dungeonstair, b_dust, b_ymin, b_ymax, b_heat, b_humid = unpack(lib_mg_continental.biome_info[t_name]:split("|", false)) + --b_name = t_biome_name + --b_cid = t_biome_cid + --b_top = t_biome_def.node_top or "default:dirt_with_grass" + --b_top_d = 1 + --b_fill = t_biome_def.node_filler or "default:dirt" + --b_fill_d = 4 + --b_stone = t_biome_def.node_stone or "default:stone" + --b_water_top = t_biome_def.node_water or "default:water_source" + --b_water_top_d = 1 + --b_water = t_biome_def.node_water or "default:water_source" + + --minetest.log("lib_mg_continental: STONE:" .. b_stone .. ";") + --print("lib_mg_continental: STONE:" .. b_stone .. "") + --minetest.log("lib_mg_continental: TOP:" .. b_top .. ";") + --print("lib_mg_continental: TOP:" .. b_top .. "") + + --c_stone = b_stone --minetest.get_content_id(b_stone) + --c_dirt = b_fill --minetest.get_content_id(b_fill) + --c_top = b_top --minetest.get_content_id(b_top) + fill_depth = tonumber(b_fill_d) or 6 + top_depth = tonumber(b_top_d) or 1 end lib_mg_continental.biomemap[index2d] = b_cid --VORONOI MARKERS FROM TECTONICMAP +--[[ local s_z, s_z_r local s_x, s_x_r @@ -561,8 +1230,8 @@ minetest.register_on_generated(function(minp, maxp, seed) if s_x_r >= 5 then s_x = s_x + 1 end - ntectonic_idx = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_idx - ntectonic_dist = lib_mg_continental.mg_custom_data.base_tectonicmap[s_z][s_x].closest_dist + ntectonic_idx = mg_custom_data.base_tectonicmap[s_z][s_x].closest_idx + ntectonic_dist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_dist --ntectonic_edist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_edist --ntectonic_mdist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_mdist --ntectonic_adist = mg_custom_data.base_tectonicmap[s_z][s_x].closest_adist @@ -570,9 +1239,9 @@ minetest.register_on_generated(function(minp, maxp, seed) s_z = z s_x = x if ((z > -500) and (z < 500)) and ((x > -500) and (x < 500)) then - ntectonic_idx = lib_mg_continental.mg_custom_data.base_tectonicmap[z][x].closest_idx - ntectonic_dist = lib_mg_continental.mg_custom_data.base_tectonicmap[z][x].closest_dist - ntectonic_edist = lib_mg_continental.mg_custom_data.base_tectonicmap[z][x].closest_edist + ntectonic_idx = mg_custom_data.base_tectonicmap[z][x].closest_idx + ntectonic_dist = mg_custom_data.base_tectonicmap[z][x].closest_dist + ntectonic_edist = mg_custom_data.base_tectonicmap[z][x].closest_edist else ntectonic_idx = -1234 ntectonic_dist = -2 @@ -582,7 +1251,7 @@ minetest.register_on_generated(function(minp, maxp, seed) if ntectonic_dist == 0 then - c_top = c_obsidian + --c_top = c_obsidian end @@ -596,18 +1265,18 @@ minetest.register_on_generated(function(minp, maxp, seed) local cell2_pos_x local cell2_pos_z - cell1_idx = lib_mg_continental.mg_custom_data.base_edgemap[s_z][s_x].cell1_index - cell2_idx = lib_mg_continental.mg_custom_data.base_edgemap[s_z][s_x].cell2_index + cell1_idx = mg_custom_data.base_edgemap[s_z][s_x].cell1_index + cell2_idx = mg_custom_data.base_edgemap[s_z][s_x].cell2_index - cell1_pos_x = lib_mg_continental.mg_custom_data.base_cellmap[cell1_idx].x * map_tectonic_scale - cell1_pos_z = lib_mg_continental.mg_custom_data.base_cellmap[cell1_idx].z * map_tectonic_scale - cell2_pos_x = lib_mg_continental.mg_custom_data.base_cellmap[cell2_idx].x * map_tectonic_scale - cell2_pos_z = lib_mg_continental.mg_custom_data.base_cellmap[cell2_idx].z * map_tectonic_scale + cell1_pos_x = mg_custom_data.base_cellmap[cell1_idx].x * map_tectonic_scale + cell1_pos_z = mg_custom_data.base_cellmap[cell1_idx].z * map_tectonic_scale + cell2_pos_x = mg_custom_data.base_cellmap[cell2_idx].x * map_tectonic_scale + cell2_pos_z = mg_custom_data.base_cellmap[cell2_idx].z * map_tectonic_scale - local cell1_dist = lib_mg_continental.get_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) - local cell1_edist = lib_mg_continental.get_euclid_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) - local cell2_dist = lib_mg_continental.get_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) - local cell2_edist = lib_mg_continental.get_euclid_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) + local cell1_dist = get_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) + local cell1_edist = get_euclid_distance({x=x,y=z}, {x=cell1_pos_x,y=cell1_pos_z}) + local cell2_dist = get_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) + local cell2_edist = get_euclid_distance({x=x,y=z}, {x=cell2_pos_x,y=cell2_pos_z}) if cell1_dist == cell2_dist then ntectonic_idx = 0 @@ -625,17 +1294,18 @@ minetest.register_on_generated(function(minp, maxp, seed) end end end +--]] end --NODE PLACEMENT FROM HEIGHTMAP - +--[[ if y < (theight - (fill_depth + top_depth)) then data[ivm] = c_stone write = true elseif y >= (theight - (fill_depth + top_depth)) and y < (theight - top_depth) then --math.ceil(nobj_terrain[index2d]) data[ivm] = c_dirt write = true - elseif y >= (theight - top_depth) and y <= theight then --math.ceil(nobj_terrain[index2d]) + elseif y >= (theight - top_depth) and y <= (theight + 1) then --math.ceil(nobj_terrain[index2d]) data[ivm] = c_top write = true elseif y > theight and y <= 1 then @@ -645,6 +1315,18 @@ minetest.register_on_generated(function(minp, maxp, seed) data[ivm] = c_air write = true end +--]] + if y < theight then + data[ivm] = c_stone + write = true + elseif y > theight and y <= 1 then + data[ivm] = c_water + write = true + else + data[ivm] = c_air + write = true + end + end @@ -679,7 +1361,7 @@ minetest.register_on_generated(function(minp, maxp, seed) -- Print generation time of this mapchunk. local chugent = math.ceil((os.clock() - t0) * 1000) - print ("[lib_mg_continental] Mapchunk generation time " .. chugent .. " ms") + print ("[lib_mg_continental_mg_custom_biomes] Mapchunk generation time " .. chugent .. " ms") table.insert(mapgen_times.noisemaps, 0) table.insert(mapgen_times.preparation, t1 - t0) @@ -691,7 +1373,7 @@ minetest.register_on_generated(function(minp, maxp, seed) -- Deal with memory issues. This, of course, is supposed to be automatic. local mem = math.floor(collectgarbage("count")/1024) if mem > 1000 then - print("lib_mg_continental is manually collecting garbage as memory use has exceeded 500K.") + print("lib_mg_continental_mg_custom_biomes is manually collecting garbage as memory use has exceeded 500K.") collectgarbage("collect") end end) @@ -716,7 +1398,7 @@ minetest.register_on_shutdown(function() end local average, standard_dev - minetest.log("lib_mg_continental lua Mapgen Times:") + minetest.log("lib_mg_continental_mg_custom_biomes lua Mapgen Times:") average = mean(mapgen_times.liquid_lighting) minetest.log(" liquid_lighting: - - - - - - - - - - - - "..average) @@ -736,15 +1418,15 @@ minetest.register_on_shutdown(function() average = mean(mapgen_times.writing) minetest.log(" writing: - - - - - - - - - - - - - - - - "..average) end) - +-- minetest.register_on_newplayer(function(obj) local nobj_terrain = minetest.get_perlin_map(np_terrain, {x=1,y=1,z=0}) local th=nobj_terrain:get_2d_map({x=1,y=1}) local height = 0 - local ntect_idx = lib_mg_continental.mg_custom_data.base_tectonicmap[0][0].closest_idx - local ntect_dist = lib_mg_continental.mg_custom_data.base_tectonicmap[0][0].closest_dist + local ntect_idx = mg_custom_data.base_tectonicmap[0][0].closest_idx + local ntect_dist = mg_custom_data.base_tectonicmap[0][0].closest_dist if ntect_dist == 0 then ntect_dist = 1 @@ -755,6 +1437,6 @@ minetest.register_on_newplayer(function(obj) return true end) - +-- diff --git a/mod.conf b/mod.conf index bbfbd7e..6c7f63e 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = lib_mg_continental description = Configurable mapgen mod with built in biome support. Contains multiple lua mapgens. Carpathian, Islands, Valleys, burli, lvm_example, and others. depends = -optional_depends = lib_materials,lib_ecology,lib_voronoi \ No newline at end of file +optional_depends = lib_materials,lib_ecology,lib_voronoi,default, \ No newline at end of file