Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6493 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
Jan 11, 2006, 5:06:43 PM (18 years ago)
Author:
patrick
Message:

network: playable creation fix

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

Legend:

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

    r6483 r6493  
    2828#include "game_world.h"
    2929#include "world_entity.h"
     30#include "playable.h"
     31#include "player.h"
    3032#include "network_manager.h"
    3133
     
    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}
     
    331336 * @param classID: The ID of the class of which an entity should be created
    332337 */
    333 void NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
     338int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
    334339{
    335340  if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) )
    336     return;
     341    return -1;
    337342  if ( !writeToClientBuffer( allOutBuffer, (int)classID ) )
    338     return;
     343    return -1;
    339344  if ( !writeToClientBuffer( allOutBuffer, uniqueID ) )
    340     return;
     345    return -1;
    341346  if ( !writeToClientBuffer( allOutBuffer, owner ) )
    342     return;
     347    return -1;
    343348
    344349  doCreateEntity( classID, uniqueID, owner );
     350
     351  return uniqueID;
    345352}
    346353
     
    412419  }
    413420
    414 
    415 }
     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
    416437
    417438/**
     
    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
  • branches/network/src/lib/network/network_game_manager.h

    r6424 r6493  
    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);
  • branches/network/src/lib/network/network_stream.cc

    r6483 r6493  
    192192          else
    193193          {
    194             //this->networkGameManager->sendEntityList( i );
     194
    195195          }
    196196          PRINT(0)("handshake finished id=%d\n", handshakes[i]->getNetworkGameManagerId());
Note: See TracChangeset for help on using the changeset viewer.