- Timestamp:
- Mar 21, 2006, 3:20:36 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/base_object.cc
r7221 r7230 186 186 int BaseObject::writeState( const byte * data, int length, int sender ) 187 187 { 188 /// FIXME STD 189 190 /* SYNCHELP_READ_BEGIN(); 191 192 if ( !objectName.empty() ) 193 { 194 delete[] objectName; 195 objectName = NULL; 196 } 197 SYNCHELP_READ_STRINGM( this->objectName, NWT_BO_NAME ); 198 if ( this->objectName && !strcmp(this->objectName, "") ) 199 { 200 delete[] this->objectName; 201 this->objectName = NULL; 202 } 203 204 return SYNCHELP_READ_N;*/ 188 SYNCHELP_READ_BEGIN(); 189 190 SYNCHELP_READ_STRING( this->objectName, NWT_BO_NAME ); 191 192 return SYNCHELP_READ_N; 205 193 } 206 194 … … 213 201 int BaseObject::readState( byte * data, int maxLength ) 214 202 { 215 ///FIXME STD 216 /* SYNCHELP_WRITE_BEGIN(); 203 SYNCHELP_WRITE_BEGIN(); 217 204 218 205 //PRINTF(0)("objectname = %s\n", this->objectName); 219 206 SYNCHELP_WRITE_STRING( this->objectName, NWT_BO_NAME ); 220 207 221 return SYNCHELP_WRITE_N; */222 } 208 return SYNCHELP_WRITE_N; 209 } -
trunk/src/lib/network/converter.cc
r6959 r7230 159 159 if ( length< INTSIZE ) 160 160 { 161 PRINTF(1)("Byte Array to small \n");161 PRINTF(1)("Byte Array to small : %d\n", length); 162 162 return 0; 163 163 } … … 457 457 * @return: the used number of bytes in byte array 458 458 */ 459 int Converter::stringToByteArray( const char * s, byte * a, int length, int maxLength )460 { 461 if ( length+INTSIZE > maxLength )462 { 463 PRINTF(1)("Byte array is too small (%d) to store %d bytes\n", maxLength, length+INTSIZE);459 int Converter::stringToByteArray( const std::string & s, byte * a, int maxLength ) 460 { 461 if ( s.length()+INTSIZE > maxLength ) 462 { 463 PRINTF(1)("Byte array is too small (%d) to store %d bytes\n", maxLength, s.length()+INTSIZE); 464 464 return -1; 465 465 } 466 466 467 int n = Converter::intToByteArray( length, a, maxLength );468 469 memcpy( a+INTSIZE, s , length);470 471 return length+ INTSIZE;467 int n = Converter::intToByteArray( s.length(), a, maxLength ); 468 469 memcpy( a+INTSIZE, s.c_str(), s.length() ); 470 471 return s.length() + INTSIZE; 472 472 } 473 473 … … 479 479 * @return: the number of read bytes in byte array 480 480 */ 481 int Converter::byteArrayToString( const byte * a, char *s, int maxLength )481 int Converter::byteArrayToString( const byte * a, std::string&s, int maxLength ) 482 482 { 483 483 int length; … … 488 488 if ( length+1 > maxLength ) 489 489 { 490 PRINTF(1)(" There is not enough space in string (%d) to store %d bytes\n", maxLength, length+1);491 s trncpy(s,"",maxLength);490 PRINTF(1)("something went wrong length > remaining bytes in buffer\n" ); 491 s = ""; 492 492 return -1; 493 493 } 494 494 495 memcpy( s, a+n, length );496 s [length] = '\0';495 s[0] = '\0'; 496 s.append( (char*)a+n, length ); 497 497 498 498 return n+length; 499 499 } 500 500 501 #if 0 501 502 /** 502 503 * reads a string out of a byte array and allocates memory for string … … 525 526 return n+length; 526 527 } 527 528 #endif 528 529 529 530 -
trunk/src/lib/network/converter.h
r6981 r7230 34 34 static int _byteArrayToInt(const byte* a, int* x); 35 35 36 static int stringToByteArray(const char* s, byte* a, int length, int maxLength);37 static int byteArrayToString(const byte* a, char*s, int maxLength);38 static int byteArrayToStringM(const byte* a, char*& s );36 static int stringToByteArray(const std::string & s, byte* a, int maxLength); 37 static int byteArrayToString(const byte* a, std::string&s, int maxLength); 38 // static int byteArrayToStringM(const byte* a, char*& s ); 39 39 40 40 //Test -
trunk/src/lib/network/synchronizeable.h
r6959 r7230 199 199 } 200 200 #define SYNCHELP_WRITE_STRING(s,n) { SYNCHELP_WRITE_DEBUG(n); \ 201 if (s!=NULL) {\202 201 __synchelp_write_n = \ 203 Converter::stringToByteArray( s, data+__synchelp_write_i, strlen(s), maxLength-__synchelp_write_i ); \ 204 assert( __synchelp_write_n == strlen(s)+INTSIZE ); \ 205 } else {\ 206 __synchelp_write_n = \ 207 Converter::stringToByteArray( "", data+__synchelp_write_i, strlen(""), maxLength-__synchelp_write_i ); \ 208 assert( __synchelp_write_n == strlen("")+INTSIZE ); } \ 202 Converter::stringToByteArray( s, data+__synchelp_write_i, maxLength-__synchelp_write_i ); \ 203 assert( __synchelp_write_n == ((std::string)s).length()+INTSIZE ); \ 209 204 if ( __synchelp_write_n <= 0) \ 210 205 { \ … … 216 211 #define SYNCHELP_WRITE_N __synchelp_write_i 217 212 #define SYNCHELP_WRITE_FKT(f,n) { SYNCHELP_WRITE_DEBUG(n); \ 218 __synchelp_write_i += \ 213 PRINTF(0)("calling %s with %d left\n", #f, maxLength - __synchelp_write_i); \ 214 byte * spos = data+__synchelp_write_i; \ 215 if (maxLength - __synchelp_write_i < INTSIZE) \ 216 { \ 217 PRINTF(1)("Buffer is too small to store more data\n"); \ 218 return 0; \ 219 } \ 220 __synchelp_write_i += INTSIZE; \ 221 __synchelp_write_n = \ 219 222 f( data+__synchelp_write_i, maxLength-__synchelp_write_i ); \ 223 __synchelp_write_i += __synchelp_write_n; \ 224 Converter::intToByteArray( __synchelp_write_n, spos, INTSIZE ); \ 220 225 } 221 226 … … 244 249 __synchelp_read_i += __synchelp_read_n; \ 245 250 } 246 #define SYNCHELP_READ_STRING(s, l,n) {SYNCHELP_READ_DEBUG(n); \247 __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, l ); \248 assert( __synchelp_read_n == s trlen(s)+INTSIZE ) ;\251 #define SYNCHELP_READ_STRING(s,n) {SYNCHELP_READ_DEBUG(n); \ 252 __synchelp_read_n = Converter::byteArrayToString( data+__synchelp_read_i, s, length-__synchelp_read_i ); \ 253 assert( __synchelp_read_n == s.length()+INTSIZE ) ;\ 249 254 if ( __synchelp_read_n <0 ) \ 250 255 { \ … … 254 259 __synchelp_read_i += __synchelp_read_n; \ 255 260 } 261 #if 0 //not needed any more 256 262 #define SYNCHELP_READ_STRINGM(s,n) { SYNCHELP_READ_DEBUG(n); \ 257 263 __synchelp_read_n = Converter::byteArrayToStringM( data+__synchelp_read_i, s ); \ … … 264 270 __synchelp_read_i += __synchelp_read_n; \ 265 271 } 272 #endif 266 273 #define SYNCHELP_READ_BYTE(b,n) { SYNCHELP_READ_DEBUG(n); \ 267 274 if ( length-__synchelp_read_i < 1 ) \ … … 274 281 } 275 282 #define SYNCHELP_READ_FKT(f,n) { SYNCHELP_READ_DEBUG(n); \ 283 int s; \ 284 if ( length-__synchelp_read_i < INTSIZE ) \ 285 { \ 286 PRINTF(1)("There is not enough data to read an int\n"); \ 287 return 0; \ 288 } \ 289 __synchelp_read_n = Converter::byteArrayToInt( data+__synchelp_read_i, &s ); \ 290 assert( __synchelp_read_n == INTSIZE ); \ 291 __synchelp_read_i += __synchelp_read_n; \ 276 292 __synchelp_read_i += \ 277 f( data+__synchelp_read_i, length-__synchelp_read_i, sender); \293 f( data+__synchelp_read_i, s, sender); \ 278 294 } 279 295 #define SYNCHELP_READ_REMAINING() ( length-__synchelp_read_i ) -
trunk/src/world_entities/skybox.cc
r7221 r7230 300 300 textureName = ""; 301 301 } 302 char*texName;303 SYNCHELP_READ_STRING M( texName, NWT_SB_TEXTURENAME );302 std::string texName; 303 SYNCHELP_READ_STRING( texName, NWT_SB_TEXTURENAME ); 304 304 305 305 this->setSize( size ); … … 330 330 331 331 SYNCHELP_WRITE_FLOAT(this->size, NWT_SB_SIZE); 332 SYNCHELP_WRITE_STRING(this->textureName .c_str(), NWT_SB_TEXTURENAME);332 SYNCHELP_WRITE_STRING(this->textureName, NWT_SB_TEXTURENAME); 333 333 334 334 return SYNCHELP_WRITE_N; -
trunk/src/world_entities/world_entity.cc
r7221 r7230 519 519 int WorldEntity::writeState( const byte * data, int length, int sender ) 520 520 { 521 char*modelFileName;521 std::string modelFileName; 522 522 SYNCHELP_READ_BEGIN(); 523 523 524 524 SYNCHELP_READ_FKT( PNode::writeState, NWT_WE_PN_WRITESTATE ); 525 525 526 SYNCHELP_READ_STRING M( modelFileName, NWT_WE_PN_MODELFILENAME );526 SYNCHELP_READ_STRING( modelFileName, NWT_WE_PN_MODELFILENAME ); 527 527 SYNCHELP_READ_FLOAT( scaling, NWT_WE_PN_SCALING ); 528 528 //check if modelFileName is relative to datadir or absolute 529 529 530 530 531 PRINTF(0)("================ LOADING MODEL %s, %f\n", modelFileName , scaling);532 533 if ( strcmp(modelFileName, ""))531 PRINTF(0)("================ LOADING MODEL %s, %f\n", modelFileName.c_str(), scaling); 532 533 if ( modelFileName != "" ) 534 534 { 535 535 loadModel( modelFileName, scaling); 536 536 PRINTF(0)("modelfilename: %s\n", getModel( 0 )->getName()); 537 537 } 538 delete[] modelFileName;539 538 540 539 /*SYNCHELP_READ_STRINGM( modelFileName ); … … 568 567 SYNCHELP_WRITE_FKT( PNode::readState, NWT_WE_PN_WRITESTATE ); 569 568 570 if ( getModel(0) && getModel(0)->getName() )571 { 572 char* name = (char*)(getModel( 0 )->getName());573 574 if ( ResourceManager::getInstance()->getDataDir() == name ) /// FIXME (do not know what to do here.)575 { 576 name += ResourceManager::getInstance()->getDataDir().size();569 if ( getModel(0) && getModel(0)->getName() != "" ) 570 { 571 std::string name = getModel( 0 )->getName(); 572 573 if ( name.find( ResourceManager::getInstance()->getDataDir() ) == 0 ) 574 { 575 name.erase(ResourceManager::getInstance()->getDataDir().size()); 577 576 } 578 577
Note: See TracChangeset
for help on using the changeset viewer.