#include "map.h"
#include "mapsector.h"
#include "mapblock.h"
-#include "main.h"
#include "filesys.h"
#include "voxel.h"
#include "porting.h"
// Save if modified
if (block->getModified() != MOD_STATE_CLEAN && save_before_unloading) {
- modprofiler.add(block->getModifiedReason(), 1);
+ modprofiler.add(block->getModifiedReasonString(), 1);
if (!saveBlock(block))
continue;
saved_blocks_count++;
}
}
+std::vector<v3s16> Map::findNodesWithMetadata(v3s16 p1, v3s16 p2)
+{
+ std::vector<v3s16> positions_with_meta;
+
+ sortBoxVerticies(p1, p2);
+ v3s16 bpmin = getNodeBlockPos(p1);
+ v3s16 bpmax = getNodeBlockPos(p2);
+
+ VoxelArea area(p1, p2);
+
+ for (s16 z = bpmin.Z; z <= bpmax.Z; z++)
+ for (s16 y = bpmin.Y; y <= bpmax.Y; y++)
+ for (s16 x = bpmin.X; x <= bpmax.X; x++) {
+ v3s16 blockpos(x, y, z);
+
+ MapBlock *block = getBlockNoCreateNoEx(blockpos);
+ if (!block) {
+ verbosestream << "Map::getNodeMetadata(): Need to emerge "
+ << PP(blockpos) << std::endl;
+ block = emergeBlock(blockpos, false);
+ }
+ if (!block) {
+ infostream << "WARNING: Map::getNodeMetadata(): Block not found"
+ << std::endl;
+ continue;
+ }
+
+ v3s16 p_base = blockpos * MAP_BLOCKSIZE;
+ std::vector<v3s16> keys = block->m_node_metadata.getAllKeys();
+ for (size_t i = 0; i != keys.size(); i++) {
+ v3s16 p(keys[i] + p_base);
+ if (!area.contains(p))
+ continue;
+
+ positions_with_meta.push_back(p);
+ }
+ }
+
+ return positions_with_meta;
+}
+
NodeMetadata *Map::getNodeMetadata(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
Set block as modified
*/
block->raiseModified(MOD_STATE_WRITE_NEEDED,
- "finishBlockMake expireDayNightDiff");
+ MOD_REASON_EXPIRE_DAYNIGHTDIFF);
}
/*
save_started = true;
}
- modprofiler.add(block->getModifiedReason(), 1);
+ modprofiler.add(block->getModifiedReasonString(), 1);
saveBlock(block);
block_count++;
{
DSTACK(__FUNCTION_NAME);
- /*infostream<<"ServerMap::saveMapMeta(): "
- <<"seed="<<m_seed
- <<std::endl;*/
-
createDirs(m_savedir);
- std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
- std::ostringstream ss(std::ios_base::binary);
-
- Settings params;
+ std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
+ std::ostringstream oss(std::ios_base::binary);
+ Settings conf;
- m_emerge->saveParamsToSettings(¶ms);
- params.writeLines(ss);
+ m_emerge->params.save(conf);
+ conf.writeLines(oss);
- ss<<"[end_of_params]\n";
+ oss << "[end_of_params]\n";
- if(!fs::safeWriteToFile(fullpath, ss.str()))
- {
- infostream<<"ERROR: ServerMap::saveMapMeta(): "
- <<"could not write "<<fullpath<<std::endl;
+ if(!fs::safeWriteToFile(fullpath, oss.str())) {
+ errorstream << "ServerMap::saveMapMeta(): "
+ << "could not write " << fullpath << std::endl;
throw FileNotGoodException("Cannot save chunk metadata");
}
{
DSTACK(__FUNCTION_NAME);
- Settings params;
- std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
+ Settings conf;
+ std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt";
- if (fs::PathExists(fullpath)) {
- std::ifstream is(fullpath.c_str(), std::ios_base::binary);
- if (!is.good()) {
- errorstream << "ServerMap::loadMapMeta(): "
- "could not open " << fullpath << std::endl;
- throw FileNotGoodException("Cannot open map metadata");
- }
+ std::ifstream is(fullpath.c_str(), std::ios_base::binary);
+ if (!is.good()) {
+ errorstream << "ServerMap::loadMapMeta(): "
+ "could not open " << fullpath << std::endl;
+ throw FileNotGoodException("Cannot open map metadata");
+ }
- if (!params.parseConfigLines(is, "[end_of_params]")) {
- throw SerializationError("ServerMap::loadMapMeta(): "
+ if (!conf.parseConfigLines(is, "[end_of_params]")) {
+ throw SerializationError("ServerMap::loadMapMeta(): "
"[end_of_params] not found!");
- }
}
- m_emerge->loadParamsFromSettings(¶ms);
+ m_emerge->params.load(conf);
verbosestream << "ServerMap::loadMapMeta(): seed="
<< m_emerge->params.seed << std::endl;