- Timestamp:
- Dec 16, 2005, 6:45:32 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 2 added
- 32 edited
- 8 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r6113 r6139 25 25 lib/gui/gl_gui/libORXglgui.a \ 26 26 lib/shell/libORXshell.a \ 27 lib/network/libORXnet.a 27 lib/network/libORXnet.a 28 28 29 29 orxonox_LDADD = util/libORXutils.a \ … … 49 49 story_entities/campaign.cc \ 50 50 story_entities/world.cc \ 51 story_entities/network_world.cc \ 51 52 world_entities/world_entity.cc \ 52 53 world_entities/camera.cc \ … … 85 86 world_entities/space_ships/space_ship.cc \ 86 87 world_entities/space_ships/helicopter.cc \ 88 world_entities/spawning_point.cc \ 87 89 subprojects/benchmark.cc 88 90 … … 94 96 story_entities/campaign.h \ 95 97 story_entities/world.h \ 98 story_entities/network_world.h \ 96 99 world_entities/world_entity.h \ 97 100 world_entities/camera.h \ … … 130 133 world_entities/space_ships/space_ship.h \ 131 134 world_entities/space_ships/helicopter.h \ 135 world_entities/spawning_point.h \ 132 136 defs/stdincl.h \ 133 137 defs/stdlibincl.h \ -
trunk/src/defs/class_id.h
r6113 r6139 147 147 CL_SPACE_SHIP = 0x0000020a, 148 148 CL_HELICOPTER = 0x0000020b, 149 CL_SPAWNING_POINT = 0x0000020b, 149 150 150 151 CL_TURRET_POWER_UP = 0x00000211, … … 230 231 231 232 // network stuff (range from 0x00000b00 to 0x00000bff) 232 CL_DATA_STREAM = 0x00b01 000,233 CL_DATA_STREAM = 0x00b01b00, 233 234 CL_NETWORK_STREAM = 0x00000b01, 234 235 CL_NETWORK_PROTOCOL = 0x00000b02, … … 236 237 CL_SERVER_SOCKET = 0X00000b04, 237 238 CL_CONNECTION_MONITOR = 0x00000b05, 239 CL_HANDSHAKE = 0x00000b06, 240 CL_ENTITY_MANAGER = 0x00000b07, 238 241 239 242 -
trunk/src/lib/graphics/importer/texture.cc
r5863 r6139 19 19 20 20 #include "debug.h" 21 #include "compiler.h" 22 #include <math.h> 21 23 22 24 // INCLUDING SDL_Image … … 37 39 this->texture = 0; 38 40 this->image = NULL; 41 this->priority = 0.5; 39 42 40 43 if (imageName != NULL) … … 177 180 * @returns a !!new!! Surface, that is loadable by openGL. 178 181 */ 179 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) 182 SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const 180 183 { 181 184 PRINTF(4)("Loading texture to OpenGL-Environment.\n"); … … 237 240 * @returns The ID of the texture. 238 241 */ 239 GLuint Texture::loadTexToGL (const SDL_Surface* surface) 242 GLuint Texture::loadTexToGL (const SDL_Surface* surface) const 240 243 { 241 244 // if (this->texture != 0 && glIsTexture(this->texture)) … … 243 246 // this->texture = 0; 244 247 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 246 254 247 255 if (surface == NULL) … … 251 259 glGenTextures(1, &texture); 252 260 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 */ 256 270 glTexImage2D(GL_TEXTURE_2D, 257 271 0, … … 262 276 GL_UNSIGNED_BYTE, 263 277 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 272 310 glBindTexture(GL_TEXTURE_2D, 0); 273 311 return texture; 274 312 } 313 -
trunk/src/lib/graphics/importer/texture.h
r5859 r6139 39 39 40 40 // 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; 43 43 44 44 protected: … … 53 53 bool bAlpha; //!< if the texture has an alpha channel. 54 54 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) 55 56 56 57 static bool texturesEnabled; //!< If the Textures are enabled. -
trunk/src/lib/network/Makefile.am
r5996 r6139 11 11 data_stream.cc \ 12 12 network_protocol.cc \ 13 server_socket.cc 13 server_socket.cc \ 14 handshake.cc \ 15 network_game_manager.cc \ 16 converter.cc 17 14 18 15 19 … … 22 26 data_stream.h \ 23 27 network_protocol.h \ 24 server_socket.h 28 server_socket.h \ 29 handshake.h \ 30 network_game_manager.h \ 31 converter.h 25 32 33 -
trunk/src/lib/network/network_manager.cc
r5997 r6139 50 50 this->tmpStream = NULL; 51 51 this->hostID = -1; 52 this->bGameServer = false; 52 53 53 54 PRINTF(0)("NetworkManager created\n"); … … 95 96 } 96 97 97 this->tmpStream = new NetworkStream(ipAddress , NET_CLIENT);98 this->tmpStream = new NetworkStream(ipAddress); 98 99 return 1; 99 100 } … … 106 107 int NetworkManager::createServer(unsigned int port) 107 108 { 108 this->tmpStream = new NetworkStream(port, NET_SERVER); 109 this->tmpStream = new NetworkStream(port); 110 this->bGameServer = true; 109 111 SDL_Delay(20); 110 112 return 1; … … 120 122 { 121 123 /* 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); 123 126 } 124 127 … … 132 135 PRINTF(0)("Create a new server socket\n"); 133 136 /* 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; 135 140 } 136 141 -
trunk/src/lib/network/network_manager.h
r5997 r6139 45 45 void setHostID(int id); 46 46 /** 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; } 48 49 49 private: 50 50 51 void connectSynchronizeable(Synchronizeable& sync); 51 52 void synchronize(); 52 53 54 private: 53 55 NetworkManager(); 54 56 55 57 56 58 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 62 65 63 66 }; -
trunk/src/lib/network/network_protocol.cc
r5822 r6139 57 57 * @arg bufferLength: the length of the internal buffer 58 58 * @arg source: reference to the source Synchronizeable object 59 * @arg remoteID: id number of the remote Synchronizeable object60 59 * @return: the new data length with header (the header data is included into byte* data) 61 60 * -1 if there isn't enough space in the buffer for the header 62 61 */ 63 int NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source , unsigned int remoteID)62 int NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source) 64 63 { 65 printf("NetworkProtocol:create header length = %i, bufferLength = %i\n", length, bufferLength);64 PRINTF(5)("create header length = %i, bufferLength = %i\n", length, bufferLength); 66 65 //If there isn't enough space for the header return -1 67 66 if (length + this->headerLength > bufferLength) 68 67 return -1; 69 68 70 // for(int i = 0; i < length; i++)71 // printf("send byte[%i]=%u\n", i, data[i]);72 69 73 74 //Create space for the header 70 // FIXME: without move Create space for the header 75 71 for( int i = length - 1; i >= 0; i--) 76 72 data[i + this->headerLength] = data[i]; 77 73 78 74 //Now create the header 79 /* protocol identifier */80 data[0] = 255;81 /* version number */82 data[1] = 0;83 75 /* 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()); 87 77 /* data length*/ 88 data[ 4] = length;78 data[1] = length; 89 79 90 80 … … 100 90 Header NetworkProtocol::extractHeader(byte* data, int length) 101 91 { 102 PRINTF( 0)("extract Header\n");92 PRINTF(5)("extract Header\n"); 103 93 //Test if received data can contain a header 104 94 if (length < headerLength) 105 95 { 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"); 107 97 Header h; 108 h. protocol= 0;98 h.length = 0; 109 99 return h; 110 100 } … … 114 104 //&h = data; 115 105 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]; 123 108 /* data length*/ 124 h.length = data[ 4];109 h.length = data[1]; 125 110 126 127 // for(int i = 0; i < length; i++)128 // printf("recS byte[%i]=%u\n", i, data[i]);129 130 //Remove header131 // for (int i = headerLength; i < length; i++)132 // data[i - headerLength] = data[i];133 111 134 112 return h; -
trunk/src/lib/network/network_protocol.h
r5822 r6139 6 6 #define _NETWORK_PROTOCOL_H 7 7 8 /* include base_object.h since all classes are derived from this one */ 8 9 #include "base_object.h" 9 10 … … 11 12 #include "netdefs.h" 12 13 13 #define HEADER_LENGTH 114 15 14 typedef struct Header 16 15 { 17 byte protocol; 18 byte version; 19 byte senderID; 20 byte receiverID; 16 byte synchronizeableID; 21 17 byte length; 22 18 }; … … 33 29 ~NetworkProtocol(); 34 30 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); 36 32 Header extractHeader(byte* data, int length); 37 33 -
trunk/src/lib/network/network_socket.cc
r5996 r6139 28 28 #include "debug.h" 29 29 30 31 30 /** 32 31 * Default constructor … … 52 51 this->tcpSocket = sock; 53 52 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); 56 55 } 57 56 … … 65 64 outgoingBufferLength = 0; 66 65 66 readThread = NULL; 67 writeThread = NULL; 68 69 70 thread_write_running = false; 71 thread_read_running = false; 72 67 73 incomingBufferMutex = SDL_CreateMutex(); 68 74 outgoingBufferMutex = SDL_CreateMutex(); 75 76 69 77 socketMutex = SDL_CreateMutex(); 70 78 terminateThread = false; … … 89 97 * Default destructor 90 98 */ 91 NetworkSocket::~ NetworkSocket( ) 92 { 99 NetworkSocket::~NetworkSocket( ) 100 { 101 this->terminateThread = true; 93 102 /* Quit SDL_net */ 94 103 // NOTE: what if other instances of NetworkSocket running? … … 99 108 SDL_DestroyMutex(outgoingBufferMutex); 100 109 SDL_DestroyMutex(socketMutex); 110 SDL_DestroyMutex(threadTerminationMutex); 101 111 } 102 112 … … 122 132 } 123 133 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); 126 136 } 127 137 … … 152 162 int NetworkSocket::writeBytes(byte * data, int length) 153 163 { 154 PRINTF( 0)("NetworkSocket::writeBytes()\n");164 PRINTF(5)("NetworkSocket::writeBytes()\n"); 155 165 #ifdef _USE_OUTGOING_BUFFER 156 166 … … 200 210 int NetworkSocket::readBytes(byte * data, int length) 201 211 { 202 PRINTF( 0)("NetworkSocket::readBytes()\n");212 PRINTF(5)("NetworkSocket::readBytes()\n"); 203 213 if (data==NULL) 204 214 return 0; … … 256 266 NetworkSocket * self = (NetworkSocket*)data; 257 267 268 self->thread_read_running = true; 269 258 270 while (!self->terminateThread) 259 271 { … … 263 275 264 276 //if buffer is full 265 if (nbytestoread<=0 )277 if (nbytestoread<=0 || !self->tcpSocket) 266 278 { 267 279 SDL_Delay(_MSECONDS_SLEEP_FULL_BUFFER); … … 275 287 if (nbytesread<=0) 276 288 { 277 printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError()); 289 if (nbytesread<0) 290 printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError()); 278 291 279 292 SDL_mutexP(self->socketMutex); … … 284 297 SDL_mutexV(self->socketMutex); 285 298 SDL_mutexV(self->incomingBufferMutex); 286 return -1;299 continue; 287 300 } 288 301 … … 295 308 } 296 309 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"); 297 325 return 0; 298 326 } … … 305 333 NetworkSocket * self = (NetworkSocket*)data; 306 334 335 self->thread_write_running = true; 336 307 337 while (!self->terminateThread) 308 338 { … … 314 344 315 345 //if buffer is full 316 if (nbytestowrite<=0 )346 if (nbytestowrite<=0 || !self->tcpSocket) 317 347 { 318 348 SDL_Delay(_MSECONDS_SLEEP_EMPTY_BUFFER); … … 342 372 343 373 SDL_mutexV(self->socketMutex); 344 return -1;374 continue; 345 375 } 346 376 347 377 } 348 378 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"); 350 394 return 0; 351 395 } … … 353 397 bool NetworkSocket::writePacket( byte * data, int length ) 354 398 { 355 PRINTF( 0)("NetworkSocket::writePacket()\n");399 PRINTF(5)("NetworkSocket::writePacket()\n"); 356 400 if (length>255) 357 401 { … … 368 412 int NetworkSocket::readPacket( byte * data, int maxLength ) 369 413 { 370 PRINTF( 0)("NetworkSocket::readPacket()\n");414 PRINTF(5)("NetworkSocket::readPacket()\n"); 371 415 if (incomingBufferLength<1) 372 416 { -
trunk/src/lib/network/network_socket.h
r5996 r6139 63 63 bool terminateThread; 64 64 65 SDL_mutex* threadTerminationMutex; 65 66 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 66 73 #ifdef _USE_OUTGOING_BUFFER 67 74 static int thread_write(void * data); … … 74 81 void init(); 75 82 83 //dont make this public use destroy() instead 84 ~NetworkSocket(); 85 76 86 public: 77 87 … … 79 89 NetworkSocket(IPaddress ip); 80 90 NetworkSocket(TCPsocket sock); 81 ~NetworkSocket(); 91 void destroy() { terminateThread = true; }; 92 82 93 83 94 void connectToServer(IPaddress ip); … … 87 98 int readPacket(byte * data, int maxLength); 88 99 100 inline bool isOk() { return tcpSocket!=NULL; } 101 89 102 }; 90 103 -
trunk/src/lib/network/network_stream.cc
r5996 r6139 26 26 #include "connection_monitor.h" 27 27 #include "synchronizeable.h" 28 #include "network_manager.h" 28 29 #include "list.h" 29 30 #include "debug.h" 31 #include "class_list.h" 30 32 31 33 /* include your own header */ … … 45 47 /* initialize the references */ 46 48 this->type = NET_CLIENT; 47 this->networkSocket = new NetworkSocket();48 49 this->networkProtocol = new NetworkProtocol(); 49 this->synchronizeables = NULL;50 50 this->connectionMonitor = new ConnectionMonitor(); 51 51 } 52 52 53 NetworkStream::NetworkStream(IPaddress& address , NodeType type)54 { 55 this->type = type;53 NetworkStream::NetworkStream(IPaddress& address) 54 { 55 this->type = NET_CLIENT; 56 56 this->init(); 57 this->networkSocket = new NetworkSocket(address);57 this->networkSockets.push_back(new NetworkSocket(address)); 58 58 this->networkProtocol = new NetworkProtocol(); 59 this->synchronizeables = NULL;60 59 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 69 NetworkStream::NetworkStream(unsigned int port) 70 { 71 this->type = NET_SERVER; 67 72 this->init(); 68 this->networkSocket = new NetworkSocket(); 69 // this->networkSocket->listen(port); 73 this->serverSocket = new ServerSocket(port); 70 74 this->networkProtocol = new NetworkProtocol(); 71 this->synchronizeables = NULL;72 75 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 ); 85 78 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 ); 100 81 } 101 82 … … 105 86 /* set the class id for the base object */ 106 87 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 107 this->state = NET_REC_HEADER;108 88 this->bActive = false; 89 this->serverSocket = NULL; 90 myHostId = 0; 109 91 } 110 92 … … 112 94 NetworkStream::~NetworkStream() 113 95 { 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 } 119 118 120 119 delete connectionMonitor; … … 125 124 void NetworkStream::connectSynchronizeable(Synchronizeable& sync) 126 125 { 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 ) 129 130 this->bActive = true; 130 131 } 131 132 133 void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync) 134 { 135 this->synchronizeables.remove(&sync); 136 137 if( this->networkSockets.size()<=0 ) 138 this->bActive = false; 139 } 140 132 141 133 142 void NetworkStream::processData() 134 143 { 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 136 193 137 194 /* 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 } 161 255 162 256 /* 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 294 void 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 364 void 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 7 7 #define _NETWORK_STREAM 8 8 9 #include <vector> 10 #include <list> 11 9 12 #include "data_stream.h" 10 13 #include "network_protocol.h" 14 #include "server_socket.h" 15 #include "handshake.h" 11 16 12 17 class Synchronizeable; 13 18 class NetworkSocket; 19 class ServerSocket; 14 20 class ConnectionMonitor; 15 21 class NetworkProtocol; 16 22 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 }; 23 typedef std::list<Synchronizeable*> SynchronizeableList; 24 typedef std::vector<NetworkSocket*> NetworkSocketVector; 25 typedef std::vector<Handshake*> HandshakeVector; 25 26 26 27 … … 30 31 public: 31 32 NetworkStream(); 32 NetworkStream(IPaddress& address , NodeType type);33 NetworkStream(unsigned int port , NodeType type);33 NetworkStream(IPaddress& address); 34 NetworkStream(unsigned int port); 34 35 35 NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);36 NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);37 36 ~NetworkStream(); 38 37 void init(); 39 38 40 39 void connectSynchronizeable(Synchronizeable& sync); 40 void disconnectSynchronizeable(Synchronizeable& sync); 41 41 42 42 inline bool isServer() const { return (this->type == NET_SERVER)? true:false; } 43 43 inline bool isActive() const { return this->bActive; } 44 45 inline int getMaxConnections(){ return maxConnections; } 46 void setMaxConnections( int n ); 44 47 45 48 virtual void processData(); … … 48 51 NetworkProtocol* networkProtocol; 49 52 ConnectionMonitor* connectionMonitor; 50 Synchronizeable* synchronizeables; 51 NetworkSocket* networkSocket; 53 SynchronizeableList synchronizeables; 54 NetworkSocketVector networkSockets; 55 HandshakeVector handshakes; 56 ServerSocket* serverSocket; 52 57 int type; 53 int state;54 58 Header packetHeader; 55 59 bool bActive; 60 std::list<int> freeSocketSlots; 61 62 int myHostId; 63 int maxConnections; 64 65 void updateConnectionList(); 56 66 }; 57 67 #endif /* _NETWORK_STREAM */ -
trunk/src/lib/network/server_socket.cc
r5996 r6139 110 110 111 111 112 NetworkSocket ServerSocket::getNewSocket( )112 NetworkSocket* ServerSocket::getNewSocket( ) 113 113 { 114 if ( !listenSocket ) 115 { 116 PRINTF(1)("listenSocket == NULL! Maybe you forgot to call listen()\n"); 117 close(); 118 return NULL; 119 } 120 114 121 TCPsocket sock = SDLNet_TCP_Accept(listenSocket); 115 122 … … 120 127 else 121 128 { 122 return NetworkSocket(sock);129 return new NetworkSocket(sock); 123 130 } 124 131 } 125 132 133 void 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 39 39 ~ServerSocket(); 40 40 bool listen( unsigned int port ); 41 NetworkSocket getNewSocket( void ); 41 NetworkSocket* getNewSocket( void ); 42 void close(); 43 inline bool isOk(){ return listenSocket!=NULL; } 42 44 }; 43 45 -
trunk/src/lib/network/synchronizeable.cc
r5997 r6139 15 15 */ 16 16 17 #define DEBUG_MODULE_NETWORK 18 17 19 #include "synchronizeable.h" 18 20 #include "netdefs.h" 21 #include "network_manager.h" 22 #include "network_stream.h" 19 23 20 24 … … 25 29 { 26 30 27 //owner = ?; 28 //hostID = ?; 31 owner = 0; 32 hostID = NetworkManager::getInstance()->getHostID(); 33 uniqueID = -1; 29 34 //state = ?; 30 35 … … 44 49 */ 45 50 Synchronizeable::~Synchronizeable() 46 {} 51 { 52 if ( this->networkStream ) 53 this->networkStream->disconnectSynchronizeable(*this); 54 } 47 55 48 56 /** … … 50 58 */ 51 59 void Synchronizeable::writeBytes(const byte* data, int length) 52 {} 60 { 61 PRINTF(1)("Synchronizeable::writeBytes was called\n"); 62 } 53 63 54 64 /** 55 65 * read data from NetworkStream 56 66 */ 57 int Synchronizeable::readBytes(byte* data) 58 {} 67 int Synchronizeable::readBytes(byte* data, int maxLength, int * reciever) 68 { 69 PRINTF(1)("Synchronizeable::readBytes was called\n"); 70 } 59 71 60 72 … … 65 77 void Synchronizeable::readDebug() const 66 78 {} 67 68 69 70 79 71 80 … … 111 120 return this->state & STATE_OUTOFSYNC == STATE_OUTOFSYNC; 112 121 } 122 123 124 -
trunk/src/lib/network/synchronizeable.h
r5997 r6139 19 19 #define STATE_OUTOFSYNC 2 20 20 21 class NetworkStream; 22 21 23 22 24 class Synchronizeable : virtual public BaseObject … … 29 31 30 32 virtual void writeBytes(const byte* data, int length); 31 virtual int readBytes(byte* data );33 virtual int readBytes(byte* data, int maxLength, int * reciever); 32 34 virtual void writeDebug() const; 33 35 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 ); 41 39 bool isServer(); 42 40 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; } 43 49 44 50 private: 45 51 46 52 int uniqueID; 47 48 49 53 54 55 50 56 //static std::vector<Synchronizeable*> classList; 51 57 int owner; … … 54 60 std::list<int> synchronizeRequests; 55 61 62 NetworkStream* networkStream; 63 56 64 }; 57 65 #endif /* _SYNCHRONIZEABLE_H */ -
trunk/src/lib/sound/sound_source.cc
r5930 r6139 69 69 SoundEngine::getInstance()->popALSource(this->sourceID); 70 70 71 printf("%d\n",sourceID);71 //printf("%d\n",sourceID); 72 72 alSourceStop(this->sourceID); 73 73 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); -
trunk/src/orxonox.cc
r6079 r6139 280 280 if( this->serverName != NULL) // we are a client 281 281 NetworkManager::getInstance()->establishConnection(this->serverName, port); 282 else if( this->port > 0) 282 else if( this->port > 0) { // we are a server 283 283 NetworkManager::getInstance()->createServer(port); 284 } 284 285 285 286 return 0; … … 352 353 this->gameLoader = GameLoader::getInstance(); 353 354 354 if( this->port != -1 || this->serverName != NULL)355 this->gameLoader->load Campaign("worlds/DefaultCampaign.oxc"); /* actualy loadNetworkCampaign*/355 if( this->port != -1) 356 this->gameLoader->loadNetworkCampaign("worlds/DefaultNetworkCampaign.oxc"); 356 357 else 357 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); 358 this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* start orxonox in single player mode */ 358 359 359 360 // this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); -
trunk/src/story_entities/campaign.cc
r5982 r6139 150 150 delete (*it); 151 151 } 152 PRINTF(1)("There is no StoryEnity left to play, quitting\n"); 152 153 } 153 154 -
trunk/src/subprojects/network/Makefile.am
r5996 r6139 11 11 network_LDADD = $(MAINSRCDIR)/lib/network/libORXnet.a \ 12 12 \ 13 $(MAINSRCDIR)/lib/ tinyxml/libtinyxml.a13 $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a 14 14 15 15 network_SOURCES= network_unit_test.cc \ -
trunk/src/subprojects/network/network_unit_test.cc
r5996 r6139 11 11 #include "network_stream.h" 12 12 #include "synchronizeable.h" 13 #include "converter.h" 13 14 14 15 #include "simple_sync.h" … … 40 41 server.listen(9999); 41 42 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(); 49 50 50 51 char buf[1024]; 51 52 52 53 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)); 54 55 55 56 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)); 57 58 58 59 int n; … … 61 62 char * str3 = "client2 to server"; 62 63 char * str4 = "server2 to client"; 63 n = client1 .writePacket((byte*)str1, strlen(str1)+1);64 n = client1->writePacket((byte*)str1, strlen(str1)+1); 64 65 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); 66 67 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); 68 69 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); 70 71 printf("%d bytes send from server2\n", n); 71 72 SDL_Delay(1000); 72 73 73 74 printf("read from server1\n"); 74 n = server1 .readPacket((byte*)buf, 1024);75 n = server1->readPacket((byte*)buf, 1024); 75 76 printf("read %d bytes\n", n); 76 77 if (n<0) … … 80 81 81 82 printf("read from server2\n"); 82 n = server2 .readPacket((byte*)buf, 1024);83 n = server2->readPacket((byte*)buf, 1024); 83 84 printf("read %d bytes\n", n); 84 85 if (n<0) … … 88 89 89 90 printf("read from client1\n"); 90 n = client1 .readPacket((byte*)buf, 1024);91 n = client1->readPacket((byte*)buf, 1024); 91 92 printf("read %d bytes\n", n); 92 93 if (n<0) … … 96 97 97 98 printf("read from client2\n"); 98 n = client2 .readPacket((byte*)buf, 1024);99 n = client2->readPacket((byte*)buf, 1024); 99 100 printf("read %d bytes\n", n); 100 101 if (n<0) … … 106 107 107 108 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); 111 112 SDL_Delay(500); 112 113 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))); 114 115 115 116 return 0; … … 190 191 Synchronizeable* ss = new SimpleSync("Server\0"); 191 192 192 netMan->createServer( *ss,port);193 netMan->createServer(/**ss, */port); 193 194 SDL_Delay(20); 194 195 … … 196 197 { 197 198 netMan->synchronize(); 198 SDL_Delay( 500);199 SDL_Delay(1000); 199 200 } 200 201 … … 229 230 Synchronizeable* ss = new SimpleSync("Client\0"); 230 231 231 netMan->establishConnection( ip, *ss);232 netMan->establishConnection((const char*)"localhost", port/*,ip, *ss*/); 232 233 233 234 for(;;) … … 280 281 delete ss; 281 282 283 return 0; 284 } 285 286 287 int 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 282 332 return 0; 283 333 } … … 308 358 else if (! strcmp( "--listen", argv[i]) || !strcmp("-l", argv[i])) 309 359 return startListen(argc, argv); 360 else if (! strcmp( "--converter", argv[i]) || !strcmp("-o", argv[i])) 361 return converter(argc, argv); 310 362 } 311 363 -
trunk/src/subprojects/network/read_sync.cc
r5996 r6139 80 80 * read data from Synchronizeable 81 81 */ 82 int ReadSync::readBytes(byte* data )82 int ReadSync::readBytes(byte* data, int maxLength, int * reciever) 83 83 { 84 84 return 0; -
trunk/src/subprojects/network/read_sync.h
r5996 r6139 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data );19 virtual int readBytes(byte* data, int maxLength, int * reciever); 20 20 21 21 -
trunk/src/subprojects/network/simple_sync.cc
r5996 r6139 86 86 * read data from Synchronizeable 87 87 */ 88 int SimpleSync::readBytes(byte* data )88 int SimpleSync::readBytes(byte* data, int maxLength, int * reciever) 89 89 { 90 90 PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength); -
trunk/src/subprojects/network/simple_sync.h
r5996 r6139 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data );19 virtual int readBytes(byte* data, int maxLength, int * reciever); 20 20 21 21 -
trunk/src/subprojects/network/write_sync.cc
r5996 r6139 86 86 * read data from Synchronizeable 87 87 */ 88 int WriteSync::readBytes(byte* data )88 int WriteSync::readBytes(byte* data, int maxLength, int * reciever) 89 89 { 90 90 PRINTF(0)("WriteSync: sent %i bytes of data\n", this->outLength); -
trunk/src/subprojects/network/write_sync.h
r5996 r6139 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data );19 virtual int readBytes(byte* data, int maxLength, int * reciever); 20 20 21 21 -
trunk/src/util/loading/game_loader.cc
r5982 r6139 46 46 /** 47 47 * simple constructor 48 */48 */ 49 49 GameLoader::GameLoader () 50 50 { … … 57 57 /** 58 58 * simple deconstructor 59 */59 */ 60 60 GameLoader::~GameLoader () 61 61 { … … 69 69 * this class is a singleton class 70 70 * @returns an instance of itself 71 72 73 */71 * 72 * if you are unsure about singleton classes, check the theory out on the internet :) 73 */ 74 74 GameLoader* GameLoader::getInstance() 75 75 { … … 81 81 /** 82 82 * initializes the GameLoader 83 */83 */ 84 84 ErrorMessage GameLoader::init() 85 85 { … … 100 100 * @param fileName to be loaded 101 101 * @returns the loaded campaign 102 103 104 */102 * 103 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 104 */ 105 105 ErrorMessage GameLoader::loadCampaign(const char* fileName) 106 106 { … … 112 112 delete[] campaignName; 113 113 } 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 */ 124 ErrorMessage 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 118 135 119 136 /** … … 121 138 * @param campaignID the identifier of the campaign. 122 139 * @returns error message if not able to do so. 123 */140 */ 124 141 ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID) 125 142 { … … 156 173 157 174 /** 158 159 160 */175 * starts the current entity 176 * @returns error code if this action has caused a error 177 */ 161 178 ErrorMessage GameLoader::start() 162 179 { … … 167 184 168 185 /** 169 170 171 172 173 174 175 176 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 */ 178 195 void GameLoader::stop() 179 196 { … … 184 201 185 202 /** 186 187 188 189 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 */ 191 208 ErrorMessage GameLoader::pause() 192 209 { … … 198 215 199 216 /** 200 201 202 203 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 */ 205 222 ErrorMessage GameLoader::resume() 206 223 { … … 224 241 * @param fileName to be loaded 225 242 * @returns the loaded campaign 226 227 228 */243 * 244 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns 245 */ 229 246 Campaign* GameLoader::fileToCampaign(const char* fileName) 230 247 { … … 273 290 274 291 /** 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 */ 298 Campaign* 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 /** 275 344 * handle keyboard commands 276 345 * @param event the event to handle … … 312 381 313 382 /** 314 \brief this changes to the next level315 */383 * \brief this changes to the next level 384 */ 316 385 void GameLoader::nextLevel() 317 386 { … … 322 391 323 392 /** 324 \briefchange to the previous level - not implemented325 326 this propably useless327 */393 * change to the previous level - not implemented 394 * 395 * this propably useless 396 */ 328 397 void GameLoader::previousLevel() 329 398 { -
trunk/src/util/loading/game_loader.h
r5982 r6139 40 40 { 41 41 42 42 43 public: 43 44 ~GameLoader (); … … 46 47 47 48 ErrorMessage init(); 48 ErrorMessage loadCampaign(const char* name);49 49 ErrorMessage start(); 50 50 void stop(); … … 53 53 ErrorMessage destroy(); 54 54 55 ErrorMessage loadCampaign(const char* name); 56 ErrorMessage loadDebugCampaign(Uint32 campaignID); 57 ErrorMessage loadNetworkCampaign(const char* fileName); 58 55 59 void nextLevel(); 56 60 void previousLevel(); 57 61 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); 61 63 62 void process(const Event &event);63 64 64 65 private: … … 66 67 67 68 Campaign* fileToCampaign(const char* name); 69 Campaign* fileToNetworkCampaign(const char* fileName); 70 68 71 69 72 private: -
trunk/src/world_entities/Makefile.am
r5915 r6139 8 8 camera.cc \ 9 9 playable.cc \ 10 player.cc \10 player.cc \ 11 11 npc.cc \ 12 12 npc2.cc \ … … 18 18 character_attributes.cc \ 19 19 test_entity.cc \ 20 space_ships/space_ship.cc \20 space_ships/space_ship.cc \ 21 21 weapons/weapon_manager.cc \ 22 22 weapons/weapon.cc \ … … 27 27 weapons/rocket.cc \ 28 28 weapons/laser.cc \ 29 weapons/ground_turret.cc \29 weapons/ground_turret.cc \ 30 30 weapons/crosshair.cc \ 31 weapons/ground_turret.cc \31 weapons/ground_turret.cc \ 32 32 power_ups/power_up.cc \ 33 33 power_ups/turret_power_up.cc \ … … 38 38 camera.h \ 39 39 playable.h \ 40 player.h \40 player.h \ 41 41 npc.h \ 42 42 npc2.h \ -
trunk/src/world_entities/camera.h
r6034 r6139 8 8 9 9 #include "p_node.h" 10 #include "vector.h"11 10 #include "event_listener.h" 12 11
Note: See TracChangeset
for help on using the changeset viewer.