- u32 i = vmanip.m_area.index(p);
- MapNode *n = &vmanip.m_data[i];
- if(n->d == CONTENT_STONE)
- n->param = mineral;
- }
- }
- }
- }
-
- orp = rp;
- }
-
- }
-
- }//timer1
- {
- // 15ms @cs=8
- //TimeTaker timer1("add mud");
-
- /*
- Add mud to the central chunk
- */
-
- for(s16 x=0; x<sectorpos_base_size*MAP_BLOCKSIZE; x++)
- for(s16 z=0; z<sectorpos_base_size*MAP_BLOCKSIZE; z++)
- {
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- // Randomize mud amount
- s16 mud_add_amount = get_mud_amount(m_seed, v2f(p2d.X,p2d.Y))/age_count;
-
- // Find ground level
- s16 surface_y = find_ground_level_clever(vmanip, p2d);
-
- /*
- If topmost node is grass, change it to mud.
- It might be if it was flown to there from a neighboring
- chunk and then converted.
- */
- {
- u32 i = vmanip.m_area.index(v3s16(p2d.X, surface_y, p2d.Y));
- MapNode *n = &vmanip.m_data[i];
- if(n->d == CONTENT_GRASS)
- n->d = CONTENT_MUD;
- }
-
- /*
- Add mud on ground
- */
- {
- s16 mudcount = 0;
- v3s16 em = vmanip.m_area.getExtent();
- s16 y_start = surface_y+1;
- u32 i = vmanip.m_area.index(v3s16(p2d.X, y_start, p2d.Y));
- for(s16 y=y_start; y<=y_nodes_max; y++)
- {
- if(mudcount >= mud_add_amount)
- break;
-
- MapNode &n = vmanip.m_data[i];
- n.d = CONTENT_MUD;
- mudcount++;
-
- vmanip.m_area.add_y(em, i, 1);
- }
- }
-
- }
-
- }//timer1
- {
- // 340ms @cs=8
- //TimeTaker timer1("flow mud");
-
- /*
- Flow mud away from steep edges
- */
-
- // Limit area by 1 because mud is flown into neighbors.
- s16 mudflow_minpos = 0-max_spread_amount+1;
- s16 mudflow_maxpos = sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-2;
-
- // Iterate a few times
- for(s16 k=0; k<3; k++)
- {
-
- for(s16 x=mudflow_minpos;
- x<=mudflow_maxpos;
- x++)
- for(s16 z=mudflow_minpos;
- z<=mudflow_maxpos;
- z++)
- {
- // Invert coordinates every 2nd iteration
- if(k%2 == 0)
- {
- x = mudflow_maxpos - (x-mudflow_minpos);
- z = mudflow_maxpos - (z-mudflow_minpos);
- }
-
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- v3s16 em = vmanip.m_area.getExtent();
- u32 i = vmanip.m_area.index(v3s16(p2d.X, y_nodes_max, p2d.Y));
- s16 y=y_nodes_max;
-
- for(;; y--)
- {
- MapNode *n = NULL;
- // Find mud
- for(; y>=y_nodes_min; y--)
- {
- n = &vmanip.m_data[i];
- //if(content_walkable(n->d))
- // break;
- if(n->d == CONTENT_MUD || n->d == CONTENT_GRASS)
- break;
-
- vmanip.m_area.add_y(em, i, -1);
- }
-
- // Stop if out of area
- //if(vmanip.m_area.contains(i) == false)
- if(y < y_nodes_min)
- break;
-
- /*// If not mud, do nothing to it
- MapNode *n = &vmanip.m_data[i];
- if(n->d != CONTENT_MUD && n->d != CONTENT_GRASS)
- continue;*/
-
- /*
- Don't flow it if the stuff under it is not mud
- */
- {
- u32 i2 = i;
- vmanip.m_area.add_y(em, i2, -1);
- // Cancel if out of area
- if(vmanip.m_area.contains(i2) == false)
- continue;
- MapNode *n2 = &vmanip.m_data[i2];
- if(n2->d != CONTENT_MUD && n2->d != CONTENT_GRASS)
- continue;
- }
-
- // Make it exactly mud
- n->d = CONTENT_MUD;
-
- /*s16 recurse_count = 0;
- mudflow_recurse:*/
-
- v3s16 dirs4[4] = {
- v3s16(0,0,1), // back
- v3s16(1,0,0), // right
- v3s16(0,0,-1), // front
- v3s16(-1,0,0), // left
- };
-
- // Theck that upper is air or doesn't exist.
- // Cancel dropping if upper keeps it in place
- u32 i3 = i;
- vmanip.m_area.add_y(em, i3, 1);
- if(vmanip.m_area.contains(i3) == true
- && content_walkable(vmanip.m_data[i3].d) == true)
- {
- continue;
- }
-
- // Drop mud on side
-
- for(u32 di=0; di<4; di++)
- {
- v3s16 dirp = dirs4[di];
- u32 i2 = i;
- // Move to side
- vmanip.m_area.add_p(em, i2, dirp);
- // Fail if out of area
- if(vmanip.m_area.contains(i2) == false)
- continue;
- // Check that side is air
- MapNode *n2 = &vmanip.m_data[i2];
- if(content_walkable(n2->d))
- continue;
- // Check that under side is air
- vmanip.m_area.add_y(em, i2, -1);
- if(vmanip.m_area.contains(i2) == false)
- continue;
- n2 = &vmanip.m_data[i2];
- if(content_walkable(n2->d))
- continue;
- /*// Check that under that is air (need a drop of 2)
- vmanip.m_area.add_y(em, i2, -1);
- if(vmanip.m_area.contains(i2) == false)
- continue;
- n2 = &vmanip.m_data[i2];
- if(content_walkable(n2->d))
- continue;*/
- // Loop further down until not air
- do{
- vmanip.m_area.add_y(em, i2, -1);
- // Fail if out of area
- if(vmanip.m_area.contains(i2) == false)
- continue;
- n2 = &vmanip.m_data[i2];
- }while(content_walkable(n2->d) == false);
- // Loop one up so that we're in air
- vmanip.m_area.add_y(em, i2, 1);
- n2 = &vmanip.m_data[i2];
-
- // Move mud to new place
- *n2 = *n;
- // Set old place to be air
- *n = MapNode(CONTENT_AIR);
-
- // Done
- break;
- }
- }
- }
-
- }
-
- }//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<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- x++)
- for(s16 z=0-max_spread_amount;
- z<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- z++)
- {
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- // Find ground level
- //s16 surface_y = find_ground_level(vmanip, p2d);
-
- /*
- If ground level is over water level, skip.
- NOTE: This leaves caves near water without water,
- which looks especially crappy when the nearby water
- won't start flowing either for some reason
- */
- /*if(surface_y > 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
-
- } // Aging loop
-
- {
- //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<sectorpos_base_size*MAP_BLOCKSIZE; x++)
- for(s16 z=0; z<sectorpos_base_size*MAP_BLOCKSIZE; z++)*/
- for(s16 x=0-max_spread_amount+1;
- x<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1;
- x++)
- for(s16 z=0-max_spread_amount+1;
- z<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1;
- z++)
- {
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- // Determine whether to have sand here
- bool have_sand = get_have_sand_coast(p2d);
-
- if(have_sand == false)
- continue;
-
- // Find ground level
- s16 surface_y = find_ground_level_clever(vmanip, p2d);
-
- if(surface_y > 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
- {
- // 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; x0<div; x0++)
- for(s16 z0=0; z0<div; z0++)
- {
- // Center position of part of division
- v2s16 p2d_center(
- sectorpos_base.X*MAP_BLOCKSIZE + sidelen/2 + sidelen*x0,
- sectorpos_base.Y*MAP_BLOCKSIZE + sidelen/2 + sidelen*z0
- );
- // Minimum edge of part of division
- v2s16 p2d_min(
- sectorpos_base.X*MAP_BLOCKSIZE + sidelen*x0,
- sectorpos_base.Y*MAP_BLOCKSIZE + sidelen*z0
- );
- // Maximum edge of part of division
- v2s16 p2d_max(
- sectorpos_base.X*MAP_BLOCKSIZE + sidelen + sidelen*x0 - 1,
- sectorpos_base.Y*MAP_BLOCKSIZE + sidelen + sidelen*z0 - 1
- );
- // Amount of trees
- u32 tree_count = area * tree_amount_2d(m_seed, p2d_center);
- // Put trees in random places on part of division
- for(u32 i=0; i<tree_count; i++)
- {
- s16 x = myrand_range(p2d_min.X, p2d_max.X);
- s16 z = myrand_range(p2d_min.Y, p2d_max.Y);
- s16 y = find_ground_level(vmanip, v2s16(x,z));
- // Don't make a tree under water level
- if(y < WATER_LEVEL)
- continue;
- v3s16 p(x,y,z);
- /*
- Trees grow only on mud and grass
- */
- {
- u32 i = vmanip.m_area.index(v3s16(p));
- MapNode *n = &vmanip.m_data[i];
- if(n->d != 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<count; i++)
- {
- s16 x = myrand_range(0, sectorpos_base_size*MAP_BLOCKSIZE-1);
- s16 z = myrand_range(0, sectorpos_base_size*MAP_BLOCKSIZE-1);
- x += sectorpos_base.X*MAP_BLOCKSIZE;
- z += sectorpos_base.Y*MAP_BLOCKSIZE;
- s16 y = find_ground_level(vmanip, v2s16(x,z));
- // Don't make a tree under water level
- if(y < WATER_LEVEL)
- continue;
- v3s16 p(x,y+1,z);
- // Make a tree
- make_tree(vmanip, p);
- }*/
- }
-
- }//timer1
-
- {
- // 19ms @cs=8
- //TimeTaker timer1("grow grass");
-
- /*
- Grow grass
- */
-
- /*for(s16 x=0-4; x<sectorpos_base_size*MAP_BLOCKSIZE+4; x++)
- for(s16 z=0-4; z<sectorpos_base_size*MAP_BLOCKSIZE+4; z++)*/
- for(s16 x=0-max_spread_amount;
- x<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- x++)
- for(s16 z=0-max_spread_amount;
- z<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- z++)
- {
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- /*
- Find the lowest surface to which enough light ends up
- to make grass grow.
-
- Basically just wait until not air and not leaves.
- */
- s16 surface_y = 0;
- {
- v3s16 em = vmanip.m_area.getExtent();
- u32 i = vmanip.m_area.index(v3s16(p2d.X, y_nodes_max, p2d.Y));
- s16 y;
- // Go to ground level
- for(y=y_nodes_max; y>=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
-
- /*
- Initial lighting (sunlight)
- */
-
- core::map<v3s16, bool> light_sources;
-
- {
- // 750ms @cs=8, can't optimize more
- TimeTaker timer1("initial lighting");
-
-#if 0
- /*
- Go through the edges and add all nodes that have light to light_sources
- */
-
- // 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);
-
- {
- 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(n->getLight(LIGHTBANK_DAY) != 0)
- {
- 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);
- }
- }
- }
-#endif
-
- /*for(s16 x=0; x<sectorpos_base_size*MAP_BLOCKSIZE; x++)
- for(s16 z=0; z<sectorpos_base_size*MAP_BLOCKSIZE; z++)*/
- /*for(s16 x=0-max_spread_amount+1;
- x<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1;
- x++)
- for(s16 z=0-max_spread_amount+1;
- z<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1;
- z++)*/
-#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<v3s16, MapBlock*>::Iterator i = changed_blocks.getIterator();
- i.atEnd() == false; i++)
- {
- MapBlock *block = i.getNode()->getValue();
- block->updateDayNightDiff();
- }
- }
-
-#endif
-
- /*
- 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;
-}
-#endif
-
-#if 0
-MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos,
- core::map<v3s16, MapBlock*> &changed_blocks,
- bool force)
-{
- DSTACK(__FUNCTION_NAME);
-
- /*
- Don't generate if already fully generated
- */
- if(force == false)
- {
- MapChunk *chunk = getChunk(chunkpos);
- if(chunk != NULL && chunk->getGenLevel() == GENERATED_FULLY)
- {
- dstream<<"generateChunkRaw(): Chunk "
- <<"("<<chunkpos.X<<","<<chunkpos.Y<<")"
- <<" already generated"<<std::endl;
- return chunk;
- }
- }
-
-#if 0
- dstream<<"generateChunkRaw(): Generating chunk "
- <<"("<<chunkpos.X<<","<<chunkpos.Y<<")"
- <<std::endl;
-
- TimeTaker timer("generateChunkRaw()");
-
- // The distance how far into the neighbors the generator is allowed to go.
- s16 max_spread_amount_sectors = 1;
- assert(max_spread_amount_sectors <= m_chunksize);
- s16 max_spread_amount = max_spread_amount_sectors * MAP_BLOCKSIZE;
-
- // Minimum amount of space left on sides for mud to fall in
- //s16 min_mud_fall_space = 2;
-
- // Maximum diameter of stone obstacles in X and Z
- /*s16 stone_obstacle_max_size = (max_spread_amount-min_mud_fall_space)*2;
- assert(stone_obstacle_max_size/2 <= max_spread_amount-min_mud_fall_space);*/
-
- s16 y_blocks_min = -2;
- s16 y_blocks_max = 3;
- //s16 h_blocks = y_blocks_max - y_blocks_min + 1;
- s16 y_nodes_min = y_blocks_min * MAP_BLOCKSIZE;
- s16 y_nodes_max = y_blocks_max * MAP_BLOCKSIZE + MAP_BLOCKSIZE - 1;
-
- 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;*/
-
- /*
- The limiting edges of the lighting update, inclusive.
- */
- s16 lighting_min_d = 0-max_spread_amount;
- s16 lighting_max_d = sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1;
-
- /*
- Create the whole area of this and the neighboring chunks
- */
- {
- TimeTaker timer("generateChunkRaw() create area");
-
- for(s16 x=0; x<sectorpos_bigbase_size; x++)
- for(s16 z=0; z<sectorpos_bigbase_size; z++)
- {
- v2s16 sectorpos = sectorpos_bigbase + v2s16(x,z);
- ServerMapSector *sector = createSector(sectorpos);
- assert(sector);
-
- for(s16 y=y_blocks_min; y<=y_blocks_max; y++)
- {
- v3s16 blockpos(sectorpos.X, y, sectorpos.Y);
- MapBlock *block = createBlock(blockpos);
-
- // Lighting won't be calculated
- //block->setLightingExpired(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);
- }
- }
- }
-
- /*
- Now we have a big empty area.
-
- Make a ManualMapVoxelManipulator that contains this and the
- neighboring chunks
- */
-
- ManualMapVoxelManipulator vmanip(this);
- // Add the area we just generated
- {
- TimeTaker timer("generateChunkRaw() initialEmerge");
- vmanip.initialEmerge(bigarea_blocks_min, bigarea_blocks_max);
- }
-
- // Clear all flags
- vmanip.clearFlag(0xff);
-
- TimeTaker timer_generate("generateChunkRaw() generate");
-
- /*
- Generate general ground level to full area
- */
-
- {
- // 22ms @cs=8
- TimeTaker timer1("ground level");
- dstream<<"Generating base ground..."<<std::endl;
-
- for(s16 x=0; x<sectorpos_bigbase_size*MAP_BLOCKSIZE; x++)
- for(s16 z=0; z<sectorpos_bigbase_size*MAP_BLOCKSIZE; z++)
- {
- // Node position
- v2s16 p2d = sectorpos_bigbase*MAP_BLOCKSIZE + v2s16(x,z);
-
- /*
- Skip if already generated
- */
- {
- v3s16 p(p2d.X, y_nodes_min, p2d.Y);
- if(vmanip.m_data[vmanip.m_area.index(p)].d != CONTENT_AIR)
- continue;
- }
-
- v2f p2df(p2d.X, p2d.Y);
-
- s16 mud_amount = get_mud_amount(m_seed, p2df);
-
- double tfxz = get_turbulence_factor_2d(m_seed, p2df);
- bool turbulence_is_used = (tfxz > 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<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- x++)
- for(s16 z=0-max_spread_amount;
- z<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- z++)
- {
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- // Find ground level
- //s16 surface_y = find_ground_level(vmanip, p2d);
-
- /*
- If ground level is over water level, skip.
- NOTE: This leaves caves near water without water,
- which looks especially crappy when the nearby water
- won't start flowing either for some reason
- */
- /*if(surface_y > 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<sectorpos_base_size*MAP_BLOCKSIZE; x++)
- for(s16 z=0; z<sectorpos_base_size*MAP_BLOCKSIZE; z++)*/
- for(s16 x=0-max_spread_amount+1;
- x<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1;
- x++)
- for(s16 z=0-max_spread_amount+1;
- z<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount-1;
- z++)
- {
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- // Determine whether to have sand here
- bool have_sand = get_have_sand_coast(m_seed, v2f(p2d.X,p2d.Y));
-
- if(have_sand == false)
- continue;
-
- // Find ground level
- s16 surface_y = find_ground_level_clever(vmanip, p2d);
-
- if(surface_y > 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<sectorpos_base_size*MAP_BLOCKSIZE+4; x++)
- for(s16 z=0-4; z<sectorpos_base_size*MAP_BLOCKSIZE+4; z++)*/
- for(s16 x=0-max_spread_amount;
- x<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- x++)
- for(s16 z=0-max_spread_amount;
- z<sectorpos_base_size*MAP_BLOCKSIZE+max_spread_amount;
- z++)
- {
- // Node position in 2d
- v2s16 p2d = sectorpos_base*MAP_BLOCKSIZE + v2s16(x,z);
-
- /*
- Find the lowest surface to which enough light ends up
- to make grass grow.
-
- Basically just wait until not air and not leaves.
- */
- s16 surface_y = 0;
- {
- v3s16 em = vmanip.m_area.getExtent();
- u32 i = vmanip.m_area.index(v3s16(p2d.X, y_nodes_max, p2d.Y));
- s16 y;
- // Go to ground level
- for(y=y_nodes_max; y>=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; x0<div; x0++)
- for(s16 z0=0; z0<div; z0++)
- {
- // Center position of part of division
- v2s16 p2d_center(
- sectorpos_base.X*MAP_BLOCKSIZE + sidelen/2 + sidelen*x0,
- sectorpos_base.Y*MAP_BLOCKSIZE + sidelen/2 + sidelen*z0
- );
- // Minimum edge of part of division
- v2s16 p2d_min(
- sectorpos_base.X*MAP_BLOCKSIZE + sidelen*x0,
- sectorpos_base.Y*MAP_BLOCKSIZE + sidelen*z0
- );
- // Maximum edge of part of division
- v2s16 p2d_max(
- sectorpos_base.X*MAP_BLOCKSIZE + sidelen + sidelen*x0 - 1,
- sectorpos_base.Y*MAP_BLOCKSIZE + sidelen + sidelen*z0 - 1
- );
- // Amount of trees
- u32 tree_count = area * tree_amount_2d(m_seed, p2d_center);
- // Put trees in random places on part of division
- for(u32 i=0; i<tree_count; i++)
- {
- s16 x = myrand_range(p2d_min.X, p2d_max.X);
- s16 z = myrand_range(p2d_min.Y, p2d_max.Y);
- s16 y = find_ground_level(vmanip, v2s16(x,z));
- // Don't make a tree under water level
- if(y < WATER_LEVEL)
- continue;
- v3s16 p(x,y,z);
- /*
- Trees grow only on mud and grass
- */
- {
- u32 i = vmanip.m_area.index(v3s16(p));
- MapNode *n = &vmanip.m_data[i];
- if(n->d != 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<count; i++)
- {
- s16 x = myrand_range(0, sectorpos_base_size*MAP_BLOCKSIZE-1);
- s16 z = myrand_range(0, sectorpos_base_size*MAP_BLOCKSIZE-1);
- x += sectorpos_base.X*MAP_BLOCKSIZE;
- z += sectorpos_base.Y*MAP_BLOCKSIZE;
- s16 y = find_ground_level(vmanip, v2s16(x,z));
- // Don't make a tree under water level
- if(y < WATER_LEVEL)
- continue;
- v3s16 p(x,y+1,z);
- // Make a tree
- make_tree(vmanip, p);
- }*/
- }
-
- }//timer1
-
-
- /*
- Initial lighting (sunlight)
- */
-
- core::map<v3s16, bool> 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<v3s16, MapBlock*>::Iterator i = changed_blocks.getIterator();
- i.atEnd() == false; i++)
- {
- MapBlock *block = i.getNode()->getValue();
- block->updateDayNightDiff();
- }
- }
-#endif
-
- /*
- 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<v3s16, MapBlock*> &changed_blocks)
-{
- dstream<<"generateChunk(): Generating chunk "
- <<"("<<chunkpos1.X<<","<<chunkpos1.Y<<")"
- <<std::endl;
-
- // Shall be not used now
- //assert(0);
-
- /*for(s16 x=-1; x<=1; x++)
- for(s16 y=-1; y<=1; y++)*/
- for(s16 x=-0; x<=0; x++)
- for(s16 y=-0; y<=0; y++)
- {
- v2s16 chunkpos0 = chunkpos1 + v2s16(x,y);
- MapChunk *chunk = getChunk(chunkpos0);
- // Skip if already generated
- if(chunk != NULL && chunk->getGenLevel() == GENERATED_FULLY)
- continue;
- generateChunkRaw(chunkpos0, changed_blocks);
- }
-
- assert(chunkNonVolatile(chunkpos1));
-
- MapChunk *chunk = getChunk(chunkpos1);
- return chunk;
-}
-#endif
-
-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"<<std::endl;
- throw InvalidPositionException("");
- }
- return sector;
- }
-
- /*
- Do not create over-limit
- */
- if(p2d.X < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE
- || p2d.X > 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<v3s16, MapBlock*> &changed_blocks)
-{
- DSTACK("%s: p2d=(%d,%d)",
- __FUNCTION_NAME,
- p2d.X, p2d.Y);
-
-#if 0
- /*
- 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);
- }
-#endif
-
- /*
- 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"<<std::endl;
- throw InvalidPositionException("");
- }
- return sector;
- }
-
- /*
- generateChunk should have generated the sector
- */
- //assert(0);
-
- dstream<<"WARNING: ServerMap::emergeSector: Cannot find sector ("
- <<p2d.X<<","<<p2d.Y<<" and chunk is already generated. "
- <<std::endl;
-
-#if 0
- dstream<<"WARNING: Forcing regeneration of chunk."<<std::endl;
-
- // Generate chunk
- generateChunkRaw(chunkpos, changed_blocks, true);
-
- /*
- Return sector if it exists now
- */
- sector = getSectorNoGenerateNoEx(p2d);
- if(sector != NULL)
- return sector;
-
- dstream<<"ERROR: Could not get sector from anywhere."<<std::endl;
-
- //assert(0);
-#endif
-
-#if 1
- dstream<<"WARNING: Creating an empty sector."<<std::endl;
-
- return createSector(p2d);
-
-#endif
-
- /*
- Generate directly
- */
- //return generateSector();
-}
-
-enum BlockType{
- BT_GROUND,
- BT_SURFACE,
- BT_SKY
-};