Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 5, 2015, 10:47:51 PM (9 years ago)
Author:
landauf
Message:

use range-based for-loop where it makes sense (e.g. ObjectList)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/Game.cc

    r10918 r10919  
    115115
    116116        // After the core has been created, we can safely instantiate the GameStates that don't require graphics
    117         for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin();
    118             it != gameStateDeclarations_s.end(); ++it)
    119         {
    120             if (!it->second.bGraphicsMode)
    121                 constructedStates_[it->second.stateName] = GameStateFactory::fabricate(it->second);
     117        for (const auto& mapEntry : gameStateDeclarations_s)
     118        {
     119            if (!mapEntry.second.bGraphicsMode)
     120                constructedStates_[mapEntry.second.stateName] = GameStateFactory::fabricate(mapEntry.second);
    122121        }
    123122
     
    262261    {
    263262        // Note: The first element is the empty root state, which doesn't need ticking
    264         for (GameStateVector::const_iterator it = this->loadedStates_.begin() + 1;
    265             it != this->loadedStates_.end(); ++it)
     263        for (const std::shared_ptr<GameState>& state : this->loadedStates_)
    266264        {
    267265            try
     
    269267                // Add tick time for most of the states
    270268                uint64_t timeBeforeTick = 0;
    271                 if ((*it)->getInfo().bIgnoreTickTime)
     269                if (state->getInfo().bIgnoreTickTime)
    272270                    timeBeforeTick = this->gameClock_->getRealMicroseconds();
    273                 (*it)->update(*this->gameClock_);
    274                 if ((*it)->getInfo().bIgnoreTickTime)
     271                state->update(*this->gameClock_);
     272                if (state->getInfo().bIgnoreTickTime)
    275273                    this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
    276274            }
    277275            catch (...)
    278276            {
    279                 orxout(user_error) << "An exception occurred while updating '" << (*it)->getName() << "': " << Exception::handleMessage() << endl;
     277                orxout(user_error) << "An exception occurred while updating '" << state->getName() << "': " << Exception::handleMessage() << endl;
    280278                orxout(user_error) << "This should really never happen!" << endl;
    281279                orxout(user_error) << "Unloading all GameStates depending on the one that crashed." << endl;
    282280                std::shared_ptr<GameStateTreeNode> current = this->loadedTopStateNode_;
    283                 while (current->name_ != (*it)->getName() && current)
     281                while (current->name_ != state->getName() && current)
    284282                    current = current->parent_.lock();
    285283                if (current && current->parent_.lock())
     
    520518
    521519            // Construct all the GameStates that require graphics
    522             for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin();
    523                 it != gameStateDeclarations_s.end(); ++it)
    524             {
    525                 if (it->second.bGraphicsMode)
     520            for (const auto& mapEntry : gameStateDeclarations_s)
     521            {
     522                if (mapEntry.second.bGraphicsMode)
    526523                {
    527524                    // Game state loading failure is serious --> don't catch
    528                     std::shared_ptr<GameState> gameState = GameStateFactory::fabricate(it->second);
     525                    std::shared_ptr<GameState> gameState = GameStateFactory::fabricate(mapEntry.second);
    529526                    if (!constructedStates_.insert(std::make_pair(
    530                         it->second.stateName, gameState)).second)
     527                        mapEntry.second.stateName, gameState)).second)
    531528                        assert(false); // GameState was already created!
    532529                }
Note: See TracChangeset for help on using the changeset viewer.