Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6139 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Dec 16, 2005, 6:45:32 PM (19 years ago)
Author:
patrick
Message:

trunk: merged branche network with trunk using command: svn merge -r5999:HEAD, conflicts resolved in favor of the trunk bla

Location:
trunk/src
Files:
2 added
32 edited
8 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r6113 r6139  
    2525                       lib/gui/gl_gui/libORXglgui.a \
    2626                       lib/shell/libORXshell.a \
    27                        lib/network/libORXnet.a 
     27                       lib/network/libORXnet.a
    2828
    2929orxonox_LDADD = util/libORXutils.a \
     
    4949                  story_entities/campaign.cc \
    5050                  story_entities/world.cc \
     51                  story_entities/network_world.cc \
    5152                  world_entities/world_entity.cc \
    5253                  world_entities/camera.cc \
     
    8586                  world_entities/space_ships/space_ship.cc \
    8687                  world_entities/space_ships/helicopter.cc \
     88                  world_entities/spawning_point.cc \
    8789                  subprojects/benchmark.cc
    8890
     
    9496                 story_entities/campaign.h \
    9597                 story_entities/world.h \
     98                 story_entities/network_world.h \
    9699                 world_entities/world_entity.h \
    97100                 world_entities/camera.h \
     
    130133                 world_entities/space_ships/space_ship.h \
    131134                 world_entities/space_ships/helicopter.h \
     135                 world_entities/spawning_point.h \
    132136                 defs/stdincl.h \
    133137                 defs/stdlibincl.h \
  • trunk/src/defs/class_id.h

    r6113 r6139  
    147147  CL_SPACE_SHIP                 =    0x0000020a,
    148148  CL_HELICOPTER                 =    0x0000020b,
     149  CL_SPAWNING_POINT             =    0x0000020b,
    149150
    150151  CL_TURRET_POWER_UP            =    0x00000211,
     
    230231
    231232  // network stuff (range from 0x00000b00 to 0x00000bff)
    232   CL_DATA_STREAM                =    0x00b01000,
     233  CL_DATA_STREAM                =    0x00b01b00,
    233234  CL_NETWORK_STREAM             =    0x00000b01,
    234235  CL_NETWORK_PROTOCOL           =    0x00000b02,
     
    236237  CL_SERVER_SOCKET              =    0X00000b04,
    237238  CL_CONNECTION_MONITOR         =    0x00000b05,
     239  CL_HANDSHAKE                  =    0x00000b06,
     240  CL_ENTITY_MANAGER             =    0x00000b07,
    238241
    239242
  • trunk/src/lib/graphics/importer/texture.cc

    r5863 r6139  
    1919
    2020#include "debug.h"
     21#include "compiler.h"
     22#include <math.h>
    2123
    2224// INCLUDING SDL_Image
     
    3739  this->texture = 0;
    3840  this->image = NULL;
     41  this->priority = 0.5;
    3942
    4043  if (imageName != NULL)
     
    177180 * @returns a !!new!! Surface, that is loadable by openGL.
    178181 */
    179 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha)
     182SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
    180183{
    181184  PRINTF(4)("Loading texture to OpenGL-Environment.\n");
     
    237240 * @returns The ID of the texture.
    238241 */
    239 GLuint Texture::loadTexToGL (const SDL_Surface* surface)
     242GLuint Texture::loadTexToGL (const SDL_Surface* surface) const
    240243{
    241244//   if (this->texture != 0 && glIsTexture(this->texture))
     
    243246//   this->texture = 0;
    244247
    245   GLuint texture;
     248  int      errorCode = 0;           //!< the error code for the texture loading functions
     249  GLuint   texture;                 //!< the OpenGL texture handle
     250  int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
     251  int      mipmapWidth = 0;         //!< the width of the mipmap
     252  int      mipmapHight = 0;         //!< the height of the mipmap
     253
    246254
    247255  if (surface == NULL)
     
    251259  glGenTextures(1, &texture);
    252260  glBindTexture(GL_TEXTURE_2D, texture);
    253   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    254   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    255   // build the Texture
     261
     262  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, /*GL_LINEAR*/ GL_LINEAR_MIPMAP_LINEAR);
     263  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, /*GL_LINEAR*/ GL_LINEAR);
     264  /* control the mipmap levels */
     265  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, -100);
     266  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0);
     267  glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority);
     268
     269  /* build the Texture  OpenGL V >= 1.1 */
    256270  glTexImage2D(GL_TEXTURE_2D,
    257271               0,
     
    262276               GL_UNSIGNED_BYTE,
    263277               surface->pixels);
    264   // build the MipMaps
    265   gluBuild2DMipmaps(GL_TEXTURE_2D,
    266                     GL_RGBA,
    267                     surface->w,
    268                     surface->h,
    269                     GL_RGBA,
    270                     GL_UNSIGNED_BYTE,
    271                     surface->pixels);
     278
     279  // build the MipMaps automaticaly
     280  errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D,
     281                                GL_RGBA,
     282                                surface->w,
     283                                surface->h,
     284                                GL_RGBA,
     285                                GL_UNSIGNED_BYTE,
     286                                surface->pixels
     287                               );
     288  if(unlikely(errorCode != 0))
     289    PRINTF(1)("Error while loading texture, gluBuild2DMipmaps returned %i\n", errorCode);
     290
     291#define max(a,b) (a>b)?a:b
     292  mipmapLevel = (int)(log2f(max(surface->w, surface->h)));
     293#undef max
     294  PRINTF(5)("Built the texture mipmpaps, got: %i levels of detail\n", mipmapLevel);
     295
     296  /* now actualy load the mipmaps into the graphics memory */
     297  glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 1, GL_TEXTURE_WIDTH, &mipmapWidth);
     298  glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 1, GL_TEXTURE_WIDTH, &mipmapHight);
     299  PRINTF(5)(" Mipmap at level %i has a %ix%i resolution\n", 1, mipmapWidth, mipmapHight);
     300  glTexImage2D(GL_PROXY_TEXTURE_2D,
     301               1,
     302               GL_RGBA,
     303               mipmapWidth, mipmapHight,
     304               0,
     305               GL_RGBA,
     306               GL_UNSIGNED_BYTE,
     307               NULL
     308               );
     309
    272310  glBindTexture(GL_TEXTURE_2D, 0);
    273311  return texture;
    274312}
     313
  • trunk/src/lib/graphics/importer/texture.h

    r5859 r6139  
    3939
    4040      // Utility functionality:
    41       static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
    42       static GLuint loadTexToGL (const SDL_Surface* surface);
     41      SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha) const;
     42      GLuint loadTexToGL (const SDL_Surface* surface) const;
    4343
    4444    protected:
     
    5353      bool             bAlpha;             //!< if the texture has an alpha channel.
    5454      SDL_Surface*     image;              //!< The SDL_Surfce that stores the Texture on it.
     55      GLclampf         priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
    5556
    5657      static bool      texturesEnabled;    //!< If the Textures are enabled.
  • trunk/src/lib/network/Makefile.am

    r5996 r6139  
    1111                      data_stream.cc \
    1212                      network_protocol.cc \
    13                       server_socket.cc
     13                      server_socket.cc \
     14                      handshake.cc \
     15                      network_game_manager.cc \
     16                      converter.cc
     17
    1418
    1519
     
    2226                 data_stream.h \
    2327                 network_protocol.h \
    24                  server_socket.h
     28                 server_socket.h \
     29                 handshake.h \
     30                 network_game_manager.h \
     31                 converter.h
    2532
     33
  • trunk/src/lib/network/network_manager.cc

    r5997 r6139  
    5050  this->tmpStream = NULL;
    5151  this->hostID = -1;
     52  this->bGameServer = false;
    5253
    5354  PRINTF(0)("NetworkManager created\n");
     
    9596  }
    9697
    97   this->tmpStream = new NetworkStream(ipAddress, NET_CLIENT);
     98  this->tmpStream = new NetworkStream(ipAddress);
    9899  return 1;
    99100}
     
    106107int NetworkManager::createServer(unsigned int port)
    107108{
    108   this->tmpStream = new NetworkStream(port, NET_SERVER);
     109  this->tmpStream = new NetworkStream(port);
     110  this->bGameServer = true;
    109111  SDL_Delay(20);
    110112  return 1;
     
    120122{
    121123  /* creating a new network stream, it will register itself automaticaly to the class list */
    122   this->tmpStream = new NetworkStream(address, sync, NET_CLIENT);
     124  this->tmpStream = new NetworkStream(address);
     125  this->tmpStream->connectSynchronizeable(sync);
    123126}
    124127
     
    132135  PRINTF(0)("Create a new server socket\n");
    133136  /* creating a new network stream, it will register itself automaticaly to the class list */
    134   this->tmpStream = new NetworkStream(port, sync, NET_SERVER);
     137  this->tmpStream = new NetworkStream(port);
     138  this->tmpStream->connectSynchronizeable(sync);
     139  this->bGameServer = true;
    135140}
    136141
  • trunk/src/lib/network/network_manager.h

    r5997 r6139  
    4545    void setHostID(int id);
    4646    /** Returns the hostID @return The hostID of the object */
    47     inline int getHostID() { return this->hostID; };
     47    inline int getHostID() { return this->hostID; }
     48    inline bool isGameServer() { return this->bGameServer; }
    4849
    49   private:
     50
    5051    void connectSynchronizeable(Synchronizeable& sync);
    5152    void synchronize();
    5253
     54  private:
    5355    NetworkManager();
    5456
    5557
    5658  private:
    57     const std::list<BaseObject*>*    netStreamList;            // list with refs to all network streams
    58     const std::list<BaseObject*>*    syncList;                 // list of synchronizeables
    59     static NetworkManager* singletonRef;           //!< Pointer to the only instance of this Class
    60     NetworkStream*         tmpStream;              //!< FIXME: this is only for testing purposes
    61     int hostID;                                    //!< The Host-ID of the Manager
     59    const std::list<BaseObject*>*    netStreamList;           // list with refs to all network streams
     60    const std::list<BaseObject*>*    syncList;                // list of synchronizeables
     61    static NetworkManager*           singletonRef;            //!< Pointer to the only instance of this Class
     62    NetworkStream*                   tmpStream;               //!< FIXME: this is only for testing purposes
     63    int                              hostID;                  //!< The Host-ID of the Manager
     64    bool                             bGameServer;             //!< true if it is a server
    6265
    6366};
  • trunk/src/lib/network/network_protocol.cc

    r5822 r6139  
    5757    * @arg bufferLength: the length of the internal buffer
    5858    * @arg source: reference to the source Synchronizeable object
    59     * @arg remoteID: id number of the remote Synchronizeable object
    6059    * @return: the new data length with header (the header data is included into byte* data)
    6160    *          -1 if there isn't enough space in the buffer for the header
    6261*/
    63 int NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source, unsigned int remoteID)
     62int NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source)
    6463{
    65   printf("NetworkProtocol: create header length = %i, bufferLength = %i\n", length, bufferLength);
     64  PRINTF(5)("create header length = %i, bufferLength = %i\n", length, bufferLength);
    6665  //If there isn't enough space for the header return -1
    6766  if (length + this->headerLength > bufferLength)
    6867    return -1;
    6968
    70 //   for(int i = 0; i < length; i++)
    71 //     printf("send byte[%i]=%u\n", i, data[i]);
    7269
    73 
    74   //Create space for the header
     70  // FIXME: without move Create space for the header
    7571  for( int i = length - 1; i >= 0; i--)
    7672    data[i + this->headerLength] = data[i];
    7773
    7874  //Now create the header
    79   /* protocol identifier */
    80   data[0] = 255;
    81   /* version number */
    82   data[1] = 0;
    8375  /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
    84   data[2] = (byte)source.getClassID();
    85   /* receiver ID */
    86   data[3] = remoteID;
     76  data[0] = (byte)(source.getUniqueID());
    8777  /* data length*/
    88   data[4] = length;
     78  data[1] = length;
    8979
    9080
     
    10090Header NetworkProtocol::extractHeader(byte* data, int length)
    10191{
    102   PRINTF(0)("extract Header\n");
     92  PRINTF(5)("extract Header\n");
    10393  //Test if received data can contain a header
    10494  if (length < headerLength)
    10595  {
    106     PRINTF(0)("Received data is to short; it can't contain a header!");
     96    PRINTF(1)("Received data is to short; it can't contain a header!\n");
    10797    Header h;
    108     h.protocol = 0;
     98    h.length = 0;
    10999    return h;
    110100  }
     
    114104  //&h = data;
    115105
    116   h.protocol = data[0];
    117   /* version number */
    118   h.version = data[1];
    119   /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
    120   h.senderID = data[2];
    121   /* receiver ID */
    122   h.receiverID = data[3];
     106  /* unique ID */
     107  h.synchronizeableID = data[0];
    123108  /* data length*/
    124   h.length = data[4];
     109  h.length = data[1];
    125110
    126 
    127 //   for(int i = 0; i < length; i++)
    128 //     printf("recS byte[%i]=%u\n", i, data[i]);
    129 
    130   //Remove header
    131 //   for (int i = headerLength; i < length; i++)
    132 //     data[i - headerLength] = data[i];
    133111
    134112  return h;
  • trunk/src/lib/network/network_protocol.h

    r5822 r6139  
    66#define _NETWORK_PROTOCOL_H
    77
     8/* include base_object.h since all classes are derived from this one */
    89#include "base_object.h"
    910
     
    1112#include "netdefs.h"
    1213
    13 #define HEADER_LENGTH 1
    14 
    1514typedef struct Header
    1615{
    17   byte protocol;
    18   byte version;
    19   byte senderID;
    20   byte receiverID;
     16  byte synchronizeableID;
    2117  byte length;
    2218};
     
    3329    ~NetworkProtocol();
    3430
    35     int createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source, unsigned int remoteID);
     31    int createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source);
    3632    Header extractHeader(byte* data, int length);
    3733
  • trunk/src/lib/network/network_socket.cc

    r5996 r6139  
    2828#include "debug.h"
    2929
    30 
    3130/**
    3231 * Default constructor
     
    5251  this->tcpSocket = sock;
    5352
    54   SDL_CreateThread(thread_read, (void*)this);
    55   SDL_CreateThread(thread_write, (void*)this);
     53  readThread = SDL_CreateThread(thread_read, (void*)this);
     54  writeThread = SDL_CreateThread(thread_write, (void*)this);
    5655}
    5756
     
    6564  outgoingBufferLength = 0;
    6665
     66  readThread = NULL;
     67  writeThread = NULL;
     68
     69
     70  thread_write_running = false;
     71  thread_read_running = false;
     72
    6773  incomingBufferMutex = SDL_CreateMutex();
    6874  outgoingBufferMutex = SDL_CreateMutex();
     75
     76
    6977  socketMutex = SDL_CreateMutex();
    7078  terminateThread = false;
     
    8997 * Default destructor
    9098 */
    91 NetworkSocket::~ NetworkSocket( )
    92 {
     99NetworkSocket::~NetworkSocket( )
     100{
     101  this->terminateThread = true;
    93102  /* Quit SDL_net */
    94103  // NOTE: what if other instances of NetworkSocket running?
     
    99108  SDL_DestroyMutex(outgoingBufferMutex);
    100109  SDL_DestroyMutex(socketMutex);
     110  SDL_DestroyMutex(threadTerminationMutex);
    101111}
    102112
     
    122132  }
    123133
    124   SDL_CreateThread(thread_read, (void*)this);
    125   SDL_CreateThread(thread_write, (void*)this);
     134  readThread = SDL_CreateThread(thread_read, (void*)this);
     135  writeThread = SDL_CreateThread(thread_write, (void*)this);
    126136}
    127137
     
    152162int NetworkSocket::writeBytes(byte * data, int length)
    153163{
    154   PRINTF(0)("NetworkSocket::writeBytes()\n");
     164  PRINTF(5)("NetworkSocket::writeBytes()\n");
    155165#ifdef _USE_OUTGOING_BUFFER
    156166
     
    200210int NetworkSocket::readBytes(byte * data, int length)
    201211{
    202   PRINTF(0)("NetworkSocket::readBytes()\n");
     212  PRINTF(5)("NetworkSocket::readBytes()\n");
    203213  if (data==NULL)
    204214    return 0;
     
    256266  NetworkSocket * self = (NetworkSocket*)data;
    257267
     268  self->thread_read_running = true;
     269
    258270  while (!self->terminateThread)
    259271  {
     
    263275
    264276    //if buffer is full
    265     if (nbytestoread<=0)
     277    if (nbytestoread<=0 || !self->tcpSocket)
    266278    {
    267279      SDL_Delay(_MSECONDS_SLEEP_FULL_BUFFER);
     
    275287    if (nbytesread<=0)
    276288    {
    277       printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());
     289      if (nbytesread<0)
     290        printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());
    278291
    279292      SDL_mutexP(self->socketMutex);
     
    284297      SDL_mutexV(self->socketMutex);
    285298      SDL_mutexV(self->incomingBufferMutex);
    286       return -1;
     299      continue;
    287300    }
    288301
     
    295308  }
    296309
     310  SDL_mutexP(self->threadTerminationMutex);
     311  self->thread_read_running = false;
     312
     313  if ( !self->thread_write_running )
     314  {
     315    //delete self;
     316    SDL_mutexV(self->threadTerminationMutex);
     317  }
     318  else
     319  {
     320    SDL_mutexV(self->threadTerminationMutex);
     321  }
     322
     323
     324  PRINTF(0)("QUIT READ THREAD\n");
    297325  return 0;
    298326}
     
    305333  NetworkSocket * self = (NetworkSocket*)data;
    306334
     335  self->thread_write_running = true;
     336
    307337  while (!self->terminateThread)
    308338  {
     
    314344
    315345    //if buffer is full
    316     if (nbytestowrite<=0)
     346    if (nbytestowrite<=0 || !self->tcpSocket)
    317347    {
    318348      SDL_Delay(_MSECONDS_SLEEP_EMPTY_BUFFER);
     
    342372
    343373      SDL_mutexV(self->socketMutex);
    344       return -1;
     374      continue;
    345375    }
    346376
    347377  }
    348378
    349   printf("QUIT WRITE THREAD\n");
     379  SDL_mutexP(self->threadTerminationMutex);
     380  self->thread_write_running = false;
     381
     382  if ( !self->thread_read_running )
     383  {
     384    //delete self;
     385    SDL_mutexV(self->threadTerminationMutex);
     386  }
     387  else
     388  {
     389    SDL_mutexV(self->threadTerminationMutex);
     390  }
     391
     392
     393  PRINTF(0)("QUIT WRITE THREAD\n");
    350394  return 0;
    351395}
     
    353397bool NetworkSocket::writePacket( byte * data, int length )
    354398{
    355   PRINTF(0)("NetworkSocket::writePacket()\n");
     399  PRINTF(5)("NetworkSocket::writePacket()\n");
    356400  if (length>255)
    357401  {
     
    368412int NetworkSocket::readPacket( byte * data, int maxLength )
    369413{
    370   PRINTF(0)("NetworkSocket::readPacket()\n");
     414  PRINTF(5)("NetworkSocket::readPacket()\n");
    371415  if (incomingBufferLength<1)
    372416  {
  • trunk/src/lib/network/network_socket.h

    r5996 r6139  
    6363  bool terminateThread;
    6464
     65  SDL_mutex* threadTerminationMutex;
    6566  static int thread_read(void * data);
     67  bool thread_read_running;
     68  bool thread_write_running;
     69
     70  SDL_Thread*            readThread;
     71  SDL_Thread*            writeThread;
     72
    6673#ifdef _USE_OUTGOING_BUFFER
    6774  static int thread_write(void * data);
     
    7481  void init();
    7582
     83  //dont make this public use destroy() instead
     84  ~NetworkSocket();
     85
    7686public:
    7787
     
    7989  NetworkSocket(IPaddress ip);
    8090  NetworkSocket(TCPsocket sock);
    81   ~NetworkSocket();
     91  void destroy() { terminateThread = true; };
     92
    8293
    8394  void connectToServer(IPaddress ip);
     
    8798  int readPacket(byte * data, int maxLength);
    8899
     100  inline bool isOk() { return tcpSocket!=NULL; }
     101
    89102};
    90103
  • trunk/src/lib/network/network_stream.cc

    r5996 r6139  
    2626#include "connection_monitor.h"
    2727#include "synchronizeable.h"
     28#include "network_manager.h"
    2829#include "list.h"
    2930#include "debug.h"
     31#include "class_list.h"
    3032
    3133/* include your own header */
     
    4547  /* initialize the references */
    4648  this->type = NET_CLIENT;
    47   this->networkSocket = new NetworkSocket();
    4849  this->networkProtocol = new NetworkProtocol();
    49   this->synchronizeables = NULL;
    5050  this->connectionMonitor = new ConnectionMonitor();
    5151}
    5252
    53 NetworkStream::NetworkStream(IPaddress& address, NodeType type)
    54 {
    55   this->type = type;
     53NetworkStream::NetworkStream(IPaddress& address)
     54{
     55  this->type = NET_CLIENT;
    5656  this->init();
    57   this->networkSocket = new NetworkSocket(address);
     57  this->networkSockets.push_back(new NetworkSocket(address));
    5858  this->networkProtocol = new NetworkProtocol();
    59   this->synchronizeables = NULL;
    6059  this->connectionMonitor = new ConnectionMonitor();
    61 }
    62 
    63 
    64 NetworkStream::NetworkStream(unsigned int port, NodeType type)
    65 {
    66   this->type = type;
     60
     61  Handshake* hs = new Handshake(false);
     62  hs->setUniqueID( 0 );
     63  this->handshakes.push_back(hs);
     64  this->connectSynchronizeable(*hs);
     65  PRINTF(0)("NetworkStream: %s\n", hs->getName());
     66}
     67
     68
     69NetworkStream::NetworkStream(unsigned int port)
     70{
     71  this->type = NET_SERVER;
    6772  this->init();
    68   this->networkSocket = new NetworkSocket();
    69 //  this->networkSocket->listen(port);
     73  this->serverSocket = new ServerSocket(port);
    7074  this->networkProtocol = new NetworkProtocol();
    71   this->synchronizeables = NULL;
    7275  this->connectionMonitor = new ConnectionMonitor();
    73 }
    74 
    75 
    76 NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type)
    77     : DataStream()
    78 {
    79   this->type = type;
    80   this->init();
    81   this->networkSocket = new NetworkSocket(address);
    82   this->networkProtocol = new NetworkProtocol();
    83   this->synchronizeables = &sync;
    84   this->connectionMonitor = new ConnectionMonitor();
     76  this->networkSockets.push_back( NULL );
     77  this->handshakes.push_back( NULL );
    8578  this->bActive = true;
    86 }
    87 
    88 
    89 NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type)
    90     : DataStream()
    91 {
    92   this->type = type;
    93   this->init();
    94   this->networkSocket = new NetworkSocket();
    95 //  this->networkSocket->listen(port);
    96   this->networkProtocol = new NetworkProtocol();
    97   this->synchronizeables = &sync;
    98   this->connectionMonitor = new ConnectionMonitor();
    99   this->bActive = true;
     79
     80  this->setMaxConnections( 10 );
    10081}
    10182
     
    10586  /* set the class id for the base object */
    10687  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    107   this->state = NET_REC_HEADER;
    10888  this->bActive = false;
     89  this->serverSocket = NULL;
     90  myHostId = 0;
    10991}
    11092
     
    11294NetworkStream::~NetworkStream()
    11395{
    114 
    115   networkSocket->disconnectServer();
    116 
    117   if( this->networkSocket)
    118     delete networkSocket;
     96  if ( this->serverSocket )
     97  {
     98    serverSocket->close();
     99    delete serverSocket;
     100  }
     101
     102  for (NetworkSocketVector::iterator i = networkSockets.begin(); i!=networkSockets.end(); i++)
     103  {
     104    if ( *i )
     105    {
     106      (*i)->disconnectServer();
     107      (*i)->destroy();
     108    }
     109  }
     110
     111  for (HandshakeVector::iterator i = handshakes.begin(); i!=handshakes.end(); i++)
     112  {
     113    if ( *i )
     114    {
     115      delete (*i);
     116    }
     117  }
    119118
    120119  delete connectionMonitor;
     
    125124void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
    126125{
    127   this->synchronizeables = &sync;
    128   if( this->networkSocket != NULL)
     126  this->synchronizeables.push_back(&sync);
     127  sync.setNetworkStream( this );
     128
     129  if( this->networkSockets.size()>0 )
    129130    this->bActive = true;
    130131}
    131132
     133void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync)
     134{
     135  this->synchronizeables.remove(&sync);
     136
     137  if( this->networkSockets.size()<=0 )
     138    this->bActive = false;
     139}
     140
    132141
    133142void NetworkStream::processData()
    134143{
    135   int dataLength = 0;
     144  if ( this->type == NET_SERVER )
     145    this->updateConnectionList();
     146  else
     147  {
     148    if ( networkSockets[0] && !networkSockets[0]->isOk() )
     149    {
     150      PRINTF(1)("lost connection to server\n");
     151
     152      //delete networkSockets[i];
     153      networkSockets[0]->disconnectServer();
     154      networkSockets[0]->destroy();
     155      networkSockets[0] = NULL;
     156      //TODO: delete handshake from synchronizeable list so i can delete it
     157      if ( handshakes[0] )
     158        delete handshakes[0];
     159      handshakes[0] = NULL;
     160    }
     161  }
     162
     163  for (int i = 0; i<handshakes.size(); i++)
     164  {
     165    if ( handshakes[i] )
     166    {
     167      if ( handshakes[i]->completed() )
     168      {
     169        if ( handshakes[i]->ok() )
     170        {
     171          if ( type != NET_SERVER )
     172          {
     173            NetworkManager::getInstance()->setHostID( handshakes[i]->getHostId() );
     174            myHostId = NetworkManager::getInstance()->getHostID();
     175          }
     176          PRINT(0)("handshake finished\n");
     177          delete handshakes[i];
     178          handshakes[i] = NULL;
     179          //TODO: replace handshake by entitymanager
     180        }
     181        else
     182        {
     183          PRINT(1)("handshake failed!\n");
     184          networkSockets[i]->disconnectServer();
     185          delete handshakes[i];
     186          handshakes[i] = NULL;
     187          //TODO: handle error
     188        }
     189      }
     190    }
     191  }
     192
    136193
    137194  /* DOWNSTREAM */
    138   printf("\nSynchronizeable: %s\n", this->synchronizeables->getName());
    139   PRINT(0)("============= DOWNSTREAM:===============\n");
    140   /* first of all read the synchronizeable's data: */
    141   if( this->isServer())
    142     dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
    143 
    144   if( dataLength > 0)
    145   {
    146     /* send the received data to connectionMonitor */
    147     this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
    148 
    149     dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
    150                  *(this->synchronizeables), 12/* some random number (no real id)*/);
    151 
    152     /* pass the data to the network socket */
    153  //   dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
    154     /* check if there was an error */
    155     if( dataLength == -1)
    156     {
    157       PRINTF(0)("Error in writing data to the NetworkSocket\n");
    158     }
    159   }
    160 
     195
     196  int dataLength;
     197  int reciever;
     198  Header header;
     199  for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
     200  {
     201    //TODO: remove items from synchronizeables if they dont exist
     202    if ( (*it)!=NULL && (*it)->getOwner() == myHostId )
     203    {
     204      do {
     205        reciever = 0;
     206        dataLength = (*it)->readBytes(downBuffer, DATA_STREAM_BUFFER_SIZE, &reciever);
     207
     208
     209        if ( dataLength<=0 ){
     210          reciever = 0;
     211          continue;
     212        }
     213
     214        dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it)));
     215
     216        //FIXME: this is a hack, find a better way
     217        Header* header = (Header*)downBuffer;
     218        if ( header->synchronizeableID<100 )
     219          header->synchronizeableID = 0;
     220
     221        if ( dataLength<=0 )
     222          continue;
     223
     224        if ( reciever!=0 )
     225        {
     226          if ( networkSockets[reciever] != NULL )
     227          {
     228            PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
     229            networkSockets[reciever]->writePacket(downBuffer, dataLength);
     230          }
     231          else
     232          {
     233            PRINTF(1)("networkSockets[reciever] == NULL\n");
     234          }
     235        }
     236        else
     237        {
     238          for ( int i = 0; i<networkSockets.size(); i++)
     239          {
     240            if ( networkSockets[i] != NULL )
     241            {
     242              PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);
     243              networkSockets[i]->writePacket(downBuffer, dataLength);
     244            }
     245          }
     246        }
     247
     248      } while( reciever!=0 );
     249    }
     250    else
     251    {
     252      PRINTF(0)("synchronizeables == NULL");
     253    }
     254  }
    161255
    162256  /* UPSTREAM */
    163   dataLength = 0;
    164   PRINT(0)("============== UPSTREAM:================\n");
    165   /* first of all read the next Orxonox Network Header */
    166 
    167   if( this->state == NET_REC_HEADER)
    168   {
    169 //    dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
    170     if( dataLength == sizeof(Header))
    171     {
    172       this->packetHeader = this->networkProtocol->extractHeader((byte*) upBuffer , dataLength);
    173       printf("NetworkStream::processData() - Got Header: Protocol %u, Version: %u, Sender: %u, Receiver: %u, Length: %u\n",
    174              this->packetHeader.protocol, this->packetHeader.version, this->packetHeader.senderID,
    175              this->packetHeader.receiverID, this->packetHeader.length);
    176       /* FIXME: what if it was no this->packetHeader? catch? eg: the protocol identifier, receiver id*/
    177 
    178       this->state = NET_REC_DATA;
    179     }
    180   }
    181   if( this->state == NET_REC_DATA)
    182   {
    183     /* now read the data */
    184 //    dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
    185     /* check if the data is available and process it if so */
    186     if( dataLength == this->packetHeader.length)
    187     {
    188       printf("NetworkStream::processData() - Got Data: %i bytes\n", dataLength);
    189       /* send the received data to connectionMonitor */
    190       this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length);
    191       /* now pass the data to the sync object */
    192       if( !this->isServer())
    193         this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
    194 
    195       this->state = NET_REC_HEADER;
    196     }
    197   }
    198 
    199 
    200 }
     257
     258  for ( int i = 0; i<networkSockets.size(); i++)
     259  {
     260    if ( networkSockets[i] )
     261    {
     262      do {
     263        dataLength = networkSockets[i]->readPacket(upBuffer, DATA_STREAM_BUFFER_SIZE);
     264
     265        if ( dataLength<=0 )
     266          continue;
     267
     268        PRINTF(5)("read %d bytes from socket\n", dataLength);
     269        header = networkProtocol->extractHeader(upBuffer, dataLength);
     270        dataLength -= sizeof(header);
     271
     272        if ( dataLength != header.length )
     273        {
     274          PRINTF(1)("packetsize in header and real packetsize do not match! %d:%d\n", dataLength, header.length);
     275          continue;
     276        }
     277
     278        if ( header.synchronizeableID == 0 )
     279        {
     280          header.synchronizeableID = i;
     281        }
     282
     283        for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++)
     284        {
     285          if ( *it && (*it)->getUniqueID()==header.synchronizeableID )
     286            (*it)->writeBytes(upBuffer+sizeof(header), dataLength);
     287        }
     288
     289      } while ( dataLength>0 );
     290    }
     291  }
     292}
     293
     294void NetworkStream::updateConnectionList( )
     295{
     296  //check for new connections
     297
     298  NetworkSocket* tempNetworkSocket = serverSocket->getNewSocket();
     299
     300  if ( tempNetworkSocket )
     301  {
     302    int clientId;
     303    if ( freeSocketSlots.size() >0 )
     304    {
     305      clientId = freeSocketSlots.back();
     306      freeSocketSlots.pop_back();
     307      networkSockets[clientId] = tempNetworkSocket;
     308      handshakes[clientId] = new Handshake(true, clientId);
     309      handshakes[clientId]->setUniqueID(clientId);
     310    } else
     311    {
     312      clientId = networkSockets.size();
     313      networkSockets.push_back(tempNetworkSocket);
     314      Handshake* tHs = new Handshake(true, clientId);
     315      tHs->setUniqueID(clientId);
     316      handshakes.push_back(tHs);
     317    }
     318
     319    if ( clientId > this->maxConnections )
     320    {
     321      handshakes[clientId]->doReject();
     322      PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId);
     323    }
     324    else
     325
     326    PRINTF(0)("New Client: %d\n", clientId);
     327
     328    this->connectSynchronizeable(*handshakes[clientId]);
     329  }
     330
     331
     332  //check if connections are ok else remove them
     333  for ( int i = 1; i<networkSockets.size(); i++)
     334  {
     335    if ( networkSockets[i] && !networkSockets[i]->isOk() )
     336    {
     337      //TODO: tell EntityManager that this player left the game
     338      PRINTF(0)("Client is gone: %d\n", i);
     339
     340      //delete networkSockets[i];
     341      networkSockets[i]->disconnectServer();
     342      networkSockets[i]->destroy();
     343      networkSockets[i] = NULL;
     344      //TODO: delete handshake from synchronizeable list so i can delete it
     345      if ( handshakes[i] )
     346        delete handshakes[i];
     347      handshakes[i] = NULL;
     348
     349      if ( i == networkSockets.size()-1 )
     350      {
     351        networkSockets.pop_back();
     352        handshakes.pop_back();
     353      }
     354      else
     355      {
     356        freeSocketSlots.push_back(i);
     357      }
     358    }
     359  }
     360
     361
     362}
     363
     364void NetworkStream::setMaxConnections( int n )
     365{
     366  if ( !this->isServer() )
     367  {
     368    PRINTF(1)("Cannot set maxConnections because I am no server.\n");
     369  }
     370  if ( this->networkSockets.size() > 1 )
     371  {
     372    PRINTF(1)("Cannot set maxConnections because there are already %d connections.\n", this->networkSockets.size());
     373    return;
     374  }
     375  this->maxConnections = n;
     376}
     377
     378
  • trunk/src/lib/network/network_stream.h

    r5996 r6139  
    77#define _NETWORK_STREAM
    88
     9#include <vector>
     10#include <list>
     11
    912#include "data_stream.h"
    1013#include "network_protocol.h"
     14#include "server_socket.h"
     15#include "handshake.h"
    1116
    1217class Synchronizeable;
    1318class NetworkSocket;
     19class ServerSocket;
    1420class ConnectionMonitor;
    1521class NetworkProtocol;
    1622
    17 
    18 //<! The state of the NetworkStream
    19 typedef enum NetStat {
    20   NET_REC_HEADER = 0,                          //!< Waiting for header
    21   NET_REC_DATA,                                //!< Waiting for data
    22 
    23   NUM_STATES                                   //!< Number of states
    24 };
     23typedef std::list<Synchronizeable*>  SynchronizeableList;
     24typedef std::vector<NetworkSocket*>  NetworkSocketVector;
     25typedef std::vector<Handshake*>      HandshakeVector;
    2526
    2627
     
    3031  public:
    3132    NetworkStream();
    32     NetworkStream(IPaddress& address, NodeType type);
    33     NetworkStream(unsigned int port, NodeType type);
     33    NetworkStream(IPaddress& address);
     34    NetworkStream(unsigned int port);
    3435
    35     NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
    36     NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);
    3736    ~NetworkStream();
    3837    void init();
    3938
    4039    void connectSynchronizeable(Synchronizeable& sync);
     40    void disconnectSynchronizeable(Synchronizeable& sync);
    4141
    4242    inline bool isServer() const { return (this->type == NET_SERVER)? true:false; }
    4343    inline bool isActive() const { return this->bActive; }
     44
     45    inline int getMaxConnections(){ return maxConnections; }
     46    void setMaxConnections( int n );
    4447
    4548    virtual void processData();
     
    4851    NetworkProtocol*       networkProtocol;
    4952    ConnectionMonitor*     connectionMonitor;
    50     Synchronizeable*       synchronizeables;
    51     NetworkSocket*         networkSocket;
     53    SynchronizeableList    synchronizeables;
     54    NetworkSocketVector    networkSockets;
     55    HandshakeVector        handshakes;
     56    ServerSocket*          serverSocket;
    5257    int                    type;
    53     int                    state;
    5458    Header                 packetHeader;
    5559    bool                   bActive;
     60    std::list<int>         freeSocketSlots;
     61
     62    int                    myHostId;
     63    int                    maxConnections;
     64
     65    void updateConnectionList();
    5666};
    5767#endif /* _NETWORK_STREAM */
  • trunk/src/lib/network/server_socket.cc

    r5996 r6139  
    110110
    111111
    112 NetworkSocket ServerSocket::getNewSocket( )
     112NetworkSocket* ServerSocket::getNewSocket( )
    113113{
     114  if ( !listenSocket )
     115  {
     116    PRINTF(1)("listenSocket == NULL! Maybe you forgot to call listen()\n");
     117    close();
     118    return NULL;
     119  }
     120
    114121  TCPsocket sock = SDLNet_TCP_Accept(listenSocket);
    115122
     
    120127  else
    121128  {
    122     return NetworkSocket(sock);
     129    return new NetworkSocket(sock);
    123130  }
    124131}
    125132
     133void ServerSocket::close( )
     134{
     135  if ( listenSocket )
     136  {
     137    SDLNet_TCP_Close( listenSocket );
     138    listenSocket = NULL;
     139  }
     140
     141  _isListening = false;
     142}
     143
  • trunk/src/lib/network/server_socket.h

    r5996 r6139  
    3939    ~ServerSocket();
    4040    bool listen( unsigned int port );
    41     NetworkSocket getNewSocket( void );
     41    NetworkSocket* getNewSocket( void );
     42    void close();
     43    inline bool isOk(){ return listenSocket!=NULL; }
    4244};
    4345
  • trunk/src/lib/network/synchronizeable.cc

    r5997 r6139  
    1515*/
    1616
     17#define DEBUG_MODULE_NETWORK
     18
    1719#include "synchronizeable.h"
    1820#include "netdefs.h"
     21#include "network_manager.h"
     22#include "network_stream.h"
    1923
    2024
     
    2529{
    2630
    27   //owner = ?;
    28   //hostID = ?;
     31  owner = 0;
     32  hostID = NetworkManager::getInstance()->getHostID();
     33  uniqueID = -1;
    2934  //state = ?;
    3035
     
    4449 */
    4550Synchronizeable::~Synchronizeable()
    46 {}
     51{
     52  if ( this->networkStream )
     53    this->networkStream->disconnectSynchronizeable(*this);
     54}
    4755
    4856/**
     
    5058 */
    5159void Synchronizeable::writeBytes(const byte* data, int length)
    52 {}
     60{
     61  PRINTF(1)("Synchronizeable::writeBytes was called\n");
     62}
    5363
    5464/**
    5565 *  read data from NetworkStream
    5666 */
    57 int Synchronizeable::readBytes(byte* data)
    58 {}
     67int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever)
     68{
     69  PRINTF(1)("Synchronizeable::readBytes was called\n");
     70}
    5971
    6072
     
    6577void Synchronizeable::readDebug() const
    6678{}
    67 
    68 
    69 
    7079
    7180
     
    111120  return this->state & STATE_OUTOFSYNC == STATE_OUTOFSYNC;
    112121}
     122
     123
     124
  • trunk/src/lib/network/synchronizeable.h

    r5997 r6139  
    1919#define STATE_OUTOFSYNC 2
    2020
     21class NetworkStream;
     22
    2123
    2224class Synchronizeable : virtual public BaseObject
     
    2931
    3032    virtual void      writeBytes(const byte* data, int length);
    31     virtual int       readBytes(byte* data);
     33    virtual int       readBytes(byte* data, int maxLength, int * reciever);
    3234    virtual void      writeDebug() const;
    3335    virtual void      readDebug() const;
    34    
    35    
    36    
    37    
    38    
    39     void setIsServer(bool isServer);
    40     void setIsOutOfSync(bool outOfSync);
     36
     37    void setIsServer( bool isServer );
     38    void setIsOutOfSync( bool outOfSync );
    4139    bool isServer();
    4240    bool isOutOfSync();
     41    void setUniqueID( int id ){ uniqueID = id; }
     42    int  getUniqueID() const { return uniqueID; };
     43    void requestSync( int hostID ){ this->synchronizeRequests.push_back( hostID ); }
     44
     45    inline int getOwner(){ return owner; }
     46    inline void setOwner(int owner){ this->owner = owner; }
     47
     48    inline void setNetworkStream(NetworkStream* stream) { this->networkStream = stream; }
    4349
    4450  private:
    4551
    4652    int               uniqueID;
    47    
    48    
    49    
     53
     54
     55
    5056    //static std::vector<Synchronizeable*> classList;
    5157    int owner;
     
    5460    std::list<int> synchronizeRequests;
    5561
     62    NetworkStream* networkStream;
     63
    5664  };
    5765#endif /* _SYNCHRONIZEABLE_H */
  • trunk/src/lib/sound/sound_source.cc

    r5930 r6139  
    6969    SoundEngine::getInstance()->popALSource(this->sourceID);
    7070
    71   printf("%d\n",sourceID);
     71  //printf("%d\n",sourceID);
    7272  alSourceStop(this->sourceID);
    7373  alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
  • trunk/src/orxonox.cc

    r6079 r6139  
    280280  if( this->serverName != NULL) // we are a client
    281281    NetworkManager::getInstance()->establishConnection(this->serverName, port);
    282   else if( this->port > 0)      // we are a server
     282  else if( this->port > 0) {    // we are a server
    283283    NetworkManager::getInstance()->createServer(port);
     284  }
    284285
    285286  return 0;
     
    352353  this->gameLoader = GameLoader::getInstance();
    353354
    354   if( this->port != -1 || this->serverName != NULL)
    355     this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* actualy loadNetworkCampaign*/
     355  if( this->port != -1)
     356    this->gameLoader->loadNetworkCampaign("worlds/DefaultNetworkCampaign.oxc");
    356357  else
    357     this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
     358    this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");                       /* start orxonox in single player mode */
    358359
    359360  //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
  • trunk/src/story_entities/campaign.cc

    r5982 r6139  
    150150      delete (*it);
    151151    }
     152    PRINTF(1)("There is no StoryEnity left to play, quitting\n");
    152153}
    153154
  • trunk/src/subprojects/network/Makefile.am

    r5996 r6139  
    1111network_LDADD = $(MAINSRCDIR)/lib/network/libORXnet.a \
    1212                \
    13                 $(MAINSRCDIR)/lib/tinyxml/libtinyxml.a
     13                $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a
    1414
    1515network_SOURCES=  network_unit_test.cc \
  • trunk/src/subprojects/network/network_unit_test.cc

    r5996 r6139  
    1111#include "network_stream.h"
    1212#include "synchronizeable.h"
     13#include "converter.h"
    1314
    1415#include "simple_sync.h"
     
    4041  server.listen(9999);
    4142
    42   NetworkSocket client1(ip);
    43 
    44   NetworkSocket server1 = server.getNewSocket();
    45 
    46   NetworkSocket client2(ip);
    47 
    48   NetworkSocket server2 = server.getNewSocket();
     43  NetworkSocket* client1 = new NetworkSocket(ip);
     44
     45  NetworkSocket* server1 = server.getNewSocket();
     46
     47  NetworkSocket* client2 = new NetworkSocket(ip);
     48
     49  NetworkSocket* server2 = server.getNewSocket();
    4950
    5051  char buf[1024];
    5152
    5253  printf("read from client1 before sending data\n");
    53   printf("result: %d bytes\n", client1.readPacket((byte*)buf, 1024));
     54  printf("result: %d bytes\n", client1->readPacket((byte*)buf, 1024));
    5455
    5556  printf("read from client2 before sending data\n");
    56   printf("result: %d bytes\n", client2.readPacket((byte*)buf, 1024));
     57  printf("result: %d bytes\n", client2->readPacket((byte*)buf, 1024));
    5758
    5859  int n;
     
    6162  char * str3 = "client2 to server";
    6263  char * str4 = "server2 to client";
    63   n = client1.writePacket((byte*)str1, strlen(str1)+1);
     64  n = client1->writePacket((byte*)str1, strlen(str1)+1);
    6465  printf("%d bytes send from client1\n", n);
    65   n = server1.writePacket((byte*)str2, strlen(str2)+1);
     66  n = server1->writePacket((byte*)str2, strlen(str2)+1);
    6667  printf("%d bytes send from server1\n", n);
    67   n = client2.writePacket((byte*)str3, strlen(str3)+1);
     68  n = client2->writePacket((byte*)str3, strlen(str3)+1);
    6869  printf("%d bytes send from client2\n", n);
    69   n = server2.writePacket((byte*)str4, strlen(str4)+1);
     70  n = server2->writePacket((byte*)str4, strlen(str4)+1);
    7071  printf("%d bytes send from server2\n", n);
    7172  SDL_Delay(1000);
    7273
    7374  printf("read from server1\n");
    74   n = server1.readPacket((byte*)buf, 1024);
     75  n = server1->readPacket((byte*)buf, 1024);
    7576  printf("read %d bytes\n", n);
    7677  if (n<0)
     
    8081
    8182  printf("read from server2\n");
    82   n = server2.readPacket((byte*)buf, 1024);
     83  n = server2->readPacket((byte*)buf, 1024);
    8384  printf("read %d bytes\n", n);
    8485  if (n<0)
     
    8889
    8990  printf("read from client1\n");
    90   n = client1.readPacket((byte*)buf, 1024);
     91  n = client1->readPacket((byte*)buf, 1024);
    9192  printf("read %d bytes\n", n);
    9293  if (n<0)
     
    9697
    9798  printf("read from client2\n");
    98   n = client2.readPacket((byte*)buf, 1024);
     99  n = client2->readPacket((byte*)buf, 1024);
    99100  printf("read %d bytes\n", n);
    100101  if (n<0)
     
    106107
    107108  printf("try to send more than 255 bytes\n");
    108   printf("result: %d\n", client1.writePacket((byte*)buf, 1000));
    109 
    110   server1.writePacket((byte*)str1, strlen(str1)+1);
     109  printf("result: %d\n", client1->writePacket((byte*)buf, 1000));
     110
     111  server1->writePacket((byte*)str1, strlen(str1)+1);
    111112  SDL_Delay(500);
    112113  printf("try to read with a too small buffer\n");
    113   printf("result: %d\n", client1.readPacket((byte*)buf, strlen(str1)));
     114  printf("result: %d\n", client1->readPacket((byte*)buf, strlen(str1)));
    114115
    115116  return 0;
     
    190191  Synchronizeable* ss = new SimpleSync("Server\0");
    191192
    192   netMan->createServer(*ss, port);
     193  netMan->createServer(/**ss, */port);
    193194  SDL_Delay(20);
    194195
     
    196197  {
    197198    netMan->synchronize();
    198     SDL_Delay(500);
     199    SDL_Delay(1000);
    199200  }
    200201
     
    229230  Synchronizeable* ss = new SimpleSync("Client\0");
    230231
    231   netMan->establishConnection(ip, *ss);
     232  netMan->establishConnection((const char*)"localhost", port/*,ip, *ss*/);
    232233
    233234  for(;;)
     
    280281  delete ss;
    281282
     283  return 0;
     284}
     285
     286
     287int converter(int argc, char** argv)
     288{
     289  int x = 200564786;
     290  printf("To convert: %i\n", x);
     291  byte* res = Converter::intToByteArray(x);
     292  for (int i = 0; i < 4; i++)
     293    printf("%i  ", res[i]);
     294  printf("\n");
     295 
     296  int z = Converter::byteArrayToInt(res);
     297 
     298  printf("ReConvert: %i\n", z);
     299
     300 
     301  //float a = 5.4f;
     302  //float b = 2.0f;
     303  //printf("%f mod %f = %f", a, b, a % b);
     304 
     305  printf("\n");
     306 
     307  float y;
     308  char* s;
     309 
     310  y = 12.0f;
     311  s = Converter::floatToBinString(y);
     312  printf("%f = ", y);
     313  printf(s); printf("\n");
     314 
     315  y = 24549026.0f;
     316  s = Converter::floatToBinString(y);
     317  printf("%f = ", y);
     318  printf(s); printf("\n");
     319 
     320  y = 12.4e20f;
     321  s = Converter::floatToBinString(y);
     322  printf("%f = ", y);
     323  printf(s); printf("\n");
     324 
     325  y = 4.7824f;
     326  s = Converter::floatToBinString(y);
     327  printf("%f = ", y);
     328  printf(s); printf("\n");
     329 
     330 
     331 
    282332  return 0;
    283333}
     
    308358    else if (! strcmp( "--listen", argv[i]) || !strcmp("-l", argv[i]))
    309359      return startListen(argc, argv);
     360    else if (! strcmp( "--converter", argv[i]) || !strcmp("-o", argv[i]))
     361      return converter(argc, argv);
    310362  }
    311363
  • trunk/src/subprojects/network/read_sync.cc

    r5996 r6139  
    8080 *  read data from Synchronizeable
    8181 */
    82 int ReadSync::readBytes(byte* data)
     82int ReadSync::readBytes(byte* data, int maxLength, int * reciever)
    8383{
    8484  return 0;
  • trunk/src/subprojects/network/read_sync.h

    r5996 r6139  
    1717
    1818    virtual void writeBytes(const byte* data, int length);
    19     virtual int readBytes(byte* data);
     19    virtual int readBytes(byte* data, int maxLength, int * reciever);
    2020
    2121
  • trunk/src/subprojects/network/simple_sync.cc

    r5996 r6139  
    8686 *  read data from Synchronizeable
    8787 */
    88 int SimpleSync::readBytes(byte* data)
     88int SimpleSync::readBytes(byte* data, int maxLength, int * reciever)
    8989{
    9090  PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);
  • trunk/src/subprojects/network/simple_sync.h

    r5996 r6139  
    1717
    1818    virtual void writeBytes(const byte* data, int length);
    19     virtual int readBytes(byte* data);
     19    virtual int readBytes(byte* data, int maxLength, int * reciever);
    2020
    2121
  • trunk/src/subprojects/network/write_sync.cc

    r5996 r6139  
    8686 *  read data from Synchronizeable
    8787 */
    88 int WriteSync::readBytes(byte* data)
     88int WriteSync::readBytes(byte* data, int maxLength, int * reciever)
    8989{
    9090  PRINTF(0)("WriteSync: sent %i bytes of data\n", this->outLength);
  • trunk/src/subprojects/network/write_sync.h

    r5996 r6139  
    1717
    1818    virtual void writeBytes(const byte* data, int length);
    19     virtual int readBytes(byte* data);
     19    virtual int readBytes(byte* data, int maxLength, int * reciever);
    2020
    2121
  • trunk/src/util/loading/game_loader.cc

    r5982 r6139  
    4646/**
    4747 *  simple constructor
    48 */
     48 */
    4949GameLoader::GameLoader ()
    5050{
     
    5757/**
    5858 *  simple deconstructor
    59 */
     59 */
    6060GameLoader::~GameLoader ()
    6161{
     
    6969 *  this class is a singleton class
    7070 * @returns an instance of itself
    71 
    72    if you are unsure about singleton classes, check the theory out on the internet :)
    73 */
     71 *
     72 * if you are unsure about singleton classes, check the theory out on the internet :)
     73 */
    7474GameLoader* GameLoader::getInstance()
    7575{
     
    8181/**
    8282 *  initializes the GameLoader
    83 */
     83 */
    8484ErrorMessage GameLoader::init()
    8585{
     
    100100 * @param fileName to be loaded
    101101 * @returns the loaded campaign
    102 
    103    this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    104 */
     102 *
     103 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     104 */
    105105ErrorMessage GameLoader::loadCampaign(const char* fileName)
    106106{
     
    112112      delete[] campaignName;
    113113    }
    114 //   World* world0 = new World(DEBUG_WORLD_0);
    115 //   world0->setNextStoryID(WORLD_ID_GAMEEND);
    116 //   this->currentCampaign->addEntity(world0, WORLD_ID_2);
    117 }
     114}
     115
     116
     117/**
     118 *  reads a campaign definition file into a campaign class
     119 * @param fileName to be loaded
     120 * @returns the loaded campaign
     121 *
     122 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     123 */
     124ErrorMessage GameLoader::loadNetworkCampaign(const char* fileName)
     125{
     126  ErrorMessage errorCode;
     127  char* campaignName = ResourceManager::getFullName(fileName);
     128  if (campaignName)
     129  {
     130    this->currentCampaign = this->fileToNetworkCampaign(campaignName);
     131    delete[] campaignName;
     132  }
     133}
     134
    118135
    119136/**
     
    121138 * @param campaignID the identifier of the campaign.
    122139 * @returns error message if not able to do so.
    123 */
     140 */
    124141ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID)
    125142{
     
    156173
    157174/**
    158   *  starts the current entity
    159   * @returns error code if this action has caused a error
    160 */
     175 *  starts the current entity
     176 * @returns error code if this action has caused a error
     177 */
    161178ErrorMessage GameLoader::start()
    162179{
     
    167184
    168185/**
    169   *  stops the current entity
    170   * @returns error code if this action has caused a error
    171 
    172     ATTENTION: this function shouldn't call other functions, or if so, they must return
    173     after finishing. If you ignore or forget to do so, the current entity is not able to
    174     terminate and it will run in the background or the ressources can't be freed or even
    175     worse: are freed and the program will end in a segmentation fault!
    176     hehehe, have ya seen it... :)
    177 */
     186 *  stops the current entity
     187 * @returns error code if this action has caused a error
     188 *
     189 *  ATTENTION: this function shouldn't call other functions, or if so, they must return
     190 *  after finishing. If you ignore or forget to do so, the current entity is not able to
     191 *  terminate and it will run in the background or the ressources can't be freed or even
     192 *  worse: are freed and the program will end in a segmentation fault!
     193 *  hehehe, have ya seen it... :)
     194 */
    178195void GameLoader::stop()
    179196{
     
    184201
    185202/**
    186   *  pause the current entity
    187   * @returns error code if this action has caused a error
    188 
    189    this pauses the current entity or passes this call forth to the running entity.
    190 */
     203 *  pause the current entity
     204 * @returns error code if this action has caused a error
     205 *
     206 * this pauses the current entity or passes this call forth to the running entity.
     207 */
    191208ErrorMessage GameLoader::pause()
    192209{
     
    198215
    199216/**
    200   *  resumes a pause
    201   * @returns error code if this action has caused a error
    202 
    203     this resumess the current entity or passes this call forth to the running entity.
    204 */
     217 *  resumes a pause
     218 * @returns error code if this action has caused a error
     219 *
     220 *  this resumess the current entity or passes this call forth to the running entity.
     221 */
    205222ErrorMessage GameLoader::resume()
    206223{
     
    224241 * @param fileName to be loaded
    225242 * @returns the loaded campaign
    226 
    227    this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    228 */
     243 *
     244 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     245 */
    229246Campaign* GameLoader::fileToCampaign(const char* fileName)
    230247{
     
    273290
    274291/**
     292 *  reads a campaign definition file into a campaign class
     293 * @param fileName to be loaded
     294 * @returns the loaded campaign
     295 *
     296 *  this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     297 */
     298Campaign* GameLoader::fileToNetworkCampaign(const char* fileName)
     299{
     300  /* do not entirely load the campaign. just the current world
     301  before start of each world, it has to be initialized so it
     302  can load everything it needs into memory then.
     303  */
     304
     305  if( fileName == NULL)
     306  {
     307    PRINTF(2)("No filename specified for loading");
     308    return NULL;
     309  }
     310
     311  TiXmlDocument* XMLDoc = new TiXmlDocument( fileName);
     312  // load the campaign document
     313  if( !XMLDoc->LoadFile())
     314  {
     315      // report an error
     316    PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName, XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
     317    delete XMLDoc;
     318    return NULL;
     319  }
     320
     321  // check basic validity
     322  TiXmlElement* root = XMLDoc->RootElement();
     323  assert( root != NULL);
     324
     325  if( strcmp( root->Value(), "Campaign"))
     326  {
     327      // report an error
     328    PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     329    delete XMLDoc;
     330    return NULL;
     331  }
     332
     333  // construct campaign
     334  Campaign* c = new Campaign( root);
     335
     336  // free the XML data
     337  delete XMLDoc;
     338
     339  return c;
     340}
     341
     342
     343/**
    275344 *  handle keyboard commands
    276345 * @param event the event to handle
     
    312381
    313382/**
    314   \brief this changes to the next level
    315 */
     383 * \brief this changes to the next level
     384 */
    316385void GameLoader::nextLevel()
    317386{
     
    322391
    323392/**
    324   \brief change to the previous level - not implemented
    325 
    326   this propably useless
    327 */
     393 * change to the previous level - not implemented
     394 *
     395 * this propably useless
     396 */
    328397void GameLoader::previousLevel()
    329398{
  • trunk/src/util/loading/game_loader.h

    r5982 r6139  
    4040{
    4141
     42
    4243 public:
    4344  ~GameLoader ();
     
    4647
    4748  ErrorMessage init();
    48   ErrorMessage loadCampaign(const char* name);
    4949  ErrorMessage start();
    5050  void stop();
     
    5353  ErrorMessage destroy();
    5454
     55  ErrorMessage loadCampaign(const char* name);
     56  ErrorMessage loadDebugCampaign(Uint32 campaignID);
     57  ErrorMessage loadNetworkCampaign(const char* fileName);
     58
    5559  void nextLevel();
    5660  void previousLevel();
    5761
    58   /** \brief a world command to send to the GameLoader @param cmd the command */
    59   bool worldCommand(Command* cmd);
    60   ErrorMessage loadDebugCampaign(Uint32 campaignID);
     62  void process(const Event &event);
    6163
    62   void process(const Event &event);
    6364
    6465 private:
     
    6667
    6768  Campaign* fileToCampaign(const char* name);
     69  Campaign* fileToNetworkCampaign(const char* fileName);
     70
    6871
    6972 private:
  • trunk/src/world_entities/Makefile.am

    r5915 r6139  
    88                  camera.cc \
    99                  playable.cc \
    10                   player.cc \
     10                              player.cc \
    1111                  npc.cc \
    1212                  npc2.cc \
     
    1818                  character_attributes.cc \
    1919                  test_entity.cc \
    20                   space_ships/space_ship.cc \
     20                              space_ships/space_ship.cc \
    2121                  weapons/weapon_manager.cc \
    2222                  weapons/weapon.cc \
     
    2727                  weapons/rocket.cc \
    2828                  weapons/laser.cc \
    29                   weapons/ground_turret.cc \
     29                              weapons/ground_turret.cc \
    3030                  weapons/crosshair.cc \
    31                   weapons/ground_turret.cc \
     31                              weapons/ground_turret.cc \
    3232                  power_ups/power_up.cc \
    3333                  power_ups/turret_power_up.cc \
     
    3838                 camera.h \
    3939                 playable.h \
    40                  player.h \
     40                             player.h \
    4141                 npc.h \
    4242                 npc2.h \
  • trunk/src/world_entities/camera.h

    r6034 r6139  
    88
    99#include "p_node.h"
    10 #include "vector.h"
    1110#include "event_listener.h"
    1211
Note: See TracChangeset for help on using the changeset viewer.