]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/map.cpp
Remove unused Map::getDayNightDiff + fix one undefined variable in mapblock.cpp
[dragonfireclient.git] / src / map.cpp
index 43a49dc2f6ddb068d930ccb61d15070c6477ebe8..972c666e4d6c4ce201824b033dc06140b3bdfffd 100644 (file)
@@ -44,6 +44,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 "script/scripting_server.h"
 #include <deque>
 #include <queue>
 #if USE_LEVELDB
@@ -64,12 +65,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 Map::Map(std::ostream &dout, IGameDef *gamedef):
        m_dout(dout),
        m_gamedef(gamedef),
-       m_sector_cache(NULL),
-       m_nodedef(gamedef->ndef()),
-       m_transforming_liquid_loop_count_multiplier(1.0f),
-       m_unprocessed_count(0),
-       m_inc_trending_up_start_time(0),
-       m_queue_size_timer_started(false)
+       m_nodedef(gamedef->ndef())
 {
 }
 
@@ -366,63 +362,6 @@ bool Map::removeNodeWithEvent(v3s16 p)
        return succeeded;
 }
 
-bool Map::getDayNightDiff(v3s16 blockpos)
-{
-       try{
-               v3s16 p = blockpos + v3s16(0,0,0);
-               MapBlock *b = getBlockNoCreate(p);
-               if(b->getDayNightDiff())
-                       return true;
-       }
-       catch(InvalidPositionException &e){}
-       // Leading edges
-       try{
-               v3s16 p = blockpos + v3s16(-1,0,0);
-               MapBlock *b = getBlockNoCreate(p);
-               if(b->getDayNightDiff())
-                       return true;
-       }
-       catch(InvalidPositionException &e){}
-       try{
-               v3s16 p = blockpos + v3s16(0,-1,0);
-               MapBlock *b = getBlockNoCreate(p);
-               if(b->getDayNightDiff())
-                       return true;
-       }
-       catch(InvalidPositionException &e){}
-       try{
-               v3s16 p = blockpos + v3s16(0,0,-1);
-               MapBlock *b = getBlockNoCreate(p);
-               if(b->getDayNightDiff())
-                       return true;
-       }
-       catch(InvalidPositionException &e){}
-       // Trailing edges
-       try{
-               v3s16 p = blockpos + v3s16(1,0,0);
-               MapBlock *b = getBlockNoCreate(p);
-               if(b->getDayNightDiff())
-                       return true;
-       }
-       catch(InvalidPositionException &e){}
-       try{
-               v3s16 p = blockpos + v3s16(0,1,0);
-               MapBlock *b = getBlockNoCreate(p);
-               if(b->getDayNightDiff())
-                       return true;
-       }
-       catch(InvalidPositionException &e){}
-       try{
-               v3s16 p = blockpos + v3s16(0,0,1);
-               MapBlock *b = getBlockNoCreate(p);
-               if(b->getDayNightDiff())
-                       return true;
-       }
-       catch(InvalidPositionException &e){}
-
-       return false;
-}
-
 struct TimeOrderedMapBlock {
        MapSector *sect;
        MapBlock *block;
@@ -637,7 +576,8 @@ s32 Map::transforming_liquid_size() {
         return m_transforming_liquid.size();
 }
 
-void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks)
+void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
+               ServerEnvironment *env)
 {
        DSTACK(FUNCTION_NAME);
        //TimeTaker timer("transformLiquids()");
@@ -897,8 +837,16 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks)
                        // set the liquid level and flow bit to 0
                        n0.param2 = ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK);
                }
+
+               // change the node.
                n0.setContent(new_node_content);
 
+               // on_flood() the node
+               if (floodable_node != CONTENT_AIR) {
+                       if (env->getScriptIface()->node_on_flood(p0, n00, n0))
+                               continue;
+               }
+
                // Ignore light (because calling voxalgo::update_lighting_nodes)
                n0.setLight(LIGHTBANK_DAY, 0, m_nodedef);
                n0.setLight(LIGHTBANK_NIGHT, 0, m_nodedef);
@@ -971,7 +919,7 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks)
 
        time_until_purge *= 1000;       // seconds -> milliseconds
 
-       u32 curr_time = getTime(PRECISION_MILLI);
+       u64 curr_time = porting::getTimeMs();
        u32 prev_unprocessed = m_unprocessed_count;
        m_unprocessed_count = m_transforming_liquid.size();
 
@@ -1226,11 +1174,11 @@ bool Map::isBlockOccluded(MapBlock *block, v3s16 cam_pos_nodes) {
 /*
        ServerMap
 */
-ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge):
+ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef,
+               EmergeManager *emerge):
        Map(dout_server, gamedef),
        settings_mgr(g_settings, savedir + DIR_DELIM + "map_meta.txt"),
-       m_emerge(emerge),
-       m_map_metadata_changed(true)
+       m_emerge(emerge)
 {
        verbosestream<<FUNCTION_NAME<<std::endl;
 
@@ -1367,6 +1315,24 @@ s16 ServerMap::getWaterLevel()
        return getMapgenParams()->water_level;
 }
 
+bool ServerMap::saoPositionOverLimit(const v3f &p)
+{
+       return getMapgenParams()->saoPosOverLimit(p);
+}
+
+bool ServerMap::blockpos_over_mapgen_limit(v3s16 p)
+{
+       const s16 mapgen_limit_bp = rangelim(
+               getMapgenParams()->mapgen_limit, 0, MAX_MAP_GENERATION_LIMIT) /
+               MAP_BLOCKSIZE;
+       return p.X < -mapgen_limit_bp ||
+               p.X >  mapgen_limit_bp ||
+               p.Y < -mapgen_limit_bp ||
+               p.Y >  mapgen_limit_bp ||
+               p.Z < -mapgen_limit_bp ||
+               p.Z >  mapgen_limit_bp;
+}
+
 bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data)
 {
        s16 csize = getMapgenParams()->chunksize;
@@ -1380,9 +1346,9 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data)
        v3s16 full_bpmin = bpmin - extra_borders;
        v3s16 full_bpmax = bpmax + extra_borders;
 
-       // Do nothing if not inside limits (+-1 because of neighbors)
-       if (blockpos_over_limit(full_bpmin) ||
-               blockpos_over_limit(full_bpmax))
+       // Do nothing if not inside mapgen limits (+-1 because of neighbors)
+       if (blockpos_over_mapgen_limit(full_bpmin) ||
+                       blockpos_over_mapgen_limit(full_bpmax))
                return false;
 
        data->seed = getSeed();
@@ -1549,25 +1515,14 @@ ServerMapSector *ServerMap::createSector(v2s16 p2d)
 #endif
 
        /*
-               Do not create over-limit.
-               We are checking for any nodes of the mapblocks of the sector being beyond the limit.
-               A sector is a vertical column of mapblocks, so sectorpos is like a 2D blockpos.
-
-               At the negative limit we are checking for
-                       block minimum nodepos < -mapgenlimit.
-               At the positive limit we are checking for
-                       block maximum nodepos > mapgenlimit.
-
-               Block minimum nodepos = blockpos * mapblocksize.
-               Block maximum nodepos = (blockpos + 1) * mapblocksize - 1.
+               Do not create over max mapgen limit
        */
-       const u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
-               g_settings->getU16("map_generation_limit"));
-       if (p2d.X * MAP_BLOCKSIZE < -map_gen_limit
-                       || (p2d.X + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit
-                       || p2d.Y * MAP_BLOCKSIZE < -map_gen_limit
-                       || (p2d.Y + 1) * MAP_BLOCKSIZE - 1 > map_gen_limit)
-               throw InvalidPositionException("createSector(): pos. over limit");
+       const s16 max_limit_bp = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
+       if (p2d.X < -max_limit_bp ||
+                       p2d.X >  max_limit_bp ||
+                       p2d.Y < -max_limit_bp ||
+                       p2d.Y >  max_limit_bp)
+               throw InvalidPositionException("createSector(): pos. over max mapgen limit");
 
        /*
                Generate blank sector
@@ -1708,10 +1663,10 @@ MapBlock * ServerMap::createBlock(v3s16 p)
                        FUNCTION_NAME, p.X, p.Y, p.Z);
 
        /*
-               Do not create over-limit
+               Do not create over max mapgen limit
        */
-       if (blockpos_over_limit(p))
-               throw InvalidPositionException("createBlock(): pos. over limit");
+       if (blockpos_over_max_limit(p))
+               throw InvalidPositionException("createBlock(): pos. over max mapgen limit");
 
        v2s16 p2d(p.X, p.Z);
        s16 block_y = p.Y;
@@ -1825,9 +1780,6 @@ MapBlock *ServerMap::getBlockOrEmerge(v3s16 p3d)
        return block;
 }
 
-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)
@@ -1934,7 +1886,7 @@ std::string ServerMap::getSectorDir(v2s16 pos, int layout)
        }
 }
 
-v2s16 ServerMap::getSectorPos(std::string dirname)
+v2s16 ServerMap::getSectorPos(const std::string &dirname)
 {
        unsigned int x = 0, y = 0;
        int r;
@@ -1964,7 +1916,7 @@ v2s16 ServerMap::getSectorPos(std::string dirname)
        return pos;
 }
 
-v3s16 ServerMap::getBlockPos(std::string sectordir, std::string blockfile)
+v3s16 ServerMap::getBlockPos(const std::string &sectordir, const std::string &blockfile)
 {
        v2s16 p2d = getSectorPos(sectordir);
 
@@ -2273,13 +2225,13 @@ bool ServerMap::loadSectorFull(v2s16 p2d)
 }
 #endif
 
-Database *ServerMap::createDatabase(
+MapDatabase *ServerMap::createDatabase(
        const std::string &name,
        const std::string &savedir,
        Settings &conf)
 {
        if (name == "sqlite3")
-               return new Database_SQLite3(savedir);
+               return new MapDatabaseSQLite3(savedir);
        if (name == "dummy")
                return new Database_Dummy();
        #if USE_LEVELDB
@@ -2291,8 +2243,11 @@ Database *ServerMap::createDatabase(
                return new Database_Redis(conf);
        #endif
        #if USE_POSTGRESQL
-       else if (name == "postgresql")
-               return new Database_PostgreSQL(conf);
+       else if (name == "postgresql") {
+               std::string connect_string = "";
+               conf.getNoEx("pgsql_connection", connect_string);
+               return new MapDatabasePostgreSQL(connect_string);
+       }
        #endif
        else
                throw BaseException(std::string("Database backend ") + name + " not supported.");
@@ -2313,7 +2268,7 @@ bool ServerMap::saveBlock(MapBlock *block)
        return saveBlock(block, dbase);
 }
 
-bool ServerMap::saveBlock(MapBlock *block, Database *db)
+bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db)
 {
        v3s16 p3d = block->getPos();
 
@@ -2344,16 +2299,15 @@ bool ServerMap::saveBlock(MapBlock *block, Database *db)
        return ret;
 }
 
-void ServerMap::loadBlock(std::string sectordir, std::string blockfile,
+void ServerMap::loadBlock(const std::string &sectordir, const std::string &blockfile,
                MapSector *sector, bool save_after_load)
 {
        DSTACK(FUNCTION_NAME);
 
        std::string fullpath = sectordir + DIR_DELIM + blockfile;
        try {
-
                std::ifstream is(fullpath.c_str(), std::ios_base::binary);
-               if(is.good() == false)
+               if (!is.good())
                        throw FileNotGoodException("Cannot open block file");
 
                v3s16 p3d = getBlockPos(sectordir, blockfile);
@@ -2438,13 +2392,6 @@ void ServerMap::loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool
                        throw SerializationError("ServerMap::loadBlock(): Failed"
                                        " to read MapBlock version");
 
-               /*u32 block_size = MapBlock::serializedLength(version);
-               SharedBuffer<u8> data(block_size);
-               is.read((char*)*data, block_size);*/
-
-               // This will always return a sector because we're the server
-               //MapSector *sector = emergeSector(p2d);
-
                MapBlock *block = NULL;
                bool created_new = false;
                block = sector->getBlockNoCreateNoEx(p3d.Y);
@@ -2596,10 +2543,18 @@ void ServerMap::PrintInfo(std::ostream &out)
        out<<"ServerMap: ";
 }
 
+bool ServerMap::repairBlockLight(v3s16 blockpos,
+       std::map<v3s16, MapBlock *> *modified_blocks)
+{
+       MapBlock *block = emergeBlock(blockpos, false);
+       if (!block || !block->isGenerated())
+               return false;
+       voxalgo::repair_block_light(this, block, modified_blocks);
+       return true;
+}
+
 MMVManip::MMVManip(Map *map):
                VoxelManipulator(),
-               m_is_dirty(false),
-               m_create_area(false),
                m_map(map)
 {
 }
@@ -2662,7 +2617,7 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
                if(block_data_inexistent)
                {
 
-                       if (load_if_inexistent && !blockpos_over_limit(p)) {
+                       if (load_if_inexistent && !blockpos_over_max_limit(p)) {
                                ServerMap *svrmap = (ServerMap *)m_map;
                                block = svrmap->emergeBlock(p, false);
                                if (block == NULL)