ABMHandler and player_collisions use sequential read/write. Switch from std::list...
authorLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Mar 2015 15:58:04 +0000 (16:58 +0100)
committerLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Mar 2015 16:02:36 +0000 (17:02 +0100)
* Also remove dead code Map::unloadUnusedData which is dead since a long time

src/environment.cpp
src/environment.h
src/localplayer.cpp
src/localplayer.h
src/map.cpp
src/map.h

index 217d50fd594b14b9300d6fc1253d2e99d18ddc30..0a3d360199d2c9d99a8a01a972afee200ca6f425 100644 (file)
@@ -382,7 +382,7 @@ ServerEnvironment::~ServerEnvironment()
        m_map->drop();
 
        // Delete ActiveBlockModifiers
-       for(std::list<ABMWithState>::iterator
+       for(std::vector<ABMWithState>::iterator
                        i = m_abms.begin(); i != m_abms.end(); ++i){
                delete i->abm;
        }
@@ -560,7 +560,7 @@ private:
        ServerEnvironment *m_env;
        std::map<content_t, std::vector<ActiveABM> > m_aabms;
 public:
-       ABMHandler(std::list<ABMWithState> &abms,
+       ABMHandler(std::vector<ABMWithState> &abms,
                        float dtime_s, ServerEnvironment *env,
                        bool use_timers):
                m_env(env)
@@ -568,8 +568,8 @@ public:
                if(dtime_s < 0.001)
                        return;
                INodeDefManager *ndef = env->getGameDef()->ndef();
-               for(std::list<ABMWithState>::iterator
-                               i = abms.begin(); i != abms.end(); ++i){
+               for(std::vector<ABMWithState>::iterator
+                               i = abms.begin(); i != abms.end(); ++i) {
                        ActiveBlockModifier *abm = i->abm;
                        float trigger_interval = abm->getTriggerInterval();
                        if(trigger_interval < 0.001)
@@ -1182,7 +1182,7 @@ void ServerEnvironment::step(float dtime)
                                        <<") being handled"<<std::endl;*/
 
                        MapBlock *block = m_map->getBlockNoCreateNoEx(p);
-                       if(block==NULL)
+                       if(block == NULL)
                                continue;
                        
                        // Set current time as timestamp
@@ -2081,7 +2081,7 @@ void ClientEnvironment::step(float dtime)
        LocalPlayer *lplayer = getLocalPlayer();
        assert(lplayer);
        // collision info queue
-       std::list<CollisionInfo> player_collisions;
+       std::vector<CollisionInfo> player_collisions;
        
        /*
                Get the speed the player is going
@@ -2196,10 +2196,8 @@ void ClientEnvironment::step(float dtime)
                
        //std::cout<<"Looped "<<loopcount<<" times."<<std::endl;
        
-       for(std::list<CollisionInfo>::iterator
-                       i = player_collisions.begin();
-                       i != player_collisions.end(); ++i)
-       {
+       for(std::vector<CollisionInfo>::iterator i = player_collisions.begin();
+                       i != player_collisions.end(); ++i) {
                CollisionInfo &info = *i;
                v3f speed_diff = info.new_speed - info.old_speed;;
                // Handle only fall damage
index 761e9068bed2998cba352ecc7345c3d572daf1df..386289307afbf40b9708c5f782f4ed2124f49984 100644 (file)
@@ -393,7 +393,7 @@ private:
        u32 m_game_time;
        // A helper variable for incrementing the latter
        float m_game_time_fraction_counter;
-       std::list<ABMWithState> m_abms;
+       std::vector<ABMWithState> m_abms;
        // An interval for generally sending object positions and stuff
        float m_recommended_send_interval;
        // Estimate for general maximum lag as determined by server.
index 69d4ec7efa104197a20b5fb04d306e1290203d72..cb183947a74d3108f74fddaace3396654768ec8b 100644 (file)
@@ -67,7 +67,7 @@ LocalPlayer::~LocalPlayer()
 }
 
 void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
-               std::list<CollisionInfo> *collision_info)
+               std::vector<CollisionInfo> *collision_info)
 {
        Map *map = &env->getMap();
        INodeDefManager *nodemgr = m_gamedef->ndef();
@@ -323,9 +323,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
        */
        bool bouncy_jump = false;
        // Dont report if flying
-       if(collision_info && !(g_settings->getBool("free_move") && fly_allowed))
-       {
-               for(size_t i=0; i<result.collisions.size(); i++){
+       if(collision_info && !(g_settings->getBool("free_move") && fly_allowed)) {
+               for(size_t i=0; i<result.collisions.size(); i++) {
                        const CollisionInfo &info = result.collisions[i];
                        collision_info->push_back(info);
                        if(info.new_speed.Y - info.old_speed.Y > 0.1*BS &&
index 16b66716da66e1874fdbee00690663b2ab8b9379..2a4a9dfc74c2f95c26baadf0bd92e53b4e85487e 100644 (file)
@@ -48,7 +48,7 @@ public:
        
        void move(f32 dtime, Environment *env, f32 pos_max_d);
        void move(f32 dtime, Environment *env, f32 pos_max_d,
-                       std::list<CollisionInfo> *collision_info);
+                       std::vector<CollisionInfo> *collision_info);
 
        void applyControl(float dtime);
 
index a9ff22c32ce324b55b9e84d1d5dd10858422eaa9..2c70280095b47f4c5cdfd31097d05a8eb85ed199 100644 (file)
@@ -1428,7 +1428,7 @@ void Map::timerUpdate(float dtime, float unload_timeout,
        // Profile modified reasons
        Profiler modprofiler;
 
-       std::list<v2s16> sector_deletion_queue;
+       std::vector<v2s16> sector_deletion_queue;
        u32 deleted_blocks_count = 0;
        u32 saved_blocks_count = 0;
        u32 block_count_all = 0;
@@ -1505,11 +1505,10 @@ void Map::unloadUnreferencedBlocks(std::vector<v3s16> *unloaded_blocks)
        timerUpdate(0.0, -1.0, unloaded_blocks);
 }
 
-void Map::deleteSectors(std::list<v2s16> &list)
+void Map::deleteSectors(std::vector<v2s16> &sectorList)
 {
-       for(std::list<v2s16>::iterator j = list.begin();
-               j != list.end(); ++j)
-       {
+       for(std::vector<v2s16>::iterator j = sectorList.begin();
+               j != sectorList.end(); ++j) {
                MapSector *sector = m_sectors[*j];
                // If sector is in sector cache, remove it from there
                if(m_sector_cache == sector)
@@ -1520,63 +1519,6 @@ void Map::deleteSectors(std::list<v2s16> &list)
        }
 }
 
-#if 0
-void Map::unloadUnusedData(float timeout,
-               core::list<v3s16> *deleted_blocks)
-{
-       core::list<v2s16> sector_deletion_queue;
-       u32 deleted_blocks_count = 0;
-       u32 saved_blocks_count = 0;
-
-       core::map<v2s16, MapSector*>::Iterator si = m_sectors.getIterator();
-       for(; si.atEnd() == false; si++)
-       {
-               MapSector *sector = si.getNode()->getValue();
-
-               bool all_blocks_deleted = true;
-
-               core::list<MapBlock*> blocks;
-               sector->getBlocks(blocks);
-               for(core::list<MapBlock*>::Iterator i = blocks.begin();
-                               i != blocks.end(); i++)
-               {
-                       MapBlock *block = (*i);
-
-                       if(block->getUsageTimer() > timeout)
-                       {
-                               // Save if modified
-                               if(block->getModified() != MOD_STATE_CLEAN)
-                               {
-                                       saveBlock(block);
-                                       saved_blocks_count++;
-                               }
-                               // Delete from memory
-                               sector->deleteBlock(block);
-                               deleted_blocks_count++;
-                       }
-                       else
-                       {
-                               all_blocks_deleted = false;
-                       }
-               }
-
-               if(all_blocks_deleted)
-               {
-                       sector_deletion_queue.push_back(si.getNode()->getKey());
-               }
-       }
-
-       deleteSectors(sector_deletion_queue);
-
-       infostream<<"Map: Unloaded "<<deleted_blocks_count<<" blocks from memory"
-                       <<", of which "<<saved_blocks_count<<" were wr."
-                       <<std::endl;
-
-       //return sector_deletion_queue.getSize();
-       //return deleted_blocks_count;
-}
-#endif
-
 void Map::PrintInfo(std::ostream &out)
 {
        out<<"Map: ";
index f4ea54f30b33994e798d6f90752106b19dc9937a..ab5f45ab96443920652dfca62f62e18174d2674b 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -288,17 +288,7 @@ public:
        // Deletes sectors and their blocks from memory
        // Takes cache into account
        // If deleted sector is in sector cache, clears cache
-       void deleteSectors(std::list<v2s16> &list);
-
-#if 0
-       /*
-               Unload unused data
-               = flush changed to disk and delete from memory, if usage timer of
-                 block is more than timeout
-       */
-       void unloadUnusedData(float timeout,
-                       core::list<v3s16> *deleted_blocks=NULL);
-#endif
+       void deleteSectors(std::vector<v2s16> &list);
 
        // For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: "
        virtual void PrintInfo(std::ostream &out);