remove some old sectors junk

This commit is contained in:
darkrose 2015-04-23 03:49:53 +10:00
parent 9a7eac64d7
commit eb1ef8a8dc
9 changed files with 57 additions and 423 deletions

View File

@ -46,64 +46,14 @@
#define WATER_VISC 1
#define LAVA_VISC 7
/*
A conversion table for backwards compatibility.
Maps <=v19 content types to current ones.
Should never be touched.
*/
content_t trans_table_19[21][2] = {
{CONTENT_GRASS, 1},
{CONTENT_TREE, 4},
{CONTENT_LEAVES, 5},
{CONTENT_FARM_DIRT, 6},
{CONTENT_MESE, 7},
{CONTENT_MUD, 8},
{CONTENT_COTTON, 10},
{CONTENT_BORDERSTONE, 11},
{CONTENT_WOOD, 12},
{CONTENT_SAND, 13},
{CONTENT_COBBLE, 18},
{CONTENT_STEEL, 19},
{CONTENT_GLASS, 20},
{CONTENT_MOSSYCOBBLE, 22},
{CONTENT_GRAVEL, 23},
{CONTENT_SANDSTONE, 24},
{CONTENT_CACTUS, 25},
{CONTENT_BRICK, 26},
{CONTENT_CLAY, 27},
{CONTENT_PAPYRUS, 28},
{CONTENT_BOOKSHELF, 29},
};
MapNode mapnode_translate_from_internal(MapNode n_from, u8 version)
{
MapNode result = n_from;
if(version <= 19)
{
content_t c_from = n_from.getContent();
for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
{
if(trans_table_19[i][0] == c_from)
{
result.setContent(trans_table_19[i][1]);
break;
}
}
}
return result;
return n_from;
}
MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
{
MapNode result = n_from;
if (version <= 19) {
content_t c_from = n_from.getContent();
for (u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++) {
if (trans_table_19[i][1] == c_from) {
result.setContent(trans_table_19[i][0]);
break;
}
}
}
if (n_from.getContent() == CONTENT_LADDER_LEGACY) {
switch (n_from.param2) {
case 1:

View File

@ -38,8 +38,6 @@ void content_mapnode_slab(bool repeat);
void content_mapnode_special(bool repeat);
void content_mapnode_plants(bool repeat);
extern content_t trans_table_19[21][2];
MapNode mapnode_translate_from_internal(MapNode n_from, u8 version);
MapNode mapnode_translate_to_internal(MapNode n_from, u8 version);

View File

@ -51,18 +51,6 @@ InventoryItem::~InventoryItem()
{
}
content_t content_translate_from_19_to_internal(content_t c_from)
{
for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
{
if(trans_table_19[i][1] == c_from)
{
return trans_table_19[i][0];
}
}
return c_from;
}
content_t InventoryItem::info(std::istream &is, u16 *count, u16 *wear)
{
DSTACK(__FUNCTION_NAME);

View File

@ -920,11 +920,7 @@ int main(int argc, char *argv[])
// (for texture atlas making)
init_mineral();
#if USE_AUDIO == 1
ISoundManager *sound = createSoundManager();
#else
ISoundManager *sound = NULL;
#endif
/*
Run unit tests
@ -1160,6 +1156,12 @@ int main(int argc, char *argv[])
drawLoadingScreen(driver,wgettext("Loading Creatures"));
content_mob_init();
drawLoadingScreen(driver,wgettext("Setting Up Sound"));
#if USE_AUDIO == 1
sound = createSoundManager();
#endif
/*
GUI stuff
*/

View File

@ -2506,12 +2506,6 @@ void ServerMap::verifyDatabase() {
}
}
bool ServerMap::loadFromFolders() {
if(!m_database && !fs::PathExists(m_savedir + DIR_DELIM + "map.sqlite"))
return true;
return false;
}
sqlite3_int64 ServerMap::getBlockAsInteger(const v3s16 pos) {
return (sqlite3_int64)pos.Z*16777216 +
(sqlite3_int64)pos.Y*4096 + (sqlite3_int64)pos.X;
@ -2601,54 +2595,42 @@ std::string ServerMap::getBlockFilename(v3s16 p)
void ServerMap::save(bool only_changed)
{
DSTACK(__FUNCTION_NAME);
if(m_map_saving_enabled == false)
{
if (m_map_saving_enabled == false) {
infostream<<"WARNING: Not saving map, saving disabled."<<std::endl;
return;
}
if(only_changed == false)
if (only_changed == false)
infostream<<"ServerMap: Saving whole map, this can take time."
<<std::endl;
if(only_changed == false || m_map_metadata_changed)
{
if (only_changed == false || m_map_metadata_changed)
saveMapMeta();
}
u32 sector_meta_count = 0;
u32 block_count = 0;
u32 block_count_all = 0; // Number of blocks in memory
// Don't do anything with sqlite unless something is really saved
bool save_started = false;
core::map<v2s16, MapSector*>::Iterator i = m_sectors.getIterator();
for(; i.atEnd() == false; i++)
{
for (core::map<v2s16, MapSector*>::Iterator i = m_sectors.getIterator(); i.atEnd() == false; i++) {
ServerMapSector *sector = (ServerMapSector*)i.getNode()->getValue();
assert(sector->getId() == MAPSECTOR_SERVER);
if(sector->differs_from_disk || only_changed == false)
{
saveSectorMeta(sector);
sector_meta_count++;
}
core::list<MapBlock*> blocks;
sector->getBlocks(blocks);
core::list<MapBlock*>::Iterator j;
for(j=blocks.begin(); j!=blocks.end(); j++)
{
for (j=blocks.begin(); j!=blocks.end(); j++) {
MapBlock *block = *j;
block_count_all++;
if(block->getModified() >= MOD_STATE_WRITE_NEEDED
|| only_changed == false)
{
if (
block->getModified() >= MOD_STATE_WRITE_NEEDED
|| only_changed == false
) {
// Lazy beginSave()
if(!save_started){
if (!save_started) {
beginSave();
save_started = true;
}
@ -2664,11 +2646,8 @@ void ServerMap::save(bool only_changed)
/*
Only print if something happened or saved whole map
*/
if(only_changed == false || sector_meta_count != 0
|| block_count != 0)
{
if (only_changed == false || block_count != 0) {
infostream<<"ServerMap: Written: "
<<sector_meta_count<<" sector metadata files, "
<<block_count<<" block files"
<<", "<<block_count_all<<" blocks in memory."
<<std::endl;
@ -2677,16 +2656,15 @@ void ServerMap::save(bool only_changed)
static s32 unsignedToSigned(s32 i, s32 max_positive)
{
if(i < max_positive)
if (i < max_positive)
return i;
else
return i - 2*max_positive;
return i - 2*max_positive;
}
// modulo of a negative number does not work consistently in C
static sqlite3_int64 pythonmodulo(sqlite3_int64 i, sqlite3_int64 mod)
{
if(i >= 0)
if (i >= 0)
return i % mod;
return mod - ((-i) % mod);
}
@ -2703,21 +2681,12 @@ v3s16 ServerMap::getIntegerAsBlock(sqlite3_int64 i)
void ServerMap::listAllLoadableBlocks(core::list<v3s16> &dst)
{
if(loadFromFolders()){
errorstream<<"Map::listAllLoadableBlocks(): Result will be missing "
<<"all blocks that are stored in flat files"<<std::endl;
}
verifyDatabase();
{
verifyDatabase();
while(sqlite3_step(m_database_list) == SQLITE_ROW)
{
sqlite3_int64 block_i = sqlite3_column_int64(m_database_list, 0);
v3s16 p = getIntegerAsBlock(block_i);
//dstream<<"block_i="<<block_i<<" p="<<PP(p)<<std::endl;
dst.push_back(p);
}
while (sqlite3_step(m_database_list) == SQLITE_ROW) {
sqlite3_int64 block_i = sqlite3_column_int64(m_database_list, 0);
v3s16 p = getIntegerAsBlock(block_i);
dst.push_back(p);
}
}
@ -2828,182 +2797,6 @@ void ServerMap::loadMapMeta()
infostream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
}
void ServerMap::saveSectorMeta(ServerMapSector *sector)
{
DSTACK(__FUNCTION_NAME);
// Format used for writing
u8 version = SER_FMT_VER_HIGHEST;
// Get destination
v2s16 pos = sector->getPos();
std::string dir = getSectorDir(pos);
createDirs(dir);
std::string fullpath = dir + DIR_DELIM + "meta";
std::ofstream o(fullpath.c_str(), std::ios_base::binary);
if(o.good() == false)
throw FileNotGoodException("Cannot open sector metafile");
sector->serialize(o, version);
sector->differs_from_disk = false;
}
MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load)
{
DSTACK(__FUNCTION_NAME);
// Get destination
v2s16 p2d = getSectorPos(sectordir);
ServerMapSector *sector = NULL;
std::string fullpath = sectordir + DIR_DELIM + "meta";
std::ifstream is(fullpath.c_str(), std::ios_base::binary);
if(is.good() == false)
{
// If the directory exists anyway, it probably is in some old
// format. Just go ahead and create the sector.
if(fs::PathExists(sectordir))
{
/*infostream<<"ServerMap::loadSectorMeta(): Sector metafile "
<<fullpath<<" doesn't exist but directory does."
<<" Continuing with a sector with no metadata."
<<std::endl;*/
sector = new ServerMapSector(this, p2d);
m_sectors.insert(p2d, sector);
}
else
{
throw FileNotGoodException("Cannot open sector metafile");
}
}
else
{
sector = ServerMapSector::deSerialize
(is, this, p2d, m_sectors);
if(save_after_load)
saveSectorMeta(sector);
}
sector->differs_from_disk = false;
return sector;
}
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/
// If we load from anything but the latest structure, we will
// immediately save to the new one, and remove the old.
int loadlayout = 1;
std::string sectordir1 = getSectorDir(p2d, 1);
std::string sectordir;
if(fs::PathExists(sectordir1))
{
sectordir = sectordir1;
}
else
{
loadlayout = 2;
sectordir = getSectorDir(p2d, 2);
}
try{
sector = loadSectorMeta(sectordir, loadlayout != 2);
}
catch(InvalidFilenameException &e)
{
return false;
}
catch(FileNotGoodException &e)
{
return false;
}
catch(std::exception &e)
{
return false;
}
return true;
}
#if 0
bool ServerMap::loadSectorFull(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/
// If we load from anything but the latest structure, we will
// immediately save to the new one, and remove the old.
int loadlayout = 1;
std::string sectordir1 = getSectorDir(p2d, 1);
std::string sectordir;
if(fs::PathExists(sectordir1))
{
sectordir = sectordir1;
}
else
{
loadlayout = 2;
sectordir = getSectorDir(p2d, 2);
}
try{
sector = loadSectorMeta(sectordir, loadlayout != 2);
}
catch(InvalidFilenameException &e)
{
return false;
}
catch(FileNotGoodException &e)
{
return false;
}
catch(std::exception &e)
{
return false;
}
/*
Load blocks
*/
std::vector<fs::DirListNode> list2 = fs::GetDirListing
(sectordir);
std::vector<fs::DirListNode>::iterator i2;
for(i2=list2.begin(); i2!=list2.end(); i2++)
{
// We want files
if(i2->dir)
continue;
try{
loadBlock(sectordir, i2->name, sector, loadlayout != 2);
}
catch(InvalidFilenameException &e)
{
// This catches unknown crap in directory
}
}
if(loadlayout != 2)
{
infostream<<"Sector converted to new layout - deleting "<<
sectordir1<<std::endl;
fs::RecursiveDelete(sectordir1);
}
return true;
}
#endif
void ServerMap::beginSave() {
verifyDatabase();
if(sqlite3_exec(m_database, "BEGIN;", NULL, NULL, NULL) != SQLITE_OK)
@ -3235,92 +3028,35 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
v2s16 p2d(blockpos.X, blockpos.Z);
if(!loadFromFolders()) {
verifyDatabase();
verifyDatabase();
if(sqlite3_bind_int64(m_database_read, 1, getBlockAsInteger(blockpos)) != SQLITE_OK)
infostream<<"WARNING: Could not bind block position for load: "
<<sqlite3_errmsg(m_database)<<std::endl;
if(sqlite3_step(m_database_read) == SQLITE_ROW) {
/*
Make sure sector is loaded
*/
MapSector *sector = createSector(p2d);
if (sqlite3_bind_int64(m_database_read, 1, getBlockAsInteger(blockpos)) != SQLITE_OK)
infostream<<"WARNING: Could not bind block position for load: "
<<sqlite3_errmsg(m_database)<<std::endl;
if (sqlite3_step(m_database_read) == SQLITE_ROW) {
/*
Make sure sector is loaded
*/
MapSector *sector = createSector(p2d);
/*
Load block
*/
const char * data = (const char *)sqlite3_column_blob(m_database_read, 0);
size_t len = sqlite3_column_bytes(m_database_read, 0);
/*
Load block
*/
const char * data = (const char *)sqlite3_column_blob(m_database_read, 0);
size_t len = sqlite3_column_bytes(m_database_read, 0);
std::string datastr(data, len);
std::string datastr(data, len);
loadBlock(&datastr, blockpos, sector, false);
loadBlock(&datastr, blockpos, sector, false);
sqlite3_step(m_database_read);
// We should never get more than 1 row, so ok to reset
sqlite3_reset(m_database_read);
return getBlockNoCreateNoEx(blockpos);
}
sqlite3_step(m_database_read);
// We should never get more than 1 row, so ok to reset
sqlite3_reset(m_database_read);
// Not found in database, try the files
return getBlockNoCreateNoEx(blockpos);
}
sqlite3_reset(m_database_read);
// The directory layout we're going to load from.
// 1 - original sectors/xxxxzzzz/
// 2 - new sectors2/xxx/zzz/
// If we load from anything but the latest structure, we will
// immediately save to the new one, and remove the old.
int loadlayout = 1;
std::string sectordir1 = getSectorDir(p2d, 1);
std::string sectordir;
if(fs::PathExists(sectordir1))
{
sectordir = sectordir1;
}
else
{
loadlayout = 2;
sectordir = getSectorDir(p2d, 2);
}
/*
Make sure sector is loaded
*/
MapSector *sector = getSectorNoGenerateNoEx(p2d);
if(sector == NULL)
{
try{
sector = loadSectorMeta(sectordir, loadlayout != 2);
}
catch(InvalidFilenameException &e)
{
return NULL;
}
catch(FileNotGoodException &e)
{
return NULL;
}
catch(std::exception &e)
{
return NULL;
}
}
/*
Make sure file exists
*/
std::string blockfilename = getBlockFilename(blockpos);
if(fs::PathExists(sectordir+DIR_DELIM+blockfilename) == false)
return NULL;
/*
Load block and save it to the database
*/
loadBlock(sectordir, blockfilename, sector, true);
return getBlockNoCreateNoEx(blockpos);
}

View File

@ -391,9 +391,6 @@ public:
static sqlite3_int64 getBlockAsInteger(const v3s16 pos);
static v3s16 getIntegerAsBlock(sqlite3_int64 i);
// Returns true if the database file does not exist
bool loadFromFolders();
// Call these before and after saving of blocks
void beginSave();
void endSave();
@ -407,25 +404,6 @@ public:
void saveMapMeta();
void loadMapMeta();
/*void saveChunkMeta();
void loadChunkMeta();*/
// The sector mutex should be locked when calling most of these
// This only saves sector-specific data such as the heightmap
// (no MapBlocks)
// DEPRECATED? Sectors have no metadata anymore.
void saveSectorMeta(ServerMapSector *sector);
MapSector* loadSectorMeta(std::string dirname, bool save_after_load);
bool loadSectorMeta(v2s16 p2d);
// Full load of a sector including all blocks.
// returns true on success, false on failure.
bool loadSectorFull(v2s16 p2d);
// If sector is not found in memory, try to load it from disk.
// Returns true if sector now resides in memory
//bool deFlushSector(v2s16 p2d);
void saveBlock(MapBlock *block);
// This will generate a sector with getSector if not found.
void loadBlock(std::string sectordir, std::string blockfile, MapSector *sector, bool save_after_load=false);

View File

@ -30,7 +30,6 @@
#include "mapblock.h"
MapSector::MapSector(Map *parent, v2s16 pos):
differs_from_disk(false),
m_parent(parent),
m_pos(pos),
m_block_cache(NULL)
@ -49,8 +48,7 @@ void MapSector::deleteBlocks()
// Delete all
core::map<s16, MapBlock*>::Iterator i = m_blocks.getIterator();
for(; i.atEnd() == false; i++)
{
for (; i.atEnd() == false; i++) {
delete i.getNode()->getValue();
}
@ -60,22 +58,16 @@ void MapSector::deleteBlocks()
MapBlock * MapSector::getBlockBuffered(s16 y)
{
MapBlock *block;
MapBlock *block = NULL;
if(m_block_cache != NULL && y == m_block_cache_y){
if (m_block_cache != NULL && y == m_block_cache_y)
return m_block_cache;
}
// If block doesn't exist, return NULL
core::map<s16, MapBlock*>::Node *n = m_blocks.find(y);
if(n == NULL)
{
block = NULL;
}
// If block exists, return it
else{
if (n != NULL)
block = n->getValue();
}
// Cache the last result
m_block_cache_y = y;
@ -114,9 +106,8 @@ void MapSector::insertBlock(MapBlock *block)
s16 block_y = block->getPos().Y;
MapBlock *block2 = getBlockBuffered(block_y);
if(block2 != NULL){
if (block2 != NULL)
throw AlreadyExistsException("Block already exists");
}
v2s16 p2d(block->getPos().X, block->getPos().Z);
assert(p2d == m_pos);
@ -146,8 +137,7 @@ void MapSector::getBlocks(core::list<MapBlock*> &dest)
core::map<s16, MapBlock*>::Iterator bi;
bi = m_blocks.getIterator();
for(; bi.atEnd() == false; bi++)
{
for (; bi.atEnd() == false; bi++) {
MapBlock *b = bi.getNode()->getValue();
dest.push_back(b);
}
@ -168,7 +158,7 @@ ServerMapSector::~ServerMapSector()
void ServerMapSector::serialize(std::ostream &os, u8 version)
{
if(!ser_ver_supported(version))
if (!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapSector format not supported");
/*
@ -208,7 +198,7 @@ ServerMapSector* ServerMapSector::deSerialize(
u8 version = SER_FMT_VER_INVALID;
is.read((char*)&version, 1);
if(!ser_ver_supported(version))
if (!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapSector format not supported");
/*
@ -223,8 +213,7 @@ ServerMapSector* ServerMapSector::deSerialize(
core::map<v2s16, MapSector*>::Node *n = sectors.find(p2d);
if(n != NULL)
{
if (n != NULL) {
dstream<<"WARNING: deSerializing existent sectors not supported "
"at the moment, because code hasn't been tested."
<<std::endl;
@ -232,9 +221,7 @@ ServerMapSector* ServerMapSector::deSerialize(
MapSector *sector = n->getValue();
assert(sector->getId() == MAPSECTOR_SERVER);
return (ServerMapSector*)sector;
}
else
{
}else{
sector = new ServerMapSector(parent, p2d);
sectors.insert(p2d, sector);
}

View File

@ -67,9 +67,6 @@ public:
void getBlocks(core::list<MapBlock*> &dest);
// Always false at the moment, because sector contains no metadata.
bool differs_from_disk;
protected:
// The pile of MapBlocks

View File

@ -213,9 +213,7 @@ void * EmergeThread::Thread()
JMutexAutoLock envlock(m_server->m_env_mutex);
// Load sector if it isn't loaded
if(map.getSectorNoGenerateNoEx(p2d) == NULL)
//map.loadSectorFull(p2d);
map.loadSectorMeta(p2d);
map.getSectorNoGenerateNoEx(p2d);
block = map.getBlockNoCreateNoEx(p);
if(!block || block->isDummy() || !block->isGenerated())