mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Replace std::list by std::vector into ServerMap::listAllLoadableBlocks ServerMap::listAllLoadedBlocks and their database backends.
This adds a speedup on database migration and /clearobjects command
This commit is contained in:
parent
c58d49977d
commit
718bcafd51
13 changed files with 43 additions and 51 deletions
|
@ -851,11 +851,10 @@ void ServerEnvironment::clearAllObjects()
|
|||
{
|
||||
infostream<<"ServerEnvironment::clearAllObjects(): "
|
||||
<<"Removing all active objects"<<std::endl;
|
||||
std::list<u16> objects_to_remove;
|
||||
std::vector<u16> objects_to_remove;
|
||||
for(std::map<u16, ServerActiveObject*>::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<u16>::iterator i = objects_to_remove.begin();
|
||||
i != objects_to_remove.end(); ++i)
|
||||
{
|
||||
for(std::vector<u16>::iterator i = objects_to_remove.begin();
|
||||
i != objects_to_remove.end(); ++i) {
|
||||
m_active_objects.erase(*i);
|
||||
}
|
||||
|
||||
// Get list of loaded blocks
|
||||
std::list<v3s16> loaded_blocks;
|
||||
std::vector<v3s16> loaded_blocks;
|
||||
infostream<<"ServerEnvironment::clearAllObjects(): "
|
||||
<<"Listing all loaded blocks"<<std::endl;
|
||||
m_map->listAllLoadedBlocks(loaded_blocks);
|
||||
|
@ -905,7 +904,7 @@ void ServerEnvironment::clearAllObjects()
|
|||
<<loaded_blocks.size()<<std::endl;
|
||||
|
||||
// Get list of loadable blocks
|
||||
std::list<v3s16> loadable_blocks;
|
||||
std::vector<v3s16> loadable_blocks;
|
||||
infostream<<"ServerEnvironment::clearAllObjects(): "
|
||||
<<"Listing all loadable blocks"<<std::endl;
|
||||
m_map->listAllLoadableBlocks(loadable_blocks);
|
||||
|
@ -915,9 +914,8 @@ void ServerEnvironment::clearAllObjects()
|
|||
<<", now clearing"<<std::endl;
|
||||
|
||||
// Grab a reference on each loaded block to avoid unloading it
|
||||
for(std::list<v3s16>::iterator i = loaded_blocks.begin();
|
||||
i != loaded_blocks.end(); ++i)
|
||||
{
|
||||
for(std::vector<v3s16>::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<v3s16>::iterator i = loadable_blocks.begin();
|
||||
i != loadable_blocks.end(); ++i)
|
||||
{
|
||||
for(std::vector<v3s16>::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<v3s16>::iterator i = loaded_blocks.begin();
|
||||
i != loaded_blocks.end(); ++i)
|
||||
{
|
||||
for(std::vector<v3s16>::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<u16> objects_to_remove;
|
||||
std::vector<u16> objects_to_remove;
|
||||
for(std::map<u16, ServerActiveObject*>::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<u16>::iterator i = objects_to_remove.begin();
|
||||
i != objects_to_remove.end(); ++i)
|
||||
{
|
||||
for(std::vector<u16>::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<StaticObject> new_stored;
|
||||
for(std::list<StaticObject>::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"<<std::endl;*/
|
||||
i != block->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 "<<PP(s_obj.pos/BS)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue