Modernize client code (#6250)
[oweals/minetest.git] / src / map.cpp
index 75dcee350dff91d6e236b726e47287b17aeee6fd..972c666e4d6c4ce201824b033dc06140b3bdfffd 100644 (file)
@@ -44,7 +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/serverscripting.h"
+#include "script/scripting_server.h"
 #include <deque>
 #include <queue>
 #if USE_LEVELDB
@@ -65,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())
 {
 }
 
@@ -367,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;
@@ -981,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();
 
@@ -1240,8 +1178,7 @@ 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;
 
@@ -1378,6 +1315,11 @@ 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(
@@ -1838,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)
@@ -2286,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
@@ -2304,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.");
@@ -2326,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();
 
@@ -2613,8 +2555,6 @@ bool ServerMap::repairBlockLight(v3s16 blockpos,
 
 MMVManip::MMVManip(Map *map):
                VoxelManipulator(),
-               m_is_dirty(false),
-               m_create_area(false),
                m_map(map)
 {
 }