Changeset 6634 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jan 21, 2006, 1:18:19 AM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r6624 r6634 505 505 { 506 506 PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE)); 507 // PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName()); 508 // assert( childNode != NULL ); 507 509 if (childNode != NULL) 510 { 508 511 this->addChild(childNode); 512 } 509 513 } 510 514 … … 1069 1073 SYNCHELP_READ_FLOAT( f3 ); 1070 1074 this->setRelCoor( f1, f2, f3 ); 1071 //this->setRelCoor( 5, 0, 0 ); 1072 1073 /*SYNCHELP_READ_FLOAT( f1 ); 1074 SYNCHELP_READ_FLOAT( f2 ); 1075 SYNCHELP_READ_FLOAT( f3 );*/ 1076 //this->setAbsCoor( f1, f2, f3 ); 1075 1077 1076 1078 1077 SYNCHELP_READ_FLOAT( f1 ); … … 1082 1081 this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) ); 1083 1082 1084 /*SYNCHELP_READ_FLOAT( f1 );1085 SYNCHELP_READ_FLOAT( f2 );1086 SYNCHELP_READ_FLOAT( f3 );1087 SYNCHELP_READ_FLOAT( f4 );*/1088 //this->setAbsDir( Quaternion( Vector(f2, f3, f4), f1 ) );1089 1090 1083 int n; 1091 1084 char * childName; 1092 1085 1086 PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]); 1093 1087 SYNCHELP_READ_INT( n ); 1088 PRINTF(0)("read %s:n=%d\n", this->getName(), n); 1094 1089 1095 1090 for (int i = 0; i<n; i++) 1096 1091 { 1097 1092 SYNCHELP_READ_STRINGM( childName ); 1098 //PRINTF(0)("childname= %s\n", childName);1093 PRINTF(0)("RCVD CHILD = %s\n", childName); 1099 1094 addChild( childName ); 1100 1095 delete childName; … … 1132 1127 SYNCHELP_WRITE_FLOAT( this->relCoordinate.z ); 1133 1128 1134 //PRINTF(0)("%s, %f, %f, %f\n", getClassName(), relCoordinate.x, relCoordinate.y, relCoordinate.z);1135 1136 /*SYNCHELP_WRITE_FLOAT( this->absCoordinate.x );1137 SYNCHELP_WRITE_FLOAT( this->absCoordinate.y );1138 SYNCHELP_WRITE_FLOAT( this->absCoordinate.z );*/1139 1140 //PRINTF(0)("%s, %f, %f, %f\n", getClassName(), absCoordinate.x, absCoordinate.y, absCoordinate.z);1141 1142 1129 SYNCHELP_WRITE_FLOAT( this->relDirection.w ); 1143 1130 SYNCHELP_WRITE_FLOAT( this->relDirection.v.x ); … … 1145 1132 SYNCHELP_WRITE_FLOAT( this->relDirection.v.z ); 1146 1133 1147 /*SYNCHELP_WRITE_FLOAT( this->absDirection.w );1148 SYNCHELP_WRITE_FLOAT( this->absDirection.v.x );1149 SYNCHELP_WRITE_FLOAT( this->absDirection.v.y );1150 SYNCHELP_WRITE_FLOAT( this->absDirection.v.z );*/1151 1152 1134 int n = children.size(); 1135 1136 //check if camera is in children 1137 for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1138 { 1139 if ( (*it)->isA(CL_CAMERA) ) 1140 n--; 1141 } 1142 PRINTF(0)("write %s:n=%d\n", this->getName(), n); 1153 1143 SYNCHELP_WRITE_INT( n ); 1144 PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]); 1154 1145 1155 1146 for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1156 1147 { 1157 SYNCHELP_WRITE_STRING( (*it)->getName() ); 1148 //dont add camera because there is only one camera attached to local player 1149 if ( !(*it)->isA(CL_CAMERA) ) 1150 { 1151 PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName()); 1152 SYNCHELP_WRITE_STRING( (*it)->getName() ); 1153 } 1158 1154 } 1159 1155 1160 1156 return SYNCHELP_WRITE_N; 1161 1157 } 1158 1159 #define __FLAG_COOR 1 1160 #define __FLAG_ROT 2 1161 1162 #define __OFFSET_POS 1 1163 #define __OFFSET_ROT 0.05 1164 1165 /** 1166 * Writes data from network containing information about the state which has changed 1167 * @param data pointer to data 1168 * @param length length of data 1169 * @param sender hostID of sender 1170 */ 1171 int PNode::writeSync( const byte * data, int length, int sender ) 1172 { 1173 SYNCHELP_READ_BEGIN(); 1174 1175 if ( this->getHostID()==this->getOwner() ) 1176 { 1177 return SYNCHELP_READ_N; 1178 } 1179 1180 byte flags = 0; 1181 SYNCHELP_READ_BYTE( flags ); 1182 //PRINTF(0)("%s::FLAGS = %d\n", this->getName(), flags); 1183 1184 float f1, f2, f3, f4; 1185 1186 if ( flags & __FLAG_COOR ) 1187 { 1188 SYNCHELP_READ_FLOAT( f1 ); 1189 SYNCHELP_READ_FLOAT( f2 ); 1190 SYNCHELP_READ_FLOAT( f3 ); 1191 PRINTF(0)("RCVD COOR: %f %f %f\n", f1, f2, f3); 1192 this->setRelCoor( f1, f2, f3 ); 1193 } 1194 1195 if ( flags & __FLAG_ROT ) 1196 { 1197 SYNCHELP_READ_FLOAT( f1 ); 1198 SYNCHELP_READ_FLOAT( f2 ); 1199 SYNCHELP_READ_FLOAT( f3 ); 1200 SYNCHELP_READ_FLOAT( f4 ); 1201 PRINTF(0)("RCVD QUAT: %f %f %f %f\n", f1, f2, f3, f4); 1202 //this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) ); 1203 Quaternion q; 1204 q.w = f1; 1205 q.v.x = f2; 1206 q.v.y = f3; 1207 q.v.z = f4; 1208 this->setAbsDir( q ); 1209 } 1210 1211 return SYNCHELP_READ_N; 1212 } 1213 1214 /** 1215 * data copied in data will bee sent to another host 1216 * @param data pointer to data 1217 * @param maxLength max length of data 1218 * @return the number of bytes writen 1219 */ 1220 int PNode::readSync( byte * data, int maxLength ) 1221 { 1222 SYNCHELP_WRITE_BEGIN(); 1223 1224 if ( this->getHostID()!=this->getOwner() ) 1225 { 1226 return SYNCHELP_WRITE_N; 1227 } 1228 1229 byte flags = 0; 1230 if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS || 1231 fabs( coory - relCoordinate.y ) > __OFFSET_POS || 1232 fabs( coorz - relCoordinate.z ) > __OFFSET_POS ) 1233 flags |= __FLAG_COOR; 1234 1235 if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT || 1236 fabs( rotx - absDirection.v.x ) > __OFFSET_ROT || 1237 fabs( roty - absDirection.v.y ) > __OFFSET_ROT || 1238 fabs( rotz - absDirection.v.z ) > __OFFSET_ROT ) 1239 flags |= __FLAG_ROT; 1240 1241 1242 SYNCHELP_WRITE_BYTE( flags ); 1243 //PRINTF(0)("FLAGS = %d\n", flags); 1244 1245 if ( flags & __FLAG_COOR ) 1246 { 1247 1248 PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z); 1249 1250 SYNCHELP_WRITE_FLOAT( this->relCoordinate.x ); 1251 SYNCHELP_WRITE_FLOAT( this->relCoordinate.y ); 1252 SYNCHELP_WRITE_FLOAT( this->relCoordinate.z ); 1253 1254 coorx = relCoordinate.x; 1255 coory = relCoordinate.y; 1256 coorz = relCoordinate.z; 1257 } 1258 1259 if ( flags & __FLAG_ROT ) 1260 { 1261 1262 PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z); 1263 1264 SYNCHELP_WRITE_FLOAT( this->absDirection.w ); 1265 SYNCHELP_WRITE_FLOAT( this->absDirection.v.x ); 1266 SYNCHELP_WRITE_FLOAT( this->absDirection.v.y ); 1267 SYNCHELP_WRITE_FLOAT( this->absDirection.v.z ); 1268 1269 rotw = absDirection.w; 1270 rotx = absDirection.v.x; 1271 roty = absDirection.v.y; 1272 rotz = absDirection.v.z; 1273 } 1274 1275 return SYNCHELP_WRITE_N; 1276 } -
trunk/src/lib/coord/p_node.h
r6616 r6634 186 186 int writeState(const byte* data, int length, int sender); 187 187 int readState(byte* data, int maxLength ); 188 int writeSync(const byte* data, int length, int sender); 189 int readSync(byte* data, int maxLength ); 188 190 189 191 private: … … 229 231 230 232 static PNode* nullParent; //!< The ROOT of the main PNode Tree. 233 234 private: 235 float coorx; 236 float coory; 237 float coorz; 238 239 float rotw; 240 float rotx; 241 float roty; 242 float rotz; 231 243 }; 232 244 -
trunk/src/lib/graphics/graphics_engine.cc
r6523 r6634 274 274 this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), " \n\t,"); 275 275 276 PRINT(4)("Running on : %s %s%s\n", vendor, renderer, version);276 PRINT(4)("Running on : vendor: %s, renderer: %s, version:%s\n", vendor, renderer, version); 277 277 PRINT(4)("Extensions:\n"); 278 278 if (this->hwExtensions != NULL) -
trunk/src/lib/graphics/importer/texture.cc
r6532 r6634 260 260 glBindTexture(target, texture); 261 261 262 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 262 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 263 glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT); 264 265 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/); 263 266 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 264 267 265 266 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT); 267 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT); 268 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority); 269 268 270 269 271 /* control the mipmap levels */ 270 // glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5);f 271 // glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 272 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, this->priority); 272 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); 273 glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); 273 274 274 275 /* build the Texture OpenGL V >= 1.1 */ … … 295 296 PRINTF(1)("Error while loading texture (mipmap generation), gluBuild2DMipmaps returned %i\n", errorCode); 296 297 298 // Deselect newly built texture, as we do not want to display with this texture. 297 299 if (target == GL_TEXTURE_2D) 298 300 glBindTexture(target, 0); 301 299 302 return texture; 300 303 } -
trunk/src/lib/lang/base_object.cc
r6517 r6634 224 224 SYNCHELP_WRITE_BEGIN(); 225 225 226 //PRINTF(0)("objectname = %s\n", this->objectName); 226 227 SYNCHELP_WRITE_STRING( this->objectName ); 227 228 -
trunk/src/lib/network/converter.cc
r6341 r6634 22 22 /* include your own header */ 23 23 #include "converter.h" 24 #include "shell_command.h" 25 26 #include <limits> 27 28 SHELL_COMMAND_STATIC(debug, Converter, Converter::debug); 24 29 25 30 … … 182 187 const int expmult = 8388608; //2^23 183 188 189 float Converter::getDenormConst() 190 { 191 const int exp = 126; 192 float result = 1.0f; 193 for (int i = 0; i < exp; i++) 194 result /= 2.0f; 195 return result; 196 } 197 184 198 /*! 185 199 * Converts a float value into a byte-array … … 189 203 byte* Converter::floatToByteArray(float x) 190 204 { 205 byte* result = new byte[4]; 206 floatToByteArray(x, result, 4); 207 return result; 208 /* 191 209 int mantisse = 0; 192 210 int exponent = 128; … … 201 219 sgn = 1; 202 220 203 float sub = 1; 204 while (sub < x) 205 { 206 sub *= 2; 221 if (x == 0) 222 { 223 exponent = 255; 224 mantisse = 0; 225 } 226 else 227 { 228 //if (x < getDenormConst()) 229 // printf("Denormalisiert!\n"); 230 //printf("DenormConst = %e", getDenormConst()); 231 232 float sub = 1; 233 while (sub < x) 234 { 235 sub *= 2; 236 exponent++; 237 } 238 239 while (x > 0) 240 { 241 if (x >= sub) 242 { 243 mantisse += 1; 244 x -= sub; 245 } 246 247 mantisse *= 2; 248 exponent--; 249 sub /= 2; 250 } 207 251 exponent++; 208 } 209 210 while (x > 0) 211 { 212 if (x >= sub) 213 { 214 mantisse += 1; 215 x -= sub; 216 } 217 218 mantisse *= 2; 219 exponent--; 220 sub /= 2; 221 } 222 exponent++; 223 mantisse /= 2; 224 while (mantisse < expmult) 225 { 226 mantisse *= 2; 227 exponent--; 228 } 229 230 //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 231 232 mantisse -= expmult; 252 mantisse /= 2; 253 254 printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent); 255 256 257 if (mantisse != 0) 258 { 259 while (mantisse < expmult) 260 { 261 mantisse *= 2; 262 exponent--; 263 } 264 265 mantisse -= expmult; 266 } 267 } 268 269 printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent); 270 233 271 234 272 int hx = mantisse + expmult * exponent; … … 238 276 239 277 return result; 278 */ 240 279 } 241 280 … … 248 287 float Converter::byteArrayToFloat(byte* a) 249 288 { 289 byte* h = new byte[4]; 290 float result = 0.0f; 291 byteArrayToFloat(a, &result); 292 return result; 293 /* 294 int hexp = a[2] + a[3] * 256; 295 int exponent = (hexp / 128) % 256; 296 250 297 int hmant = a[0] + a[1] * 256 + a[2] * 65536; 251 298 int mantisse = hmant % expmult; 299 if (mantisse == 0 && exponent == 255) 300 return 0; 301 252 302 mantisse += expmult; 253 254 int hexp = a[2] + a[3] * 256; 255 int exponent = (hexp / 128) % 256 - 128; 303 exponent -= 128; 304 256 305 257 306 int sgn; … … 261 310 sgn = 1; 262 311 263 //printf("mantisse = %i exponent = %i \n", mantisse, exponent);312 printf("ReConv: mantisse = %i exponent = %i \n", mantisse, exponent); 264 313 265 314 float emult = 1; … … 276 325 277 326 return result; 278 } 279 280 /*! 281 * Converts a float value into a byte-array 282 * @param x: The float which is to convert 283 * @return: A byte-array which accords the given float 284 */ 285 byte* Converter::_floatToByteArray(float x) 286 { 287 byte* p = (byte*)&x; 288 byte* result = new byte[4]; 289 for (int i = 0; i < 4; i++) 290 result[i] = p[i]; 291 return result; 292 } 293 294 295 /*! 296 * Converts a byte-array into a float value 297 * @param a: The byte-array which is to convert 298 * @return: A float value which accords the given byte-array 299 */ 300 float Converter::_byteArrayToFloat(byte* a) 301 { 302 float* p = (float*)a; 303 float result = *p; 304 return result; 327 */ 305 328 } 306 329 … … 310 333 * @return: A byte-array which accords the given float 311 334 */ 312 int Converter:: floatToByteArray(float x, byte* a, int length)335 int Converter::_floatToByteArray(float x, byte* a, int length) 313 336 { 314 337 if (length < FLOATSIZE) … … 319 342 320 343 //handle 0 else function will loop for ever 321 if ( x == 0 )344 /*if ( x == 0 ) 322 345 { 323 346 for ( int i = 0; i<FLOATSIZE; i++) 324 347 a[i] = 0; 325 348 return FLOATSIZE; 326 } 349 }*/ 327 350 328 351 int mantisse = 0; … … 338 361 sgn = 1; 339 362 340 float sub = 1; 341 while (sub < x) 342 { 343 sub *= 2; 363 if (x == 0) 364 { 365 exponent = 255; 366 mantisse = 0; 367 } 368 else 369 { 370 //if (x < getDenormConst()) 371 // printf("Denormalisiert!\n"); 372 //printf("DenormConst = %e", getDenormConst()); 373 374 float sub = 1; 375 while (sub < x) 376 { 377 sub *= 2; 378 exponent++; 379 } 380 381 while (x > 0) 382 { 383 if (x >= sub) 384 { 385 mantisse += 1; 386 x -= sub; 387 } 388 389 mantisse *= 2; 390 exponent--; 391 sub /= 2; 392 } 344 393 exponent++; 345 } 346 347 while (x > 0) 348 { 349 if (x >= sub) 350 { 351 mantisse += 1; 352 x -= sub; 353 } 354 355 mantisse *= 2; 356 exponent--; 357 sub /= 2; 358 } 359 exponent++; 360 mantisse /= 2; 361 while (mantisse < expmult) 362 { 363 mantisse *= 2; 364 exponent--; 365 } 366 367 //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 368 369 mantisse -= expmult; 394 mantisse /= 2; 395 396 397 /// printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent); 398 399 400 if (mantisse != 0) 401 { 402 while (mantisse < expmult) 403 { 404 mantisse *= 2; 405 exponent--; 406 } 407 408 mantisse -= expmult; 409 } 410 } 411 412 /// printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent); 413 370 414 371 415 int hx = mantisse + expmult * exponent; … … 374 418 a[3] += sgnadd; 375 419 420 421 // int hx = mantisse + expmult * exponent; 422 // byte* result = intToByteArray(hx); 423 // if (sgn == -1) 424 // result[3] += sgnadd; 425 376 426 return result; 377 427 } … … 383 433 * @return: A float value which accords the given byte-array 384 434 */ 385 int Converter:: byteArrayToFloat(const byte* a, float* x)386 { 387 //handle 0388 for (int i = 0; i<FLOATSIZE; i++)435 int Converter::_byteArrayToFloat(const byte* a, float* x) 436 { 437 //handle 0 438 /*for (int i = 0; i<FLOATSIZE; i++) 389 439 { 390 440 if (a[i]!=0) … … 395 445 return FLOATSIZE; 396 446 } 397 } 398 447 }*/ 448 449 int hexp = a[2] + a[3] * 256; 450 int exponent = (hexp / 128) % 256; 399 451 400 452 int hmant = a[0] + a[1] * 256 + a[2] * 65536; 401 453 int mantisse = hmant % expmult; 454 455 //handle 0 456 if (mantisse == 0 && exponent == 255) 457 { 458 *x = 0; 459 return FLOATSIZE; 460 } 461 402 462 mantisse += expmult; 403 404 int hexp = a[2] + a[3] * 256; 405 int exponent = (hexp / 128) % 256 - 128; 463 exponent -= 128; 464 406 465 407 466 int sgn; … … 411 470 sgn = 1; 412 471 413 //printf("mantisse = %i exponent = %i \n", mantisse, exponent);472 /// printf("ReConv: mantisse = %i exponent = %i \n", mantisse, exponent); 414 473 415 474 float emult = 1; … … 421 480 emult /= 2; 422 481 482 /* 483 float result = mantisse * emult; 484 if (sgn == -1) 485 result = -result; 486 487 return result; 488 */ 489 423 490 *x = mantisse * emult; 424 491 if (sgn == -1) … … 426 493 427 494 return FLOATSIZE; 495 } 496 497 /*! 498 * Converts a float value into a byte-array 499 * @param x: The float which is to convert 500 * @return: A byte-array which accords the given float 501 */ 502 int Converter::floatToByteArray(float x, byte* a, int length) 503 { 504 if ( length<4 ) 505 { 506 PRINTF(1)("Byte Array to small\n"); 507 return 0; 508 } 509 byte* p = (byte*)&x; 510 511 for (int i = 0; i < 4; i++) 512 a[i] = p[i]; 513 return 4; 514 } 515 516 517 /*! 518 * Converts a byte-array into a float value 519 * @param a: The byte-array which is to convert 520 * @return: A float value which accords the given byte-array 521 */ 522 int Converter::byteArrayToFloat(const byte* a, float* x) 523 { 524 *x = *((float*)a); 525 526 return 4; 428 527 } 429 528 … … 504 603 } 505 604 605 606 607 608 void Converter::floatTest(float x) 609 { 610 //float x = 8.0f; 611 //float x = numeric_limits<float>::infinity(); 612 613 printf("To Convert: %e\n", x); 614 615 byte* res = floatToByteArray(x); 616 for (int i = 0; i < 4; i++) 617 printf("%i ", res[i]); 618 printf("\n"); 619 620 float y = byteArrayToFloat(res); 621 printf("ReConvert: %e\n", y); 622 623 if (x == y) 624 printf("equal\n"); 625 else 626 printf("different\n"); 627 } 628 629 void Converter::debug() 630 { 631 printf("We rulez\n"); 632 633 //Denormalized? 634 //floatTest(-9.87624e-38f); 635 //floatTest(-9.87624e-37f); 636 //floatTest(-9.87624e-36f); 637 //floatTest(-9.87624e-35f); 638 639 /* 640 floatTest(14.7f); 641 floatTest(12.07e15f); 642 floatTest(0.0f); 643 floatTest(5.67e-15f); 644 */ 645 646 //floatTest(-18.0098f); 647 //floatTest(-24.07e23f); 648 //floatTest(-0.0f); 649 //floatTest(-5.67e-29f); 650 floatTest(-45.7e-32f); 651 floatTest(45.7e-33f); 652 floatTest(-45.7e-34f); 653 floatTest(45.7e-35f); 654 } -
trunk/src/lib/network/converter.h
r6341 r6634 9 9 /* include this file, it contains some default definitions */ 10 10 #include "netdefs.h" 11 11 12 12 13 /* include base_object.h since all classes are derived from this one */ … … 21 22 * a class that can convert int to byte-array and vice versa 22 23 */ 23 class Converter : public BaseObject24 class Converter : public BaseObject 24 25 { 25 26 public: … … 43 44 static float byteArrayToFloat(byte* a); 44 45 45 static byte* _floatToByteArray(float x); 46 static float _byteArrayToFloat(byte* a); 46 static int _floatToByteArray(float x, byte* a, int length); 47 static int _byteArrayToFloat(const byte* a, float* x); 48 49 50 static void debug(); 51 static void floatTest(float x); 52 static float getDenormConst(); 53 54 47 55 private: 48 56 Converter(); … … 50 58 }; 51 59 60 #undef byte 61 52 62 #endif /*_CONVERTER*/ -
trunk/src/lib/network/network_game_manager.cc
r6498 r6634 52 52 this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager"); 53 53 54 allOutBuffer.length = 0;55 56 allOutBuffer.maxLength = 10*1024;57 58 allOutBuffer.buffer = new byte[10*1024];59 60 54 newUniqueID = MAX_CONNECTIONS + 2; 61 55 … … 74 68 } 75 69 76 if ( allOutBuffer.buffer )77 delete allOutBuffer.buffer;78 70 } 79 71 … … 107 99 if ( b == CREATE_ENTITY ) 108 100 { 101 PRINTF(0)("CREATE_ENTITY\n"); 109 102 if ( !handleCreateEntity( i, data, length, sender ) ) 110 103 return i; … … 137 130 } 138 131 132 if ( b == REQUEST_ENTITY_LIST ) 133 { 134 sendEntityList( sender ); 135 continue; 136 } 137 139 138 if ( b == REQUEST_SYNC ) 140 139 { 141 140 if ( !handleRequestSync( i, data, length, sender ) ) 142 141 return i; 143 continue;144 }145 146 if ( b == REQUEST_ENTITY_LIST )147 {148 sendEntityList( sender );149 142 continue; 150 143 } … … 188 181 } 189 182 190 *reciever = 0; 191 int nbytes = allOutBuffer.length; 192 allOutBuffer.length = 0; 193 194 if ( nbytes <=0 ) 195 return 0; 196 197 if ( nbytes > maxLength ) 198 { 199 PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.length\n", nbytes, maxLength); 200 return 0; 201 } 202 203 memcpy( data, allOutBuffer.buffer, nbytes ); 204 return nbytes; 183 return 0; 205 184 } 206 185 … … 221 200 int NetworkGameManager::createEntity( ClassID classID, int owner ) 222 201 { 223 224 202 if ( this->isServer() ) 225 203 { … … 254 232 return NULL; 255 233 } 256 newUniqueID++;257 234 258 235 BaseObject * b = Factory::fabricate( element ); … … 268 245 { 269 246 Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); 270 s->setUniqueID( newUniqueID );247 s->setUniqueID( newUniqueID++ ); 271 248 s->setOwner( 0 ); 272 249 this->networkStream->connectSynchronizeable( *s ); … … 313 290 void NetworkGameManager::requestCreateEntity(ClassID classID) 314 291 { 315 if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_CREATE ) ) 316 return; 317 if ( !writeToClientBuffer( allOutBuffer, (int)classID ) ) 318 return; 292 for ( int i = 0; i<outBuffer.size(); i++) 293 { 294 if ( !this->networkStream->isUserIdActive( i ) ) 295 continue; 296 297 if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_CREATE ) ) 298 return; 299 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) 300 return; 301 } 319 302 } 320 303 … … 325 308 void NetworkGameManager::requestRemoveEntity(int uniqueID) 326 309 { 327 if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_REMOVE ) ) 328 return; 329 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 330 return; 310 for ( int i = 0; i<outBuffer.size(); i++) 311 { 312 if ( !this->networkStream->isUserIdActive( i ) ) 313 continue; 314 315 if ( !writeToClientBuffer( outBuffer[i], (byte)REQUEST_REMOVE ) ) 316 return; 317 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 318 return; 319 } 331 320 } 332 321 … … 338 327 int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner) 339 328 { 340 if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) ) 341 return -1; 342 if ( !writeToClientBuffer( allOutBuffer, (int)classID ) ) 343 return -1; 344 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 345 return -1; 346 if ( !writeToClientBuffer( allOutBuffer, owner ) ) 347 return -1; 329 for ( int i = 0; i<outBuffer.size(); i++) 330 { 331 if ( !this->networkStream->isUserIdActive( i ) ) 332 continue; 333 334 if ( !writeToClientBuffer( outBuffer[i], (byte)CREATE_ENTITY ) ) 335 return -1; 336 if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) 337 return -1; 338 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 339 return -1; 340 if ( !writeToClientBuffer( outBuffer[i], owner ) ) 341 return -1; 342 } 348 343 349 344 doCreateEntity( classID, uniqueID, owner ); … … 359 354 void NetworkGameManager::executeRemoveEntity(int uniqueID) 360 355 { 361 if ( !writeToClientBuffer( allOutBuffer, (byte)REMOVE_ENTITY ) ) 362 return; 363 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 364 return; 356 for ( int i = 0; i<outBuffer.size(); i++) 357 { 358 if ( !this->networkStream->isUserIdActive( i ) ) 359 continue; 360 361 if ( !writeToClientBuffer( outBuffer[i], (byte)REMOVE_ENTITY ) ) 362 return; 363 if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) 364 return; 365 } 365 366 366 367 doRemoveEntity(uniqueID); … … 406 407 while ( it != e ) 407 408 { 408 409 PRINTF(5)("SENDING ENTITY %s id %d\n", (*it)->getClassName(), (*it)->getUniqueID() ); 409 410 if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) ) 410 411 return; … … 426 427 bool NetworkGameManager::signalNewPlayer(int userId) 427 428 { 429 if ( userId >= outBuffer.size() ) 430 resizeBufferVector( userId ); 428 431 429 432 /* create new playable for Player*/ … … 483 486 484 487 //HACK: hack to prevent collision 485 if ( b->isA(CL_WORLD_ENTITY) )488 if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) ) 486 489 { 487 490 if ( NetworkManager::getInstance()->getHostID()!=0 ) … … 489 492 static Vector pos = Vector(1000.0, 1000.0, 1000.0); 490 493 PNode *p = dynamic_cast<PNode*>(b); 491 p->set RelCoor(pos);492 p->updateNode(0);494 p->setAbsCoor(pos); 495 //p->updateNode(0); 493 496 pos += Vector(1000.0, 1000.0, 1000.0); 494 497 } … … 596 599 597 600 Playable *p = NULL; 601 Synchronizeable *s = NULL; 598 602 599 603 for ( ; it !=networkStream->getSyncEnd(); it++ ) … … 601 605 if ( (*it)->getUniqueID()==uniqueID ) 602 606 { 607 if ( (*it)->isA( CL_SYNCHRONIZEABLE ) ) 608 { 609 s = dynamic_cast<Synchronizeable*>(*it); 610 } 603 611 if ( (*it)->isA( CL_PLAYABLE ) ) 604 612 { … … 614 622 Player* player = State::getPlayer(); 615 623 assert(p != NULL); 624 assert(s != NULL); 616 625 assert(player != NULL); 626 627 s->setIsOutOfSync( true ); 628 629 PRINTF(0)("uniqueID = %d\n", s->getUniqueID()); 617 630 618 631 player->setControllable(p); … … 871 884 void NetworkGameManager::sync( int uniqueID, int owner ) 872 885 { 873 if ( owner==this->getHostID() )874 return;886 /*if ( owner==this->getHostID() ) 887 return;*/ 875 888 876 889 if ( !isServer() ) -
trunk/src/lib/network/network_game_manager.h
r6498 r6634 122 122 private: 123 123 std::vector<clientBuffer> outBuffer; 124 clientBuffer allOutBuffer;124 //clientBuffer allOutBuffer; 125 125 static NetworkGameManager* singletonRef; 126 126 -
trunk/src/lib/network/network_socket.cc
r6341 r6634 398 398 bool NetworkSocket::writePacket( byte * data, int length ) 399 399 { 400 PRINTF(5)("NetworkSocket::writePacket()\n"); 400 PRINTF(5)("NetworkSocket::writePacket() size=%d\n", length); 401 402 if ( length > 1024 ) 403 PRINTF(2)("WARNING SENDING BIG PACKET SIZE = %d\n", length); 401 404 402 405 byte blen[INTSIZE]; -
trunk/src/lib/network/network_stream.cc
r6498 r6634 78 78 this->connectionMonitor = new ConnectionMonitor(); 79 79 this->networkSockets.push_back( NULL ); 80 this->networkSockets[0] = NULL; //TODO: remove this 80 81 this->handshakes.push_back( NULL ); 81 82 this->bActive = true; … … 266 267 if ( networkSockets[i] != NULL ) 267 268 { 268 PRINTF(5)("write %d bytes to socket %d\n", dataLength, reciever);269 PRINTF(5)("write %d bytes to socket %d\n", dataLength, i); 269 270 networkSockets[i]->writePacket(downBuffer, dataLength); 270 271 } … … 310 311 if ( (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i) != header.length ) 311 312 { 312 PRINTF(1)("%s did not read all the data !\n", (*it)->getClassName());313 PRINTF(1)("%s did not read all the data id = %d!\n", (*it)->getClassName(), (*it)->getUniqueID()); 313 314 break; 314 315 } -
trunk/src/lib/network/network_stream.h
r6341 r6634 55 55 inline int getSyncCount(){ return synchronizeables.size(); } 56 56 57 inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; } 58 57 59 private: 58 60 NetworkProtocol* networkProtocol; -
trunk/src/lib/sound/sound_source.h
r5930 r6634 44 44 ALuint sourceID; //!< The ID of the Source 45 45 const SoundBuffer* buffer; //!< The buffer to play in this source. 46 const PNode* sourceNode; //!< The SourceNode represent ethe position/velocity... of this source.46 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 47 47 }; 48 48 #endif /* _SOUND_SOURCE_H */
Note: See TracChangeset
for help on using the changeset viewer.