From: Perttu Ahola Date: Wed, 2 Mar 2011 00:00:11 +0000 (+0200) Subject: mapgen work-in-progress X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=2e7b15fed37e6e81844b3cac0e37671ff3a8b4da;p=zefram%2Fminetest%2Fminetest_engine.git mapgen work-in-progress --- diff --git a/data/water.png b/data/water.png index a304059e..785a9585 100644 Binary files a/data/water.png and b/data/water.png differ diff --git a/src/client.cpp b/src/client.cpp index fe1669dd..cede0af8 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -510,10 +510,13 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) assert(player != NULL); player->setPosition(playerpos_f); } - - // Get map seed - m_map_seed = readU64(&data[2+1+6]); - dstream<<"Client: received map seed: "<= 2+1+6+8) + { + // Get map seed + m_map_seed = readU64(&data[2+1+6]); + dstream<<"Client: received map seed: "<getMapSeed(), pf)) +#if 0 + else if(get_have_sand_ground(client->getMapSeed(), pf) + || (h < WATER_LEVEL + 2 + && get_have_sand_coast(client->getMapSeed(), pf))) + { + h -= WATER_LEVEL; + h /= 50.0; + h = 1.0 - exp(-h); + + video::SColor c1(255,237,201,175); + //video::SColor c2(255,20,20,20); + video::SColor c2(255,150,0,0); + c = c2.getInterpolated(c1, h); + } + else + { + h -= WATER_LEVEL; + h /= 50.0; + h = 1.0 - exp(-h); + + video::SColor c1(255,110,185,90); + //video::SColor c2(255,20,20,20); + video::SColor c2(255,150,0,0); + c = c2.getInterpolated(c1, h); + } +#endif +#if 1 +#if 0 + else if(get_have_sand_ground(client->getMapSeed(), pf)) + { + h -= WATER_LEVEL; + h /= 20.0; + h = 1.0 - exp(-h); + + video::SColor c1(255,237,201,175); + //video::SColor c2(255,20,20,20); + video::SColor c2(255,150,0,0); + c = c2.getInterpolated(c1, h); + } +#endif + // Sand + else if(h < WATER_LEVEL + 2 + && get_have_sand_coast(client->getMapSeed(), pf)) c.set(255, 237, 201, 175); #if 1 else if(h < WATER_LEVEL + 10) @@ -1325,14 +1366,7 @@ void updateMapPlotTexture(v2f centerpos, video::IVideoDriver* driver, else c.set(255, 255, 255, 255); // White #endif - /*else if(h < WATER_LEVEL + d1) - { - h -= WATER_LEVEL; - u32 a = (u32)(h / d1 * 255); - if(a > 255) - a = 255; - c.set(255, 0, a, 0); - }*/ +#endif #if 0 else { @@ -1350,6 +1384,22 @@ void updateMapPlotTexture(v2f centerpos, video::IVideoDriver* driver, a = 255-a; c.set(255, a, a, a);*/ } +#endif +#if 1 + if(h >= WATER_LEVEL - 0.5 + && get_have_sand_ground(client->getMapSeed(), pf)) + { + video::SColor c1(255,237,201,175); + c = c.getInterpolated(c1, 0.5); + } +#endif +#if 1 + double tf = get_turbulence_factor_2d(client->getMapSeed(), pf); + if(tf > 0.001) + { + video::SColor c1(255,255,0,0); + c = c.getInterpolated(c1, 1.0-(0.5*tf)); + } #endif img->setPixel(x, y, c); } @@ -2911,7 +2961,7 @@ int main(int argc, char *argv[]) driver->setFog( bgcolor, video::EFT_FOG_LINEAR, - range*0.6, + range*0.4, range*1.0, 0.01, false, // pixel fog diff --git a/src/map.cpp b/src/map.cpp index d48003d4..6e1a62ca 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1952,12 +1952,12 @@ 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, 5, 0.66); - double zeroval = -0.3; + seed+2, 5, 0.7); + double zeroval = -0.4; if(noise < zeroval) return 0; else - return 0.04 * (noise-zeroval) / (1.0-zeroval); + return 0.025 * (noise-zeroval) / (1.0-zeroval); } #define AVERAGE_MUD_AMOUNT 4.0 @@ -1969,12 +1969,20 @@ double get_mud_amount(u64 seed, v2f p) seed+1, 5, 0.65)); } -bool get_have_sand(u64 seed, v2f p) +bool get_have_sand_coast(u64 seed, v2f p) { double sandnoise = noise2d_perlin( - 0.5+(float)p.X/500, 0.5+(float)p.Y/500, + 0.5+(float)p.X/250, 0.5+(float)p.Y/250, seed+59420, 3, 0.50); - return (sandnoise > -0.15); + return (sandnoise > -0.25); +} + +bool get_have_sand_ground(u64 seed, v2f p) +{ + double sandnoise = noise2d_perlin( + 0.5+(float)p.X/500, 0.5+(float)p.Y/500, + seed+54290232, 6, 0.65); + return (sandnoise > 0.8); } // -1->0, 0->1, 1->0 @@ -2096,16 +2104,17 @@ double base_rock_level_2d(u64 seed, v2f p) #endif /* - The sutff before this comment is usually not used. + The stuff before this comment is usually not used. The stuff after this comment is usually used. */ #if 1 { - // Pretty neat looking mountains - double m4 = 100.0 - 400.0 * noise2d_perlin_abs( + // Mountains + double m4 = 1.0 - 3.0 * noise2d_perlin_abs( 0.324+(float)p.X/2000., 0.423+(float)p.Y/2000., - (seed>>32)+65012102, 7, 0.6); + (seed>>32)+65012102, 9, 0.57); + m4 *= 120; if(m4 > h) h = m4; } @@ -2114,9 +2123,10 @@ double base_rock_level_2d(u64 seed, v2f p) #if 1 // Some kind of hill chains or something { - double a1 = 30 - 130. * noise2d_perlin_abs( - 0.5+(float)p.X/500., 0.5+(float)p.Y/500., - seed+850342, 6, 0.63); + double a1 = 1.0 - 2.5 * noise2d_perlin_abs( + 0.5+(float)p.X/250., 0.5+(float)p.Y/250., + seed+850342, 5, 0.6); + a1 *= 30; double d = 15; if(a1 > d) a1 = d + sqrt(a1-d); @@ -2128,9 +2138,9 @@ double base_rock_level_2d(u64 seed, v2f p) #endif #if 1 - double base = -2. + 30. * noise2d_perlin( - 0.5+(float)p.X/1000., 0.5+(float)p.Y/1000., - (seed>>32)+653876, 7, 0.6); + double base = -2. + 25. * noise2d_perlin( + 0.5+(float)p.X/500., 0.5+(float)p.Y/500., + (seed>>32)+653876, 7, 0.65); #else double base = 0; #endif @@ -2139,6 +2149,8 @@ double base_rock_level_2d(u64 seed, v2f p) /* Combined with turbulence, this thing here is able to make very awesome terrain, albeit rarely. + + This is also responsible for small islands. */ double higher = 40. * noise2d_perlin( @@ -2212,16 +2224,68 @@ double base_rock_level_2d(u64 seed, v2s16 p) return base_rock_level_2d(seed, v2f((float)p.X, (float)p.Y)); } +double get_turbulence_factor_2d(u64 seed, v2f p) +{ + double vv = -0.50 + 2.0 * noise2d_perlin( + 0.5+p.X/100, + 0.5+p.Y/100, + seed+85498783983, 4, 0.5); + vv = rangelim(vv, 0.0, 1.0); + return vv; +} + +#define TURBULENCE_BOTTOM_CUTOFF_Y (WATER_LEVEL-7) + +double get_turbulence_factor_y(u64 seed, f32 y) +{ + double d = 14; + double min = TURBULENCE_BOTTOM_CUTOFF_Y; + if(y < min) + return 0.0; + else if(y < min + d) + return ((y-min)/d); + return 1.0; +} + +v2f get_raw_turbulence(u64 seed, v3f p) +{ + double f = 8; + + double v1 = f * noise3d_perlin( + 0.5+p.X/100, + 0.5+p.Y/100, + 0.5+p.Z/100, + seed+4045, 5, 0.65); + + double v2 = f * noise3d_perlin( + 0.5+p.X/100, + 0.5+p.Y/100, + 0.5+p.Z/100, + seed+9495, 5, 0.65); + + return v2f(v1, v2); +} + +// Shouldn't be used, provided for compatibility. +v2f base_ground_turbulence(u64 seed, v3f p) +{ + double tfxz = get_turbulence_factor_2d(seed, v2f(p.X,p.Z)); + double tfy = get_turbulence_factor_y(seed, p.Y); + v2f t = get_raw_turbulence(seed, p); + return t*tfxz*tfy; +} + +#if 0 v2f base_ground_turbulence(u64 seed, v3f p) { #if 1 - double f = 20; + double f = 8; #if 1 // Cut off at a minimum height { - double d = 5; - double min = WATER_LEVEL; + double d = 15; + double min = WATER_LEVEL-5; if(p.Y < min) return v2f(0,0); else if(p.Y < min + d) @@ -2230,7 +2294,7 @@ v2f base_ground_turbulence(u64 seed, v3f p) #endif #if 1 - double vv = 0.75 + 1.0 * noise3d_perlin( + double vv = 0.50 + 1.0 * noise3d_perlin( 0.5+p.X/250, 0.5+p.Y/250, 0.5+p.Z/250, @@ -2250,7 +2314,7 @@ v2f base_ground_turbulence(u64 seed, v3f p) vve = (1.-a) * vve;*/ // Increase turbulence in elevated heights - double ah = WATER_LEVEL + 40; + double ah = WATER_LEVEL + 30; if(p.Y > ah) { vve *= p.Y/ah; @@ -2260,22 +2324,23 @@ v2f base_ground_turbulence(u64 seed, v3f p) #endif double v1 = f * noise3d_perlin( - 0.5+p.X/200, - 0.5+p.Y/200, - 0.5+p.Z/200, - seed+4045, 6, 0.7); + 0.5+p.X/100, + 0.5+p.Y/100, + 0.5+p.Z/100, + seed+4045, 5, 0.65); double v2 = f * noise3d_perlin( - 0.5+p.X/200, - 0.5+p.Y/200, - 0.5+p.Z/200, - seed+9495, 6, 0.7); + 0.5+p.X/100, + 0.5+p.Y/100, + 0.5+p.Z/100, + seed+9495, 5, 0.65); return v2f(v1*vve, v2*vve); #else return v2f(0,0); #endif } +#endif bool is_carved(u64 seed, v3f p) { @@ -2426,6 +2491,7 @@ bool is_base_ground(u64 seed, v3f p, double *depth_guess=NULL) This is the main map generation method */ +#if 0 MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, core::map &changed_blocks, bool force) @@ -3531,7 +3597,7 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z); // Determine whether to have sand here - bool have_sand = get_have_sand(p2d); + bool have_sand = get_have_sand_coast(p2d); if(have_sand == false) continue; @@ -4005,147 +4071,851 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, */ return chunk; } +#endif -MapChunk* ServerMap::generateChunk(v2s16 chunkpos1, - core::map &changed_blocks) +MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, + core::map &changed_blocks, + bool force) { - dstream<<"generateChunk(): Generating chunk " - <<"("<getGenLevel() == GENERATED_FULLY) - continue; - generateChunkRaw(chunkpos0, changed_blocks); - } - - assert(chunkNonVolatile(chunkpos1)); + DSTACK(__FUNCTION_NAME); - MapChunk *chunk = getChunk(chunkpos1); - return chunk; -} -ServerMapSector * ServerMap::createSector(v2s16 p2d) -{ - DSTACK("%s: p2d=(%d,%d)", - __FUNCTION_NAME, - p2d.X, p2d.Y); - - /* - Check if it exists already in memory - */ - ServerMapSector *sector = (ServerMapSector*)getSectorNoGenerateNoEx(p2d); - if(sector != NULL) - return sector; - /* - Try to load it from disk (with blocks) + Don't generate if already fully generated */ - if(loadSectorFull(p2d) == true) + if(force == false) { - ServerMapSector *sector = (ServerMapSector*)getSectorNoGenerateNoEx(p2d); - if(sector == NULL) + MapChunk *chunk = getChunk(chunkpos); + if(chunk != NULL && chunk->getGenLevel() == GENERATED_FULLY) { - dstream<<"ServerMap::createSector(): loadSectorFull didn't make a sector"< MAP_GENERATION_LIMIT / MAP_BLOCKSIZE - || p2d.Y < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE - || p2d.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE) - throw InvalidPositionException("createSector(): pos. over limit"); - - /* - Generate blank sector - */ + dstream<<"generateChunkRaw(): Generating chunk " + <<"("< &changed_blocks) -{ - DSTACK("%s: p2d=(%d,%d)", - __FUNCTION_NAME, - p2d.X, p2d.Y); + v2s16 sectorpos_base = chunk_to_sector(chunkpos); + s16 sectorpos_base_size = m_chunksize; + + /*v2s16 sectorpos_bigbase = chunk_to_sector(chunkpos - v2s16(1,1)); + s16 sectorpos_bigbase_size = m_chunksize * 3;*/ + v2s16 sectorpos_bigbase = + sectorpos_base - v2s16(1,1) * max_spread_amount_sectors; + s16 sectorpos_bigbase_size = + sectorpos_base_size + 2 * max_spread_amount_sectors; + + v3s16 bigarea_blocks_min( + sectorpos_bigbase.X, + y_blocks_min, + sectorpos_bigbase.Y + ); + + v3s16 bigarea_blocks_max( + sectorpos_bigbase.X + sectorpos_bigbase_size - 1, + y_blocks_max, + sectorpos_bigbase.Y + sectorpos_bigbase_size - 1 + ); + // Relative values to control amount of stuff in one chunk + /*u32 relative_area = (u32)sectorpos_base_size*MAP_BLOCKSIZE + *(u32)sectorpos_base_size*MAP_BLOCKSIZE;*/ + /*u32 relative_volume = (u32)sectorpos_base_size*MAP_BLOCKSIZE + *(u32)sectorpos_base_size*MAP_BLOCKSIZE + *(u32)h_blocks*MAP_BLOCKSIZE;*/ + /* - Check chunk status + The limiting edges of the lighting update, inclusive. */ - v2s16 chunkpos = sector_to_chunk(p2d); - /*bool chunk_nonvolatile = false; - MapChunk *chunk = getChunk(chunkpos); - if(chunk && chunk->getIsVolatile() == false) - chunk_nonvolatile = true;*/ - bool chunk_nonvolatile = chunkNonVolatile(chunkpos); + s16 lighting_min_d = 0-max_spread_amount; + s16 lighting_max_d = sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1; /* - If chunk is not fully generated, generate chunk + Create the whole area of this and the neighboring chunks */ - if(chunk_nonvolatile == false) { - // Generate chunk and neighbors - generateChunk(chunkpos, changed_blocks); + TimeTaker timer("generateChunkRaw() create area"); + + for(s16 x=0; xsetLightingExpired(true); + // Lighting will be calculated + block->setLightingExpired(false); + + /* + Block gets sunlight if this is true. + + This should be set to true when the top side of a block + is completely exposed to the sky. + + Actually this doesn't matter now because the + initial lighting is done here. + */ + block->setIsUnderground(y != y_blocks_max); + } + } } /* - Return sector if it exists now - */ - MapSector *sector = getSectorNoGenerateNoEx(p2d); - if(sector != NULL) - return sector; - - /* - Try to load it from disk + Now we have a big empty area. + + Make a ManualMapVoxelManipulator that contains this and the + neighboring chunks */ - if(loadSectorFull(p2d) == true) + + ManualMapVoxelManipulator vmanip(this); + // Add the area we just generated { - MapSector *sector = getSectorNoGenerateNoEx(p2d); - if(sector == NULL) - { - dstream<<"ServerMap::emergeSector(): loadSectorFull didn't make a sector"< 0.001); + + s16 surface_y = 0; + + float noturb_surface_y_f = base_rock_level_2d(m_seed, p2df); + s16 noturb_surface_y = noturb_surface_y_f; + + { + s16 depth_counter = 0; + s16 min = y_nodes_min; + s16 max = y_nodes_max; + // Use fast index incrementing + v3s16 em = vmanip.m_area.getExtent(); + u32 i = vmanip.m_area.index(v3s16(p2d.X, max, p2d.Y)); + for(s16 y=max; y>=min; y--) + { + v3f p3df(p2df.X, y, p2df.Y); + + bool is_ground = false; + + bool turb_for_node = (turbulence_is_used + && y >= TURBULENCE_BOTTOM_CUTOFF_Y); + + if(is_carved(m_seed, p3df)) + { + is_ground = false; + } + else + { + if(turb_for_node) + { + double depth_guess; + is_ground = is_base_ground(m_seed, + p3df, &depth_guess); + + // Estimate the surface height + surface_y = y + depth_guess; + } + else + { + surface_y = noturb_surface_y; + } + + is_ground = (y <= surface_y); + } + + if(is_ground) + { + //vmanip.m_data[i].d = CONTENT_STONE; + /*if(y > surface_y - mud_amount) + vmanip.m_data[i].d = CONTENT_MUD; + else + vmanip.m_data[i].d = CONTENT_STONE;*/ + if(depth_counter < mud_amount) + vmanip.m_data[i].d = CONTENT_MUD; + else + vmanip.m_data[i].d = CONTENT_STONE; + } + else + vmanip.m_data[i].d = CONTENT_AIR; + + if(is_ground || depth_counter != 0) + depth_counter++; + +#if 0 +#if 1 + bool is = is_base_ground(m_seed, v3f(p2df.X,y,p2df.Y)); + if(is) + vmanip.m_data[i].d = CONTENT_STONE; + else + vmanip.m_data[i].d = CONTENT_AIR; +#endif +#endif + + vmanip.m_area.add_y(em, i, -1); + } + } + } + + }//timer1 + + { + // 50ms @cs=8 + //TimeTaker timer1("add water"); + + /* + Add water to the central chunk (and a bit more) + */ + + for(s16 x=0-max_spread_amount; + x WATER_LEVEL) + continue;*/ + + /* + Add water on ground + */ + { + v3s16 em = vmanip.m_area.getExtent(); + u8 light = LIGHT_MAX; + // Start at global water surface level + s16 y_start = WATER_LEVEL; + u32 i = vmanip.m_area.index(v3s16(p2d.X, y_start, p2d.Y)); + MapNode *n = &vmanip.m_data[i]; + + /*// Add first one to transforming liquid queue, if water + if(n->d == CONTENT_WATER || n->d == CONTENT_WATERSOURCE) + { + v3s16 p = v3s16(p2d.X, y_start, p2d.Y); + m_transforming_liquid.push_back(p); + }*/ + + for(s16 y=y_start; y>=y_nodes_min; y--) + { + n = &vmanip.m_data[i]; + + // Stop when there is no water and no air + if(n->d != CONTENT_AIR && n->d != CONTENT_WATERSOURCE + && n->d != CONTENT_WATER) + { + /*// Add bottom one to transforming liquid queue + vmanip.m_area.add_y(em, i, 1); + n = &vmanip.m_data[i]; + if(n->d == CONTENT_WATER || n->d == CONTENT_WATERSOURCE) + { + v3s16 p = v3s16(p2d.X, y, p2d.Y); + m_transforming_liquid.push_back(p); + }*/ + + break; + } + + // Make water only not in dungeons + if(!(vmanip.m_flags[i]&VMANIP_FLAG_DUNGEON)) + { + n->d = CONTENT_WATERSOURCE; + //n->setLight(LIGHTBANK_DAY, light); + + // Add to transforming liquid queue (in case it'd + // start flowing) + v3s16 p = v3s16(p2d.X, y, p2d.Y); + m_transforming_liquid.push_back(p); + } + + // Next one + vmanip.m_area.add_y(em, i, -1); + if(light > 0) + light--; + } + } + + } + + }//timer1 + + { + //TimeTaker timer1("convert mud to sand"); + + /* + Convert mud to sand + */ + + //s16 mud_add_amount = myrand_range(2, 4); + //s16 mud_add_amount = 0; + + /*for(s16 x=0; x WATER_LEVEL + 2) + continue; + + { + v3s16 em = vmanip.m_area.getExtent(); + s16 y_start = surface_y; + u32 i = vmanip.m_area.index(v3s16(p2d.X, y_start, p2d.Y)); + u32 not_sand_counter = 0; + for(s16 y=y_start; y>=y_nodes_min; y--) + { + MapNode *n = &vmanip.m_data[i]; + if(n->d == CONTENT_MUD || n->d == CONTENT_GRASS) + { + n->d = CONTENT_SAND; + } + else + { + not_sand_counter++; + if(not_sand_counter > 3) + break; + } + + vmanip.m_area.add_y(em, i, -1); + } + } + + } + + }//timer1 + + { + // 19ms @cs=8 + //TimeTaker timer1("grow grass"); + + /* + Grow grass + */ + + /*for(s16 x=0-4; x=y_nodes_min; y--) + { + MapNode &n = vmanip.m_data[i]; + if(n.d != CONTENT_AIR + && n.d != CONTENT_LEAVES) + break; + vmanip.m_area.add_y(em, i, -1); + } + if(y >= y_nodes_min) + surface_y = y; + else + surface_y = y_nodes_min; + } + + u32 i = vmanip.m_area.index(p2d.X, surface_y, p2d.Y); + MapNode *n = &vmanip.m_data[i]; + if(n->d == CONTENT_MUD) + n->d = CONTENT_GRASS; + } + + }//timer1 + + { + // 1ms @cs=8 + //TimeTaker timer1("generate trees"); + + /* + Generate some trees + */ + { + // Divide area into parts + s16 div = 8; + s16 sidelen = sectorpos_base_size*MAP_BLOCKSIZE / div; + double area = sidelen * sidelen; + for(s16 x0=0; x0d != CONTENT_MUD && n->d != CONTENT_GRASS) + continue; + } + p.Y++; + // Make a tree + make_tree(vmanip, p); + } + } + /*u32 tree_max = relative_area / 60; + //u32 count = myrand_range(0, tree_max); + for(u32 i=0; i light_sources; + + { + // 750ms @cs=8, can't optimize more + TimeTaker timer1("initial lighting"); + +#if 1 + /* + This has to be 1 smaller than the actual area, because + neighboring nodes are checked. + */ + for(s16 x=lighting_min_d+1; + x<=lighting_max_d-1; + x++) + for(s16 z=lighting_min_d+1; + z<=lighting_max_d-1; + z++) + { + // Node position in 2d + v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z); + + /* + Apply initial sunlight + */ + { + u8 light = LIGHT_SUN; + bool add_to_sources = false; + 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--; + } + + // This doesn't take much time + if(add_to_sources == false) + { + /* + Check sides. If side is not air or water, start + adding to light_sources. + */ + v3s16 dirs4[4] = { + v3s16(0,0,1), // back + v3s16(1,0,0), // right + v3s16(0,0,-1), // front + v3s16(-1,0,0), // left + }; + for(u32 di=0; di<4; di++) + { + v3s16 dirp = dirs4[di]; + u32 i2 = i; + vmanip.m_area.add_p(em, i2, dirp); + MapNode *n2 = &vmanip.m_data[i2]; + if( + n2->d != CONTENT_AIR + && n2->d != CONTENT_WATERSOURCE + && n2->d != CONTENT_WATER + ){ + add_to_sources = true; + break; + } + } + } + + n->setLight(LIGHTBANK_DAY, light); + n->setLight(LIGHTBANK_NIGHT, 0); + + // This doesn't take much time + if(light != 0 && add_to_sources) + { + // 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 + + // Spread light around + { + TimeTaker timer("generateChunkRaw() spreadLight"); + vmanip.spreadLight(LIGHTBANK_DAY, light_sources); + } + + /* + Generation ended + */ + + timer_generate.stop(); + + /* + Blit generated stuff to map + */ + { + // 70ms @cs=8 + //TimeTaker timer("generateChunkRaw() blitBackAll"); + vmanip.blitBackAll(&changed_blocks); + } + + /* + Update day/night difference cache of the MapBlocks + */ + { + for(core::map::Iterator i = changed_blocks.getIterator(); + i.atEnd() == false; i++) + { + MapBlock *block = i.getNode()->getValue(); + block->updateDayNightDiff(); + } + } + + + /* + Create chunk metadata + */ + + for(s16 x=-1; x<=1; x++) + for(s16 y=-1; y<=1; y++) + { + v2s16 chunkpos0 = chunkpos + v2s16(x,y); + // Add chunk meta information + MapChunk *chunk = getChunk(chunkpos0); + if(chunk == NULL) + { + chunk = new MapChunk(); + m_chunks.insert(chunkpos0, chunk); + } + //chunk->setIsVolatile(true); + if(chunk->getGenLevel() > GENERATED_PARTLY) + chunk->setGenLevel(GENERATED_PARTLY); + } + + /* + Set central chunk non-volatile + */ + MapChunk *chunk = getChunk(chunkpos); + assert(chunk); + // Set non-volatile + //chunk->setIsVolatile(false); + chunk->setGenLevel(GENERATED_FULLY); + + /* + Save changed parts of map + */ + save(true); + + /* + Return central chunk (which was requested) + */ + return chunk; +} + + +MapChunk* ServerMap::generateChunk(v2s16 chunkpos1, + core::map &changed_blocks) +{ + dstream<<"generateChunk(): Generating chunk " + <<"("<getGenLevel() == GENERATED_FULLY) + continue; + generateChunkRaw(chunkpos0, changed_blocks); + } + + assert(chunkNonVolatile(chunkpos1)); + + MapChunk *chunk = getChunk(chunkpos1); + return chunk; +} + +ServerMapSector * ServerMap::createSector(v2s16 p2d) +{ + DSTACK("%s: p2d=(%d,%d)", + __FUNCTION_NAME, + p2d.X, p2d.Y); + + /* + Check if it exists already in memory + */ + ServerMapSector *sector = (ServerMapSector*)getSectorNoGenerateNoEx(p2d); + if(sector != NULL) + return sector; + + /* + Try to load it from disk (with blocks) + */ + if(loadSectorFull(p2d) == true) + { + ServerMapSector *sector = (ServerMapSector*)getSectorNoGenerateNoEx(p2d); + if(sector == NULL) + { + dstream<<"ServerMap::createSector(): loadSectorFull didn't make a sector"< MAP_GENERATION_LIMIT / MAP_BLOCKSIZE + || p2d.Y < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE + || p2d.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE) + throw InvalidPositionException("createSector(): pos. over limit"); + + /* + Generate blank sector + */ + + sector = new ServerMapSector(this, p2d); + + // Sector position on map in nodes + v2s16 nodepos2d = p2d * MAP_BLOCKSIZE; + + /* + Insert to container + */ + m_sectors.insert(p2d, sector); + + return sector; +} + +MapSector * ServerMap::emergeSector(v2s16 p2d, + core::map &changed_blocks) +{ + DSTACK("%s: p2d=(%d,%d)", + __FUNCTION_NAME, + p2d.X, p2d.Y); + + /* + Check chunk status + */ + v2s16 chunkpos = sector_to_chunk(p2d); + /*bool chunk_nonvolatile = false; + MapChunk *chunk = getChunk(chunkpos); + if(chunk && chunk->getIsVolatile() == false) + chunk_nonvolatile = true;*/ + bool chunk_nonvolatile = chunkNonVolatile(chunkpos); + + /* + If chunk is not fully generated, generate chunk + */ + if(chunk_nonvolatile == false) + { + // Generate chunk and neighbors + generateChunk(chunkpos, changed_blocks); + } + + /* + Return sector if it exists now + */ + MapSector *sector = getSectorNoGenerateNoEx(p2d); + if(sector != NULL) + return sector; + + /* + Try to load it from disk + */ + if(loadSectorFull(p2d) == true) + { + MapSector *sector = getSectorNoGenerateNoEx(p2d); + if(sector == NULL) + { + dstream<<"ServerMap::emergeSector(): loadSectorFull didn't make a sector"< 0.001); + + float surface_y_f = 0; + s16 surface_y = 0; + + if(turbulence_is_used == false) + { + surface_y_f = base_rock_level_2d(m_seed, real_p2d_f), + surface_y = surface_y_f; + + // Get some statistics of surface height + if(surface_y < lowest_ground_y) + lowest_ground_y = surface_y; + if(surface_y > highest_ground_y) + highest_ground_y = surface_y; + } for(s16 y0=0; y0 highest_ground_y) - highest_ground_y = surface_y; + if(turbulence_is_used) + { + double depth_guess; + is_ground = is_base_ground(m_seed, + real_pos_f, &depth_guess); + + // Estimate the surface height + surface_y_f = (float)real_y + depth_guess; + surface_y = real_y + depth_guess; + + // Get some statistics of surface height + if(surface_y < lowest_ground_y) + lowest_ground_y = surface_y; + if(surface_y > highest_ground_y) + highest_ground_y = surface_y; + } + else + { + if(is_carved(m_seed, real_pos_f)) + is_ground = false; + else + is_ground = (real_y <= surface_y); + } // If node is not ground, it's air or water if(is_ground == false) @@ -4395,8 +5195,11 @@ MapBlock * ServerMap::generateBlock( if(real_y < WATER_LEVEL) { n.d = water_material; + u8 dist = 16; + if(real_y >= surface_y) + dist = WATER_LEVEL-real_y+1; n.setLight(LIGHTBANK_DAY, - diminish_light(LIGHT_SUN, WATER_LEVEL-real_y+1)); + diminish_light(LIGHT_SUN, dist)); /* Add to transforming liquid queue (in case it'd start flowing) @@ -4419,7 +5222,7 @@ MapBlock * ServerMap::generateBlock( n.d = CONTENT_STONE; } else if(surface_y_f <= WATER_LEVEL + 2.1 - && get_have_sand(m_seed, real_pos_f_2d)) + && get_have_sand_coast(m_seed, real_p2d_f)) { n.d = CONTENT_SAND; } @@ -4435,8 +5238,11 @@ MapBlock * ServerMap::generateBlock( { n.d = CONTENT_GRASS; }*/ - - n.d = CONTENT_MUD; + + if(get_have_sand_ground(m_seed, real_p2d_f)) + n.d = CONTENT_SAND; + else + n.d = CONTENT_MUD; /*// If under water level, it's mud if(real_y < WATER_LEVEL) diff --git a/src/map.h b/src/map.h index 62df5646..da2e0fcb 100644 --- a/src/map.h +++ b/src/map.h @@ -45,7 +45,9 @@ with this program; if not, write to the Free Software Foundation, Inc., */ double base_rock_level_2d(u64 seed, v2f p); -bool get_have_sand(u64 seed, v2f p); +bool get_have_sand_coast(u64 seed, v2f p); +bool get_have_sand_ground(u64 seed, v2f p); +double get_turbulence_factor_2d(u64 seed, v2f p); /* */ diff --git a/src/noise.cpp b/src/noise.cpp index 06ef8a39..00772455 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -44,10 +44,10 @@ double linearInterpolation(double x0, double x1, double t){ } double biLinearInterpolation(double x0y0, double x1y0, double x0y1, double x1y1, double x, double y){ - /*double tx = easeCurve(x); - double ty = easeCurve(y);*/ - double tx = x; - double ty = y; + double tx = easeCurve(x); + double ty = easeCurve(y); + /*double tx = x; + double ty = y;*/ double u = linearInterpolation(x0y0,x1y0,tx); double v = linearInterpolation(x0y1,x1y1,tx); return linearInterpolation(u,v,ty); diff --git a/src/server.cpp b/src/server.cpp index db9c569e..61f35417 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3430,9 +3430,9 @@ Player *Server::emergePlayer(const char *name, const char *password, != m_env.getServerMap().sector_to_chunk(sectorpos+v2s16(-1,-1))) continue; } - // Get sector - m_env.getMap().emergeSector(sectorpos); - // Get ground height at point + // Get sector (NOTE: Don't get because it's slow) + //m_env.getMap().emergeSector(sectorpos); + // Get ground height at point (fallbacks to heightmap function) groundheight = m_env.getServerMap().findGroundLevel(nodepos); // Don't go underwater if(groundheight < WATER_LEVEL) @@ -3440,7 +3440,15 @@ Player *Server::emergePlayer(const char *name, const char *password, //dstream<<"-> Underwater"< WATER_LEVEL + 4) + { + //dstream<<"-> Underwater"<