Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 25, 2011, 8:22:36 PM (13 years ago)
Author:
scheusso
Message:

merging network6 into trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r7801 r8327  
    5757
    5858namespace orxonox
    59 {
     59{ 
    6060  GamestateManager::GamestateManager() :
    6161  currentGamestate_(0), id_(0)
     
    122122  bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID)
    123123  {
     124    assert( gamestateID != ACKID_NACK );
    124125    packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID);
    125126    if( !this->sendPacket(ack))
     
    139140    if ( currentGamestate_ != 0 )
    140141      delete currentGamestate_;
    141     currentGamestate_ = new packet::Gamestate();
    142142    uint8_t gsMode;
    143143    if( GameMode::isMaster() )
     
    149149      newID = ++id_;
    150150    else
    151       newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID;
     151    {
     152      assert(peerMap_.size()!=0);
     153      newID = peerMap_[NETWORK_PEER_ID_SERVER].lastReceivedGamestateID;
     154      if( newID == GAMESTATEID_INITIAL )
     155      {
     156        return false;
     157      }
     158    }
    152159   
    153     if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send
     160    currentGamestate_ = new packet::Gamestate();
     161   
     162    if(!currentGamestate_->collectData(newID, gsMode))
     163    { //we have no data to send
    154164      delete currentGamestate_;
    155165      currentGamestate_=0;
     166      return false;
    156167    }
    157168    return true;
     
    172183        continue;
    173184      }
    174       COUT(4) << "client id: " << peerIt->first << std::endl;
     185      COUT(5) << "client id: " << peerIt->first << std::endl;
    175186      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
    176187      int peerID = peerIt->first; //get client id
     
    187198      }
    188199
    189       peerGamestates.push_back(0);  // insert an empty gamestate* to change
     200      peerGamestates.push_back(0);  // insert an empty gamestate* to be changed
    190201      finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
    191202      if( peerGamestates.back()==0 )
     
    244255//     assert(b);
    245256    clock.capture();
    246     COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
     257    COUT(5) << "diff and compress time: " << clock.getDeltaTime() << endl;
    247258//     COUT(5) << "sending gamestate with id " << gs->getID();
    248259//     if(gamestate->isDiffed())
     
    263274    unsigned int curid = it->second.lastAckedGamestateID;
    264275
    265     if(gamestateID == ACKID_NACK){
    266       it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
    267 //       temp->setGamestateID(GAMESTATEID_INITIAL);
    268       // now delete all saved gamestates for this client
    269       std::map<uint32_t, packet::Gamestate*>::iterator it2;
    270       for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
    271         delete it2->second;
    272       }
    273       it->second.gamestates.clear();
    274       return true;
    275     }
    276 
    277     assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID);
    278     COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
     276    assert(gamestateID != ACKID_NACK);
     277//     if(gamestateID == ACKID_NACK){
     278//       it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
     279// //       temp->setGamestateID(GAMESTATEID_INITIAL);
     280//       // now delete all saved gamestates for this client
     281//       std::map<uint32_t, packet::Gamestate*>::iterator it2;
     282//       for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
     283//         delete it2->second;
     284//       }
     285//       it->second.gamestates.clear();
     286//       return true;
     287//     }
     288
     289//    assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); // this line is commented out because acknowledgements are unreliable and may arrive in distorted order
     290    if( gamestateID <= curid )
     291        return true;
     292COUT(4) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
    279293    std::map<uint32_t, packet::Gamestate*>::iterator it2;
    280294    for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
     
    300314  }
    301315 
    302   uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID)
     316  uint32_t GamestateManager::getLastReceivedGamestateID(unsigned int peerID)
    303317  {
    304318    assert( this->peerMap_.find(peerID)!=this->peerMap_.end() );
    305319    if( this->peerMap_.find(peerID) != this->peerMap_.end() )
    306       return this->peerMap_[peerID].lastProcessedGamestateID;
     320      return this->peerMap_[peerID].lastReceivedGamestateID;
    307321    else
    308322      return GAMESTATEID_INITIAL;
     
    314328    assert(peerMap_.find(peerID)==peerMap_.end());
    315329    peerMap_[peerID].peerID = peerID;
    316     peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL;
     330    peerMap_[peerID].lastReceivedGamestateID = GAMESTATEID_INITIAL;
    317331    peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL;
    318332    if( GameMode::isMaster() )
     
    360374    if( gs->spreadData(gsMode) )
    361375    {
    362       this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID();
     376      this->peerMap_[gs->getPeerID()].lastReceivedGamestateID = gs->getID();
    363377      return true;
    364378    }
Note: See TracChangeset for help on using the changeset viewer.