#include "environment.h"
#include "emerge.h"
#include "mapgen_v6.h"
-#include "biome.h"
+#include "mg_biome.h"
#include "config.h"
#include "server.h"
#include "database.h"
}
// Returns a CONTENT_IGNORE node if not found
-MapNode Map::getNodeNoEx(v3s16 p)
+MapNode Map::getNodeNoEx(v3s16 p, bool *is_valid_position)
{
v3s16 blockpos = getNodeBlockPos(p);
MapBlock *block = getBlockNoCreateNoEx(blockpos);
- if(block == NULL)
+ if (block == NULL) {
+ if (is_valid_position != NULL)
+ *is_valid_position = false;
return MapNode(CONTENT_IGNORE);
+ }
+
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- return block->getNodeNoCheck(relpos);
+ bool is_valid_p;
+ MapNode node = block->getNodeNoCheck(relpos, &is_valid_p);
+ if (is_valid_position != NULL)
+ *is_valid_position = is_valid_p;
+ return node;
}
+#if 0
+// Deprecated
// throws InvalidPositionException if not found
+// TODO: Now this is deprecated, getNodeNoEx should be renamed
MapNode Map::getNode(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
MapBlock *block = getBlockNoCreateNoEx(blockpos);
- if(block == NULL)
+ if (block == NULL)
throw InvalidPositionException();
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- return block->getNodeNoCheck(relpos);
+ bool is_valid_position;
+ MapNode node = block->getNodeNoCheck(relpos, &is_valid_position);
+ if (!is_valid_position)
+ throw InvalidPositionException();
+ return node;
}
+#endif
// throws InvalidPositionException if not found
void Map::setNode(v3s16 p, MapNode & n)
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
// Never allow placing CONTENT_IGNORE, it fucks up stuff
if(n.getContent() == CONTENT_IGNORE){
+ bool temp_bool;
errorstream<<"Map::setNode(): Not allowing to place CONTENT_IGNORE"
<<" while trying to replace \""
- <<m_gamedef->ndef()->get(block->getNodeNoCheck(relpos)).name
+ <<m_gamedef->ndef()->get(block->getNodeNoCheck(relpos, &temp_bool)).name
<<"\" at "<<PP(p)<<" (block "<<PP(blockpos)<<")"<<std::endl;
debug_stacks_print_to(infostream);
return;
// Get the block where the node is located
v3s16 blockpos = getNodeBlockPos(n2pos);
- try
- {
- // Only fetch a new block if the block position has changed
- try{
- if(block == NULL || blockpos != blockpos_last){
- block = getBlockNoCreate(blockpos);
- blockpos_last = blockpos;
+ // Only fetch a new block if the block position has changed
+ try {
+ if(block == NULL || blockpos != blockpos_last){
+ block = getBlockNoCreate(blockpos);
+ blockpos_last = blockpos;
- block_checked_in_modified = false;
- blockchangecount++;
- }
- }
- catch(InvalidPositionException &e)
- {
- continue;
+ block_checked_in_modified = false;
+ blockchangecount++;
}
+ }
+ catch(InvalidPositionException &e) {
+ continue;
+ }
- // Calculate relative position in block
- v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
- // Get node straight from the block
- MapNode n2 = block->getNode(relpos);
+ // Calculate relative position in block
+ v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
+ // Get node straight from the block
+ bool is_valid_position;
+ MapNode n2 = block->getNode(relpos, &is_valid_position);
+ if (!is_valid_position)
+ continue;
- bool changed = false;
+ bool changed = false;
- //TODO: Optimize output by optimizing light_sources?
+ //TODO: Optimize output by optimizing light_sources?
+ /*
+ If the neighbor is dimmer than what was specified
+ as oldlight (the light of the previous node)
+ */
+ if(n2.getLight(bank, nodemgr) < oldlight)
+ {
/*
- If the neighbor is dimmer than what was specified
- as oldlight (the light of the previous node)
+ And the neighbor is transparent and it has some light
*/
- if(n2.getLight(bank, nodemgr) < oldlight)
+ if(nodemgr->get(n2).light_propagates
+ && n2.getLight(bank, nodemgr) != 0)
{
/*
- And the neighbor is transparent and it has some light
+ Set light to 0 and add to queue
*/
- if(nodemgr->get(n2).light_propagates
- && n2.getLight(bank, nodemgr) != 0)
- {
- /*
- Set light to 0 and add to queue
- */
-
- u8 current_light = n2.getLight(bank, nodemgr);
- n2.setLight(bank, 0, nodemgr);
- block->setNode(relpos, n2);
-
- unlighted_nodes[n2pos] = current_light;
- changed = true;
-
- /*
- Remove from light_sources if it is there
- NOTE: This doesn't happen nearly at all
- */
- /*if(light_sources.find(n2pos))
- {
- infostream<<"Removed from light_sources"<<std::endl;
- light_sources.remove(n2pos);
- }*/
- }
- /*// DEBUG
- if(light_sources.find(n2pos) != NULL)
- light_sources.remove(n2pos);*/
- }
- else{
- light_sources.insert(n2pos);
- }
+ u8 current_light = n2.getLight(bank, nodemgr);
+ n2.setLight(bank, 0, nodemgr);
+ block->setNode(relpos, n2);
- // Add to modified_blocks
- if(changed == true && block_checked_in_modified == false)
- {
- // If the block is not found in modified_blocks, add.
- if(modified_blocks.find(blockpos) == modified_blocks.end())
+ unlighted_nodes[n2pos] = current_light;
+ changed = true;
+
+ /*
+ Remove from light_sources if it is there
+ NOTE: This doesn't happen nearly at all
+ */
+ /*if(light_sources.find(n2pos))
{
- modified_blocks[blockpos] = block;
- }
- block_checked_in_modified = true;
+ infostream<<"Removed from light_sources"<<std::endl;
+ light_sources.remove(n2pos);
+ }*/
}
+
+ /*// DEBUG
+ if(light_sources.find(n2pos) != NULL)
+ light_sources.remove(n2pos);*/
}
- catch(InvalidPositionException &e)
+ else{
+ light_sources.insert(n2pos);
+ }
+
+ // Add to modified_blocks
+ if(changed == true && block_checked_in_modified == false)
{
- continue;
+ // If the block is not found in modified_blocks, add.
+ if(modified_blocks.find(blockpos) == modified_blocks.end())
+ {
+ modified_blocks[blockpos] = block;
+ }
+ block_checked_in_modified = true;
}
}
}
v3s16 blockpos = getNodeBlockPos(pos);
// Only fetch a new block if the block position has changed
- try{
+ try {
if(block == NULL || blockpos != blockpos_last){
block = getBlockNoCreate(blockpos);
blockpos_last = blockpos;
blockchangecount++;
}
}
- catch(InvalidPositionException &e)
- {
+ catch(InvalidPositionException &e) {
continue;
}
v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
// Get node straight from the block
- MapNode n = block->getNode(relpos);
+ bool is_valid_position;
+ MapNode n = block->getNode(relpos, &is_valid_position);
- u8 oldlight = n.getLight(bank, nodemgr);
+ u8 oldlight = is_valid_position ? n.getLight(bank, nodemgr) : 0;
u8 newlight = diminish_light(oldlight);
// Loop through 6 neighbors
// Get the block where the node is located
v3s16 blockpos = getNodeBlockPos(n2pos);
- try
- {
- // Only fetch a new block if the block position has changed
- try{
- if(block == NULL || blockpos != blockpos_last){
- block = getBlockNoCreate(blockpos);
- blockpos_last = blockpos;
+ // Only fetch a new block if the block position has changed
+ try {
+ if(block == NULL || blockpos != blockpos_last){
+ block = getBlockNoCreate(blockpos);
+ blockpos_last = blockpos;
- block_checked_in_modified = false;
- blockchangecount++;
- }
- }
- catch(InvalidPositionException &e)
- {
- continue;
+ block_checked_in_modified = false;
+ blockchangecount++;
}
+ }
+ catch(InvalidPositionException &e) {
+ continue;
+ }
- // Calculate relative position in block
- v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
- // Get node straight from the block
- MapNode n2 = block->getNode(relpos);
+ // Calculate relative position in block
+ v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
+ // Get node straight from the block
+ MapNode n2 = block->getNode(relpos, &is_valid_position);
+ if (!is_valid_position)
+ continue;
- bool changed = false;
- /*
- If the neighbor is brighter than the current node,
- add to list (it will light up this node on its turn)
- */
- if(n2.getLight(bank, nodemgr) > undiminish_light(oldlight))
+ bool changed = false;
+ /*
+ If the neighbor is brighter than the current node,
+ add to list (it will light up this node on its turn)
+ */
+ if(n2.getLight(bank, nodemgr) > undiminish_light(oldlight))
+ {
+ lighted_nodes.insert(n2pos);
+ changed = true;
+ }
+ /*
+ If the neighbor is dimmer than how much light this node
+ would spread on it, add to list
+ */
+ if(n2.getLight(bank, nodemgr) < newlight)
+ {
+ if(nodemgr->get(n2).light_propagates)
{
+ n2.setLight(bank, newlight, nodemgr);
+ block->setNode(relpos, n2);
lighted_nodes.insert(n2pos);
changed = true;
}
- /*
- If the neighbor is dimmer than how much light this node
- would spread on it, add to list
- */
- if(n2.getLight(bank, nodemgr) < newlight)
- {
- if(nodemgr->get(n2).light_propagates)
- {
- n2.setLight(bank, newlight, nodemgr);
- block->setNode(relpos, n2);
- lighted_nodes.insert(n2pos);
- changed = true;
- }
- }
+ }
- // Add to modified_blocks
- if(changed == true && block_checked_in_modified == false)
+ // Add to modified_blocks
+ if(changed == true && block_checked_in_modified == false)
+ {
+ // If the block is not found in modified_blocks, add.
+ if(modified_blocks.find(blockpos) == modified_blocks.end())
{
- // If the block is not found in modified_blocks, add.
- if(modified_blocks.find(blockpos) == modified_blocks.end())
- {
- modified_blocks[blockpos] = block;
- }
- block_checked_in_modified = true;
+ modified_blocks[blockpos] = block;
}
- }
- catch(InvalidPositionException &e)
- {
- continue;
+ block_checked_in_modified = true;
}
}
}
// Get the position of the neighbor node
v3s16 n2pos = p + dirs[i];
MapNode n2;
- try{
- n2 = getNode(n2pos);
- }
- catch(InvalidPositionException &e)
- {
+ bool is_valid_position;
+ n2 = getNodeNoEx(n2pos, &is_valid_position);
+ if (!is_valid_position)
continue;
- }
+
if(n2.getLight(bank, nodemgr) > brightest_light || found_something == false){
brightest_light = n2.getLight(bank, nodemgr);
brightest_pos = n2pos;
}
v3s16 relpos = pos - blockpos*MAP_BLOCKSIZE;
- MapNode n = block->getNode(relpos);
+ bool is_valid_position;
+ MapNode n = block->getNode(relpos, &is_valid_position);
+ if (!is_valid_position)
+ break;
if(nodemgr->get(n).sunlight_propagates)
{
for(s16 x=0; x<MAP_BLOCKSIZE; x++)
for(s16 y=0; y<MAP_BLOCKSIZE; y++)
{
-
- try{
- v3s16 p(x,y,z);
- MapNode n = block->getNode(p);
- u8 oldlight = n.getLight(bank, nodemgr);
- n.setLight(bank, 0, nodemgr);
- block->setNode(p, n);
-
- // If node sources light, add to list
- u8 source = nodemgr->get(n).light_source;
- if(source != 0)
- light_sources.insert(p + posnodes);
-
- // Collect borders for unlighting
- if((x==0 || x == MAP_BLOCKSIZE-1
- || y==0 || y == MAP_BLOCKSIZE-1
- || z==0 || z == MAP_BLOCKSIZE-1)
- && oldlight != 0)
- {
- v3s16 p_map = p + posnodes;
- unlight_from[p_map] = oldlight;
- }
- }
- catch(InvalidPositionException &e)
- {
- /*
- This would happen when dealing with a
- dummy block.
+ v3s16 p(x,y,z);
+ bool is_valid_position;
+ MapNode n = block->getNode(p, &is_valid_position);
+ if (!is_valid_position) {
+ /* This would happen when dealing with a
+ dummy block.
*/
- //assert(0);
infostream<<"updateLighting(): InvalidPositionException"
<<std::endl;
+ continue;
}
+ u8 oldlight = n.getLight(bank, nodemgr);
+ n.setLight(bank, 0, nodemgr);
+ block->setNode(p, n);
+
+ // If node sources light, add to list
+ u8 source = nodemgr->get(n).light_source;
+ if(source != 0)
+ light_sources.insert(p + posnodes);
+
+ // Collect borders for unlighting
+ if((x==0 || x == MAP_BLOCKSIZE-1
+ || y==0 || y == MAP_BLOCKSIZE-1
+ || z==0 || z == MAP_BLOCKSIZE-1)
+ && oldlight != 0)
+ {
+ v3s16 p_map = p + posnodes;
+ unlight_from[p_map] = oldlight;
+ }
+
+
}
if(bank == LIGHTBANK_DAY)
Otherwise there probably is.
*/
- try{
- MapNode topnode = getNode(toppos);
- if(topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
- node_under_sunlight = false;
- }
- catch(InvalidPositionException &e)
- {
- }
+ bool is_valid_position;
+ MapNode topnode = getNodeNoEx(toppos, &is_valid_position);
+
+ if(is_valid_position && topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
+ node_under_sunlight = false;
/*
Remove all light that has come out of this node
{
enum LightBank bank = banks[i];
- u8 lightwas = getNode(p).getLight(bank, ndef);
+ u8 lightwas = getNodeNoEx(p).getLight(bank, ndef);
// Add the block of the added node to modified_blocks
v3s16 blockpos = getNodeBlockPos(p);
v3s16 n2pos(p.X, y, p.Z);
MapNode n2;
- try{
- n2 = getNode(n2pos);
- }
- catch(InvalidPositionException &e)
- {
+
+ n2 = getNodeNoEx(n2pos, &is_valid_position);
+ if (!is_valid_position)
break;
- }
if(n2.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
{
};
for(u16 i=0; i<7; i++)
{
- try
- {
-
v3s16 p2 = p + dirs[i];
- MapNode n2 = getNode(p2);
- if(ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
+ MapNode n2 = getNodeNoEx(p2, &is_valid_position);
+ if(is_valid_position
+ && (ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR))
{
m_transforming_liquid.push_back(p2);
}
-
- }catch(InvalidPositionException &e)
- {
- }
}
}
If there is a node at top and it doesn't have sunlight,
there will be no sunlight going down.
*/
- try{
- MapNode topnode = getNode(toppos);
+ bool is_valid_position;
+ MapNode topnode = getNodeNoEx(toppos, &is_valid_position);
- if(topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
- node_under_sunlight = false;
- }
- catch(InvalidPositionException &e)
- {
- }
+ if(is_valid_position && topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
+ node_under_sunlight = false;
std::set<v3s16> light_sources;
Unlight neighbors (in case the node is a light source)
*/
unLightNeighbors(bank, p,
- getNode(p).getLight(bank, ndef),
+ getNodeNoEx(p).getLight(bank, ndef),
light_sources, modified_blocks);
}
{
// Set the lighting of this node to 0
// TODO: Is this needed? Lighting is cleared up there already.
- try{
- MapNode n = getNode(p);
+ MapNode n = getNodeNoEx(p, &is_valid_position);
+ if (is_valid_position) {
n.setLight(LIGHTBANK_DAY, 0, ndef);
setNode(p, n);
- }
- catch(InvalidPositionException &e)
- {
+ } else {
assert(0);
}
}
};
for(u16 i=0; i<7; i++)
{
- try
- {
-
v3s16 p2 = p + dirs[i];
- MapNode n2 = getNode(p2);
- if(ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
+ bool is_position_valid;
+ MapNode n2 = getNodeNoEx(p2, &is_position_valid);
+ if (is_position_valid
+ && (ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR))
{
m_transforming_liquid.push_back(p2);
}
-
- }catch(InvalidPositionException &e)
- {
- }
}
}
v3s16 p = block->getPos();
// Save if modified
- if(block->getModified() != MOD_STATE_CLEAN
- && save_before_unloading)
+ if (block->getModified() != MOD_STATE_CLEAN && save_before_unloading)
{
modprofiler.add(block->getModifiedReason(), 1);
- saveBlock(block);
+ if (!saveBlock(block))
+ continue;
saved_blocks_count++;
}
void ServerMap::prepareBlock(MapBlock *block) {
}
+// N.B. This requires no synchronization, since data will not be modified unless
+// the VoxelManipulator being updated belongs to the same thread.
+void ServerMap::updateVManip(v3s16 pos)
+{
+ Mapgen *mg = m_emerge->getCurrentMapgen();
+ if (!mg)
+ return;
+
+ ManualMapVoxelManipulator *vm = mg->vm;
+ if (!vm)
+ return;
+
+ if (!vm->m_area.contains(pos))
+ return;
+
+ s32 idx = vm->m_area.index(pos);
+ vm->m_data[idx] = getNodeNoEx(pos);
+ vm->m_flags[idx] &= ~VOXELFLAG_NO_DATA;
+
+ vm->m_is_dirty = true;
+}
+
s16 ServerMap::findGroundLevel(v2s16 p2d)
{
#if 0
{
DSTACK(__FUNCTION_NAME);
- /*infostream<<"ServerMap::loadMapMeta(): Loading map metadata"
- <<std::endl;*/
-
- std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
+ std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
- if(is.good() == false)
- {
- infostream<<"ERROR: ServerMap::loadMapMeta(): "
- <<"could not open"<<fullpath<<std::endl;
+ if (!is.good()) {
+ errorstream << "ServerMap::loadMapMeta(): "
+ << "could not open" << fullpath << std::endl;
throw FileNotGoodException("Cannot open map metadata");
}
Settings params;
- for(;;)
- {
- if(is.eof())
- throw SerializationError
- ("ServerMap::loadMapMeta(): [end_of_params] not found");
- std::string line;
- std::getline(is, line);
- std::string trimmedline = trim(line);
- if(trimmedline == "[end_of_params]")
- break;
- params.parseConfigLine(line);
+ if (!params.parseConfigLines(is, "[end_of_params]")) {
+ throw SerializationError("ServerMap::loadMapMeta(): "
+ "[end_of_params] not found!");
}
m_emerge->loadParamsFromSettings(¶ms);
- verbosestream<<"ServerMap::loadMapMeta(): seed="
- << m_emerge->params.seed<<std::endl;
+ verbosestream << "ServerMap::loadMapMeta(): seed="
+ << m_emerge->params.seed << std::endl;
}
void ServerMap::saveSectorMeta(ServerMapSector *sector)
}
#endif
-void ServerMap::beginSave() {
+void ServerMap::beginSave()
+{
dbase->beginSave();
}
-void ServerMap::endSave() {
+void ServerMap::endSave()
+{
dbase->endSave();
}
-void ServerMap::saveBlock(MapBlock *block)
+bool ServerMap::saveBlock(MapBlock *block)
+{
+ return saveBlock(block, dbase);
+}
+
+bool ServerMap::saveBlock(MapBlock *block, Database *db)
{
- dbase->saveBlock(block);
+ v3s16 p3d = block->getPos();
+
+ // Dummy blocks are not written
+ if (block->isDummy()) {
+ errorstream << "WARNING: saveBlock: Not writing dummy block "
+ << PP(p3d) << std::endl;
+ return true;
+ }
+
+ // Format used for writing
+ u8 version = SER_FMT_VER_HIGHEST_WRITE;
+
+ /*
+ [0] u8 serialization version
+ [1] data
+ */
+ std::ostringstream o(std::ios_base::binary);
+ o.write((char*) &version, 1);
+ block->serialize(o, version, true);
+
+ std::string data = o.str();
+ bool ret = db->saveBlock(p3d, data);
+ if(ret) {
+ // We just wrote it to the disk so clear modified flag
+ block->resetModified();
+ }
+ return ret;
}
-void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSector *sector, bool save_after_load)
+void ServerMap::loadBlock(std::string sectordir, std::string blockfile,
+ MapSector *sector, bool save_after_load)
{
DSTACK(__FUNCTION_NAME);
std::string fullpath = sectordir+DIR_DELIM+blockfile;
- try{
+ try {
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if(is.good() == false)
v2s16 p2d(blockpos.X, blockpos.Z);
- MapBlock *ret;
+ std::string ret;
ret = dbase->loadBlock(blockpos);
- if (ret) return (ret);
+ if (ret != "") {
+ loadBlock(&ret, blockpos, createSector(p2d), false);
+ return getBlockNoCreateNoEx(blockpos);
+ }
// Not found in database, try the files
// The directory layout we're going to load from.
out<<"ServerMap: ";
}
-/*
- MapVoxelManipulator
-*/
-
-MapVoxelManipulator::MapVoxelManipulator(Map *map)
-{
- m_map = map;
-}
-
-MapVoxelManipulator::~MapVoxelManipulator()
-{
- /*infostream<<"MapVoxelManipulator: blocks: "<<m_loaded_blocks.size()
- <<std::endl;*/
-}
-
-void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
-{
- TimeTaker timer1("emerge", &emerge_time);
-
- // Units of these are MapBlocks
- v3s16 p_min = getNodeBlockPos(a.MinEdge);
- v3s16 p_max = getNodeBlockPos(a.MaxEdge);
-
- VoxelArea block_area_nodes
- (p_min*MAP_BLOCKSIZE, (p_max+1)*MAP_BLOCKSIZE-v3s16(1,1,1));
-
- addArea(block_area_nodes);
-
- for(s32 z=p_min.Z; z<=p_max.Z; z++)
- for(s32 y=p_min.Y; y<=p_max.Y; y++)
- for(s32 x=p_min.X; x<=p_max.X; x++)
- {
- u8 flags = 0;
- MapBlock *block;
- v3s16 p(x,y,z);
- std::map<v3s16, u8>::iterator n;
- n = m_loaded_blocks.find(p);
- if(n != m_loaded_blocks.end())
- continue;
-
- bool block_data_inexistent = false;
- try
- {
- TimeTaker timer1("emerge load", &emerge_load_time);
-
- /*infostream<<"Loading block (caller_id="<<caller_id<<")"
- <<" ("<<p.X<<","<<p.Y<<","<<p.Z<<")"
- <<" wanted area: ";
- a.print(infostream);
- infostream<<std::endl;*/
-
- block = m_map->getBlockNoCreate(p);
- if(block->isDummy())
- block_data_inexistent = true;
- else
- block->copyTo(*this);
- }
- catch(InvalidPositionException &e)
- {
- block_data_inexistent = true;
- }
-
- if(block_data_inexistent)
- {
- flags |= VMANIP_BLOCK_DATA_INEXIST;
-
- VoxelArea a(p*MAP_BLOCKSIZE, (p+1)*MAP_BLOCKSIZE-v3s16(1,1,1));
- // Fill with VOXELFLAG_NO_DATA
- for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
- for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++)
- {
- s32 i = m_area.index(a.MinEdge.X,y,z);
- memset(&m_flags[i], VOXELFLAG_NO_DATA, MAP_BLOCKSIZE);
- }
- }
- /*else if (block->getNode(0, 0, 0).getContent() == CONTENT_IGNORE)
- {
- // Mark that block was loaded as blank
- flags |= VMANIP_BLOCK_CONTAINS_CIGNORE;
- }*/
-
- m_loaded_blocks[p] = flags;
- }
-
- //infostream<<"emerge done"<<std::endl;
-}
-
-/*
- SUGG: Add an option to only update eg. water and air nodes.
- This will make it interfere less with important stuff if
- run on background.
-*/
-void MapVoxelManipulator::blitBack
- (std::map<v3s16, MapBlock*> & modified_blocks)
-{
- if(m_area.getExtent() == v3s16(0,0,0))
- return;
-
- //TimeTaker timer1("blitBack");
-
- /*infostream<<"blitBack(): m_loaded_blocks.size()="
- <<m_loaded_blocks.size()<<std::endl;*/
-
- /*
- Initialize block cache
- */
- v3s16 blockpos_last;
- MapBlock *block = NULL;
- bool block_checked_in_modified = false;
-
- for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++)
- for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++)
- for(s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++)
- {
- v3s16 p(x,y,z);
-
- u8 f = m_flags[m_area.index(p)];
- if(f & (VOXELFLAG_NO_DATA))
- continue;
-
- MapNode &n = m_data[m_area.index(p)];
-
- v3s16 blockpos = getNodeBlockPos(p);
-
- try
- {
- // Get block
- if(block == NULL || blockpos != blockpos_last){
- block = m_map->getBlockNoCreate(blockpos);
- blockpos_last = blockpos;
- block_checked_in_modified = false;
- }
-
- // Calculate relative position in block
- v3s16 relpos = p - blockpos * MAP_BLOCKSIZE;
-
- // Don't continue if nothing has changed here
- if(block->getNode(relpos) == n)
- continue;
-
- //m_map->setNode(m_area.MinEdge + p, n);
- block->setNode(relpos, n);
-
- /*
- Make sure block is in modified_blocks
- */
- if(block_checked_in_modified == false)
- {
- modified_blocks[blockpos] = block;
- block_checked_in_modified = true;
- }
- }
- catch(InvalidPositionException &e)
- {
- }
- }
-}
-
ManualMapVoxelManipulator::ManualMapVoxelManipulator(Map *map):
- MapVoxelManipulator(map),
- m_create_area(false)
+ VoxelManipulator(),
+ m_is_dirty(false),
+ m_create_area(false),
+ m_map(map)
{
}
{
}
-void ManualMapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
-{
- // Just create the area so that it can be pointed to
- VoxelManipulator::addArea(a);
-}
-
void ManualMapVoxelManipulator::initialEmerge(v3s16 blockpos_min,
v3s16 blockpos_max, bool load_if_inexistent)
{
m_loaded_blocks[p] = flags;
}
+
+ m_is_dirty = false;
}
void ManualMapVoxelManipulator::blitBackAll(
- std::map<v3s16, MapBlock*> * modified_blocks)
+ std::map<v3s16, MapBlock*> *modified_blocks,
+ bool overwrite_generated)
{
if(m_area.getExtent() == v3s16(0,0,0))
return;
v3s16 p = i->first;
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
bool existed = !(i->second & VMANIP_BLOCK_DATA_INEXIST);
- if((existed == false) || (block == NULL))
- {
+ if ((existed == false) || (block == NULL) ||
+ (overwrite_generated == false && block->isGenerated() == true))
continue;
- }
block->copyFrom(*this);