Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 20, 2009, 4:27:38 PM (16 years ago)
Author:
scheusso
Message:

merged netp4 back to trunk

Location:
code/trunk/src/network
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/Client.cc

    r3084 r3198  
    169169      bool b = packet->process();
    170170      assert(b);
     171      delete event;
    171172    }
    172173    if(gamestate.processGamestates())
  • code/trunk/src/network/ClientConnection.cc

    r3084 r3198  
    169169//              assert(0);
    170170          printf("ClientConnection: ENet returned with an error!\n");
    171           quit_=true;
    172           break;
     171//           quit_=true;
     172          continue;
    173173          // add some error handling here ========================
    174174        }
     
    197197      }
    198198    }
     199    delete event;
    199200    // now disconnect
    200201
    201202    if(!disconnectConnection())
     203    {
     204      printf("could not disconnect properly\n");
    202205      // if disconnecting failed destroy conn.
    203206      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    204207      enet_peer_reset(server);
     208    }
     209    else
     210      printf("properly disconnected\n");
    205211    return;
    206212  }
     
    221227        break;
    222228      case ENET_EVENT_TYPE_DISCONNECT:
     229        printf("received disconnect confirmation from server");
    223230        return true;
    224231      }
  • code/trunk/src/network/ClientInformation.h

    r2773 r3198  
    9191    bool getSynched();
    9292
    93 
    9493  private:
    9594    static ClientInformation *head_;
  • code/trunk/src/network/ConnectionManager.cc

    r3093 r3198  
    132132    quit_=true;
    133133    receiverThread_->join();
     134    delete receiverThread_;
    134135    return true;
    135136  }
     
    206207          // we should never reach this point
    207208          printf("ConnectionManager: ENet returned with an error\n");
    208           quit_=true;
    209           printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
     209//           quit_=true;
     210//           printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
    210211          continue;
    211212          // add some error handling here ========================
     
    218219//             printf("====================================================================");
    219220        case ENET_EVENT_TYPE_DISCONNECT:
     221//           printf("====================================================================");
    220222        case ENET_EVENT_TYPE_RECEIVE:
    221             processData(event);
    222             event = new ENetEvent;
     223          processData(event);
     224          event = new ENetEvent;
    223225          break;
    224226        case ENET_EVENT_TYPE_NONE:
    225227          //receiverThread_->yield();
    226           msleep(10);
     228          msleep(1);
    227229          break;
    228230      }
  • code/trunk/src/network/ConnectionManager.h

    r3093 r3198  
    5555    const int NETWORK_PORT = 55556;
    5656    const int NETWORK_MAX_CONNECTIONS = 50;
    57     const int NETWORK_WAIT_TIMEOUT = 10;
     57    const int NETWORK_WAIT_TIMEOUT = 1;
    5858    const int NETWORK_DEFAULT_CHANNEL = 0;
    5959
  • code/trunk/src/network/GamestateManager.cc

    r3102 r3198  
    6363  GamestateManager::~GamestateManager()
    6464  {
     65    if( this->reference )
     66      delete this->reference;
     67    for( std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.begin(); it != gamestateQueue.end(); it++ )
     68      delete (*it).second;
    6569    delete trafficControl_;
    6670  }
     
    133137//       COUT(3) << "diffing" << std::endl;
    134138//       packet::Gamestate* gs1  = gs;
    135       gs = gs->diff(client);
     139      packet::Gamestate *diffed = gs->diff(client);
     140      //packet::Gamestate *gs2 = diffed->undiff(gs);
     141//       assert(*gs == *gs2);
     142      gs = diffed;
    136143//       packet::Gamestate* gs2 = gs->undiff(client);
    137144//       gs = new packet::Gamestate(*gs);
  • code/trunk/src/network/Server.cc

    r3196 r3198  
    128128  */
    129129  void Server::close() {
     130    ClientInformation *temp = ClientInformation::getBegin();
     131    ClientInformation *temp2;
     132    // disconnect all connected clients
     133    while( temp )
     134    {
     135      temp2 = temp;
     136      temp = temp->next();
     137      disconnectClient( temp2 );
     138    }
    130139    connection->quitListener();
    131140    return;
     
    198207      switch( event->type ) {
    199208      case ENET_EVENT_TYPE_CONNECT:
    200         COUT(3) << "processing event_Type_connect" << std::endl;
     209        COUT(4) << "processing event_Type_connect" << std::endl;
    201210        addClient(event);
    202211        break;
     
    304313      // gs gets automatically deleted by enet callback
    305314    }
     315    delete del;
    306316    return true;
    307317  }
     
    381391    if(!client)
    382392      return false;
     393    else
     394      disconnectClient( client );
     395    return true;
     396  }
     397
     398  void Server::disconnectClient(int clientID){
     399    ClientInformation *client = ClientInformation::findClient(clientID);
     400    if(client)
     401      disconnectClient(client);
     402  }
     403 
     404  void Server::disconnectClient( ClientInformation *client){
     405    connection->disconnectClient(client);
    383406    gamestates_->removeClient(client);
    384 
    385407// inform all the listeners
    386408    ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin();
    387409    while(listener){
    388410      listener->clientDisconnected(client->getID());
    389       listener++;
    390     }
    391 
    392     return ClientInformation::removeClient(event->peer);
    393   }
    394 
    395   void Server::disconnectClient(int clientID){
    396     ClientInformation *client = ClientInformation::findClient(clientID);
    397     if(client)
    398       disconnectClient(client);
    399   }
    400   void Server::disconnectClient( ClientInformation *client){
    401     connection->disconnectClient(client);
    402     gamestates_->removeClient(client);
     411      ++listener;
     412    }
     413    delete client; //remove client from list
    403414  }
    404415
  • code/trunk/src/network/TrafficControl.cc

    r3084 r3198  
    137137        void TrafficControl::ack(unsigned int clientID, unsigned int gamestateID)
    138138        {
     139    if ( !this->bActive_ )
     140      return;
    139141          std::list<obj>::iterator itvec;  // iterator to iterate through the acked objects
    140142
     
    189191  void TrafficControl::updateClientListTemp(std::list<obj>& list)
    190192  {
    191     clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(list);
     193    clientListTemp_[currentClientID][currentGamestateID] = list;
    192194  }
    193195
     
    227229        {
    228230
    229           //now the sorting
    230 
    231           //compare listToProcess vs clientListPerm
    232     //if listToProcess contains new Objects, add them to clientListPerm
    233     std::list<obj>::iterator itvec;
     231    if( bActive_ )
     232    {
     233      //now the sorting
     234
     235      //compare listToProcess vs clientListPerm
     236      //if listToProcess contains new Objects, add them to clientListPerm
     237      std::list<obj>::iterator itvec;
    234238   
    235     std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     239      std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
    236240   
    237           for( itvec=list.begin(); itvec != list.end(); itvec++)
    238           {
    239             if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
    240       {
     241      for( itvec=list.begin(); itvec != list.end(); itvec++)
     242      {
     243        if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
     244        {
    241245        // we already have the object in our map
    242246        //obj bleibt in liste und permanente prio wird berechnet
    243         objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
    244         continue;//check next objId
    245       }
    246       else
    247       {
     247          objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
     248          continue;//check next objId
     249        }
     250        else
     251        {
    248252        // insert the object into clientListPerm
    249         insertinClientListPerm(clientID,*itvec);
    250         continue;//check next objId
    251       }
    252     }
    253           //end compare listToProcess vs clientListPerm
    254 
    255     if( bActive_ )
    256     {
     253          insertinClientListPerm(clientID,*itvec);
     254          continue;//check next objId
     255        }
     256      }
     257    //end compare listToProcess vs clientListPerm
     258     
    257259      //sort copied list according to priorities
    258260      // use boost bind here because we need to pass a memberfunction to stl sort
     
    275277//       sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    276278      list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) );
     279     
     280      //diese Funktion updateClientList muss noch gemacht werden
     281      updateClientListTemp(list);
     282      //end of sorting
    277283    }
    278     //diese Funktion updateClientList muss noch gemacht werden
    279     updateClientListTemp(list);
    280     //end of sorting
    281284  }
    282285
  • code/trunk/src/network/packet/Acknowledgement.cc

    r2710 r3198  
    6464
    6565bool Acknowledgement::process(){
    66 COUT(6) << "processing ACK with ID: " << getAckID() << endl;
     66  COUT(5) << "processing ACK with ID: " << getAckID() << endl;
    6767  bool b = GamestateHandler::ackGamestate(getAckID(), clientID_);
    6868  delete this;
  • code/trunk/src/network/packet/Gamestate.cc

    r3196 r3198  
    7979Gamestate::~Gamestate()
    8080{
     81  if( header_ )
     82    delete header_;
    8183}
    8284
     
    98100 
    99101  // create the header object
     102  assert( header_ == 0 );
    100103  header_ = new GamestateHeader(data_);
    101104
     
    137140  header_->setDataSize( currentsize );
    138141  header_->setID( id );
     142  header_->setBaseID( GAMESTATEID_INITIAL );
    139143  header_->setDiffed( false );
    140144  header_->setComplete( true );
     
    207211  }
    208212#endif
    209 
    210213  return true;
    211214}
     
    320323}
    321324
    322 Gamestate *Gamestate::diff(Gamestate *base)
     325/*Gamestate *Gamestate::diff(Gamestate *base)
    323326{
    324327  assert(data_);
     
    355358  g->packetDirection_ = packetDirection_;
    356359  return g;
    357 }
     360}*/
     361
     362Gamestate *Gamestate::diff(Gamestate *base)
     363{
     364  assert(this && base); assert(data_ && base->data_);
     365  assert(!header_->isCompressed() && !base->header_->isCompressed());
     366  assert(!header_->isDiffed());
     367 
     368  uint8_t *basep = GAMESTATE_START(base->data_);
     369  uint8_t *gs = GAMESTATE_START(this->data_);
     370  uint32_t dest_length = header_->getDataSize();
     371 
     372  if(dest_length==0)
     373    return NULL;
     374 
     375  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     376  uint8_t *dest = GAMESTATE_START(ndata);
     377 
     378  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
     379#ifndef NDEBUG
     380  uint8_t *dest2 = new uint8_t[dest_length];
     381  rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() );
     382  assert( memcmp( dest2, gs, dest_length) == 0 );
     383#endif
     384
     385  Gamestate *g = new Gamestate(ndata, getClientID());
     386  assert(g->header_);
     387  *(g->header_) = *header_;
     388  g->header_->setDiffed( true );
     389  g->header_->setBaseID( base->getID() );
     390  g->flags_=flags_;
     391  g->packetDirection_ = packetDirection_;
     392  assert(g->isDiffed());
     393  assert(!g->isCompressed());
     394  return g;
     395}
     396
     397Gamestate *Gamestate::undiff(Gamestate *base)
     398{
     399  assert(this && base); assert(data_ && base->data_);
     400  assert(!header_->isCompressed() && !base->header_->isCompressed());
     401  assert(header_->isDiffed());
     402 
     403  uint8_t *basep = GAMESTATE_START(base->data_);
     404  uint8_t *gs = GAMESTATE_START(this->data_);
     405  uint32_t dest_length = header_->getDataSize();
     406 
     407  if(dest_length==0)
     408    return NULL;
     409 
     410  uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     411  uint8_t *dest = ndata + GamestateHeader::getSize();
     412 
     413  rawDiff( dest, gs, basep, header_->getDataSize(), base->header_->getDataSize() );
     414 
     415  Gamestate *g = new Gamestate(ndata, getClientID());
     416  assert(g->header_);
     417  *(g->header_) = *header_;
     418  g->header_->setDiffed( false );
     419  g->flags_=flags_;
     420  g->packetDirection_ = packetDirection_;
     421  assert(!g->isDiffed());
     422  assert(!g->isCompressed());
     423  return g;
     424}
     425
    358426
    359427// Gamestate *Gamestate::diff(Gamestate *base)
     
    409477// }
    410478
     479
     480void Gamestate::rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength)
     481{
     482  uint64_t* gd = (uint64_t*)data;
     483  uint64_t* bd = (uint64_t*)basedata;
     484  uint64_t* nd = (uint64_t*)newdata;
     485 
     486  unsigned int i;
     487  for( i=0; i<datalength/8; i++ )
     488  {
     489    if( i<baselength/8 )
     490      *(nd+i) = *(gd+i) ^ *(bd+i);  // xor the data
     491    else
     492      *(nd+i) = *(gd+i); // just copy over the data
     493  }
     494  unsigned int j;
     495  // now process the rest (when datalength isn't a multiple of 4)
     496  for( j = 8*(datalength/8); j<datalength; j++ )
     497  {
     498    if( j<baselength )
     499      *(newdata+j) = *(data+j) ^ *(basedata+j); // xor
     500    else
     501      *(newdata+j) = *(data+j); // just copy
     502  }
     503  assert(j==datalength);
     504}
     505
    411506Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    412507  assert(data_);
     
    478573
    479574
    480 Gamestate *Gamestate::undiff(Gamestate *base)
     575/*Gamestate *Gamestate::undiff(Gamestate *base)
    481576{
    482577  assert(this && base);assert(data_);
     
    514609  assert(!g->isCompressed());
    515610  return g;
    516 }
    517 
     611}*/
    518612
    519613uint32_t Gamestate::calcGamestateSize(int32_t id, uint8_t mode)
  • code/trunk/src/network/packet/Gamestate.h

    r3084 r3198  
    124124    // Packet functions
    125125  private:
     126    void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);
    126127    virtual uint32_t getSize() const;
    127128    virtual inline bool process();
  • code/trunk/src/network/synchronisable/Synchronisable.cc

    r3088 r3198  
    9898    // delete callback function objects
    9999    if(!Identifier::isCreatingHierarchy()){
     100      // remove object from the static objectMap
     101      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
     102        deletedObjects_.push(objectID);
     103      // delete all Synchronisable Variables from syncList ( which are also in stringList )
    100104      for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
    101105        delete (*it);
    102       if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
    103         deletedObjects_.push(objectID);
     106      syncList.clear();
     107      stringList.clear();
    104108    }
    105109    std::map<uint32_t, Synchronisable*>::iterator it;
     
    174178    COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
    175179          // update data and create object/entity...
     180    assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
     181    Synchronisable::objectMap_[header.getObjectID()] = no;
    176182    bool b = no->updateData(mem, mode, true);
    177183    assert(b);
     
    213219      return it1->second;
    214220
    215     ObjectList<Synchronisable>::iterator it;
    216     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    217       if( it->getObjectID()==objectID ){
    218         objectMap_[objectID] = *it;
    219         return *it;
    220       }
    221     }
     221//     ObjectList<Synchronisable>::iterator it;
     222//     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
     223//       if( it->getObjectID()==objectID ){
     224//         objectMap_[objectID] = *it;
     225//         return *it;
     226//       }
     227//     }
     228    // if the objects not in the map it should'nt exist at all anymore
    222229    return NULL;
    223230  }
Note: See TracChangeset for help on using the changeset viewer.