Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6503 in orxonox.OLD for branches


Ignore:
Timestamp:
Jan 11, 2006, 11:54:32 PM (19 years ago)
Author:
rennerc
Message:

networkGameManager now copies data to one buffer for each client

Location:
branches/network/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_game_manager.cc

    r6500 r6503  
    5252  this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
    5353
    54   allOutBuffer.length = 0;
    55 
    56   allOutBuffer.maxLength = 10*1024;
    57 
    58   allOutBuffer.buffer = new byte[10*1024];
    59 
    6054  newUniqueID = MAX_CONNECTIONS + 2;
    6155
     
    7468  }
    7569
    76   if ( allOutBuffer.buffer )
    77     delete allOutBuffer.buffer;
    7870}
    7971
     
    10799      if ( b == CREATE_ENTITY )
    108100      {
     101        PRINTF(0)("CREATE_ENTITY\n");
    109102        if ( !handleCreateEntity( i, data, length, sender ) )
    110103          return i;
     
    188181  }
    189182
    190   *reciever = 0;
    191   int nbytes = allOutBuffer.length;
    192   allOutBuffer.length = 0;
    193 
    194   if ( nbytes <=0 )
    195     return 0;
    196 
    197   if ( nbytes > maxLength )
    198   {
    199     PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.length\n", nbytes, maxLength);
    200     return 0;
    201   }
    202 
    203   memcpy( data, allOutBuffer.buffer, nbytes );
    204   return nbytes;
     183  return 0;
    205184}
    206185
     
    221200int NetworkGameManager::createEntity( ClassID classID, int owner )
    222201{
    223 
    224202  if ( this->isServer() )
    225203  {
     
    254232      return NULL;
    255233    }
    256     newUniqueID++;
    257234
    258235    BaseObject * b = Factory::fabricate( element );
     
    268245    {
    269246      Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
    270       s->setUniqueID( newUniqueID );
     247      s->setUniqueID( newUniqueID++ );
    271248      s->setOwner( 0 );
    272249      this->networkStream->connectSynchronizeable( *s );
     
    313290void NetworkGameManager::requestCreateEntity(ClassID classID)
    314291{
    315   if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_CREATE ) )
    316     return;
    317   if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
    318     return;
     292  for ( int i = 0; i<outBuffer.size(); i++)
     293  {
     294    if ( !this->networkStream->isUserIdActive( i ) )
     295      continue;
     296
     297    if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_CREATE ) )
     298      return;
     299    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
     300      return;
     301  }
    319302}
    320303
     
    325308void NetworkGameManager::requestRemoveEntity(int uniqueID)
    326309{
    327   if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_REMOVE ) )
    328     return;
    329   if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    330     return;
     310  for ( int i = 0; i<outBuffer.size(); i++)
     311  {
     312    if ( !this->networkStream->isUserIdActive( i ) )
     313      continue;
     314
     315    if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_REMOVE ) )
     316      return;
     317    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     318      return;
     319  }
    331320}
    332321
     
    338327int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
    339328{
    340   if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) )
    341     return -1;
    342   if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
    343     return -1;
    344   if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    345     return -1;
    346   if ( !writeToClientBuffer( allOutBuffer, owner ) )
    347     return -1;
     329  for ( int i = 0; i<outBuffer.size(); i++)
     330  {
     331    if ( !this->networkStream->isUserIdActive( i ) )
     332      continue;
     333
     334    if ( !writeToClientBuffer( outBuffer[i], (byte)CREATE_ENTITY ) )
     335      return -1;
     336    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
     337      return -1;
     338    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     339      return -1;
     340    if ( !writeToClientBuffer( outBuffer[i], owner ) )
     341      return -1;
     342  }
    348343
    349344  doCreateEntity( classID, uniqueID, owner );
     
    359354void NetworkGameManager::executeRemoveEntity(int uniqueID)
    360355{
    361   if ( !writeToClientBuffer( allOutBuffer, (byte)REMOVE_ENTITY ) )
    362     return;
    363   if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    364     return;
     356  for ( int i = 0; i<outBuffer.size(); i++)
     357  {
     358    if ( !this->networkStream->isUserIdActive( i ) )
     359      continue;
     360
     361    if ( !writeToClientBuffer( outBuffer[i], (byte)REMOVE_ENTITY ) )
     362      return;
     363    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
     364      return;
     365  }
    365366
    366367  doRemoveEntity(uniqueID);
     
    406407  while ( it != e )
    407408  {
    408 
     409    PRINTF(5)("SENDING ENTITY %s id %d\n", (*it)->getClassName(), (*it)->getUniqueID() );
    409410    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
    410411      return;
     
    426427bool NetworkGameManager::signalNewPlayer(int userId)
    427428{
     429  if ( userId >= outBuffer.size() )
     430    resizeBufferVector( userId );
    428431
    429432  /* create new playable for Player*/
  • branches/network/src/lib/network/network_game_manager.h

    r6500 r6503  
    122122  private:
    123123    std::vector<clientBuffer>     outBuffer;
    124     clientBuffer                  allOutBuffer;
     124    //clientBuffer                  allOutBuffer;
    125125    static NetworkGameManager*    singletonRef;
    126126
  • branches/network/src/lib/network/network_stream.cc

    r6500 r6503  
    7878  this->connectionMonitor = new ConnectionMonitor();
    7979  this->networkSockets.push_back( NULL );
     80  this->networkSockets[0] = NULL; //TODO: remove this
    8081  this->handshakes.push_back( NULL );
    8182  this->bActive = true;
     
    266267            if ( networkSockets[i] != NULL )
    267268            {
    268               PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
     269              PRINTF(5)("write %d bytes to socket %d\n", dataLength, i);
    269270              networkSockets[i]->writePacket(downBuffer, dataLength);
    270271            }
  • branches/network/src/lib/network/network_stream.h

    r6341 r6503  
    5555    inline int getSyncCount(){ return synchronizeables.size(); }
    5656
     57    inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; }
     58
    5759  private:
    5860    NetworkProtocol*       networkProtocol;
  • branches/network/src/world_entities/space_ships/space_ship.cc

    r6500 r6503  
    539539  }
    540540
     541  return SYNCHELP_READ_N;
     542
    541543  if ( b == DATA_flags && this->getHostID()!=this->getOwner() )
    542544  {
     
    591593  }
    592594
     595  return 0;
    593596
    594597  *reciever = 0;
Note: See TracChangeset for help on using the changeset viewer.