Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 21, 2006, 1:18:19 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network-branche back to the trunk

merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6500:HEAD
minor conflicts in texture and one Makefile resolved to the trunk

also made a small patch to texture, so it Modulates with GL_REPEAT

File:
1 edited

Legend:

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

    r6498 r6634  
    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;
     
    137130    }
    138131
     132    if ( b == REQUEST_ENTITY_LIST )
     133    {
     134      sendEntityList( sender );
     135      continue;
     136    }
     137
    139138    if ( b == REQUEST_SYNC )
    140139    {
    141140      if ( !handleRequestSync( i, data, length, sender ) )
    142141        return i;
    143       continue;
    144     }
    145 
    146     if ( b == REQUEST_ENTITY_LIST )
    147     {
    148       sendEntityList( sender );
    149142      continue;
    150143    }
     
    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*/
     
    483486
    484487    //HACK: hack to prevent collision
    485     if ( b->isA(CL_WORLD_ENTITY) )
     488    if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) )
    486489    {
    487490      if ( NetworkManager::getInstance()->getHostID()!=0 )
     
    489492        static Vector pos = Vector(1000.0, 1000.0, 1000.0);
    490493        PNode *p = dynamic_cast<PNode*>(b);
    491         p->setRelCoor(pos);
    492         p->updateNode(0);
     494        p->setAbsCoor(pos);
     495        //p->updateNode(0);
    493496        pos += Vector(1000.0, 1000.0, 1000.0);
    494497      }
     
    596599
    597600  Playable *p = NULL;
     601  Synchronizeable *s = NULL;
    598602
    599603  for ( ; it !=networkStream->getSyncEnd(); it++ )
     
    601605    if ( (*it)->getUniqueID()==uniqueID )
    602606    {
     607      if ( (*it)->isA( CL_SYNCHRONIZEABLE ) )
     608      {
     609        s = dynamic_cast<Synchronizeable*>(*it);
     610      }
    603611      if ( (*it)->isA( CL_PLAYABLE ) )
    604612      {
     
    614622  Player* player = State::getPlayer();
    615623  assert(p != NULL);
     624  assert(s != NULL);
    616625  assert(player != NULL);
     626
     627  s->setIsOutOfSync( true );
     628
     629  PRINTF(0)("uniqueID = %d\n", s->getUniqueID());
    617630
    618631  player->setControllable(p);
     
    871884void NetworkGameManager::sync( int uniqueID, int owner )
    872885{
    873   if ( owner==this->getHostID() )
    874     return;
     886  /*if ( owner==this->getHostID() )
     887  return;*/
    875888
    876889  if ( !isServer() )
Note: See TracChangeset for help on using the changeset viewer.