diff --git a/src/database-dummy.cpp b/src/database-dummy.cpp index 271d9c975..5b1a14341 100644 --- a/src/database-dummy.cpp +++ b/src/database-dummy.cpp @@ -65,7 +65,7 @@ bool Database_Dummy::deleteBlock(v3s16 blockpos) return true; } -void Database_Dummy::listAllLoadableBlocks(std::list &dst) +void Database_Dummy::listAllLoadableBlocks(std::vector &dst) { for(std::map::iterator x = m_database.begin(); x != m_database.end(); ++x) { diff --git a/src/database-dummy.h b/src/database-dummy.h index a1535937d..732a206f8 100644 --- a/src/database-dummy.h +++ b/src/database-dummy.h @@ -36,7 +36,7 @@ public: virtual bool saveBlock(v3s16 blockpos, std::string &data); virtual std::string loadBlock(v3s16 blockpos); virtual bool deleteBlock(v3s16 blockpos); - virtual void listAllLoadableBlocks(std::list &dst); + virtual void listAllLoadableBlocks(std::vector &dst); virtual int Initialized(void); ~Database_Dummy(); private: diff --git a/src/database-leveldb.cpp b/src/database-leveldb.cpp index de510e533..b35e612b6 100644 --- a/src/database-leveldb.cpp +++ b/src/database-leveldb.cpp @@ -93,7 +93,7 @@ bool Database_LevelDB::deleteBlock(v3s16 blockpos) return true; } -void Database_LevelDB::listAllLoadableBlocks(std::list &dst) +void Database_LevelDB::listAllLoadableBlocks(std::vector &dst) { leveldb::Iterator* it = m_database->NewIterator(leveldb::ReadOptions()); for (it->SeekToFirst(); it->Valid(); it->Next()) { diff --git a/src/database-leveldb.h b/src/database-leveldb.h index c195260da..5d44ba3e7 100644 --- a/src/database-leveldb.h +++ b/src/database-leveldb.h @@ -39,7 +39,7 @@ public: virtual bool saveBlock(v3s16 blockpos, std::string &data); virtual std::string loadBlock(v3s16 blockpos); virtual bool deleteBlock(v3s16 blockpos); - virtual void listAllLoadableBlocks(std::list &dst); + virtual void listAllLoadableBlocks(std::vector &dst); virtual int Initialized(void); ~Database_LevelDB(); private: diff --git a/src/database-redis.cpp b/src/database-redis.cpp index b086f899d..0962e97ba 100644 --- a/src/database-redis.cpp +++ b/src/database-redis.cpp @@ -147,7 +147,7 @@ bool Database_Redis::deleteBlock(v3s16 blockpos) return true; } -void Database_Redis::listAllLoadableBlocks(std::list &dst) +void Database_Redis::listAllLoadableBlocks(std::vector &dst) { redisReply *reply; reply = (redisReply*) redisCommand(ctx, "HKEYS %s", hash.c_str()); @@ -155,8 +155,7 @@ void Database_Redis::listAllLoadableBlocks(std::list &dst) throw FileNotGoodException(std::string("redis command 'HKEYS %s' failed: ") + ctx->errstr); if(reply->type != REDIS_REPLY_ARRAY) throw FileNotGoodException("Failed to get keys from database"); - for(size_t i = 0; i < reply->elements; i++) - { + for(size_t i = 0; i < reply->elements; i++) { assert(reply->element[i]->type == REDIS_REPLY_STRING); dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str))); } diff --git a/src/database-redis.h b/src/database-redis.h index 34b90fa59..3c4e2b6d8 100644 --- a/src/database-redis.h +++ b/src/database-redis.h @@ -39,7 +39,7 @@ public: virtual bool saveBlock(v3s16 blockpos, std::string &data); virtual std::string loadBlock(v3s16 blockpos); virtual bool deleteBlock(v3s16 blockpos); - virtual void listAllLoadableBlocks(std::list &dst); + virtual void listAllLoadableBlocks(std::vector &dst); virtual int Initialized(void); ~Database_Redis(); private: diff --git a/src/database-sqlite3.cpp b/src/database-sqlite3.cpp index 0679da97d..2edae8be2 100644 --- a/src/database-sqlite3.cpp +++ b/src/database-sqlite3.cpp @@ -274,12 +274,11 @@ void Database_SQLite3::createDatabase() } -void Database_SQLite3::listAllLoadableBlocks(std::list &dst) +void Database_SQLite3::listAllLoadableBlocks(std::vector &dst) { verifyDatabase(); - while(sqlite3_step(m_database_list) == SQLITE_ROW) - { + 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="< &dst) = 0; + virtual void listAllLoadableBlocks(std::vector &dst) = 0; virtual int Initialized(void)=0; virtual ~Database() {}; }; diff --git a/src/environment.cpp b/src/environment.cpp index 166523a4f..e805a59a5 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -851,11 +851,10 @@ void ServerEnvironment::clearAllObjects() { infostream<<"ServerEnvironment::clearAllObjects(): " <<"Removing all active objects"< objects_to_remove; + std::vector objects_to_remove; for(std::map::iterator i = m_active_objects.begin(); - i != m_active_objects.end(); ++i) - { + i != m_active_objects.end(); ++i) { ServerActiveObject* obj = i->second; if(obj->getType() == ACTIVEOBJECT_TYPE_PLAYER) continue; @@ -888,15 +887,15 @@ void ServerEnvironment::clearAllObjects() // Id to be removed from m_active_objects objects_to_remove.push_back(id); } + // Remove references from m_active_objects - for(std::list::iterator i = objects_to_remove.begin(); - i != objects_to_remove.end(); ++i) - { + for(std::vector::iterator i = objects_to_remove.begin(); + i != objects_to_remove.end(); ++i) { m_active_objects.erase(*i); } // Get list of loaded blocks - std::list loaded_blocks; + std::vector loaded_blocks; infostream<<"ServerEnvironment::clearAllObjects(): " <<"Listing all loaded blocks"<listAllLoadedBlocks(loaded_blocks); @@ -905,7 +904,7 @@ void ServerEnvironment::clearAllObjects() < loadable_blocks; + std::vector loadable_blocks; infostream<<"ServerEnvironment::clearAllObjects(): " <<"Listing all loadable blocks"<listAllLoadableBlocks(loadable_blocks); @@ -915,9 +914,8 @@ void ServerEnvironment::clearAllObjects() <<", now clearing"<::iterator i = loaded_blocks.begin(); - i != loaded_blocks.end(); ++i) - { + for(std::vector::iterator i = loaded_blocks.begin(); + i != loaded_blocks.end(); ++i) { v3s16 p = *i; MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block); @@ -931,9 +929,8 @@ void ServerEnvironment::clearAllObjects() u32 num_blocks_checked = 0; u32 num_blocks_cleared = 0; u32 num_objs_cleared = 0; - for(std::list::iterator i = loadable_blocks.begin(); - i != loadable_blocks.end(); ++i) - { + for(std::vector::iterator i = loadable_blocks.begin(); + i != loadable_blocks.end(); ++i) { v3s16 p = *i; MapBlock *block = m_map->emergeBlock(p, false); if(!block){ @@ -969,9 +966,8 @@ void ServerEnvironment::clearAllObjects() m_map->unloadUnreferencedBlocks(); // Drop references that were added above - for(std::list::iterator i = loaded_blocks.begin(); - i != loaded_blocks.end(); ++i) - { + for(std::vector::iterator i = loaded_blocks.begin(); + i != loaded_blocks.end(); ++i) { v3s16 p = *i; MapBlock *block = m_map->getBlockNoCreateNoEx(p); assert(block); @@ -1542,11 +1538,10 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, */ void ServerEnvironment::removeRemovedObjects() { - std::list objects_to_remove; + std::vector objects_to_remove; for(std::map::iterator i = m_active_objects.begin(); - i != m_active_objects.end(); ++i) - { + i != m_active_objects.end(); ++i) { u16 id = i->first; ServerActiveObject* obj = i->second; // This shouldn't happen but check it @@ -1616,13 +1611,13 @@ void ServerEnvironment::removeRemovedObjects() // Delete if(obj->environmentDeletes()) delete obj; + // Id to be removed from m_active_objects objects_to_remove.push_back(id); } // Remove references from m_active_objects - for(std::list::iterator i = objects_to_remove.begin(); - i != objects_to_remove.end(); ++i) - { + for(std::vector::iterator i = objects_to_remove.begin(); + i != objects_to_remove.end(); ++i) { m_active_objects.erase(*i); } } @@ -1666,8 +1661,9 @@ static void print_hexdump(std::ostream &o, const std::string &data) */ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) { - if(block==NULL) + if(block == NULL) return; + // Ignore if no stored objects (to not set changed flag) if(block->m_static_objects.m_stored.empty()) return; @@ -1693,17 +1689,14 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) std::list new_stored; for(std::list::iterator i = block->m_static_objects.m_stored.begin(); - i != block->m_static_objects.m_stored.end(); ++i) - { - /*infostream<<"Server: Creating an active object from " - <<"static data"<m_static_objects.m_stored.end(); ++i) { StaticObject &s_obj = *i; + // Create an active object from the data ServerActiveObject *obj = ServerActiveObject::create ((ActiveObjectType) s_obj.type, this, 0, s_obj.pos, s_obj.data); // If couldn't create object, store static data back. - if(obj==NULL) - { + if(obj == NULL) { errorstream<<"ServerEnvironment::activateObjects(): " <<"failed to create active object from static object " <<"in block "< blocks; + std::vector blocks; ServerMap &old_map = ((ServerMap&)server->getMap()); old_map.listAllLoadableBlocks(blocks); int count = 0; new_db->beginSave(); - for (std::list::iterator i = blocks.begin(); i != blocks.end(); i++) { + for (std::vector::iterator i = blocks.begin(); i != blocks.end(); i++) { MapBlock *block = old_map.loadBlock(*i); if (!block) { errorstream << "Failed to load block " << PP(*i) << ", skipping it."; - } else { + } + else { old_map.saveBlock(block, new_db); MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z)); sector->deleteBlock(block); diff --git a/src/map.cpp b/src/map.cpp index d8f018742..cfad92e3e 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3070,7 +3070,7 @@ void ServerMap::save(ModifiedState save_level) } } -void ServerMap::listAllLoadableBlocks(std::list &dst) +void ServerMap::listAllLoadableBlocks(std::vector &dst) { if(loadFromFolders()){ errorstream<<"Map::listAllLoadableBlocks(): Result will be missing " @@ -3079,7 +3079,7 @@ void ServerMap::listAllLoadableBlocks(std::list &dst) dbase->listAllLoadableBlocks(dst); } -void ServerMap::listAllLoadedBlocks(std::list &dst) +void ServerMap::listAllLoadedBlocks(std::vector &dst) { for(std::map::iterator si = m_sectors.begin(); si != m_sectors.end(); ++si) diff --git a/src/map.h b/src/map.h index 1089e6d34..e2736d560 100644 --- a/src/map.h +++ b/src/map.h @@ -466,8 +466,8 @@ public: void endSave(); void save(ModifiedState save_level); - void listAllLoadableBlocks(std::list &dst); - void listAllLoadedBlocks(std::list &dst); + void listAllLoadableBlocks(std::vector &dst); + void listAllLoadedBlocks(std::vector &dst); // Saves map seed and possibly other stuff void saveMapMeta(); void loadMapMeta();