Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/GamestateManager.cc

    r8858 r11071  
    6060{
    6161  GamestateManager::GamestateManager() :
    62   currentGamestate_(0), id_(0)
     62  currentGamestate_(nullptr), id_(0)
    6363  {
    6464//     trafficControl_ = new TrafficControl();
     
    7070  {
    7171    if( this->currentGamestate_ )
    72         delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it;
    73     for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it )
    74       delete it->second;
    75     std::map<uint32_t, peerInfo>::iterator peerIt;
    76     std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt;
    77     for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt )
    78     {
    79       for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt )
    80         delete gamestateIt->second;
     72        delete this->currentGamestate_;
     73    for( const auto& mapEntry : gamestateQueue )
     74      delete mapEntry.second;
     75    for( const auto& mapEntryPeer : peerMap_ )
     76    {
     77      for( const auto& mapEntryGamestate : mapEntryPeer.second.gamestates )
     78        delete mapEntryGamestate.second;
    8179    }
    8280//     this->trafficControl_->destroy();
     
    107105    if( this->gamestateQueue.empty() )
    108106        return true;
    109     std::map<unsigned int, packet::Gamestate*>::iterator it;
    110107    // now push only the most recent gamestates we received (ignore obsolete ones)
    111     for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++)
    112     {
    113       OrxVerify(processGamestate(it->second), "ERROR: could not process Gamestate");
    114       sendAck( it->second->getID(), it->second->getPeerID() );
    115       delete it->second;
     108    for(const auto& mapEntry : gamestateQueue)
     109    {
     110      OrxVerify(processGamestate(mapEntry.second), "ERROR: could not process Gamestate");
     111      sendAck( mapEntry.second->getID(), mapEntry.second->getPeerID() );
     112      delete mapEntry.second;
    116113    }
    117114    // now clear the queue
     
    140137
    141138  bool GamestateManager::getSnapshot(){
    142     if ( currentGamestate_ != 0 )
     139    if ( currentGamestate_ != nullptr )
    143140      delete currentGamestate_;
    144141    uint8_t gsMode;
     
    165162    { //we have no data to send
    166163      delete currentGamestate_;
    167       currentGamestate_=0;
     164      currentGamestate_=nullptr;
    168165      return false;
    169166    }
     
    177174    std::vector<packet::Gamestate*> peerGamestates;
    178175   
    179     std::map<uint32_t, peerInfo>::iterator peerIt;
    180     for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt )
    181     {
    182       if( !peerIt->second.isSynched )
     176    for( const auto& mapEntry : peerMap_ )
     177    {
     178      if( !mapEntry.second.isSynched )
    183179      {
    184180        orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl;
    185181        continue;
    186182      }
    187       orxout(verbose_more, context::network) << "client id: " << peerIt->first << endl;
     183      orxout(verbose_more, context::network) << "client id: " << mapEntry.first << endl;
    188184      orxout(verbose_more, context::network) << "Server: doing gamestate gamestate preparation" << endl;
    189       int peerID = peerIt->first; //get client id
    190 
    191       unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;
    192 
    193       packet::Gamestate* baseGamestate=0;
     185      int peerID = mapEntry.first; //get client id
     186
     187      unsigned int lastAckedGamestateID = mapEntry.second.lastAckedGamestateID;
     188
     189      packet::Gamestate* baseGamestate=nullptr;
    194190      if(lastAckedGamestateID != GAMESTATEID_INITIAL)
    195191      {
     
    200196      }
    201197
    202       peerGamestates.push_back(0);  // insert an empty gamestate* to be changed
     198      peerGamestates.push_back(nullptr);  // insert an empty gamestate* to be changed
    203199      finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
    204       if( peerGamestates.back()==0 )
     200      if( peerGamestates.back()==nullptr )
    205201        // nothing to send to remove pointer from vector
    206202        peerGamestates.pop_back();
     
    243239      {
    244240        delete diffed1;
    245         destgamestate = 0;
     241        destgamestate = nullptr;
    246242        return;
    247243      }
     
    340336  {
    341337    assert(peerMap_.find(peerID)!=peerMap_.end());
    342     std::map<uint32_t, packet::Gamestate*>::iterator peerIt;
    343     for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt )
    344     {
    345       delete peerIt->second;
     338    for( const auto& mapEntry : peerMap_[peerID].gamestates )
     339    {
     340      delete mapEntry.second;
    346341    }
    347342    peerMap_.erase(peerMap_.find(peerID));
     
    351346//   void GamestateManager::removeClient(ClientInformation* client){
    352347//     assert(client);
    353 //     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
     348//     std::map<unsigned int, std::map<unsigned int, packet::Gamestate*>>::iterator clientMap = gamestateMap_.find(client->getID());
    354349//     // first delete all remained gamestates
    355350//     std::map<unsigned int, packet::Gamestate*>::iterator it;
Note: See TracChangeset for help on using the changeset viewer.