Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 29, 2006, 3:28:41 PM (19 years ago)
Author:
patrick
Message:

trunk: merged the network branche back to trunk.

File:
1 edited

Legend:

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

    r7354 r7954  
    2727#include "shared_network_data.h"
    2828#include "converter.h"
     29#include "message_manager.h"
    2930
    3031#include "playable.h"
     
    5253  this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
    5354
    54   hasRequestedWorld = false;
    5555  this->setSynchronized(true);
     56 
     57  MessageManager::getInstance()->registerMessageHandler( MSGID_YOU_ARE, youAreHandler, NULL );
    5658}
    5759
     
    6163NetworkGameManager::~NetworkGameManager()
    6264{
     65#if 0
    6366  for ( int i = 0; i<outBuffer.size(); i++)
    6467  {
     
    6669      delete outBuffer[i].buffer;
    6770  }
    68 
    69 }
    70 
    71 
     71#endif
     72
     73}
     74
     75#if 0
    7276int NetworkGameManager::writeBytes(const byte* data, int length, int sender)
    7377{
     
    141145    {
    142146      sendEntityList( sender );
    143       continue;
    144     }
    145     else if ( b == NET_REQUEST_SYNC )
    146     {
    147       if ( !handleRequestSync( i, data, length, sender ) )
    148         return i;
    149147      continue;
    150148    }
     
    160158  return i;
    161159}
    162 
     160#endif
     161
     162#if 0
    163163int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever)
    164164{
     
    192192  return 0;
    193193}
    194 
     194#endif
     195
     196#if 0
    195197void NetworkGameManager::writeDebug() const
    196198{
     
    200202{
    201203}
     204#endif
    202205
    203206
     
    211214  if ( this->isServer())
    212215  {
    213     if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
     216    int res = this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
     217   
     218    if ( res < 0 )
    214219    {
    215220      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
    216221      return -1;
    217222    }
    218     return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
     223   
     224    return res;
    219225  }
    220226  else
    221227  {
     228#if 0
    222229    this->requestCreateEntity( classID );
     230#endif
    223231    return -1;
    224232  }
     
    288296  else
    289297  {
     298#if 0
    290299    this->requestRemoveEntity( uniqueID );
    291   }
    292 }
    293 
    294 
    295 
     300#endif
     301  }
     302}
     303
     304
     305#if 0
    296306/*!
    297307 * Creates the needed entity on the server if possible
     
    311321  }
    312322}
    313 
     323#endif
     324
     325#if 0
    314326/*!
    315327 * Removes the specified entity on the server
     
    329341  }
    330342}
     343#endif
    331344
    332345/*!
     
    337350int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
    338351{
     352#if 0
    339353  for ( int i = 0; i<outBuffer.size(); i++)
    340354  {
     
    351365      return -1;
    352366  }
    353 
     367#endif
    354368  PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
    355369  doCreateEntity( classID, uniqueID, owner );
     
    365379void NetworkGameManager::executeRemoveEntity(int uniqueID)
    366380{
     381#if 0
    367382  for ( int i = 0; i<outBuffer.size(); i++)
    368383  {
     
    375390      return;
    376391  }
     392#endif
    377393
    378394  doRemoveEntity(uniqueID);
     
    388404}
    389405
     406#if 0
    390407/*!
    391408 * Sends the Entities to the new connected client
     
    443460  signalNewPlayer( userID );
    444461}
     462#endif
    445463
    446464
     
    448466bool NetworkGameManager::signalNewPlayer(int userId)
    449467{
    450   if ( userId >= outBuffer.size() )
    451     resizeBufferVector( userId );
    452 
    453468  /* create new playable for Player*/
    454469  PRINTF(0)("Request for creation: %i\n", userId);
     
    456471  PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId);
    457472  this->sendYouAre(uniqueId, userId);
    458 
    459473}
    460474
     
    464478{
    465479  const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
     480 
     481  if ( !playableList )
     482    return false;
     483 
    466484  std::list<BaseObject*>::const_iterator it = playableList->begin();
    467485
     
    478496}
    479497
    480 
     498#if 0
    481499/**
    482500 * Creates a buffer for user n
     
    498516  }
    499517}
     518#endif
    500519
    501520/**
     
    532551    s->setSynchronized(true);
    533552    //this->networkStream->connectSynchronizeable( *s );
    534     if ( !isServer() )
    535       s->setIsOutOfSync( true );
     553
    536554    PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());
    537555
     
    601619}
    602620
    603 /**
    604  * Tell the synchronizeable that a user's synchronizeable is out of sync
    605  * @param uniqueID: unique ID assigned with the entity which is out of sync
    606  * @param userID: user ID who's synchronizeable is out of sync
    607  */
    608 void NetworkGameManager::doRequestSync( int uniqueID, int userID )
    609 {
    610   SynchronizeableList::const_iterator it,e;
    611   it = this->networkStream->getSyncBegin();
    612   e = this->networkStream->getSyncEnd();
    613 
    614   while ( it != e )
    615   {
    616     if ( (*it)->getUniqueID() == uniqueID )
    617     {
    618       (*it)->requestSync( userID );
    619       break;
    620     }
    621     it++;
    622   }
    623 }
    624 
     621#if 0
    625622/**
    626623 * Copies length bytes to the clientBuffer with error checking
     
    641638  return true;
    642639}
    643 
     640#endif
     641
     642#if 0
    644643/**
    645644 * Reads data from clientBuffer with error checking
     
    660659  return true;
    661660}
     661#endif
    662662
    663663/**
     
    687687      } else
    688688      {
    689         PRINTF(1)("UniqueID is not a Playable\n");
     689        PRINTF(1)("UniqueID %d is not a Playable\n", uniqueID);
    690690      }
    691691    }
     
    697697  assert(player != NULL);
    698698
    699   s->setIsOutOfSync( true );
    700 
    701699  PRINTF(0)("uniqueID = %d\n", s->getUniqueID());
    702700
     
    715713  if ( !isServer() )
    716714    return;
    717 
    718   if ( userID != 0 )
    719   {
    720     if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) )
    721       return;
    722 
    723     if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) )
    724       return;
    725   }
    726   else
    727   {
    728     doYouAre(uniqueID);
    729   }
     715 
     716  byte buf[INTSIZE];
     717 
     718  Converter::intToByteArray( uniqueID, buf, INTSIZE );
     719 
     720  MessageManager::getInstance()->sendMessage( MSGID_YOU_ARE, buf, INTSIZE, RT_USER, userID, MP_HIGHBANDWIDTH);
    730721}
    731722
     
    902893  return true;
    903894}
    904 
    905 bool NetworkGameManager::handleRequestSync( int & i, const byte * data, int length, int sender )
    906 {
    907   if ( INTSIZE > length-i )
    908   {
    909     PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
    910     return false;
    911   }
    912   int uniqueID;
    913   i += Converter::byteArrayToInt( &data[i], &uniqueID );
    914 
    915   PRINTF(0)("handleRequestSync %d %d\n", uniqueID, sender);
    916   doRequestSync( uniqueID, sender );
    917 
    918   return true;
    919 }
    920 
    921895
    922896/**
     
    958932}
    959933
    960 
     934bool NetworkGameManager::youAreHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
     935{
     936  assert( dataLength == INTSIZE );
     937  int uniqueId;
     938 
     939  Converter::byteArrayToInt( data, &uniqueId );
     940 
     941  SynchronizeableList::const_iterator it = NetworkGameManager::getInstance()->networkStream->getSyncBegin();
     942
     943  Playable *p = NULL;
     944  Synchronizeable *s = NULL;
     945
     946  for ( ; it !=NetworkGameManager::getInstance()->networkStream->getSyncEnd(); it++ )
     947  {
     948    if ( (*it)->getUniqueID()==uniqueId )
     949    {
     950      break;
     951    }
     952  }
     953 
     954  if ( it == NetworkGameManager::getInstance()->networkStream->getSyncEnd() )
     955    return false;
     956 
     957  NetworkGameManager::getInstance()->doYouAre( uniqueId );
     958 
     959  return true;
     960}
     961
     962#if 0
    961963bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b )
    962964{
     
    971973  return true;
    972974}
     975
    973976
    974977bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i )
     
    985988  return true;
    986989}
    987 
    988 void NetworkGameManager::sync( int uniqueID, int owner )
    989 {
    990   /*if ( owner==this->getHostID() )
    991   return;*/
    992 
    993   if ( !isServer() )
    994     executeRequestSync( uniqueID, 0 );
    995   else
    996     executeRequestSync( uniqueID, owner );
    997 }
    998 
    999 void NetworkGameManager::executeRequestSync( int uniqueID, int user )
    1000 {
    1001   PRINTF(0)("executeRequestSync %d %d\n", uniqueID, user);
    1002   if ( user >= outBuffer.size() )
    1003     resizeBufferVector( user );
    1004 
    1005   if ( !writeToClientBuffer( outBuffer[user], (byte)NET_REQUEST_SYNC ) )
    1006     return;
    1007   if ( !writeToClientBuffer( outBuffer[user], uniqueID ) )
    1008     return;
    1009 }
    1010 
     990#endif
     991
     992
Note: See TracChangeset for help on using the changeset viewer.