Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10587


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

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

Location:
code/branches/towerdefenseFabien/src/modules/towerdefense
Files:
2 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)
  • code/branches/towerdefenseFabien/src/modules/towerdefense/TowerDefense.h

    r10586 r10587  
    9696        int lifes_;
    9797        Timer nextwaveTimer_;
    98         std::vector<orxonox::WeakPtr<TowerDefenseEnemy> > enemies_;
     98        std::list<orxonox::WeakPtr<TowerDefenseEnemy> > enemies_;
    9999        TowerDefenseField* fields_[16][16];
    100100        std::vector<orxonox::WeakPtr<TowerDefenseField> > waypoints_;
Note: See TracChangeset for help on using the changeset viewer.