Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

network: playable creation fix

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.