Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9249 in orxonox.OLD for branches


Ignore:
Timestamp:
Jul 12, 2006, 10:41:00 AM (18 years ago)
Author:
patrick
Message:

more framework switch

Location:
branches/proxy/src/lib/network
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/network_stream.cc

    r9248 r9249  
    7575  this->peers[0].socket = new UdpSocket( host, port );
    7676  this->peers[0].userId = 0;
    77   this->peers[0].isServer = true;
     77  this->peers[0].isMasterServer = true;
    7878  this->peers[0].connectionMonitor = new ConnectionMonitor( 0 );
    7979}
     
    222222  currentState++;
    223223
    224   if ( this->type == NET_SERVER )
     224  if ( this->type == NET_MASTER_SERVER )
    225225  {
    226226    if ( serverSocket )
     
    284284      peers[clientId].handshake->setUniqueID(clientId);
    285285      peers[clientId].userId = clientId;
    286       peers[clientId].isServer = false;
     286      peers[clientId].isMasterServer = false;
    287287    }
    288288    else
     
    299299      peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );
    300300      peers[clientId].userId = clientId;
    301       peers[clientId].isServer = false;
     301      peers[clientId].isMasterServer = false;
    302302
    303303      PRINTF(0)("num sync: %d\n", synchronizeables.size());
     
    423423          if ( !it->second.handshake->allowDel() )
    424424          {
    425             if ( type != NET_SERVER )
     425            if ( type != NET_MASTER_SERVER )
    426426            {
    427427              SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() );
     
    442442            if ( it->second.handshake->canDel() )
    443443            {
    444               if ( type == NET_SERVER )
     444              if ( type == NET_MASTER_SERVER )
    445445              {
    446446                handleNewClient( it->second.userId );
     
    516516
    517517      // if we are a server and this is not our handshake
    518       if ( isServer() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
     518      if ( isMasterServer() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
    519519        continue;
    520520
     
    576576    // now compress the data with the zip library
    577577    int compLength = 0;
    578     if ( this->isServer() )
     578    if ( this->isMasterServer() )
    579579      compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer );
    580580    else
     
    691691          }
    692692
    693           if ( !peers[peer->second.userId].isServer )
     693          if ( !peers[peer->second.userId].isMasterServer )
    694694          {
    695695            offset += syncDataLength;
  • branches/proxy/src/lib/network/network_stream.h

    r9248 r9249  
    2727  public:
    2828    PeerInfo() { clear(); }
    29     void clear() { userId = 0; isServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }
     29    void clear() { userId = 0; isMasterServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }
    3030
    3131
    3232  public:
    3333    int                 userId;
    34     bool                isServer;
     34    bool                isMasterServer;
     35    bool                isProxyServer;
     36    bool                isClient;
    3537    NetworkSocket *     socket;
    3638    Handshake *         handshake;
     
    7577
    7678    inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }
    77     inline bool isUserServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isServer; }
     79    inline bool isUserMasterServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isMasterServer; }
     80    inline bool isUserProxyServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServer; }
     81    inline bool isUserClient( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isClient; }
    7882
    7983    void debug();
  • branches/proxy/src/lib/network/synchronizeable.cc

    r9110 r9249  
    4242  this->networkStream = NULL;
    4343  this->bSynchronize = false;
    44  
     44
    4545  if( State::isOnline())
    4646  {
     
    5454  assert( syncVarList.size() == 0 );
    5555  mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId" ) );
    56    
     56
    5757  this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner" ) );
    5858  this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) );
     
    6969  {
    7070    this->networkStream->disconnectSynchronizeable(*this);
    71  
     71
    7272    if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) )
    7373      NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
    7474  }
    75    
     75
    7676  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
    7777  {
     
    7979  }
    8080  syncVarList.clear();
    81  
     81
    8282  for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ )
    8383  {
     
    9393
    9494  }
    95  
     95
    9696  for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ )
    9797  {
     
    169169        (*it2)->data = NULL;
    170170      }
    171      
     171
    172172      delete *it2;
    173173    }
     
    181181  while ( it != sentStates[userId].end() && (*it)->stateId != fromStateId )
    182182    it++;
    183  
     183
    184184//  if ( getLeafClassID() == CL_SPACE_SHIP )
    185185//  {
     
    196196
    197197    stateFrom = initialEntry;
    198    
     198
    199199    sentStates[userId].push_back( stateFrom );
    200200  }
     
    205205
    206206  sentStates[userId].push_back( stateTo );
    207  
     207
    208208  stateTo->stateId = stateId;
    209209  stateTo->dataLength = neededSize;
     
    214214  int i = 0;
    215215  int n;
    216  
     216
    217217  bool hasPermission;
    218218  bool sizeChanged = false;
     
    225225        this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||
    226226            this->isServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) ||
    227             (*it)->checkPermission( PERMISSION_ALL ) 
     227            (*it)->checkPermission( PERMISSION_ALL )
    228228                    );
    229    
    230     if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 
     229
     230    if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() )
    231231      sizeChanged = true;
    232    
     232
    233233    if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeChanged )
    234234    {
     
    303303    it++;
    304304
    305  
     305
    306306//  if ( getLeafClassID() == CL_SPACE_SHIP )
    307307//  {
     
    318318
    319319    stateFrom = initialEntry;
    320    
     320
    321321    recvStates[userId].push_back( stateFrom );
    322322  }
    323323  else
    324324    stateFrom = (*it);
    325  
     325
    326326  //apply diff
    327327  for ( int i = 0; i<length; i++ )
     
    331331    else
    332332      stateTo->data[i] = data[i];
    333    
    334   }
    335  
     333
     334  }
     335
    336336  //add state to state history
    337337  recvStates[userId].push_back( stateTo );
    338  
     338
    339339  int i = 0;
    340340  int n = 0;
    341341  std::list<int> changes;
    342  
     342
    343343  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
    344344  {
    345345    if (
    346         (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) ||
     346        (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserMasterServer( userId ) ||
    347347        (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId ||
    348         networkStream->isUserServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||
    349         (*it)->checkPermission( PERMISSION_ALL ) 
     348        networkStream->isUserMasterServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||
     349        (*it)->checkPermission( PERMISSION_ALL )
    350350       )
    351351    {
     
    370370
    371371  this->varChangeHandler( changes );
    372  
     372
    373373  return i;
    374374}
     
    423423        (*it)->data = NULL;
    424424      }
    425    
     425
    426426      delete *it;
    427427    }
    428428    recvStates[userId].clear();
    429429  }
    430  
     430
    431431  if ( sentStates.size() > userId )
    432432  {
    433    
     433
    434434    for ( std::list<StateHistoryEntry*>::iterator it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ )
    435435    {
     
    439439        (*it)->data = NULL;
    440440      }
    441    
     441
    442442      delete *it;
    443443    }
     
    448448/**
    449449 * this function is called after recieving a state.
    450  * @param userId 
    451  * @param stateId 
    452  * @param fromStateId 
     450 * @param userId
     451 * @param stateId
     452 * @param fromStateId
    453453 */
    454454void Synchronizeable::handleRecvState( int userId, int stateId, int fromStateId )
     
    457457  if ( recvStates.size() <= userId )
    458458    recvStates.resize( userId+1 );
    459  
     459
    460460  //remove old states
    461461  StateHistory::iterator it = recvStates[userId].begin();
     
    485485      StateHistory::iterator delIt = it;
    486486      it ++;
    487      
     487
    488488      if ( (*delIt)->data )
    489489      {
     
    493493      delete *delIt;
    494494      recvStates[userId].erase( delIt );
    495      
     495
    496496      continue;
    497497    }
    498498    it++;
    499499  }
    500  
     500
    501501  StateHistory::iterator fromState = recvStates[userId].end();
    502502  StateHistory::iterator toState = recvStates[userId].end();
    503  
     503
    504504  for ( it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ )
    505505  {
     
    508508    if ( (*it)->stateId == fromStateId )
    509509      fromState = it;
    510    
     510
    511511    if ( fromState != recvStates[userId].end() && toState != recvStates[userId].end() )
    512512      break;
    513513  }
    514  
     514
    515515  // setStateDiff was not called and i know fromStateId
    516516  if ( fromState != recvStates[userId].end() && toState == recvStates[userId].end() )
    517517  {
    518518    StateHistoryEntry * entry = new StateHistoryEntry;
    519    
     519
    520520    entry->dataLength = (*fromState)->dataLength;
    521521    if ( entry->dataLength > 0 )
    522522    {
    523523      entry->data = new byte[entry->dataLength];
    524          
     524
    525525      assert( (*fromState)->data );
    526526      memcpy( entry->data, (*fromState)->data, entry->dataLength );
     
    528528    else
    529529      entry->data = NULL;
    530    
     530
    531531    entry->sizeList = (*fromState)->sizeList;
    532532    entry->stateId = stateId;
    533    
     533
    534534    recvStates[userId].push_back(entry);
    535535  }
     
    538538/**
    539539 * this function is called after sending a state
    540  * @param userId 
    541  * @param stateId 
    542  * @param fromStateId 
     540 * @param userId
     541 * @param stateId
     542 * @param fromStateId
    543543 */
    544544void Synchronizeable::handleSentState( int userId, int stateId, int fromStateId )
     
    557557      StateHistory::iterator delIt = it;
    558558      it ++;
    559      
     559
    560560      if ( (*delIt)->data )
    561561      {
     
    565565      delete *delIt;
    566566      sentStates[userId].erase( delIt );
    567      
     567
    568568      continue;
    569569    }
     
    571571  }
    572572
    573  
     573
    574574  StateHistory::iterator fromState = sentStates[userId].end();
    575575  StateHistory::iterator toState = sentStates[userId].end();
    576  
     576
    577577  for ( it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ )
    578578  {
     
    581581    if ( (*it)->stateId == fromStateId )
    582582      fromState = it;
    583    
     583
    584584    if ( fromState != sentStates[userId].end() && toState != sentStates[userId].end() )
    585585      break;
    586586  }
    587587
    588  
     588
    589589  // getStateDiff was not called and i know fromStateId
    590590  if ( fromState != sentStates[userId].end() && toState == sentStates[userId].end() )
    591591  {
    592592    StateHistoryEntry * entry = new StateHistoryEntry;
    593    
     593
    594594    entry->dataLength = (*fromState)->dataLength;
    595595    if ( entry->dataLength > 0 )
    596596    {
    597597      entry->data = new byte[entry->dataLength];
    598      
     598
    599599      assert( (*fromState)->data );
    600600      memcpy( entry->data, (*fromState)->data, entry->dataLength );
     
    602602    else
    603603      entry->data = NULL;
    604    
     604
    605605    entry->sizeList = (*fromState)->sizeList;
    606606    entry->stateId = stateId;
    607    
     607
    608608    sentStates[userId].push_back(entry);
    609609  }
    610  
    611 }
    612 
    613 
    614 
     610
     611}
     612
     613
     614
Note: See TracChangeset for help on using the changeset viewer.