#include "database.h"
#include "database-dummy.h"
#include "database-sqlite3.h"
+#include "script/scripting_server.h"
#include <deque>
#include <queue>
#if USE_LEVELDB
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()");
// 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);
time_until_purge *= 1000; // seconds -> milliseconds
- u32 curr_time = getTime(PRECISION_MILLI);
+ u32 curr_time = porting::getTime(PRECISION_MILLI);
u32 prev_unprocessed = m_unprocessed_count;
m_unprocessed_count = m_transforming_liquid.size();
/*
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),
return getMapgenParams()->water_level;
}
+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;
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();
#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
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;
}
}
-v2s16 ServerMap::getSectorPos(std::string dirname)
+v2s16 ServerMap::getSectorPos(const std::string &dirname)
{
unsigned int x = 0, y = 0;
int r;
return pos;
}
-v3s16 ServerMap::getBlockPos(std::string sectordir, std::string blockfile)
+v3s16 ServerMap::getBlockPos(const std::string §ordir, const std::string &blockfile)
{
v2s16 p2d = getSectorPos(sectordir);
}
#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
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.");
return saveBlock(block, dbase);
}
-bool ServerMap::saveBlock(MapBlock *block, Database *db)
+bool ServerMap::saveBlock(MapBlock *block, MapDatabase *db)
{
v3s16 p3d = block->getPos();
return ret;
}
-void ServerMap::loadBlock(std::string sectordir, std::string blockfile,
+void ServerMap::loadBlock(const std::string §ordir, 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);
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),
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)