Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6493 in orxonox.OLD


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

network: playable creation fix

Location:
branches/network/src
Files:
9 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());
  • branches/network/src/story_entities/multi_player_world_data.cc

    r6466 r6493  
    160160        }
    161161      }
    162       else if( !strcmp( element->Value(), "SpaceShip"))       /// FIXME it is not said to be a SpaceShip
    163       {
    164         BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
    165         if( created != NULL )
    166           PRINTF(1)("Created a %s: %s (%8.u)\n", created->getClassName(), created->getName(), created->getLeafClassID());
    167         else
    168           PRINTF(1)("MultiPlayerWorld: could not create this entity\n");
    169       }
    170162      element = element->NextSiblingElement();
     163
    171164
    172165      glmis->step();
     
    174167    }
    175168
    176 
    177     /* create a Player */
    178     this->localPlayer = new Player();
    179 //     Playable* playable;
    180 //     const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
    181 //     assert( playableList != NULL);
    182 //
    183 //     if (playableList != NULL)
    184 //     {
    185 //       playable = dynamic_cast<Playable*>(playableList->front());
    186 //       this->localPlayer->setControllable(playable);
    187 //     }
     169    if( NetworkManager::getInstance()->isGameServer())
     170    {
     171      this->localPlayer = new Player();
     172      State::setPlayer(this->localPlayer);
     173
     174      Playable* playable;
     175      const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
     176      assert( playableList != NULL);
     177
     178      if (playableList != NULL)
     179      {
     180        playable = dynamic_cast<Playable*>(playableList->front());
     181        this->localPlayer->setControllable(playable);
     182      }
     183    }
     184    else
     185    {
     186      /* create a Player */
     187      this->localPlayer = new Player();
     188      State::setPlayer(this->localPlayer);
     189    }
     190
    188191
    189192    /* init the pnode tree */
  • branches/network/src/util/state.cc

    r6459 r6493  
    3333StoryEntity* State::storyEntity = NULL;
    3434
     35Player* State::player = NULL;
     36
    3537/**
    3638 *  sets camera and target of the current Camera
  • branches/network/src/util/state.h

    r6459 r6493  
    1111class PNode;
    1212class WorldEntity;
     13class Player;
    1314class ObjectManager;
    1415class StoryEntity;
     
    4950  static inline StoryEntity* getCurrentStoryEntity() { return State::storyEntity; };
    5051
     52  //////////////
     53  /// PLAYER ///
     54  //////////////
     55  /** @param storyEntity sets the current StoryEntity that is been played */
     56  static inline void setPlayer(Player* player) { State::player = player; };
     57  /** @returns the current StoryEntity played */
     58  static inline Player* getPlayer() { return State::player; };
    5159
    5260  /////////////////////////
     
    6270  static ObjectManager*         objectManager;      //!< A reference to the current ObjectManager
    6371  static StoryEntity*           storyEntity;        //!< A reference to the current StoryEntity played
     72  static Player*                player;             //!< A reference to the Player
    6473
    6574};
  • branches/network/src/world_entities/power_ups/power_up.cc

    r6424 r6493  
    9696}
    9797
     98
     99
     100/********************************************************************************************
     101 NETWORK STUFF
     102 ********************************************************************************************/
     103
     104
    98105/**
    99106 * data copied in data will bee sent to another host
     
    108115  return SYNCHELP_WRITE_N;
    109116}
     117
    110118
    111119/**
  • branches/network/src/world_entities/power_ups/turret_power_up.cc

    r6424 r6493  
    119119}
    120120
     121
     122
     123
     124/********************************************************************************************
     125 NETWORK STUFF
     126 ********************************************************************************************/
     127
     128
    121129int TurretPowerUp::writeBytes( const byte * data, int length, int sender )
    122130{
     
    130138  return SYNCHELP_READ_N;
    131139}
    132 
    133140
    134141
  • branches/network/src/world_entities/world_entity.cc

    r6469 r6493  
    370370
    371371
     372
     373
     374/********************************************************************************************
     375 NETWORK STUFF
     376 ********************************************************************************************/
     377
     378
    372379/**
    373380 * Writes data from network containing information about the state
     
    417424}
    418425
     426
    419427/**
    420428 * data copied in data will bee sent to another host
Note: See TracChangeset for help on using the changeset viewer.