Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6959 in orxonox.OLD for trunk/src/lib/network


Ignore:
Timestamp:
Feb 1, 2006, 4:40:34 PM (19 years ago)
Author:
patrick
Message:

trunk: merged network branche into trunk

Location:
trunk/src/lib/network
Files:
7 edited

Legend:

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

    r6753 r6959  
    9090 * @return: The number of written bytes
    9191 */
    92 int Converter::intToByteArray(int x, byte* a, int length)
     92int Converter::_intToByteArray(int x, byte* a, int length)
    9393{
    9494  if (length < INTSIZE)
     
    127127 * @return: The number of read bytes
    128128 */
    129 int Converter::byteArrayToInt(const byte* a, int* x)
     129int Converter::_byteArrayToInt(const byte* a, int* x)
    130130{
    131131  int mult = 1;
     
    146146    *x += a[INTSIZE - 1] * mult;
    147147
     148  return INTSIZE;
     149}
     150
     151int Converter::byteArrayToInt(const byte* a, int* x)
     152{
     153  memcpy( x, a, INTSIZE );
     154  return INTSIZE;
     155}
     156
     157int Converter::intToByteArray(int x, byte* a, int length)
     158{
     159  if ( length< INTSIZE )
     160  {
     161    PRINTF(1)("Byte Array to small\n");
     162    return 0;
     163  }
     164  memcpy(a, &x, INTSIZE);
    148165  return INTSIZE;
    149166}
  • trunk/src/lib/network/converter.h

    r6753 r6959  
    3030    static int intToByteArray(int x, byte* a, int length);
    3131    static int byteArrayToInt(const byte* a, int* x);
     32   
     33    static int _intToByteArray(int x, byte* a, int length);
     34    static int _byteArrayToInt(const byte* a, int* x);
    3235
    3336    static int stringToByteArray(const char* s, byte* a, int length, int maxLength);
  • trunk/src/lib/network/network_game_manager.cc

    r6868 r6959  
    2929#include "world_entity.h"
    3030#include "playable.h"
     31#include "space_ships/space_ship.h"
    3132#include "player.h"
    32 #include "network_manager.h"
     33#include "shared_network_data.h"
    3334
    3435#include "class_list.h"
     
    541542    if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) )
    542543    {
    543       if ( NetworkManager::getInstance()->getHostID()!=0 )
     544      if ( SharedNetworkData::getInstance()->getHostID()!=0 )
    544545      {
    545546        static Vector pos = Vector(1000.0, 1000.0, 1000.0);
     
    550551      }
    551552    }
     553    ///HACK this is only for network multiplayer games.
     554    if( b->isA(CL_SPACE_SHIP))
     555    {
     556      SpaceShip* ss = dynamic_cast<SpaceShip*>(b);
     557      if( owner%2 == 0)
     558      {
     559
     560        ss->loadModel("models/ships/reap_#.obj");
     561        ss->toList(OM_GROUP_00);
     562      }
     563      else
     564      {
     565        ss->loadModel( "models/ships/fighter.obj" );
     566        ss->toList(OM_GROUP_01);
     567      }
     568    }
    552569
    553570    return b;
     
    576593    {
    577594      assert((*it)->isA(CL_WORLD_ENTITY));
     595      dynamic_cast<WorldEntity*>(*it)->leaveWorld();
    578596      dynamic_cast<WorldEntity*>(*it)->toList(OM_DEAD);
    579597      break;
     
    895913  i += Converter::byteArrayToInt( &data[i], &uniqueID );
    896914
     915  PRINTF(0)("handleRequestSync %d %d\n", uniqueID, sender);
    897916  doRequestSync( uniqueID, sender );
    898917
     
    980999void NetworkGameManager::executeRequestSync( int uniqueID, int user )
    9811000{
     1001  PRINTF(0)("executeRequestSync %d %d\n", uniqueID, user);
    9821002  if ( user >= outBuffer.size() )
    9831003    resizeBufferVector( user );
  • trunk/src/lib/network/network_socket.cc

    r6695 r6959  
    172172
    173173  if (!tcpSocket || data==NULL || nbytes<=0)
    174     return 0;
     174  {
     175    assert(_OUTGOING_BUFFER_SIZE - outgoingBufferLength > 0);
     176    return 0;
     177  }
    175178
    176179  SDL_mutexP(outgoingBufferMutex);
     
    324327
    325328
     329#ifdef DONTEXITTHREADS
     330  while ( true )
     331  {
     332    SDL_Delay(1000);
     333  }
     334#endif
     335 
    326336  PRINTF(0)("QUIT READ THREAD\n");
     337 
    327338  return 0;
    328339}
     
    392403  }
    393404
     405#ifdef DONTEXITTHREADS
     406  while ( true )
     407  {
     408  SDL_Delay(1000);
     409  }
     410#endif
    394411
    395412  PRINTF(0)("QUIT WRITE THREAD\n");
     413
    396414  return 0;
     415 
    397416}
    398417
     
    426445  {
    427446    PRINTF(1)("Buffersize is too small (%d) for packet (%d)\n", maxLength, blen);
     447    assert(false);
    428448    return 0;
    429449  }
  • trunk/src/lib/network/network_socket.h

    r6695 r6959  
    88#define _NETWORK_SOCKET
    99
     10//HACK else gdb will not work on server
     11#define DONTEXITTHREADS
     12
    1013//if you want to use outgoing buffer define _USE_OUTGOING_BUFFER
    1114#define _USE_OUTGOING_BUFFER
    1215
    13 #define _INCOMING_BUFFER_SIZE 10240
     16#define _INCOMING_BUFFER_SIZE 2024000
    1417#define _OUTGOING_BUFFER_SIZE 2024000
    1518#define _LOCAL_BUFFER_SIZE 1024
  • trunk/src/lib/network/network_stream.cc

    r6868 r6959  
    2626#include "connection_monitor.h"
    2727#include "synchronizeable.h"
    28 #include "network_manager.h"
    2928#include "network_game_manager.h"
     29#include "shared_network_data.h"
    3030
    3131#include "debug.h"
     
    195195          {
    196196            SharedNetworkData::getInstance()->setHostID( handshakes[i]->getHostId() );
    197             myHostId = NetworkManager::getInstance()->getHostID();
     197            myHostId = SharedNetworkData::getInstance()->getHostID();
    198198
    199199            this->networkGameManager = NetworkGameManager::getInstance();
     
    231231  int reciever;
    232232  Header header;
     233  int counter;
     234
    233235  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
    234236  {
     237    counter = 0;
     238
    235239    if ( (*it)!=NULL && (*it)->beSynchronized() /*&& (*it)->getOwner() == myHostId*/ )
    236240    {
    237241      do {
     242        counter++;
     243
     244        //check for endless loop
     245        if ( counter > 50 )
     246        {
     247          PRINTF(1)("there seems to be an error in readBytes of %s\n", (*it)->getClassName());
     248          assert(false);
     249        }
     250
    238251        reciever = 0;
    239252        dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, &reciever);
    240 
    241253
    242254        if ( dataLength<=0 ){
     
    267279            for ( int i = 0; i<networkSockets.size(); i++)
    268280            {
    269               if ( i!=-reciever && networkSockets[i] != NULL )
     281              if ( i!=abs(reciever) && networkSockets[i] != NULL )
    270282              {
    271                 PRINTF(5)("write %d bytes to socket %d\n", dataLength, i);
     283                PRINTF(0)("write %d bytes to socket %d uniqueid %d reciever %d\n", dataLength, i, (*it)->getUniqueID(), reciever);
    272284                networkSockets[i]->writePacket(downBuffer, dataLength);
    273285              }
  • trunk/src/lib/network/synchronizeable.h

    r6868 r6959  
    3434  NWT_SS_VELZ,
    3535  NWT_SS_PL_SYNC,
    36  
     36  NWT_SS_CO_N,
     37  NWT_SS_CO_CLID,
     38
    3739  NWT_HS_HOST_ID,
    3840  NWT_HS_NGM_ID,
    39  
     41
     42  NWT_PL_B,
    4043  NWT_PL_FLAGS,
    41  
     44  NWT_PL_SCORE,
     45
    4246  NWT_PN_BO_WRITESTATE,
    4347  NWT_PN_PARENTMODE,
     
    4953  NWT_PN_ROTZ,
    5054  NWT_PN_ROTV,
    51  
     55
    5256  NWT_PN_FLAGS,
    5357  NWT_PN_SCOORX,
     
    5862  NWT_PN_SROTZ,
    5963  NWT_PN_SROTV,
    60  
     64
    6165  NWT_BO_NAME,
    62  
     66
    6367  NWT_WE_PN_WRITESTATE,
    6468  NWT_WE_PN_MODELFILENAME,
    6569  NWT_WE_PN_SCALING,
    66  
     70
    6771  NWT_GT_WE_STATE,
    68  
     72
    6973  NWT_SB_WE_STATE,
    7074  NWT_SB_SIZE,
    7175  NWT_SB_TEXTURENAME,
    72  
     76
    7377  NWT_TER_WE_STATE,
    74  
     78
    7579  NWT_PU_WE_STATE,
    76  
     80
    7781  NWT_TPU_WE_STATE,
    78  
     82
    7983  NWT_LPU_WE_STATE,
    80  
     84
    8185  NWT_WPU_WE_STATE,
    82  
     86
    8387  NWT_PPU_WE_STATE,
    8488  NWT_PPU_TYPE,
     
    133137 *  delete[] textureName;
    134138 *  textureName = NULL;
    135  *  SYNCHELP_READ_STRINGM( texturename );      //this will call new char[strlen()+1] 
     139 *  SYNCHELP_READ_STRINGM( texturename );      //this will call new char[strlen()+1]
    136140 *
    137141 * Example 2:
     
    142146 *
    143147 */
    144  
     148
    145149#define SYNCHELP_WRITE_DEBUG(n) {\
    146150  __synchelp_write_n = Converter::intToByteArray( n, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \
Note: See TracChangeset for help on using the changeset viewer.