From 25a7fabed83caccb2c321bb4d080c5907f37b60a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 6 Feb 2011 16:35:27 +0200 Subject: mapgen tweaking --- src/map.cpp | 265 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 214 insertions(+), 51 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index e748b1433..ef6263c73 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1736,7 +1736,7 @@ ServerMap::ServerMap(std::string savedir): //m_chunksize = 64; //m_chunksize = 16; // Too slow - m_chunksize = 8; // Fine. Takes a few seconds. + m_chunksize = 8; // Takes a few seconds //m_chunksize = 4; //m_chunksize = 2; @@ -1973,22 +1973,22 @@ double tree_amount_2d(u64 seed, v2s16 p) { double noise = noise2d_perlin( 0.5+(float)p.X/250, 0.5+(float)p.Y/250, - seed+2, 4, 0.6); - double zeroval = -0.3; + seed+2, 5, 0.6); + double zeroval = -0.4; if(noise < zeroval) return 0; else return 0.04 * (noise-zeroval) / (1.0-zeroval); } -double base_rock_level_2d(u64 seed, v2s16 p) +/*double base_rock_level_2d(u64 seed, v2s16 p) { return WATER_LEVEL - 6.0 + 25. * noise2d_perlin( 0.5+(float)p.X/500., 0.5+(float)p.Y/500., seed, 6, 0.6); -} +}*/ -double highlands_level_2d(u64 seed, v2s16 p) +/*double highlands_level_2d(u64 seed, v2s16 p) { double a = noise2d_perlin( 0.5+(float)p.X/1000., 0.5+(float)p.Y/1000., @@ -1996,12 +1996,53 @@ double highlands_level_2d(u64 seed, v2s16 p) if(a > 0.0) //if(1) { + return WATER_LEVEL + 25; return WATER_LEVEL + 55. * noise2d_perlin( 0.5+(float)p.X/500., 0.5+(float)p.Y/500., seed+85039, 6, 0.69); } else return -100000; +}*/ + +double base_rock_level_2d(u64 seed, v2s16 p) +{ + // The base ground level + double base = WATER_LEVEL - 4.0 + 25. * noise2d_perlin( + 0.5+(float)p.X/500., 0.5+(float)p.Y/500., + seed, 6, 0.6); + + // Higher ground level + double higher = WATER_LEVEL + 23. + 30. * noise2d_perlin( + 0.5+(float)p.X/500., 0.5+(float)p.Y/500., + seed+85039, 6, 0.69); + //higher = 30; // For debugging + + // Limit higher to at least base + if(higher < base) + higher = base; + + // Steepness factor of cliffs + double b = 1.0 + 1.0 * noise2d_perlin( + 0.5+(float)p.X/250., 0.5+(float)p.Y/250., + seed-932, 7, 0.7); + b = rangelim(b, 0.0, 1000.0); + // Make steep stuff very steep and non-steep stuff very non-steep + b = pow(b, 4); + b *= 10; + //double b = 20; + + // High/low selector + double a = 0.5 + b * noise2d_perlin( + 0.5+(float)p.X/500., 0.5+(float)p.Y/500., + seed-359, 6, 0.7); + a = rangelim(a, 0.0, 1.0); + + //dstream<<"a="< surface_y_f) surface_y_f = a; - } + }*/ // Convert to integer s16 surface_y = (s16)surface_y_f; @@ -2208,20 +2249,20 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, Randomize some parameters */ - //TODO s32 stone_obstacle_count = 0; - /*s32 stone_obstacle_count = (1.0+noise2d(m_seed+90443, sectorpos_base.X, - sectorpos_base.Y))/2.0 * stone_obstacle_amount/3;*/ + /*s32 stone_obstacle_count = + rangelim((1.0+noise2d(m_seed+897, + sectorpos_base.X, sectorpos_base.Y))/2.0 * 30, 0, 100000);*/ s16 stone_obstacle_max_height = 0; - - //u32 stone_obstacle_amount = - // myrand_range(0, myrand_range(20, myrand_range(80,150))); + /*s16 stone_obstacle_max_height = + rangelim((1.0+noise2d(m_seed+5902, + sectorpos_base.X, sectorpos_base.Y))/2.0 * 30, 0, 100000);*/ /* Loop this part, it will make stuff look older and newer nicely */ - + //for(u32 i_age=0; i_age<1; i_age++) for(u32 i_age=0; i_age<2; i_age++) { // Aging loop @@ -2238,7 +2279,8 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, // Randomize max height so usually stuff will be quite low s16 maxheight_randomized = myrand_range(0, stone_obstacle_max_height); - s16 stone_obstacle_max_size = sectorpos_base_size * MAP_BLOCKSIZE - 10; + //s16 stone_obstacle_max_size = sectorpos_base_size * MAP_BLOCKSIZE - 10; + s16 stone_obstacle_max_size = MAP_BLOCKSIZE*4-4; v3s16 ob_size( myrand_range(5, stone_obstacle_max_size), @@ -2371,11 +2413,15 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, if(bruise_surface) { - //min_tunnel_diameter = 5; - //max_tunnel_diameter = myrand_range(10, 20); - min_tunnel_diameter = MYMAX(0, stone_surface_max_y/6); - max_tunnel_diameter = myrand_range(MYMAX(0, stone_surface_max_y/6), MYMAX(0, stone_surface_max_y/4)); - tunnel_routepoints = 3; + min_tunnel_diameter = 5; + max_tunnel_diameter = myrand_range(10, 20); + /*min_tunnel_diameter = MYMAX(0, stone_surface_max_y/6); + max_tunnel_diameter = myrand_range(MYMAX(0, stone_surface_max_y/6), MYMAX(0, stone_surface_max_y/2));*/ + + /*s16 tunnel_rou = rangelim(25*(0.5+1.0*noise2d(m_seed+42, + sectorpos_base.X, sectorpos_base.Y)), 0, 15);*/ + + tunnel_routepoints = 5; } // Allowed route area size in nodes @@ -2441,11 +2487,16 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, for(u16 j=0; j light_sources; { // 750ms @cs=8, can't optimize more - //TimeTaker timer1("initial lighting"); + TimeTaker timer1("initial lighting"); #if 0 /* @@ -3209,6 +3255,81 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, { light_sources.insert(v3s16(p2d.X, y, p2d.Y), true); } + //NOTE: This is broken, at least the index has to + // be incremented + } + } + } +#endif + +#if 1 + /* + Go through the edges and apply sunlight to them, not caring + about neighbors + */ + + // Four edges + for(s16 i=0; i<4; i++) + // Edge length + for(s16 j=lighting_min_d; + j<=lighting_max_d; + j++) + { + s16 x; + s16 z; + // +-X + if(i == 0 || i == 1) + { + x = (i==0) ? lighting_min_d : lighting_max_d; + if(i == 0) + z = lighting_min_d; + else + z = lighting_max_d; + } + // +-Z + else + { + z = (i==0) ? lighting_min_d : lighting_max_d; + if(i == 0) + x = lighting_min_d; + else + x = lighting_max_d; + } + + // Node position in 2d + v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z); + + // Loop from top to down + { + u8 light = LIGHT_SUN; + v3s16 em = vmanip.m_area.getExtent(); + s16 y_start = y_nodes_max; + u32 i = vmanip.m_area.index(v3s16(p2d.X, y_start, p2d.Y)); + for(s16 y=y_start; y>=y_nodes_min; y--) + { + MapNode *n = &vmanip.m_data[i]; + if(light_propagates_content(n->d) == false) + { + light = 0; + } + else if(light != LIGHT_SUN + || sunlight_propagates_content(n->d) == false) + { + if(light > 0) + light--; + } + + n->setLight(LIGHTBANK_DAY, light); + n->setLight(LIGHTBANK_NIGHT, 0); + + if(light != 0) + { + // Insert light source + light_sources.insert(v3s16(p2d.X, y, p2d.Y), true); + } + + // Increment index by y + vmanip.m_area.add_y(em, i, -1); } } } @@ -3222,7 +3343,7 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, for(s16 z=0-max_spread_amount+1; z=y_nodes_min; y--) + { + MapNode *n = &vmanip.m_data[i]; + + if(light_propagates_content(n->d) == false) + { + light = 0; + } + else if(light != LIGHT_SUN + || sunlight_propagates_content(n->d) == false) + { + if(light > 0) + light--; + } + + n->setLight(LIGHTBANK_DAY, light); + n->setLight(LIGHTBANK_NIGHT, 0); + + // This doesn't take much time + if(light != 0) + { + // Insert light source + light_sources.insert(v3s16(p2d.X, y, p2d.Y), true); + } + + // Increment index by y + vmanip.m_area.add_y(em, i, -1); + } + } + } +#endif }//timer1 @@ -4006,7 +4179,7 @@ continue_generating: /* Add coal */ - u16 coal_amount = 30.0 * g_settings.getFloat("coal_amount"); + u16 coal_amount = 30; u16 coal_rareness = 60 / coal_amount; if(coal_rareness == 0) coal_rareness = 1; @@ -4039,7 +4212,7 @@ continue_generating: Add iron */ //TODO: change to iron_amount or whatever - u16 iron_amount = 30.0 * g_settings.getFloat("coal_amount"); + u16 iron_amount = 15; u16 iron_rareness = 60 / iron_amount; if(iron_rareness == 0) iron_rareness = 1; @@ -4286,16 +4459,6 @@ MapBlock * ServerMap::emergeBlock( } } - /* - Debug mode operation - */ - bool haxmode = g_settings.getBool("haxmode"); - if(haxmode) - { - // Don't calculate lighting at all - //lighting_invalidated_blocks.clear(); - } - return block; } -- cgit v1.2.3