Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8096 in orxonox.OLD for branches/network


Ignore:
Timestamp:
Jun 1, 2006, 6:36:55 PM (18 years ago)
Author:
rennerc
Message:

teamchoice works now

Location:
branches/network/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/message_manager.h

    r8068 r8096  
    2929{
    3030  TESTMESSAGEID = 1,
    31   MSGID_DELETESYNCHRONIZEABLE
     31  MSGID_DELETESYNCHRONIZEABLE,
     32  MSGID_PREFEREDTEAM
    3233};
    3334
  • branches/network/src/lib/network/network_game_manager.cc

    r8068 r8096  
    5959 
    6060  MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL );
     61  MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL );
    6162 
    6263  this->gameState = 0;
     
    8687 
    8788  int team = rules.getTeamForNewUser();
    88   ClassID playableClassId = rules.getPlayableClassId( team );
    89   std::string playableModel = rules.getPlayableModelFileName( team, playableClassId );
     89  ClassID playableClassId = rules.getPlayableClassId( userId, team );
     90  std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );
    9091 
    9192  BaseObject * bo = Factory::fabricate( playableClassId );
     
    180181
    181182
    182 
    183 
    184 
     183/**
     184 * handler for MSGID_PREFEREDTEAM message
     185 * @param messageId
     186 * @param data
     187 * @param dataLength
     188 * @param someData
     189 * @param userId
     190 * @return
     191 */
     192bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     193{
     194  assert( NetworkGameManager::getInstance()->isServer() );
     195 
     196  int teamId = 0;
     197  int len = Converter::byteArrayToInt( data, &teamId );
     198 
     199  if ( len != dataLength )
     200  {
     201    PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId);
     202    return true;
     203  }
     204 
     205  NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId );
     206}
     207
     208void NetworkGameManager::setPreferedTeam( int userId, int teamId )
     209{
     210  if ( !PlayerStats::getStats( userId ) )
     211    return;
     212 
     213  PlayerStats & stats = *(PlayerStats::getStats( userId ));
     214 
     215  stats.setPreferedTeamId( teamId );
     216 
     217}
     218
     219/**
     220 * set prefered team for this host
     221 * @param teamId
     222 */
     223void NetworkGameManager::prefereTeam( int teamId )
     224{
     225  if ( isServer() )
     226    setPreferedTeam( getHostID(), teamId );
     227  else
     228  {
     229    byte buf[INTSIZE];
     230   
     231    assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE );
     232   
     233    MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH );
     234  }
     235}
     236
     237
     238
     239
  • branches/network/src/lib/network/network_game_manager.h

    r8068 r8096  
    5656   
    5757    void removeSynchronizeable( int uniqueId );
     58   
     59    void prefereTeam( int teamId );
    5860
    5961    inline void setGameState( int gameState ){ this->gameState = gameState; }
     
    6466   
    6567    static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     68    static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     69   
     70    void setPreferedTeam( int userId, int teamId );
    6671
    6772    static NetworkGameManager*    singletonRef;
  • branches/network/src/lib/network/player_stats.cc

    r8068 r8096  
    8686   
    8787    PRINTF(0)("uniqueID changed %d %d\n", userId, getHostID());
    88    
    89     if ( userId == getHostID() )
    90       State::getPlayer()->setPlayable( getPlayable() );
    9188  }
    9289}
     
    10097{
    10198  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
     99 
     100  if ( !list )
     101    return NULL;
    102102 
    103103  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     
    121121  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    122122 
     123  if ( !list )
     124  {
     125    this->playableUniqueId = uniqueId;
     126    return;
     127  }
     128 
    123129  this->playable = NULL;
    124130  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     
    130136    }
    131137  }
     138 
     139  if ( /*this->playable &&*/ userId == getHostID() )
     140    State::getPlayer()->setPlayable( this->playable );
    132141 
    133142  this->playableUniqueId = uniqueId;
  • branches/network/src/lib/network/synchronizeable.cc

    r8068 r8096  
    108108
    109109  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
     110  {
     111    //PRINTF(0)("SIZE = %d %s\n", (*it)->getSize(), (*it)->getName().c_str());
    110112    neededSize += (*it)->getSize();
     113  }
    111114
    112115  if ( !( neededSize <= maxLength ) )
     
    183186                    );
    184187   
    185     if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
     188    if ( ( sizeIter != stateFrom->sizeList.end() && *sizeIter != (*it)->getSize() ) || ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
    186189    {
    187190      n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
     
    209212  sentStates[userId].push_back( stateTo );
    210213 
    211   assert( i == neededSize );
     214  if ( i != neededSize )
     215  {
     216    PRINTF(0)("strange error: (%s) %d != %d\n", this->getClassName(), i, neededSize);
     217    assert(false);
     218  }
    212219
    213220  //write diff to data
  • branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc

    r7954 r8096  
    4848 
    4949  assert( res > 0 );
     50  assert( res == vPtrIn->length()+INTSIZE );
    5051 
    5152  return res;
  • branches/network/src/util/multiplayer_team_deathmatch.cc

    r8068 r8096  
    3737
    3838#include "network_game_manager.h"
     39
     40#include "event_handler.h"
     41
     42#include "glgui.h"
     43
     44#include "story_entity.h"
    3945
    4046
     
    5965  this->currentGameState = GAMESTATE_PRE_GAME;
    6066  this->gameStateTimer = 10.0f;
     67 
     68  this->box = NULL;
    6169
    6270  this->deathScreen = new ImagePlane();
     
    138146void MultiplayerTeamDeathmatch::tick(float dt)
    139147{
     148  //on client side hostId is -1 until hanshake finished
     149  if ( SharedNetworkData::getInstance()->getHostID() < 0 )
     150    return;
     151 
     152  if ( currentGameState == GAMESTATE_PRE_GAME )
     153  {
     154    if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
     155         && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM
     156         && box == NULL
     157       )
     158    {
     159      EventHandler::getInstance()->pushState( ES_MENU );
     160     
     161      OrxGui::GLGuiHandler::getInstance()->activateCursor();
     162     
     163      box = new OrxGui::GLGuiBox();
     164      box->setAbsCoor2D( 300, 100 );
     165     
     166      OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator");
     167      box->pack( buttonSpectator );
     168      buttonSpectator->connect(SIGNAL(buttonSpectator, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonSpectator));
     169     
     170      OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random");
     171      box->pack( buttonRandom );
     172      buttonRandom->connect(SIGNAL(buttonRandom, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonRandom));
     173     
     174      OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team");
     175      box->pack( buttonTeam0 );
     176      buttonTeam0->connect(SIGNAL(buttonTeam0, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam0));
     177     
     178      OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team");
     179      box->pack( buttonTeam1 );
     180      buttonTeam1->connect(SIGNAL(buttonTeam1, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam1));
     181     
     182      OrxGui::GLGuiPushButton * buttonExit = new OrxGui::GLGuiPushButton("Exit");
     183      box->pack( buttonExit );
     184      buttonExit->connect(SIGNAL(buttonExit, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonExit));
     185     
     186      box->showAll();
     187    }
     188  }
     189
     190  if ( box != NULL
     191       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
     192       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM
     193     )
     194  {
     195    delete box;
     196    box = NULL;
     197     
     198    OrxGui::GLGuiHandler::getInstance()->deactivateCursor( true );
     199     
     200    EventHandler::getInstance()->popState();
     201  }
     202 
     203  if ( box != NULL )
     204  {
     205    OrxGui::GLGuiHandler::getInstance()->tick( dt );
     206  }
     207 
     208  assignPlayable();
     209 
    140210  if ( !SharedNetworkData::getInstance()->isGameServer() )
    141211    return;
    142212 
    143213  gameStateTimer -= dt;
    144   PRINTF(0)("TICK %f\n", gameStateTimer);
     214  //PRINTF(0)("TICK %f\n", gameStateTimer);
    145215 
    146216  if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 )
     
    210280 * @return group id
    211281 */
    212 int MultiplayerTeamDeathmatch::getTeamForNewUser( )
     282int MultiplayerTeamDeathmatch::getTeamForNewUser()
    213283{
    214284  return TEAM_NOTEAM;
    215285}
    216286
    217 ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int team )
    218 {
    219   return CL_SPECTATOR;
    220 }
    221 
    222 std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int team, ClassID classId )
    223 {
    224   return "";
     287ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int userId, int team )
     288{
     289  if ( team == TEAM_NOTEAM || team == TEAM_SPECTATOR )
     290    return CL_SPECTATOR;
     291 
     292  if ( team == 0 || team == 1 )
     293    return CL_SPACE_SHIP;
     294 
     295  assert( false );
     296}
     297
     298std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId )
     299{
     300  if ( team == 0 )
     301    return "models/ships/reap_#.obj";
     302  else if ( team == 1 )
     303    return "models/ships/fighter.obj";
     304  else
     305    return "";
    225306}
    226307
     
    334415    if ( stats.getTeamId() != stats.getPreferedTeamId() )
    335416    {
    336       if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() <= 0 && stats.getPreferedTeamId() < numTeams ) )
     417      if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() >= 0 && stats.getPreferedTeamId() < numTeams ) )
    337418      {
    338419        teamChange( stats.getUserId() );
     
    362443  PlayerStats & stats = *(PlayerStats::getStats( userId ));
    363444 
    364   assert(false);
    365 }
    366 
    367 
    368 
    369 
    370 
    371 
     445  stats.setTeamId( stats.getPreferedTeamId() );
     446 
     447  Playable * oldPlayable = stats.getPlayable();
     448 
     449 
     450  ClassID playableClassId = getPlayableClassId( userId, stats.getPreferedTeamId() );
     451  std::string playableModel = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId );
     452 
     453  BaseObject * bo = Factory::fabricate( playableClassId );
     454 
     455  assert( bo != NULL );
     456  assert( bo->isA( CL_PLAYABLE ) );
     457 
     458  Playable & playable = *(dynamic_cast<Playable*>(bo));
     459 
     460  playable.loadModel( playableModel );
     461  playable.setOwner( userId );
     462  playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
     463  playable.setSynchronized( true );
     464 
     465  stats.setTeamId( stats.getPreferedTeamId() );
     466  stats.setPlayableClassId( playableClassId );
     467  stats.setPlayableUniqueId( playable.getUniqueID() );
     468  stats.setModelFileName( playableModel );
     469 
     470  if ( oldPlayable )
     471  {
     472    //if ( userId == SharedNetworkData::getInstance()->getHostID() )
     473    //  State::getPlayer()->setPlayable( NULL );
     474    delete oldPlayable;
     475  }
     476}
     477
     478void MultiplayerTeamDeathmatch::onButtonExit( )
     479{
     480  State::getCurrentStoryEntity()->stop();
     481}
     482
     483void MultiplayerTeamDeathmatch::onButtonRandom( )
     484{
     485  NetworkGameManager::getInstance()->prefereTeam( TEAM_RANDOM );
     486}
     487
     488void MultiplayerTeamDeathmatch::onButtonTeam0( )
     489{
     490  NetworkGameManager::getInstance()->prefereTeam( 0 );
     491}
     492
     493void MultiplayerTeamDeathmatch::onButtonTeam1( )
     494{
     495  NetworkGameManager::getInstance()->prefereTeam( 1 );
     496}
     497
     498void MultiplayerTeamDeathmatch::onButtonSpectator( )
     499{
     500  NetworkGameManager::getInstance()->prefereTeam( TEAM_SPECTATOR );
     501}
     502
     503void MultiplayerTeamDeathmatch::assignPlayable( )
     504{
     505  if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) )
     506    PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPlayable();
     507}
     508
     509
     510
     511
     512
     513
  • branches/network/src/util/multiplayer_team_deathmatch.h

    r8068 r8096  
    1212#include "network_game_rules.h"
    1313
     14#include "glgui_box.h"
    1415
    1516class TiXmlElement;
     
    3637
    3738    virtual int getTeamForNewUser();
    38     virtual ClassID getPlayableClassId( int team );
    39     virtual std::string getPlayableModelFileName( int team, ClassID classId );
     39    virtual ClassID getPlayableClassId( int userId, int team );
     40    virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId );
    4041
    4142    virtual void onPlayerSpawn();
     
    7374    float              gameStateTimer;             //!< if less than 0 -> change game state
    7475
     76    OrxGui::GLGuiBox* box;
     77
     78
    7579    void calculateTeamScore();
    7680    void nextGameState();
    7781    void handleTeamChanges();
    7882    void teamChange( int userId );
     83    void assignPlayable();
     84   
     85    void onButtonSpectator();
     86    void onButtonRandom();
     87    void onButtonTeam0();
     88    void onButtonTeam1();
     89    void onButtonExit();
    7990};
    8091
  • branches/network/src/util/network_game_rules.cc

    r8068 r8096  
    3838}
    3939
    40 std::string NetworkGameRules::getPlayableModelFileName( int team, ClassID classId )
     40std::string NetworkGameRules::getPlayableModelFileName( int uesrId, int team, ClassID classId )
    4141{
    4242  return "models/ships/reap_#.obj";
    4343}
    4444
    45 ClassID NetworkGameRules::getPlayableClassId( int team )
     45ClassID NetworkGameRules::getPlayableClassId( int userId, int team )
    4646{
    4747  return CL_SPACE_SHIP;
  • branches/network/src/util/network_game_rules.h

    r8068 r8096  
    2121   
    2222    virtual int getTeamForNewUser();
    23     virtual ClassID getPlayableClassId( int team );
    24     virtual std::string getPlayableModelFileName( int team, ClassID classId );
     23    virtual ClassID getPlayableClassId( int userId, int team );
     24    virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId );
    2525   
    2626    virtual PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); }
  • branches/network/src/world_entities/playable.cc

    r8055 r8096  
    7979  // this->setPlayer(NULL);
    8080  // IN ITS DESTRUCTOR.
     81  detachCamera();
    8182  assert(this->currentPlayer == NULL);
    8283}
     
    281282 */
    282283void  Playable::detachCamera()
    283 {}
     284{
     285  PRINTF(0)("detach camera\n");
     286  if ( (PNode*)(State::getCameraTarget()) == this )
     287  {
     288    PRINTF(0)("lookAt nullParent\n");
     289   
     290    State::getCameraNode()->setParentSoft(PNode::getNullParent());
     291    State::getCameraTargetNode()->setParentSoft(PNode::getNullParent());
     292   
     293    State::getCamera()->lookAt( PNode::getNullParent() );
     294  }
     295}
    284296
    285297
  • branches/network/src/world_entities/player.cc

    r7868 r8096  
    8181      return true;
    8282  }
     83 
     84  if ( playable == NULL )
     85    this->playable = NULL;
    8386
    8487  return true;
Note: See TracChangeset for help on using the changeset viewer.