]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/map.cpp
Fix gettext on MSVC
[dragonfireclient.git] / src / map.cpp
index fdc35558d342f1707f5383c4fbc121c557172b0b..d8f018742c506b670e1fd7c8ad50097d826fbc70 100644 (file)
@@ -43,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "database.h"
 #include "database-dummy.h"
 #include "database-sqlite3.h"
+#include <deque>
 #if USE_LEVELDB
 #include "database-leveldb.h"
 #endif
@@ -334,7 +335,8 @@ void Map::unspreadLight(enum LightBank bank,
                        v3s16 n2pos = pos + dirs[i];
 
                        // Get the block where the node is located
-                       v3s16 blockpos = getNodeBlockPos(n2pos);
+                       v3s16 blockpos, relpos;
+                       getNodeBlockPosWithOffset(n2pos, blockpos, relpos);
 
                        // Only fetch a new block if the block position has changed
                        try {
@@ -350,8 +352,6 @@ void Map::unspreadLight(enum LightBank bank,
                                continue;
                        }
 
-                       // 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);
@@ -418,9 +418,9 @@ void Map::unspreadLight(enum LightBank bank,
        }
 
        /*infostream<<"unspreadLight(): Changed block "
-                       <<blockchangecount<<" times"
-                       <<" for "<<from_nodes.size()<<" nodes"
-                       <<std::endl;*/
+       <<blockchangecount<<" times"
+       <<" for "<<from_nodes.size()<<" nodes"
+       <<std::endl;*/
 
        if(!unlighted_nodes.empty())
                unspreadLight(bank, unlighted_nodes, light_sources, modified_blocks);
@@ -471,14 +471,16 @@ void Map::spreadLight(enum LightBank bank,
        */
        v3s16 blockpos_last;
        MapBlock *block = NULL;
-       // Cache this a bit, too
+               // Cache this a bit, too
        bool block_checked_in_modified = false;
 
        for(std::set<v3s16>::iterator j = from_nodes.begin();
                j != from_nodes.end(); ++j)
        {
                v3s16 pos = *j;
-               v3s16 blockpos = getNodeBlockPos(pos);
+               v3s16 blockpos, relpos;
+
+               getNodeBlockPosWithOffset(pos, blockpos, relpos);
 
                // Only fetch a new block if the block position has changed
                try {
@@ -497,9 +499,6 @@ void Map::spreadLight(enum LightBank bank,
                if(block->isDummy())
                        continue;
 
-               // Calculate relative position in block
-               v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
-
                // Get node straight from the block
                bool is_valid_position;
                MapNode n = block->getNode(relpos, &is_valid_position);
@@ -513,7 +512,8 @@ void Map::spreadLight(enum LightBank bank,
                        v3s16 n2pos = pos + dirs[i];
 
                        // Get the block where the node is located
-                       v3s16 blockpos = getNodeBlockPos(n2pos);
+                       v3s16 blockpos, relpos;
+                       getNodeBlockPosWithOffset(n2pos, blockpos, relpos);
 
                        // Only fetch a new block if the block position has changed
                        try {
@@ -529,8 +529,6 @@ void Map::spreadLight(enum LightBank bank,
                                continue;
                        }
 
-                       // 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)
@@ -700,7 +698,7 @@ void Map::updateLighting(enum LightBank bank,
        //bool debug=true;
        //u32 count_was = modified_blocks.size();
 
-       std::map<v3s16, MapBlock*> blocks_to_update;
+       //std::map<v3s16, MapBlock*> blocks_to_update;
 
        std::set<v3s16> light_sources;
 
@@ -725,7 +723,7 @@ void Map::updateLighting(enum LightBank bank,
                        v3s16 pos = block->getPos();
                        v3s16 posnodes = block->getPosRelative();
                        modified_blocks[pos] = block;
-                       blocks_to_update[pos] = block;
+                       //blocks_to_update[pos] = block;
 
                        /*
                                Clear all light from block
@@ -1189,8 +1187,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
                This also clears the lighting.
        */
 
-       MapNode n;
-       n.setContent(replace_material);
+       MapNode n(replace_material);
        setNode(p, n);
 
        for(s32 i=0; i<2; i++)
@@ -1603,6 +1600,16 @@ struct NodeNeighbor {
        NeighborType t;
        v3s16 p;
        bool l; //can liquid
+
+       NodeNeighbor()
+               : n(CONTENT_AIR)
+       { }
+
+       NodeNeighbor(const MapNode &node, NeighborType n_type, v3s16 pos)
+               : n(node),
+                 t(n_type),
+                 p(pos)
+       { }
 };
 
 void Map::transforming_liquid_add(v3s16 p) {
@@ -1628,7 +1635,7 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
                infostream<<"transformLiquids(): initial_size="<<initial_size<<std::endl;*/
 
        // list of nodes that due to viscosity have not reached their max level height
-       UniqueQueue<v3s16> must_reflow;
+       std::deque<v3s16> must_reflow;
 
        // List of MapBlocks that will require a lighting update (due to lava)
        std::map<v3s16, MapBlock*> lighting_modified_blocks;
@@ -1716,7 +1723,7 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
                                        break;
                        }
                        v3s16 npos = p0 + dirs[i];
-                       NodeNeighbor nb = {getNodeNoEx(npos), nt, npos};
+                       NodeNeighbor nb(getNodeNoEx(npos), nt, npos);
                        switch (nodemgr->get(nb.n.getContent()).liquid_type) {
                                case LIQUID_NONE:
                                        if (nb.n.getContent() == CONTENT_AIR) {
@@ -1909,11 +1916,10 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
                }
        }
        //infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
-       while (must_reflow.size() > 0)
-       {
-               m_transforming_liquid.push_back(must_reflow.front());
-               must_reflow.pop_front();
-       }
+
+       for (std::deque<v3s16>::iterator iter = must_reflow.begin(); iter != must_reflow.end(); ++iter)
+               m_transforming_liquid.push_back(*iter);
+
        updateLighting(lighting_modified_blocks, modified_blocks);
 
 
@@ -3103,7 +3109,7 @@ void ServerMap::saveMapMeta()
 
        createDirs(m_savedir);
 
-       std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
+       std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
        std::ostringstream ss(std::ios_base::binary);
 
        Settings params;
@@ -3127,19 +3133,21 @@ void ServerMap::loadMapMeta()
 {
        DSTACK(__FUNCTION_NAME);
 
+       Settings params;
        std::string fullpath = m_savedir + DIR_DELIM "map_meta.txt";
-       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");
-       }
 
-       Settings params;
+       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");
+               }
 
-       if (!params.parseConfigLines(is, "[end_of_params]")) {
-               throw SerializationError("ServerMap::loadMapMeta(): "
+               if (!params.parseConfigLines(is, "[end_of_params]")) {
+                       throw SerializationError("ServerMap::loadMapMeta(): "
                                "[end_of_params] not found!");
+               }
        }
 
        m_emerge->loadParamsFromSettings(&params);
@@ -3214,8 +3222,6 @@ bool ServerMap::loadSectorMeta(v2s16 p2d)
 {
        DSTACK(__FUNCTION_NAME);
 
-       MapSector *sector = NULL;
-
        // The directory layout we're going to load from.
        //  1 - original sectors/xxxxzzzz/
        //  2 - new sectors2/xxx/zzz/
@@ -3235,7 +3241,7 @@ bool ServerMap::loadSectorMeta(v2s16 p2d)
        }
 
        try{
-               sector = loadSectorMeta(sectordir, loadlayout != 2);
+               loadSectorMeta(sectordir, loadlayout != 2);
        }
        catch(InvalidFilenameException &e)
        {