Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 15, 2015, 4:43:03 PM (5 years ago)
Author:
landauf
Message:

use list instead of vector - list is better suited for removing elements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.cc

    r10586 r10587  
    320320        //if ships are at the end they get destroyed
    321321
    322         std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator itBegin = enemies_.begin();
    323         std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator it = itBegin;
    324         std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator itEnd = enemies_.end();
    325 
    326         while(it != itEnd)
     322        for (std::list<WeakPtr<TowerDefenseEnemy> >::iterator it = enemies_.begin(); it != enemies_.end(); )
    327323        {
    328324            //destroys enemys at the end of the path and reduces the life by 1. No credits gifted
     
    331327            if(distance < 50)
    332328            {
    333                 std::vector<orxonox::WeakPtr<TowerDefenseEnemy> >::iterator itTemp = it;
    334                 ++ it;
    335329                orxout() << "enemy deleted" << endl;               
    336                 enemies_.erase(itTemp);
    337                 (*itTemp)->destroy();
     330                (*it)->destroy();
     331                enemies_.erase(it++);
    338332                this->reduceLifes(1);
    339333                if (this->getLifes() == 0)
Note: See TracChangeset for help on using the changeset viewer.