00001
00033 #include "linden_common.h"
00034
00035 #include "partsyspacket.h"
00036 #include "imageids.h"
00037
00038
00039 void gSetInitDataDefaults(LLPartInitData *setMe)
00040 {
00041 U32 i;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 setMe->bounce_b = 1.0f;
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 for(i = 0; i < 3; i++)
00069 {
00070 setMe->diffEqAlpha[i] = 0.0f;
00071 setMe->diffEqScale[i] = 0.0f;
00072 }
00073
00074 setMe->scale_range[0] = 1.00f;
00075 setMe->scale_range[1] = 5.00f;
00076 setMe->scale_range[2] = setMe->scale_range[3] = 0.0f;
00077
00078 setMe->alpha_range[0] = setMe->alpha_range[1] = 1.0f;
00079 setMe->alpha_range[2] = setMe->alpha_range[3] = 0.0f;
00080
00081 setMe->vel_offset[0] = 0.0f;
00082 setMe->vel_offset[1] = 0.0f;
00083 setMe->vel_offset[2] = 0.0f;
00084
00085
00086 setMe->mDistBeginFadeout = 256.0f;
00087 setMe->mDistEndFadeout = 1.414f * 512.0f;
00088
00089
00090 setMe->mImageUuid = IMG_SHOT;
00091
00092 for(i = 0; i < 8; i++)
00093 {
00094 setMe->mFlags[i] = 0x00;
00095 }
00096
00097 setMe->createMe = TRUE;
00098
00099 setMe->maxParticles = 25;
00100 setMe->initialParticles = 25;
00101
00102
00103
00104 setMe->mFlags[PART_SYS_ACTION_BYTE] = PART_SYS_AFFECTED_BY_WIND | PART_SYS_AFFECTED_BY_GRAVITY | PART_SYS_DISTANCE_DEATH;
00105 setMe->mFlags[PART_SYS_KILL_BYTE] = PART_SYS_DISTANCE_DEATH + PART_SYS_TIME_DEATH;
00106
00107 setMe->killPlaneNormal[0] = 0.0f;setMe->killPlaneNormal[1] = 0.0f;setMe->killPlaneNormal[2] = 1.0f;
00108 setMe->killPlaneZ = 0.0f;
00109 setMe->bouncePlaneNormal[0] = 0.0f;setMe->bouncePlaneNormal[1] = 0.0f;setMe->bouncePlaneNormal[2] = 1.0f;
00110 setMe->bouncePlaneZ = 0.0f;
00111 setMe->spawnRange = 1.0f;
00112 setMe->spawnFrequency = 0.0f;
00113 setMe->spawnFreqencyRange = 0.0f;
00114 setMe->spawnDirection[0] = 0.0f;setMe->spawnDirection[1] = 0.0f;setMe->spawnDirection[2] = 1.0f;
00115 setMe->spawnDirectionRange = 1.0f;
00116 setMe->spawnVelocity = 0.75f;
00117 setMe->spawnVelocityRange = 0.25f;
00118 setMe->speedLimit = 1.0f;
00119
00120 setMe->windWeight = 0.5f;
00121 setMe->currentGravity[0] = 0.0f;setMe->currentGravity[1] = 0.0f;setMe->currentGravity[2] = -9.81f;
00122
00123
00124 setMe->gravityWeight = 0.5f;
00125 setMe->globalLifetime = 0.0f;
00126 setMe->individualLifetime = 5.0f;
00127 setMe->individualLifetimeRange = 1.0f;
00128 setMe->alphaDecay = 1.0f;
00129 setMe->scaleDecay = 0.0f;
00130 setMe->distanceDeath = 10.0f;
00131 setMe->dampMotionFactor = 0.0f;
00132
00133 setMe->windDiffusionFactor[0] = 0.0f;
00134 setMe->windDiffusionFactor[1] = 0.0f;
00135 setMe->windDiffusionFactor[2] = 0.0f;
00136 }
00137
00138 LLPartSysCompressedPacket::LLPartSysCompressedPacket()
00139 {
00140
00141 for(int i = 0; i < MAX_PART_SYS_PACKET_SIZE; i++)
00142 {
00143 mData[i] = '\0';
00144 }
00145
00146 gSetInitDataDefaults(&mDefaults);
00147 }
00148
00149 LLPartSysCompressedPacket::~LLPartSysCompressedPacket()
00150 {
00151
00152 }
00153
00154 void LLPartSysCompressedPacket::writeFlagByte(LLPartInitData *in)
00155 {
00156 mData[0] = mData[1] = mData[2] = '\0';
00157
00158 U32 i;
00159
00160
00161
00162
00163
00164
00165
00166
00167 if(in->killPlaneZ != mDefaults.killPlaneZ ||
00168 in->killPlaneNormal[0] != mDefaults.killPlaneNormal[0] ||
00169 in->killPlaneNormal[1] != mDefaults.killPlaneNormal[1] ||
00170 in->killPlaneNormal[2] != mDefaults.killPlaneNormal[2] ||
00171 in->distanceDeath != mDefaults.distanceDeath)
00172 {
00173 mData[0] |= PART_SYS_KILL_P_MASK;
00174 }
00175
00176
00177
00178 if(in->bouncePlaneZ != mDefaults.bouncePlaneZ ||
00179 in->bouncePlaneNormal[0] != mDefaults.bouncePlaneNormal[0] ||
00180 in->bouncePlaneNormal[1] != mDefaults.bouncePlaneNormal[1] ||
00181 in->bouncePlaneNormal[2] != mDefaults.bouncePlaneNormal[2])
00182 {
00183 mData[0] |= PART_SYS_BOUNCE_P_MASK;
00184 }
00185
00186 if(in->bounce_b != mDefaults.bounce_b)
00187 {
00188 mData[0] |= PART_SYS_BOUNCE_B_MASK;
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 if(in->diffEqAlpha[0] != mDefaults.diffEqAlpha[0] ||
00208 in->diffEqAlpha[1] != mDefaults.diffEqAlpha[1] ||
00209 in->diffEqAlpha[2] != mDefaults.diffEqAlpha[2] ||
00210 in->diffEqScale[0] != mDefaults.diffEqScale[0] ||
00211 in->diffEqScale[1] != mDefaults.diffEqScale[1] ||
00212 in->diffEqScale[2] != mDefaults.diffEqScale[2])
00213 {
00214 mData[0] |= PART_SYS_ALPHA_SCALE_DIFF_MASK;
00215 }
00216
00217
00218 if(in->scale_range[0] != mDefaults.scale_range[0] ||
00219 in->scale_range[1] != mDefaults.scale_range[1] ||
00220 in->scale_range[2] != mDefaults.scale_range[2] ||
00221 in->scale_range[3] != mDefaults.scale_range[3])
00222 {
00223 mData[0] |= PART_SYS_SCALE_RANGE_MASK;
00224 }
00225
00226
00227 if(in->alpha_range[0] != mDefaults.alpha_range[0] ||
00228 in->alpha_range[1] != mDefaults.alpha_range[1] ||
00229 in->alpha_range[2] != mDefaults.alpha_range[2] ||
00230 in->alpha_range[3] != mDefaults.alpha_range[3])
00231 {
00232 mData[2] |= PART_SYS_BYTE_3_ALPHA_MASK;
00233 }
00234
00235 if(in->vel_offset[0] != mDefaults.vel_offset[0] ||
00236 in->vel_offset[1] != mDefaults.vel_offset[1] ||
00237 in->vel_offset[2] != mDefaults.vel_offset[2])
00238 {
00239 mData[0] |= PART_SYS_VEL_OFFSET_MASK;
00240 }
00241
00242
00243 if(in->mImageUuid != mDefaults.mImageUuid)
00244 {
00245 mData[0] |= PART_SYS_M_IMAGE_UUID_MASK;
00246 }
00247
00248 for( i = 0; i < 8; i++)
00249 {
00250 if(in->mFlags[i])
00251 {
00252 mData[1] |= 1<<i;
00253
00254 }
00255 }
00256
00257
00258 if(in->spawnRange != mDefaults.spawnRange ||
00259 in->spawnFrequency != mDefaults.spawnFrequency ||
00260 in->spawnFreqencyRange != mDefaults.spawnFreqencyRange ||
00261 in->spawnDirection[0] != mDefaults.spawnDirection[0] ||
00262 in->spawnDirection[1] != mDefaults.spawnDirection[1] ||
00263 in->spawnDirection[2] != mDefaults.spawnDirection[2] ||
00264 in->spawnDirectionRange != mDefaults.spawnDirectionRange ||
00265 in->spawnVelocity != mDefaults.spawnVelocity ||
00266 in->spawnVelocityRange != mDefaults.spawnVelocityRange)
00267 {
00268 mData[3] |= PART_SYS_BYTE_SPAWN_MASK;
00269 }
00270
00271
00272 if(in->windWeight != mDefaults.windWeight ||
00273 in->currentGravity[0] != mDefaults.currentGravity[0] ||
00274 in->currentGravity[1] != mDefaults.currentGravity[1] ||
00275 in->currentGravity[2] != mDefaults.currentGravity[2] ||
00276 in->gravityWeight != mDefaults.gravityWeight)
00277 {
00278 mData[3] |= PART_SYS_BYTE_ENVIRONMENT_MASK;
00279 }
00280
00281
00282 if(in->globalLifetime != mDefaults.globalLifetime ||
00283 in->individualLifetime != mDefaults.individualLifetime ||
00284 in->individualLifetimeRange != mDefaults.individualLifetimeRange)
00285 {
00286 mData[3] |= PART_SYS_BYTE_LIFESPAN_MASK;
00287 }
00288
00289
00290 if(in->speedLimit != mDefaults.speedLimit ||
00291 in->alphaDecay != mDefaults.alphaDecay ||
00292 in->scaleDecay != mDefaults.scaleDecay ||
00293 in->dampMotionFactor != mDefaults.dampMotionFactor)
00294 {
00295 mData[3] |= PART_SYS_BYTE_DECAY_DAMP_MASK;
00296 }
00297
00298 if(in->windDiffusionFactor[0] != mDefaults.windDiffusionFactor[0] ||
00299 in->windDiffusionFactor[1] != mDefaults.windDiffusionFactor[1] ||
00300 in->windDiffusionFactor[2] != mDefaults.windDiffusionFactor[2])
00301 {
00302 mData[3] |= PART_SYS_BYTE_WIND_DIFF_MASK;
00303 }
00304 }
00305
00306 F32 floatFromTwoBytes(S8 bMant, S8 bExp)
00307 {
00308 F32 result = bMant;
00309 while(bExp > 0)
00310 {
00311 result *= 2.0f;
00312 bExp--;
00313 }
00314 while(bExp < 0)
00315 {
00316 result *= 0.5f;
00317 bExp++;
00318 }
00319 return result;
00320 }
00321
00322 void twoBytesFromFloat(F32 fIn, S8 &bMant, S8 &bExp)
00323 {
00324 bExp = 0;
00325 if(fIn > 127.0f)
00326 {
00327 fIn = 127.0f;
00328 }
00329 if(fIn < -127.0f)
00330 {
00331 fIn = -127.0f;
00332 }
00333 while(fIn < 64 && fIn > -64 && bExp > -127)
00334 {
00335 fIn *= 2.0f;
00336 bExp--;
00337 }
00338 while((fIn > 128 || fIn < -128) && bExp < 127)
00339 {
00340 fIn *= 0.5f;
00341 bExp++;
00342 }
00343 bMant = (S8)fIn;
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 U32 LLPartSysCompressedPacket::writeKill_p(LLPartInitData *in, U32 startByte)
00384 {
00385 S8 bMant, bExp;
00386
00387 twoBytesFromFloat(in->killPlaneNormal[0], bMant, bExp);
00388 mData[startByte++] = bMant;
00389 mData[startByte++] = bExp;
00390 twoBytesFromFloat(in->killPlaneNormal[1], bMant, bExp);
00391 mData[startByte++] = bMant;
00392 mData[startByte++] = bExp;
00393 twoBytesFromFloat(in->killPlaneNormal[2], bMant, bExp);
00394 mData[startByte++] = bMant;
00395 mData[startByte++] = bExp;
00396
00397 twoBytesFromFloat(in->killPlaneZ, bMant, bExp);
00398 mData[startByte++] = bMant;
00399 mData[startByte++] = bExp;
00400 twoBytesFromFloat(in->distanceDeath, bMant, bExp);
00401 mData[startByte++] = bMant;
00402 mData[startByte++] = bExp;
00403
00404 return startByte;
00405 }
00406
00407 U32 LLPartSysCompressedPacket::writeBounce_p(LLPartInitData *in, U32 startByte)
00408 {
00409 S8 bMant, bExp;
00410
00411 twoBytesFromFloat(in->bouncePlaneNormal[0], bMant, bExp);
00412 mData[startByte++] = bMant;
00413 mData[startByte++] = bExp;
00414 twoBytesFromFloat(in->bouncePlaneNormal[1], bMant, bExp);
00415 mData[startByte++] = bMant;
00416 mData[startByte++] = bExp;
00417 twoBytesFromFloat(in->bouncePlaneNormal[2], bMant, bExp);
00418 mData[startByte++] = bMant;
00419 mData[startByte++] = bExp;
00420
00421
00422 twoBytesFromFloat(in->bouncePlaneZ, bMant, bExp);
00423 mData[startByte++] = bMant;
00424 mData[startByte++] = bExp;
00425
00426 return startByte;
00427 }
00428
00429 U32 LLPartSysCompressedPacket::writeBounce_b(LLPartInitData *in, U32 startByte)
00430 {
00431 S8 bMant, bExp;
00432 twoBytesFromFloat(in->bounce_b, bMant, bExp);
00433 mData[startByte++] = bMant;
00434 mData[startByte++] = bExp;
00435 return startByte;
00436 }
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 U32 LLPartSysCompressedPacket::writeAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte)
00463 {
00464 S8 bExp, bMant;
00465 int i;
00466 for(i = 0; i < 3; i++)
00467 {
00468 twoBytesFromFloat(in->diffEqAlpha[i], bMant, bExp);
00469 mData[startByte++] = bMant;
00470 mData[startByte++] = bExp;
00471 }
00472 for(i = 0; i < 3; i++)
00473 {
00474 twoBytesFromFloat(in->diffEqScale[i], bMant, bExp);
00475 mData[startByte++] = bMant;
00476 mData[startByte++] = bExp;
00477 }
00478 return startByte;
00479 }
00480
00481 U32 LLPartSysCompressedPacket::writeScale_range(LLPartInitData *in, U32 startByte)
00482 {
00483 S8 bExp, bMant;
00484 int i;
00485 for(i = 0; i < 4; i++)
00486 {
00487 twoBytesFromFloat(in->scale_range[i], bMant, bExp);
00488 mData[startByte++] = bMant;
00489 mData[startByte++] = bExp;
00490 }
00491 return startByte;
00492 }
00493
00494
00495 U32 LLPartSysCompressedPacket::writeAlpha_range(LLPartInitData *in, U32 startByte)
00496 {
00497 S8 bExp, bMant;
00498 int i;
00499 for(i = 0; i < 4; i++)
00500 {
00501 twoBytesFromFloat(in->alpha_range[i], bMant, bExp);
00502 mData[startByte++] = bMant;
00503 mData[startByte++] = bExp;
00504 }
00505 return startByte;
00506 }
00507
00508 U32 LLPartSysCompressedPacket::writeVelocityOffset(LLPartInitData *in, U32 startByte)
00509 {
00510 S8 bExp, bMant;
00511 int i;
00512 for(i = 0; i < 3; i++)
00513 {
00514 twoBytesFromFloat(in->vel_offset[i], bMant, bExp);
00515 mData[startByte++] = bMant;
00516 mData[startByte++] = bExp;
00517 }
00518 return startByte;
00519 }
00520
00521 U32 LLPartSysCompressedPacket::writeUUID(LLPartInitData *in, U32 startByte)
00522 {
00523 U8 * bufPtr = mData + startByte;
00524 if(in->mImageUuid == IMG_SHOT) {
00525 mData[startByte++] = 0x01;
00526 return startByte;
00527 }
00528
00529 if(in->mImageUuid == IMG_SPARK) {
00530 mData[startByte++] = 0x02;
00531 return startByte;
00532 }
00533
00534
00535 if(in->mImageUuid == IMG_BIG_EXPLOSION_1) {
00536 mData[startByte++] = 0x03;
00537 return startByte;
00538 }
00539
00540 if(in->mImageUuid == IMG_BIG_EXPLOSION_2) {
00541 mData[startByte++] = 0x04;
00542 return startByte;
00543 }
00544
00545
00546 if(in->mImageUuid == IMG_SMOKE_POOF) {
00547 mData[startByte++] = 0x05;
00548 return startByte;
00549 }
00550
00551 if(in->mImageUuid == IMG_FIRE) {
00552 mData[startByte++] = 0x06;
00553 return startByte;
00554 }
00555
00556
00557 if(in->mImageUuid == IMG_EXPLOSION) {
00558 mData[startByte++] = 0x07;
00559 return startByte;
00560 }
00561
00562 if(in->mImageUuid == IMG_EXPLOSION_2) {
00563 mData[startByte++] = 0x08;
00564 return startByte;
00565 }
00566
00567
00568 if(in->mImageUuid == IMG_EXPLOSION_3) {
00569 mData[startByte++] = 0x09;
00570 return startByte;
00571 }
00572
00573 if(in->mImageUuid == IMG_EXPLOSION_4) {
00574 mData[startByte++] = 0x0A;
00575 return startByte;
00576 }
00577
00578 mData[startByte++] = 0x00;
00579
00580 memcpy(bufPtr, in->mImageUuid.mData, 16);
00581 return (startByte+16);
00582 }
00583
00584 U32 LLPartSysCompressedPacket::writeSpawn(LLPartInitData *in, U32 startByte)
00585 {
00586 S8 bExp, bMant;
00587 int i;
00588
00589 twoBytesFromFloat(in->spawnRange, bMant, bExp);
00590 mData[startByte++] = bMant;
00591 mData[startByte++] = bExp;
00592 twoBytesFromFloat(in->spawnFrequency, bMant, bExp);
00593 mData[startByte++] = bMant;
00594 mData[startByte++] = bExp;
00595 twoBytesFromFloat(in->spawnFreqencyRange, bMant, bExp);
00596 mData[startByte++] = bMant;
00597 mData[startByte++] = bExp;
00598
00599
00600
00601 for(i = 0; i < 3; i++)
00602 {
00603 twoBytesFromFloat(in->spawnDirection[i], bMant, bExp);
00604 mData[startByte++] = bMant;
00605 mData[startByte++] = bExp;
00606 }
00607
00608 twoBytesFromFloat(in->spawnDirectionRange, bMant, bExp);
00609 mData[startByte++] = bMant;
00610 mData[startByte++] = bExp;
00611 twoBytesFromFloat(in->spawnVelocity, bMant, bExp);
00612 mData[startByte++] = bMant;
00613 mData[startByte++] = bExp;
00614 twoBytesFromFloat(in->spawnVelocityRange, bMant, bExp);
00615 mData[startByte++] = bMant;
00616 mData[startByte++] = bExp;
00617
00618 return startByte;
00619 }
00620
00621 U32 LLPartSysCompressedPacket::writeEnvironment(LLPartInitData *in, U32 startByte)
00622 {
00623 S8 bExp, bMant;
00624 int i;
00625
00626 twoBytesFromFloat(in->windWeight, bMant, bExp);
00627 mData[startByte++] = bMant;
00628 mData[startByte++] = bExp;
00629
00630 for(i = 0; i < 3; i++)
00631 {
00632 twoBytesFromFloat(in->currentGravity[i], bMant, bExp);
00633 mData[startByte++] = bMant;
00634 mData[startByte++] = bExp;
00635 }
00636
00637 twoBytesFromFloat(in->gravityWeight, bMant, bExp);
00638 mData[startByte++] = bMant;
00639 mData[startByte++] = bExp;
00640 return startByte;
00641 }
00642
00643 U32 LLPartSysCompressedPacket::writeLifespan(LLPartInitData *in, U32 startByte)
00644 {
00645 S8 bExp, bMant;
00646
00647 twoBytesFromFloat(in->globalLifetime, bMant, bExp);
00648 mData[startByte++] = bMant;
00649 mData[startByte++] = bExp;
00650
00651 twoBytesFromFloat(in->individualLifetime, bMant, bExp);
00652 mData[startByte++] = bMant;
00653 mData[startByte++] = bExp;
00654
00655 twoBytesFromFloat(in->individualLifetimeRange, bMant, bExp);
00656 mData[startByte++] = bMant;
00657 mData[startByte++] = bExp;
00658
00659 return startByte;
00660 }
00661
00662
00663 U32 LLPartSysCompressedPacket::writeDecayDamp(LLPartInitData *in, U32 startByte)
00664 {
00665 S8 bExp, bMant;
00666
00667 twoBytesFromFloat(in->speedLimit, bMant, bExp);
00668 mData[startByte++] = bMant;
00669 mData[startByte++] = bExp;
00670
00671 twoBytesFromFloat(in->alphaDecay, bMant, bExp);
00672 mData[startByte++] = bMant;
00673 mData[startByte++] = bExp;
00674
00675 twoBytesFromFloat(in->scaleDecay, bMant, bExp);
00676 mData[startByte++] = bMant;
00677 mData[startByte++] = bExp;
00678
00679 twoBytesFromFloat(in->dampMotionFactor, bMant, bExp);
00680 mData[startByte++] = bMant;
00681 mData[startByte++] = bExp;
00682
00683 return startByte;
00684 }
00685
00686 U32 LLPartSysCompressedPacket::writeWindDiffusionFactor(LLPartInitData *in, U32 startByte)
00687 {
00688 S8 bExp, bMant;
00689
00690 twoBytesFromFloat(in->windDiffusionFactor[0], bMant, bExp);
00691 mData[startByte++] = bMant;
00692 mData[startByte++] = bExp;
00693
00694 twoBytesFromFloat(in->windDiffusionFactor[1], bMant, bExp);
00695 mData[startByte++] = bMant;
00696 mData[startByte++] = bExp;
00697
00698 twoBytesFromFloat(in->windDiffusionFactor[2], bMant, bExp);
00699 mData[startByte++] = bMant;
00700 mData[startByte++] = bExp;
00701
00702 return startByte;
00703 }
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746 U32 LLPartSysCompressedPacket::readKill_p(LLPartInitData *in, U32 startByte)
00747 {
00748 S8 bMant, bExp;
00749
00750 bMant = mData[startByte++];
00751 bExp = mData[startByte++];
00752 in->killPlaneNormal[0] = floatFromTwoBytes(bMant, bExp);
00753 bMant = mData[startByte++];
00754 bExp = mData[startByte++];
00755 in->killPlaneNormal[1] = floatFromTwoBytes(bMant, bExp);
00756 bMant = mData[startByte++];
00757 bExp = mData[startByte++];
00758 in->killPlaneNormal[2] = floatFromTwoBytes(bMant, bExp);
00759
00760 bMant = mData[startByte++];
00761 bExp = mData[startByte++];
00762 in->killPlaneZ = floatFromTwoBytes(bMant, bExp);
00763 bMant = mData[startByte++];
00764 bExp = mData[startByte++];
00765 in->distanceDeath = floatFromTwoBytes(bMant, bExp);
00766
00767 return startByte;
00768 }
00769
00770 U32 LLPartSysCompressedPacket::readBounce_p(LLPartInitData *in, U32 startByte)
00771 {
00772
00773 S8 bMant, bExp;
00774
00775 bMant = mData[startByte++];
00776 bExp = mData[startByte++];
00777 in->bouncePlaneNormal[0] = floatFromTwoBytes(bMant, bExp);
00778 bMant = mData[startByte++];
00779 bExp = mData[startByte++];
00780 in->bouncePlaneNormal[1] = floatFromTwoBytes(bMant, bExp);
00781 bMant = mData[startByte++];
00782 bExp = mData[startByte++];
00783 in->bouncePlaneNormal[2] = floatFromTwoBytes(bMant, bExp);
00784
00785 bMant = mData[startByte++];
00786 bExp = mData[startByte++];
00787 in->bouncePlaneZ = floatFromTwoBytes(bMant, bExp);
00788
00789 return startByte;
00790 }
00791
00792 U32 LLPartSysCompressedPacket::readBounce_b(LLPartInitData *in, U32 startByte)
00793 {
00794 S8 bMant, bExp;
00795 bMant = mData[startByte++];
00796 bExp = mData[startByte++];
00797 in->bounce_b = floatFromTwoBytes(bMant, bExp);
00798 return startByte;
00799 }
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 U32 LLPartSysCompressedPacket::readAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte)
00829 {
00830 int i;
00831 S8 bMant, bExp;
00832 for(i = 0; i < 3; i++)
00833 {
00834 bMant = mData[startByte++];
00835 bExp = mData[startByte++];
00836 in->diffEqAlpha[i] = floatFromTwoBytes(bMant, bExp);
00837 }
00838 for(i = 0; i < 3; i++)
00839 {
00840 bMant = mData[startByte++];
00841 bExp = mData[startByte++];
00842 in->diffEqScale[i] = floatFromTwoBytes(bMant, bExp);
00843 }
00844 return startByte;
00845 }
00846
00847 U32 LLPartSysCompressedPacket::readAlpha_range(LLPartInitData *in, U32 startByte)
00848 {
00849 int i;
00850 S8 bMant, bExp;
00851 for(i = 0; i < 4; i++)
00852 {
00853 bMant = mData[startByte++];
00854 bExp = mData[startByte++];
00855 in->alpha_range[i] = floatFromTwoBytes(bMant, bExp);
00856 }
00857 return startByte;
00858 }
00859
00860 U32 LLPartSysCompressedPacket::readScale_range(LLPartInitData *in, U32 startByte)
00861 {
00862 int i;
00863 S8 bMant, bExp;
00864 for(i = 0; i < 4; i++)
00865 {
00866 bMant = mData[startByte++];
00867 bExp = mData[startByte++];
00868 in->scale_range[i] = floatFromTwoBytes(bMant, bExp);
00869 }
00870 return startByte;
00871 }
00872
00873 U32 LLPartSysCompressedPacket::readVelocityOffset(LLPartInitData *in, U32 startByte)
00874 {
00875 int i;
00876 S8 bMant, bExp;
00877 for(i = 0; i < 3; i++)
00878 {
00879 bMant = mData[startByte++];
00880 bExp = mData[startByte++];
00881 in->vel_offset[i] = floatFromTwoBytes(bMant, bExp);
00882 }
00883 return startByte;
00884 }
00885
00886 U32 LLPartSysCompressedPacket::readUUID(LLPartInitData *in, U32 startByte)
00887 {
00888 U8 * bufPtr = mData + startByte;
00889
00890 if(mData[startByte] == 0x01)
00891 {
00892 in->mImageUuid = IMG_SHOT;
00893 return startByte+1;
00894 }
00895 if(mData[startByte] == 0x02)
00896 {
00897 in->mImageUuid = IMG_SPARK;
00898 return startByte+1;
00899 }
00900 if(mData[startByte] == 0x03)
00901 {
00902 in->mImageUuid = IMG_BIG_EXPLOSION_1;
00903 return startByte+1;
00904 }
00905 if(mData[startByte] == 0x04)
00906 {
00907 in->mImageUuid = IMG_BIG_EXPLOSION_2;
00908 return startByte+1;
00909 }
00910 if(mData[startByte] == 0x05)
00911 {
00912 in->mImageUuid = IMG_SMOKE_POOF;
00913 return startByte+1;
00914 }
00915 if(mData[startByte] == 0x06)
00916 {
00917 in->mImageUuid = IMG_FIRE;
00918 return startByte+1;
00919 }
00920 if(mData[startByte] == 0x07)
00921 {
00922 in->mImageUuid = IMG_EXPLOSION;
00923 return startByte+1;
00924 }
00925 if(mData[startByte] == 0x08)
00926 {
00927 in->mImageUuid = IMG_EXPLOSION_2;
00928 return startByte+1;
00929 }
00930 if(mData[startByte] == 0x09)
00931 {
00932 in->mImageUuid = IMG_EXPLOSION_3;
00933 return startByte+1;
00934 }
00935 if(mData[startByte] == 0x0A)
00936 {
00937 in->mImageUuid = IMG_EXPLOSION_4;
00938 return startByte+1;
00939 }
00940
00941 startByte++;
00942 memcpy(in->mImageUuid.mData, bufPtr, 16);
00943 return (startByte+16);
00944 }
00945
00946
00947
00948
00949 U32 LLPartSysCompressedPacket::readSpawn(LLPartInitData *in, U32 startByte)
00950 {
00951 S8 bMant, bExp;
00952 U32 i;
00953
00954 bMant = mData[startByte++];
00955 bExp = mData[startByte++];
00956 in->spawnRange = floatFromTwoBytes(bMant, bExp);
00957 bMant = mData[startByte++];
00958 bExp = mData[startByte++];
00959 in->spawnFrequency = floatFromTwoBytes(bMant, bExp);
00960 bMant = mData[startByte++];
00961 bExp = mData[startByte++];
00962 in->spawnFreqencyRange = floatFromTwoBytes(bMant, bExp);
00963
00964 for(i = 0; i < 3; i++)
00965 {
00966 bMant = mData[startByte++];
00967 bExp = mData[startByte++];
00968 in->spawnDirection[i] = floatFromTwoBytes(bMant, bExp);
00969 }
00970
00971 bMant = mData[startByte++];
00972 bExp = mData[startByte++];
00973 in->spawnDirectionRange = floatFromTwoBytes(bMant, bExp);
00974 bMant = mData[startByte++];
00975 bExp = mData[startByte++];
00976 in->spawnVelocity = floatFromTwoBytes(bMant, bExp);
00977 bMant = mData[startByte++];
00978 bExp = mData[startByte++];
00979 in->spawnVelocityRange = floatFromTwoBytes(bMant, bExp);
00980
00981 return startByte;
00982 }
00983
00984 U32 LLPartSysCompressedPacket::readEnvironment(LLPartInitData *in, U32 startByte)
00985 {
00986 S8 bMant, bExp;
00987 U32 i;
00988
00989
00990 bMant = mData[startByte++];
00991 bExp = mData[startByte++];
00992 in->windWeight = floatFromTwoBytes(bMant, bExp);
00993
00994 for(i = 0; i < 3; i++)
00995 {
00996 bMant = mData[startByte++];
00997 bExp = mData[startByte++];
00998 in->currentGravity[i] = floatFromTwoBytes(bMant, bExp);
00999 }
01000
01001 bMant = mData[startByte++];
01002 bExp = mData[startByte++];
01003 in->gravityWeight = floatFromTwoBytes(bMant, bExp);
01004
01005 return startByte;
01006 }
01007
01008 U32 LLPartSysCompressedPacket::readLifespan(LLPartInitData *in, U32 startByte)
01009 {
01010 S8 bMant, bExp;
01011
01012 bMant = mData[startByte++];
01013 bExp = mData[startByte++];
01014 in->globalLifetime = floatFromTwoBytes(bMant, bExp);
01015 bMant = mData[startByte++];
01016 bExp = mData[startByte++];
01017 in->individualLifetime = floatFromTwoBytes(bMant, bExp);
01018 bMant = mData[startByte++];
01019 bExp = mData[startByte++];
01020 in->individualLifetimeRange = floatFromTwoBytes(bMant, bExp);
01021
01022 return startByte;
01023 }
01024
01025 U32 LLPartSysCompressedPacket::readDecayDamp(LLPartInitData *in, U32 startByte)
01026 {
01027 S8 bMant, bExp;
01028
01029 bMant = mData[startByte++];
01030 bExp = mData[startByte++];
01031 in->speedLimit = floatFromTwoBytes(bMant, bExp);
01032 bMant = mData[startByte++];
01033 bExp = mData[startByte++];
01034 in->alphaDecay = floatFromTwoBytes(bMant, bExp);
01035 bMant = mData[startByte++];
01036 bExp = mData[startByte++];
01037 in->scaleDecay = floatFromTwoBytes(bMant, bExp);
01038 bMant = mData[startByte++];
01039 bExp = mData[startByte++];
01040 in->dampMotionFactor = floatFromTwoBytes(bMant, bExp);
01041
01042 return startByte;
01043 }
01044
01045 U32 LLPartSysCompressedPacket::readWindDiffusionFactor(LLPartInitData *in, U32 startByte)
01046 {
01047 int i;
01048 S8 bMant, bExp;
01049 for(i = 0; i < 3; i++)
01050 {
01051 bMant = mData[startByte++];
01052 bExp = mData[startByte++];
01053 in->windDiffusionFactor[i] = floatFromTwoBytes(bMant, bExp);
01054 }
01055 return startByte;
01056 }
01057
01058 BOOL LLPartSysCompressedPacket::fromLLPartInitData(LLPartInitData *in, U32 &bytesUsed)
01059 {
01060
01061 writeFlagByte(in);
01062 U32 currByte = 4;
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073 if(mData[0] & PART_SYS_KILL_P_MASK)
01074 {
01075 currByte = writeKill_p(in, currByte);
01076 }
01077
01078 if(mData[0] & PART_SYS_BOUNCE_P_MASK)
01079 {
01080 currByte = writeBounce_p(in, currByte);
01081 }
01082
01083 if(mData[0] & PART_SYS_BOUNCE_B_MASK)
01084 {
01085 currByte = writeBounce_b(in, currByte);
01086 }
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098 if(mData[0] & PART_SYS_ALPHA_SCALE_DIFF_MASK)
01099 {
01100 currByte = writeAlphaScaleDiffEqn_range(in, currByte);
01101 }
01102
01103 if(mData[0] & PART_SYS_SCALE_RANGE_MASK)
01104 {
01105 currByte = writeScale_range(in, currByte);
01106 }
01107
01108 if(mData[0] & PART_SYS_VEL_OFFSET_MASK)
01109 {
01110 currByte = writeVelocityOffset(in, currByte);
01111 }
01112
01113 if(mData[0] & PART_SYS_M_IMAGE_UUID_MASK)
01114 {
01115 currByte = writeUUID(in, currByte);
01116 }
01117
01118
01119 if(mData[3] & PART_SYS_BYTE_SPAWN_MASK)
01120 {
01121 currByte = writeSpawn(in, currByte);
01122 }
01123
01124 if(mData[3] & PART_SYS_BYTE_ENVIRONMENT_MASK)
01125 {
01126 currByte = writeEnvironment(in, currByte);
01127 }
01128
01129 if(mData[3] & PART_SYS_BYTE_LIFESPAN_MASK)
01130 {
01131 currByte = writeLifespan(in, currByte);
01132 }
01133
01134 if(mData[3] & PART_SYS_BYTE_DECAY_DAMP_MASK)
01135 {
01136 currByte = writeDecayDamp(in, currByte);
01137 }
01138
01139 if(mData[3] & PART_SYS_BYTE_WIND_DIFF_MASK)
01140 {
01141 currByte = writeWindDiffusionFactor(in, currByte);
01142 }
01143
01144
01145 if(mData[2] & PART_SYS_BYTE_3_ALPHA_MASK)
01146 {
01147 currByte = writeAlpha_range(in, currByte);
01148 }
01149
01150 mData[currByte++] = (U8)in->maxParticles;
01151 mData[currByte++] = (U8)in->initialParticles;
01152
01153
01154 U32 flagFlag = 1;
01155
01156 for(U32 i = 0; i < 8; i++)
01157 {
01158
01159
01160 if(mData[1] & flagFlag)
01161 {
01162 mData[currByte++] = in->mFlags[i];
01163
01164 }
01165 flagFlag <<= 1;
01166 }
01167
01168 bytesUsed = mNumBytes = currByte;
01169
01170
01171
01172
01173
01174 return TRUE;
01175 }
01176
01177 BOOL LLPartSysCompressedPacket::toLLPartInitData(LLPartInitData *out, U32 *bytesUsed)
01178 {
01179 U32 currByte = 4;
01180
01181 gSetInitDataDefaults(out);
01182
01183 if(mData[0] & PART_SYS_KILL_P_MASK)
01184 {
01185 currByte = readKill_p(out, currByte);
01186 }
01187
01188 if(mData[0] & PART_SYS_BOUNCE_P_MASK)
01189 {
01190 currByte = readBounce_p(out, currByte);
01191 }
01192
01193 if(mData[0] & PART_SYS_BOUNCE_B_MASK)
01194 {
01195 currByte = readBounce_b(out, currByte);
01196 }
01197
01198 if(mData[0] & PART_SYS_ALPHA_SCALE_DIFF_MASK)
01199 {
01200 currByte = readAlphaScaleDiffEqn_range(out, currByte);
01201 }
01202
01203 if(mData[0] & PART_SYS_SCALE_RANGE_MASK)
01204 {
01205 currByte = readScale_range(out, currByte);
01206 }
01207
01208 if(mData[0] & PART_SYS_VEL_OFFSET_MASK)
01209 {
01210 currByte = readVelocityOffset(out, currByte);
01211 }
01212
01213 if(mData[0] & PART_SYS_M_IMAGE_UUID_MASK)
01214 {
01215 currByte = readUUID(out, currByte);
01216 }
01217
01218
01219 if(mData[3] & PART_SYS_BYTE_SPAWN_MASK)
01220 {
01221 currByte = readSpawn(out, currByte);
01222 }
01223
01224 if(mData[3] & PART_SYS_BYTE_ENVIRONMENT_MASK)
01225 {
01226 currByte = readEnvironment(out, currByte);
01227 }
01228
01229 if(mData[3] & PART_SYS_BYTE_LIFESPAN_MASK)
01230 {
01231 currByte = readLifespan(out, currByte);
01232 }
01233
01234 if(mData[3] & PART_SYS_BYTE_DECAY_DAMP_MASK)
01235 {
01236 currByte = readDecayDamp(out, currByte);
01237 }
01238
01239 if(mData[3] & PART_SYS_BYTE_WIND_DIFF_MASK)
01240 {
01241 currByte = readWindDiffusionFactor(out, currByte);
01242 }
01243
01244 if(mData[2] & PART_SYS_BYTE_3_ALPHA_MASK)
01245 {
01246 currByte = readAlpha_range(out, currByte);
01247 }
01248
01249 out->maxParticles = mData[currByte++];
01250 out->initialParticles = mData[currByte++];
01251
01252 U32 flagFlag = 1;
01253
01254 for(U32 i = 0; i < 8; i++)
01255 {
01256 flagFlag = 1<<i;
01257
01258 if((mData[1] & flagFlag))
01259 {
01260 out->mFlags[i] = mData[currByte++];
01261 }
01262 }
01263
01264 *bytesUsed = currByte;
01265 return TRUE;
01266 }
01267
01268 BOOL LLPartSysCompressedPacket::fromUnsignedBytes(U8 *in, U32 bytesUsed)
01269 {
01270 if ((in != NULL) && (bytesUsed <= sizeof(mData)))
01271 {
01272 memcpy(mData, in, bytesUsed);
01273 mNumBytes = bytesUsed;
01274 return TRUE;
01275 }
01276 else
01277 {
01278 llerrs << "NULL input data or number of bytes exceed mData size" << llendl;
01279 return FALSE;
01280 }
01281 }
01282
01283
01284 U32 LLPartSysCompressedPacket::bufferSize()
01285 {
01286 return mNumBytes;
01287 }
01288
01289 BOOL LLPartSysCompressedPacket::toUnsignedBytes(U8 *out)
01290 {
01291 memcpy(out, mData, mNumBytes);
01292 return TRUE;
01293 }
01294
01295 U8 * LLPartSysCompressedPacket::getBytePtr()
01296 {
01297 return mData;
01298 }
01299
01300