Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6498 in orxonox.OLD for trunk/src/lib/network


Ignore:
Timestamp:
Jan 11, 2006, 9:58:22 PM (18 years ago)
Author:
patrick
Message:

trunk: merged the network branche into the trunk

Location:
trunk/src/lib/network
Files:
3 edited

Legend:

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

    r6424 r6498  
    2525
    2626#include "p_node.h"
     27#include "state.h"
     28#include "game_world.h"
     29#include "world_entity.h"
     30#include "playable.h"
     31#include "player.h"
     32#include "network_manager.h"
    2733
    2834
     
    8187  {
    8288    b = data[i++];
    83 
    84     PRINTF(0)("WriteBytes: b = %d\n", b);
    8589
    8690    if ( isServer() )
     
    142146    if ( b == REQUEST_ENTITY_LIST )
    143147    {
    144       PRINTF(0)("sending THE list\n");
    145148      sendEntityList( sender );
    146149      continue;
     
    163166    SYNCHELP_WRITE_BYTE( b );
    164167    hasRequestedWorld = true;
    165     PRINTF(0)("the world is enough! id=%d\n", this->getUniqueID());
    166168    return SYNCHELP_WRITE_N;
    167169  }
     170
    168171  for ( int i = 0; i<outBuffer.size(); i++ )
    169172  {
     
    216219 * @param classID: The ID of the class of which an entity should be created
    217220 */
    218 void NetworkGameManager::createEntity( ClassID classID, int owner )
    219 {
     221int NetworkGameManager::createEntity( ClassID classID, int owner )
     222{
     223
    220224  if ( this->isServer() )
    221225  {
     
    223227    {
    224228      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
    225       return;
    226     }
    227 
    228     this->executeCreateEntity( classID, newUniqueID++, owner );
     229      return -1;
     230    }
     231
     232    return this->executeCreateEntity( classID, newUniqueID++, owner );
    229233  }
    230234  else
    231235  {
    232236    this->requestCreateEntity( classID );
     237    return -1;
    233238  }
    234239}
     
    273278      delete b;
    274279    }
     280
    275281  }
    276282  else
     
    330336 * @param classID: The ID of the class of which an entity should be created
    331337 */
    332 void NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
     338int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
    333339{
    334340  if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) )
    335     return;
     341    return -1;
    336342  if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
    337     return;
     343    return -1;
    338344  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    339     return;
     345    return -1;
    340346  if ( !writeToClientBuffer( allOutBuffer, owner ) )
    341     return;
     347    return -1;
    342348
    343349  doCreateEntity( classID, uniqueID, owner );
     350
     351  return uniqueID;
    344352}
    345353
     
    401409    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
    402410      return;
    403       //PRINTF(0)("SendEntityList: ClassID = %x\n", (*it)->getRealClassID());
    404411
    405412    if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) )
     
    409416      return;
    410417
    411 
    412     PRINTF(0)("id = %x %s %s\n", (int)((*it)->getLeafClassID()), (*it)->getClassName(), (*it)->getName());
    413 
    414 
    415     /*if ( (*it)->isA(CL_WORLD_ENTITY) )
    416     {
    417       n = dynamic_cast<WorldEntity*>((*it))->readState( outBuffer[userID].buffer, outBuffer[userID].maxLength-outBuffer[userID].length );
    418       if ( n = 0 )
    419       {
    420         PRINTF(2)("n = 0\n");
    421       }
    422       outBuffer[userID].length += n;
    423   }*/
    424 
    425418    it++;
    426419  }
    427420
    428 
    429 }
     421  signalNewPlayer( userID );
     422}
     423
     424
     425
     426bool NetworkGameManager::signalNewPlayer(int userId)
     427{
     428
     429  /* create new playable for Player*/
     430  PRINTF(0)("Request for creation: %i\n", userId);
     431  int uniqueId = this->createEntity(CL_SPACE_SHIP, userId);
     432  PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId);
     433  this->sendYouAre(uniqueId, userId);
     434
     435}
     436
    430437
    431438/**
     
    474481      s->setIsOutOfSync( true );
    475482    PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());
     483
     484    //HACK: hack to prevent collision
     485    if ( b->isA(CL_WORLD_ENTITY) )
     486    {
     487      if ( NetworkManager::getInstance()->getHostID()!=0 )
     488      {
     489        static Vector pos = Vector(1000.0, 1000.0, 1000.0);
     490        PNode *p = dynamic_cast<PNode*>(b);
     491        p->setRelCoor(pos);
     492        p->updateNode(0);
     493        pos += Vector(1000.0, 1000.0, 1000.0);
     494      }
     495    }
     496
    476497    return b;
    477498  }
     
    571592void NetworkGameManager::doYouAre( int uniqueID )
    572593{
    573   //TODO: what has to be done
     594
     595  SynchronizeableList::const_iterator it = this->networkStream->getSyncBegin();
     596
     597  Playable *p = NULL;
     598
     599  for ( ; it !=networkStream->getSyncEnd(); it++ )
     600  {
     601    if ( (*it)->getUniqueID()==uniqueID )
     602    {
     603      if ( (*it)->isA( CL_PLAYABLE ) )
     604      {
     605        p = dynamic_cast<Playable*>(*it);
     606        break;
     607      } else
     608      {
     609        PRINTF(1)("UniqueID is not a Playable\n");
     610      }
     611    }
     612  }
     613
     614  Player* player = State::getPlayer();
     615  assert(p != NULL);
     616  assert(player != NULL);
     617
     618  player->setControllable(p);
     619
     620
    574621}
    575622
     
    716763    i += Converter::byteArrayToInt( &data[i], &owner );
    717764
    718     PRINTF(0)("before fabricate\n");
    719765    if ( classID != CL_NETWORK_GAME_MANAGER && classID != CL_HANDSHAKE )
    720766    {
  • trunk/src/lib/network/network_game_manager.h

    r6424 r6498  
    7474    virtual void readDebug() const;
    7575
    76     void createEntity( ClassID classID, int owner = 0 );
     76    int createEntity( ClassID classID, int owner = 0 );
    7777    BaseObject* createEntity(const TiXmlElement* element);
    7878    void removeEntity( int uniqueID );
     
    8787
    8888    void requestCreateEntity(ClassID classID);
    89     void executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0);
     89    int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0);
    9090
    9191    void requestRemoveEntity(int uniqueID);
     
    100100
    101101    bool canCreateEntity(ClassID classID);
     102
     103    bool signalNewPlayer(int userId);
    102104
    103105    void resizeBufferVector(int n);
  • trunk/src/lib/network/network_stream.cc

    r6341 r6498  
    166166      networkSockets[0]->destroy();
    167167      networkSockets[0] = NULL;
    168       //TODO: delete handshake from synchronizeable list so i can delete it
     168
    169169      if ( handshakes[0] )
    170170        delete handshakes[0];
     
    192192          else
    193193          {
    194             //this->networkGameManager->sendEntityList( i );
     194
    195195          }
    196196          PRINT(0)("handshake finished id=%d\n", handshakes[i]->getNetworkGameManagerId());
     
    252252          if ( networkSockets[reciever] != NULL )
    253253          {
    254             PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
     254            PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
    255255            networkSockets[reciever]->writePacket(downBuffer, dataLength);
    256256          }
     
    266266            if ( networkSockets[i] != NULL )
    267267            {
    268               PRINTF(0)("write %d bytes to socket %d\n", dataLength, reciever);
     268              PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
    269269              networkSockets[i]->writePacket(downBuffer, dataLength);
    270270            }
     
    291291        dataLength -= sizeof(header);
    292292
    293         PRINTF(0)("read %d bytes from socket uniqueID = %d\n", dataLength, header.synchronizeableID);
     293        PRINTF(5)("read %d bytes from socket uniqueID = %d\n", dataLength, header.synchronizeableID);
    294294
    295295        if ( dataLength != header.length )
     
    372372      networkSockets[i]->destroy();
    373373      networkSockets[i] = NULL;
    374       //TODO: delete handshake from synchronizeable list so i can delete it
     374
    375375      if ( handshakes[i] )
    376376        delete handshakes[i];
Note: See TracChangeset for help on using the changeset viewer.