Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2015, 7:05:53 PM (8 years ago)
Author:
muemart
Message:

Run clang-modernize -loop-convert

  • Again, not all possible loops were converted
  • It can do pretty cool transformations, but I had to fix a few compile errors, so there might be some runtime errors lurking around too
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/orxonox/gametypes/Gametype.cc

    r10768 r10821  
    139139        if (!this->gtinfo_->hasStarted())
    140140        {
    141             for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     141            for (auto & elem : this->players_)
    142142            {
    143143                // Inform the GametypeInfo that the player is ready to spawn.
    144                 if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
    145                     this->gtinfo_->playerReadyToSpawn(it->first);
     144                if(elem.first->isHumanPlayer() && elem.first->isReadyToSpawn())
     145                    this->gtinfo_->playerReadyToSpawn(elem.first);
    146146            }
    147147
     
    169169        }
    170170
    171         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    172         {
    173             if (it->first->getControllableEntity())
    174             {
    175                 ControllableEntity* oldentity = it->first->getControllableEntity();
     171        for (auto & elem : this->players_)
     172        {
     173            if (elem.first->getControllableEntity())
     174            {
     175                ControllableEntity* oldentity = elem.first->getControllableEntity();
    176176
    177177                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getContext());
     
    186186                    entity->setOrientation(oldentity->getWorldOrientation());
    187187                }
    188                 it->first->startControl(entity);
     188                elem.first->startControl(entity);
    189189            }
    190190            else
    191                 this->spawnPlayerAsDefaultPawn(it->first);
     191                this->spawnPlayerAsDefaultPawn(elem.first);
    192192        }
    193193    }
     
    341341            unsigned int index = 0;
    342342            std::vector<SpawnPoint*> activeSpawnPoints;
    343             for (std::set<SpawnPoint*>::const_iterator it = this->spawnpoints_.begin(); it != this->spawnpoints_.end(); ++it)
     343            for (const auto & elem : this->spawnpoints_)
    344344            {
    345345                if (index == randomspawn)
    346                     fallbackSpawnPoint = (*it);
    347 
    348                 if (*it != nullptr && (*it)->isActive())
    349                     activeSpawnPoints.push_back(*it);
     346                    fallbackSpawnPoint = (elem);
     347
     348                if (elem != nullptr && (elem)->isActive())
     349                    activeSpawnPoints.push_back(elem);
    350350
    351351                ++index;
     
    366366    void Gametype::assignDefaultPawnsIfNeeded()
    367367    {
    368         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    369         {
    370             if (!it->first->getControllableEntity())
    371             {
    372                 it->second.state_ = PlayerState::Dead;
    373 
    374                 if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted())
    375                 {
    376                     this->spawnPlayerAsDefaultPawn(it->first);
    377                     it->second.state_ = PlayerState::Dead;
     368        for (auto & elem : this->players_)
     369        {
     370            if (!elem.first->getControllableEntity())
     371            {
     372                elem.second.state_ = PlayerState::Dead;
     373
     374                if (!elem.first->isReadyToSpawn() || !this->gtinfo_->hasStarted())
     375                {
     376                    this->spawnPlayerAsDefaultPawn(elem.first);
     377                    elem.second.state_ = PlayerState::Dead;
    378378                }
    379379            }
     
    404404                    bool allplayersready = true;
    405405                    bool hashumanplayers = false;
    406                     for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
     406                    for (auto & elem : this->players_)
    407407                    {
    408                         if (!it->first->isReadyToSpawn())
     408                        if (!elem.first->isReadyToSpawn())
    409409                            allplayersready = false;
    410                         if (it->first->isHumanPlayer())
     410                        if (elem.first->isHumanPlayer())
    411411                            hashumanplayers = true;
    412412                    }
     
    430430    void Gametype::spawnPlayersIfRequested()
    431431    {
    432         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    433         {
    434             if (it->first->isReadyToSpawn() || this->bForceSpawn_)
    435                 this->spawnPlayer(it->first);
     432        for (auto & elem : this->players_)
     433        {
     434            if (elem.first->isReadyToSpawn() || this->bForceSpawn_)
     435                this->spawnPlayer(elem.first);
    436436        }
    437437    }
     
    439439    void Gametype::spawnDeadPlayersIfRequested()
    440440    {
    441         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    442             if (it->second.state_ == PlayerState::Dead)
    443                 if (it->first->isReadyToSpawn() || this->bForceSpawn_)
    444                     this->spawnPlayer(it->first);
     441        for (auto & elem : this->players_)
     442            if (elem.second.state_ == PlayerState::Dead)
     443                if (elem.first->isReadyToSpawn() || this->bForceSpawn_)
     444                    this->spawnPlayer(elem.first);
    445445    }
    446446
     
    538538    GSLevelMementoState* Gametype::exportMementoState()
    539539    {
    540         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    541         {
    542             if (it->first->isHumanPlayer() && it->first->getControllableEntity() && it->first->getControllableEntity()->getCamera())
    543             {
    544                 Camera* camera = it->first->getControllableEntity()->getCamera();
     540        for (auto & elem : this->players_)
     541        {
     542            if (elem.first->isHumanPlayer() && elem.first->getControllableEntity() && elem.first->getControllableEntity()->getCamera())
     543            {
     544                Camera* camera = elem.first->getControllableEntity()->getCamera();
    545545
    546546                GametypeMementoState* state = new GametypeMementoState();
     
    559559        // find correct memento state
    560560        GametypeMementoState* state = nullptr;
    561         for (size_t i = 0; i < states.size(); ++i)
    562         {
    563             state = dynamic_cast<GametypeMementoState*>(states[i]);
     561        for (auto & states_i : states)
     562        {
     563            state = dynamic_cast<GametypeMementoState*>(states_i);
    564564            if (state)
    565565                break;
     
    587587
    588588        // find correct player and assign default entity with original position & orientation
    589         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    590         {
    591             if (it->first->isHumanPlayer())
     589        for (auto & elem : this->players_)
     590        {
     591            if (elem.first->isHumanPlayer())
    592592            {
    593593                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(scene->getContext());
    594594                entity->setPosition(state->cameraPosition_);
    595595                entity->setOrientation(state->cameraOrientation_);
    596                 it->first->startControl(entity);
     596                elem.first->startControl(entity);
    597597                break;
    598598            }
Note: See TracChangeset for help on using the changeset viewer.