- Timestamp:
- Dec 24, 2005, 2:15:49 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/lang/base_object.cc
r6257 r6275 75 75 this->classID |= (long)classID; 76 76 this->className = className; 77 this->realClassID = classID;78 77 79 78 ClassList::addToClassList(this, classID, className); -
branches/network/src/lib/lang/base_object.h
r6257 r6275 34 34 /** @returns the classID of the corresponding Object */ 35 35 inline int getClassID() const { return this->classID; }; 36 inline int getRealClassID() const { return this->realClassID; };36 inline ClassID getLeafID() { return (ClassID)(this->classID & CL_MASK_LOWLEVEL_CLASS); } 37 37 38 38 bool isA (ClassID classID) const; … … 50 50 const char* className; //!< the name of the class 51 51 long classID; //!< this is the id from the class_id.h enumeration 52 long realClassID; //!< classID which can be used with factory53 52 char* objectName; //!< The name of this object 54 53 }; -
branches/network/src/lib/network/converter.cc
r6273 r6275 444 444 { 445 445 PRINTF(1)("There is not enough space in string (%d) to store %d bytes\n", maxLength, length+1 ); 446 strncpy(s,"",maxLength); 446 447 return -1; 447 448 } -
branches/network/src/lib/network/data_stream.h
r5822 r6275 13 13 #include "netdefs.h" 14 14 15 #define DATA_STREAM_BUFFER_SIZE 1024 15 #define DATA_STREAM_BUFFER_SIZE 10240 16 16 17 17 class DataStream : public BaseObject -
branches/network/src/lib/network/network_game_manager.cc
r6273 r6275 236 236 } 237 237 238 238 239 if ( b->isA(CL_SYNCHRONIZEABLE) ) 239 240 { … … 372 373 while ( it != e ) 373 374 { 374 if ( (*it)->get RealClassID() != CL_NETWORK_GAME_MANAGER && (*it)->getRealClassID() != CL_HANDSHAKE )375 { 376 377 if ( !writeToClientBuffer( outBuffer[userID], ( *it)->getRealClassID() ) )375 if ( (*it)->getLeafID() != CL_NETWORK_GAME_MANAGER && (*it)->getLeafID() != CL_HANDSHAKE ) 376 { 377 378 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafID()) ) ) 378 379 return; 379 380 … … 425 426 PRINTF(1)("Could not fabricate Object with classID %x\n", classID); 426 427 return; 427 }428 else429 {430 //PRINTF(0)("Fabricated entity: %s\n", b->getClassName());431 428 } 432 429 … … 439 436 if ( !isServer() ) 440 437 s->setIsOutOfSync( true ); 438 PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID()); 441 439 } 442 440 else -
branches/network/src/lib/network/synchronizeable.h
r6273 r6275 21 21 #define STATE_REQUESTEDSYNC 4 22 22 23 23 24 //macros to help writing data in byte buffer 24 #define SYNCHELP_WRITE_BEGIN() { int __synchelp_write_i = 0; \ 25 bool __synchelp_write_err = false; \ 26 int __synchelp_write_n; } 25 /* 26 * Important: these macros must be used in 27 * SYNCHELP_READ_*: virtual void writeBytes(const byte* data, int length, int sender); 28 * SYNCHELP_WRITE_*: virtual int readBytes(byte* data, int maxLength, int * reciever); 29 * with the same argument names! 30 * 31 * 32 * Example 1: 33 * SYNCHELP_READ_BEGIN(); 34 * SYNCHELP_READ_FLOAT(size); 35 * SYNCHELP_READ_STRING( textureName, 1024 ); //1024 is the length of textureName 36 * 37 * Example 2: 38 * SYNCHELP_WRITE_BEGIN(); 39 * SYNCHELP_WRITE_FLOAT(this->size); 40 * SYNCHELP_WRITE_STRING(this->textureName); 41 * return SYNCHELP_WRITE_N; 42 * 43 */ 44 #define SYNCHELP_WRITE_BEGIN() int __synchelp_write_i = 0; \ 45 int __synchelp_write_n 27 46 #define SYNCHELP_WRITE_RESET() { __synchelp_write_i = 0; __synchelp_write_err = false; } 28 #define SYNCHELP_WRITE_INT(i) { __synchelp_write_n = } 29 #define SYNCHELP_WIRTE_FLOAT() 30 #define SYNCHELP_WRITE_BYTE() 31 #define SYNCHELP_WRITE_STRING() 47 #define SYNCHELP_WRITE_INT(i) { __synchelp_write_n = \ 48 Converter::intToByteArray( i, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \ 49 if ( __synchelp_write_n <= 0) \ 50 { \ 51 PRINTF(1)("Buffer is too small to store a int\n"); \ 52 return 0; \ 53 } \ 54 __synchelp_write_i += __synchelp_write_n; \ 55 } 56 #define SYNCHELP_WRITE_FLOAT(f) { __synchelp_write_n = \ 57 Converter::floatToByteArray( f, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \ 58 if ( __synchelp_write_n <= 0) \ 59 { \ 60 PRINTF(1)("Buffer is too small to store a float\n"); \ 61 return 0; \ 62 } \ 63 __synchelp_write_i += __synchelp_write_n; \ 64 } 65 #define SYNCHELP_WRITE_BYTE(b) { \ 66 if (maxLength - __synchelp_write_i < 1) \ 67 { \ 68 PRINTF(1)("Buffer is too small to store string\n"); \ 69 return 0; \ 70 } \ 71 data[__synchelp_write_i] = b; \ 72 __synchelp_write_i++; \ 73 } 74 #define SYNCHELP_WRITE_STRING(s) { __synchelp_write_n = \ 75 Converter::stringToByteArray( s, data+__synchelp_write_i, strlen(s), maxLength-__synchelp_write_i ); \ 76 if ( __synchelp_write_n <= 0) \ 77 { \ 78 PRINTF(1)("Buffer is too small to store string\n"); \ 79 return 0; \ 80 } \ 81 __synchelp_write_i += __synchelp_write_n; \ 82 } 83 #define SYNCHELP_WRITE_N __synchelp_write_i 84 85 86 #define SYNCHELP_READ_BEGIN() int __synchelp_read_i = 0; \ 87 int __synchelp_read_n 88 89 #define SYNCHELP_READ_INT(i) { \ 90 if ( length-__synchelp_read_i < INTSIZE ) \ 91 { \ 92 PRINTF(1)("There is not enough data to read an int\n"); \ 93 return; \ 94 } \ 95 __synchelp_read_i += Converter::byteArrayToInt( data+__synchelp_read_i, &i ); \ 96 } 97 #define SYNCHELP_READ_FLOAT(f) { \ 98 if ( length-__synchelp_read_i < FLOATSIZE ) \ 99 { \ 100 PRINTF(1)("There is not enough data to read a flaot\n"); \ 101 return; \ 102 } \ 103 __synchelp_read_i += Converter::byteArrayToFloat( data+__synchelp_read_i, &f ); \ 104 } 105 #define SYNCHELP_READ_STRING(s,l) { \ 106 __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, l ); \ 107 if ( __synchelp_read_n <0 ) \ 108 { \ 109 PRINTF(1)("There is not enough data to read string\n"); \ 110 return; \ 111 } \ 112 } 113 #define SYNCHELP_READ_BYTE(b) { \ 114 if ( length-__synchelp_read_i < 1 ) \ 115 { \ 116 PRINTF(1)("There is not enough data to read a byte\n"); \ 117 return; \ 118 } \ 119 b = data[__synchelp_read_i]; \ 120 __synchelp_read_i ++; \ 121 } 32 122 33 123 class NetworkStream; -
branches/network/src/world_entities/skybox.cc
r6273 r6275 218 218 setIsOutOfSync( false ); 219 219 220 int flsize = Converter::byteArrayToFloat( data, &size ); 221 Converter::byteArrayToString( data+flsize, textureName, length-flsize ); 222 223 PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName); 220 /*int flsize = Converter::byteArrayToFloat( data, &size ); 221 Converter::byteArrayToString( data+flsize, textureName, length-flsize );*/ 222 223 SYNCHELP_READ_BEGIN(); 224 SYNCHELP_READ_FLOAT(size); 225 SYNCHELP_READ_STRING( textureName, 1024 ); 226 227 //PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName); 224 228 225 229 this->setSize( size ); … … 228 232 } 229 233 234 235 230 236 int SkyBox::readBytes( byte * data, int maxLength, int * reciever ) 231 237 { 232 238 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 233 239 { 234 PRINTF(0)("Requesting sync! %d\n", this->getUniqueID());240 //PRINTF(0)("Requesting sync! %d\n", this->getUniqueID()); 235 241 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 236 242 setRequestedSync( true ); … … 240 246 if ( rec > 0 ) 241 247 { 242 PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName);248 //PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName); 243 249 *reciever = rec; 244 250 245 int flsize = Converter::floatToByteArray( this->size, data, maxLength ); 246 247 if ( flsize <= 0 ) 248 { 249 PRINTF(1)("Byte array is too small (%d) to store float\n", maxLength ); 250 return 0; 251 } 252 253 if ( strlen(textureName)+INTSIZE+flsize > maxLength ) 254 { 255 PRINTF(1)("Byte array is too small (%d) to store data\n", maxLength ); 256 return 0; 257 } 258 259 return flsize + Converter::stringToByteArray( textureName, data+flsize, strlen(textureName), maxLength-flsize ); 260 251 SYNCHELP_WRITE_BEGIN(); 252 SYNCHELP_WRITE_FLOAT(this->size); 253 SYNCHELP_WRITE_STRING(this->textureName); 254 255 return SYNCHELP_WRITE_N; 261 256 } 262 257 -
branches/network/src/world_entities/terrain.cc
r6142 r6275 24 24 #include "resource_manager.h" 25 25 #include "model.h" 26 #include "network_game_manager.h" 27 26 28 27 29 #include "glincl.h" … … 57 59 { 58 60 this->loadModel(fileName); 61 strncpy( terrainFile, fileName, 1024 ); 59 62 } 60 63 else … … 98 101 this->ssp = NULL; 99 102 this->vegetation = NULL; 103 strncpy( this->vegetationFile, "", 1024 ); 104 strncpy( this->terrainFile, "", 1024 ); 100 105 } 101 106 … … 111 116 void Terrain::loadVegetation(const char* vegetationFile) 112 117 { 118 PRINTF(0)("loadVegetation: %s\n", vegetationFile); 113 119 if (this->vegetation) 114 120 ResourceManager::getInstance()->unload(this->vegetation, RP_LEVEL); … … 116 122 { 117 123 PRINTF(4)("fetching %s\n", vegetationFile); 118 this->vegetation = (Model*)ResourceManager::getInstance()->load(vegetationFile, OBJ, RP_CAMPAIGN); 124 this->vegetation = (Model*)ResourceManager::getInstance()->load(vegetationFile, OBJ, RP_CAMPAIGN); 125 strncpy( this->vegetationFile, vegetationFile, 1024); 119 126 } 120 127 else … … 315 322 } 316 323 } 324 325 void Terrain::writeBytes( const byte * data, int length, int sender ) 326 { 327 setRequestedSync( false ); 328 setIsOutOfSync( false ); 329 330 int n = Converter::byteArrayToString( data, vegetationFile, length ); 331 Converter::byteArrayToString( data+n, terrainFile, length-n ); 332 333 //PRINT(0)("GOT DATA: size=%f texture=%s\n", size, textureName); 334 335 if ( strcmp(vegetationFile, "") ) 336 this->loadVegetation( vegetationFile ); 337 if ( strcmp(terrainFile, "") ) 338 this->loadModel( terrainFile ); 339 340 } 341 342 int Terrain::readBytes( byte * data, int maxLength, int * reciever ) 343 { 344 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) 345 { 346 //PRINTF(0)("Requesting sync! %d\n", this->getUniqueID()); 347 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); 348 setRequestedSync( true ); 349 } 350 351 int rec = this->getRequestSync(); 352 if ( rec > 0 ) 353 { 354 //PRINTF(0)("Serving client %d which requested sync %d size=%f texture=%s\n", rec, this->getUniqueID(), this->size, this->textureName); 355 *reciever = rec; 356 357 if ( strlen(vegetationFile)+INTSIZE > maxLength ) 358 { 359 PRINTF(1)("Byte array is too small (%d) to store data\n", maxLength ); 360 return 0; 361 } 362 363 int n = Converter::stringToByteArray( vegetationFile, data, strlen(vegetationFile), maxLength ); 364 365 return n + Converter::stringToByteArray( terrainFile, data+n, strlen(terrainFile), maxLength-n ); 366 367 } 368 369 *reciever = 0; 370 return 0; 371 } 372 373 void Terrain::writeDebug( ) const 374 { 375 } 376 377 void Terrain::readDebug( ) const 378 { 379 } -
branches/network/src/world_entities/terrain.h
r5500 r6275 30 30 virtual ~Terrain(); 31 31 32 virtual void writeBytes(const byte* data, int length, int sender); 33 virtual int readBytes(byte* data, int maxLength, int * reciever); 34 virtual void writeDebug() const; 35 virtual void readDebug() const; 36 32 37 void init(); 33 38 void loadParams(const TiXmlElement* root); … … 44 49 Model* vegetation; 45 50 int objectList; 51 char vegetationFile[1024]; 52 char terrainFile[1024]; 46 53 }; 47 54
Note: See TracChangeset
for help on using the changeset viewer.