diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/partsyspacket.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llmessage/partsyspacket.cpp')
-rw-r--r-- | linden/indra/llmessage/partsyspacket.cpp | 1296 |
1 files changed, 1296 insertions, 0 deletions
diff --git a/linden/indra/llmessage/partsyspacket.cpp b/linden/indra/llmessage/partsyspacket.cpp new file mode 100644 index 0000000..d491540 --- /dev/null +++ b/linden/indra/llmessage/partsyspacket.cpp | |||
@@ -0,0 +1,1296 @@ | |||
1 | /** | ||
2 | * @file partsyspacket.cpp | ||
3 | * @brief Object for packing particle system initialization parameters | ||
4 | * before sending them over the network. | ||
5 | * | ||
6 | * Copyright (c) 2000-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
9 | * to you under the terms of the GNU General Public License, version 2.0 | ||
10 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
11 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
12 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
13 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
14 | * | ||
15 | * There are special exceptions to the terms and conditions of the GPL as | ||
16 | * it is applied to this Source Code. View the full text of the exception | ||
17 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
18 | * online at http://secondlife.com/developers/opensource/flossexception | ||
19 | * | ||
20 | * By copying, modifying or distributing this software, you acknowledge | ||
21 | * that you have read and understood your obligations described above, | ||
22 | * and agree to abide by those obligations. | ||
23 | * | ||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
26 | * COMPLETENESS OR PERFORMANCE. | ||
27 | */ | ||
28 | |||
29 | #include "linden_common.h" | ||
30 | |||
31 | #include "partsyspacket.h" | ||
32 | #include "imageids.h" | ||
33 | |||
34 | // this function is global | ||
35 | void gSetInitDataDefaults(LLPartInitData *setMe) | ||
36 | { | ||
37 | U32 i; | ||
38 | |||
39 | //for(i = 0; i < 18; i++) | ||
40 | //{ | ||
41 | // setMe->k[i] = 0.0f; | ||
42 | //} | ||
43 | |||
44 | //setMe->kill_p[0] = setMe->kill_p[1] = setMe->kill_p[2] = 0.0f; | ||
45 | //setMe->kill_p[3] = -0.2f; // time parameter, die when t= 5.0f | ||
46 | //setMe->kill_p[4] = 1.0f; | ||
47 | //setMe->kill_p[5] = -0.5f; // or radius == 2 (contracting) | ||
48 | |||
49 | //setMe->bounce_p[0] = setMe->bounce_p[1] = | ||
50 | // setMe->bounce_p[2] = setMe->bounce_p[3] = 0.0f; | ||
51 | //setMe->bounce_p[4] = 1.0f; | ||
52 | |||
53 | setMe->bounce_b = 1.0f; | ||
54 | // i just changed the meaning of bounce_b | ||
55 | // its now the attenuation from revlecting your velocity across the normal | ||
56 | // set by bounce_p | ||
57 | |||
58 | //setMe->pos_ranges[0] = setMe->pos_ranges[2] = setMe->pos_ranges[4] = -1.0f; | ||
59 | //setMe->pos_ranges[1] = setMe->pos_ranges[3] = setMe->pos_ranges[5] = 1.0f; | ||
60 | |||
61 | //setMe->vel_ranges[0] = setMe->vel_ranges[2] = setMe->vel_ranges[4] = -1.0f; | ||
62 | //setMe->vel_ranges[1] = setMe->vel_ranges[3] = setMe->vel_ranges[5] = 1.0f; | ||
63 | |||
64 | for(i = 0; i < 3; i++) | ||
65 | { | ||
66 | setMe->diffEqAlpha[i] = 0.0f; | ||
67 | setMe->diffEqScale[i] = 0.0f; | ||
68 | } | ||
69 | |||
70 | setMe->scale_range[0] = 1.00f; | ||
71 | setMe->scale_range[1] = 5.00f; | ||
72 | setMe->scale_range[2] = setMe->scale_range[3] = 0.0f; | ||
73 | |||
74 | setMe->alpha_range[0] = setMe->alpha_range[1] = 1.0f; | ||
75 | setMe->alpha_range[2] = setMe->alpha_range[3] = 0.0f; | ||
76 | |||
77 | setMe->vel_offset[0] = 0.0f; | ||
78 | setMe->vel_offset[1] = 0.0f; | ||
79 | setMe->vel_offset[2] = 0.0f; | ||
80 | |||
81 | // start dropping particles when I'm more then one sim away | ||
82 | setMe->mDistBeginFadeout = 256.0f; | ||
83 | setMe->mDistEndFadeout = 1.414f * 512.0f; | ||
84 | // stop displaying particles when I'm more then two sim diagonals away | ||
85 | |||
86 | setMe->mImageUuid = IMG_SHOT; | ||
87 | |||
88 | for(i = 0; i < 8; i++) | ||
89 | { | ||
90 | setMe->mFlags[i] = 0x00; | ||
91 | } | ||
92 | |||
93 | setMe->createMe = TRUE; | ||
94 | |||
95 | setMe->maxParticles = 25; | ||
96 | setMe->initialParticles = 25; | ||
97 | |||
98 | //These defaults are for an explosion - a short lived set of debris affected by gravity. | ||
99 | //Action flags default to PART_SYS_AFFECTED_BY_WIND + PART_SYS_AFFECTED_BY_GRAVITY + PART_SYS_DISTANCE_DEATH | ||
100 | setMe->mFlags[PART_SYS_ACTION_BYTE] = PART_SYS_AFFECTED_BY_WIND | PART_SYS_AFFECTED_BY_GRAVITY | PART_SYS_DISTANCE_DEATH; | ||
101 | setMe->mFlags[PART_SYS_KILL_BYTE] = PART_SYS_DISTANCE_DEATH + PART_SYS_TIME_DEATH; | ||
102 | |||
103 | setMe->killPlaneNormal[0] = 0.0f;setMe->killPlaneNormal[1] = 0.0f;setMe->killPlaneNormal[2] = 1.0f; //Straight up | ||
104 | setMe->killPlaneZ = 0.0f; //get local ground z as an approximation if turn on PART_SYS_KILL_PLANE | ||
105 | setMe->bouncePlaneNormal[0] = 0.0f;setMe->bouncePlaneNormal[1] = 0.0f;setMe->bouncePlaneNormal[2] = 1.0f; //Straight up | ||
106 | setMe->bouncePlaneZ = 0.0f; //get local ground z as an approximation if turn on PART_SYS_BOUNCE | ||
107 | setMe->spawnRange = 1.0f; | ||
108 | setMe->spawnFrequency = 0.0f; //Create the instant one dies | ||
109 | setMe->spawnFreqencyRange = 0.0f; | ||
110 | setMe->spawnDirection[0] = 0.0f;setMe->spawnDirection[1] = 0.0f;setMe->spawnDirection[2] = 1.0f; //Straight up | ||
111 | setMe->spawnDirectionRange = 1.0f; //global scattering | ||
112 | setMe->spawnVelocity = 0.75f; | ||
113 | setMe->spawnVelocityRange = 0.25f; //velocity +/- 0.25 | ||
114 | setMe->speedLimit = 1.0f; | ||
115 | |||
116 | setMe->windWeight = 0.5f; //0.0f means looks like a heavy object (if gravity is on), 1.0f means light and fluffy | ||
117 | setMe->currentGravity[0] = 0.0f;setMe->currentGravity[1] = 0.0f;setMe->currentGravity[2] = -9.81f; | ||
118 | //This has to be constant to allow for compression | ||
119 | |||
120 | setMe->gravityWeight = 0.5f; //0.0f means boyed by air, 1.0f means it's a lead weight | ||
121 | setMe->globalLifetime = 0.0f; //Arbitrary, but default is no global die, so doesn't matter | ||
122 | setMe->individualLifetime = 5.0f; | ||
123 | setMe->individualLifetimeRange = 1.0f; //Particles last 5 secs +/- 1 | ||
124 | setMe->alphaDecay = 1.0f; //normal alpha fadeout | ||
125 | setMe->scaleDecay = 0.0f; //no scale decay | ||
126 | setMe->distanceDeath = 10.0f; //die if hit unit radius | ||
127 | setMe->dampMotionFactor = 0.0f; | ||
128 | |||
129 | setMe->windDiffusionFactor[0] = 0.0f; | ||
130 | setMe->windDiffusionFactor[1] = 0.0f; | ||
131 | setMe->windDiffusionFactor[2] = 0.0f; | ||
132 | } | ||
133 | |||
134 | LLPartSysCompressedPacket::LLPartSysCompressedPacket() | ||
135 | { | ||
136 | // default constructor for mDefaults called implicitly/automatically here | ||
137 | for(int i = 0; i < MAX_PART_SYS_PACKET_SIZE; i++) | ||
138 | { | ||
139 | mData[i] = '\0'; | ||
140 | } | ||
141 | |||
142 | gSetInitDataDefaults(&mDefaults); | ||
143 | } | ||
144 | |||
145 | LLPartSysCompressedPacket::~LLPartSysCompressedPacket() | ||
146 | { | ||
147 | // no dynamic data is stored by this class, do nothing. | ||
148 | } | ||
149 | |||
150 | void LLPartSysCompressedPacket::writeFlagByte(LLPartInitData *in) | ||
151 | { | ||
152 | mData[0] = mData[1] = mData[2] = '\0'; | ||
153 | |||
154 | U32 i; | ||
155 | //for(i = 1; i < 18; i++) { | ||
156 | // if(in->k[i] != mDefaults.k[i]) | ||
157 | // { | ||
158 | // mData[0] |= PART_SYS_K_MASK; | ||
159 | // break; | ||
160 | // } | ||
161 | //} | ||
162 | |||
163 | if(in->killPlaneZ != mDefaults.killPlaneZ || | ||
164 | in->killPlaneNormal[0] != mDefaults.killPlaneNormal[0] || | ||
165 | in->killPlaneNormal[1] != mDefaults.killPlaneNormal[1] || | ||
166 | in->killPlaneNormal[2] != mDefaults.killPlaneNormal[2] || | ||
167 | in->distanceDeath != mDefaults.distanceDeath) | ||
168 | { | ||
169 | mData[0] |= PART_SYS_KILL_P_MASK; | ||
170 | } | ||
171 | |||
172 | |||
173 | |||
174 | if(in->bouncePlaneZ != mDefaults.bouncePlaneZ || | ||
175 | in->bouncePlaneNormal[0] != mDefaults.bouncePlaneNormal[0] || | ||
176 | in->bouncePlaneNormal[1] != mDefaults.bouncePlaneNormal[1] || | ||
177 | in->bouncePlaneNormal[2] != mDefaults.bouncePlaneNormal[2]) | ||
178 | { | ||
179 | mData[0] |= PART_SYS_BOUNCE_P_MASK; | ||
180 | } | ||
181 | |||
182 | if(in->bounce_b != mDefaults.bounce_b) | ||
183 | { | ||
184 | mData[0] |= PART_SYS_BOUNCE_B_MASK; | ||
185 | } | ||
186 | |||
187 | |||
188 | //if(in->pos_ranges[0] != mDefaults.pos_ranges[0] || in->pos_ranges[1] != mDefaults.pos_ranges[1] || | ||
189 | // in->pos_ranges[2] != mDefaults.pos_ranges[2] || in->pos_ranges[3] != mDefaults.pos_ranges[3] || | ||
190 | // in->pos_ranges[4] != mDefaults.pos_ranges[4] || in->pos_ranges[5] != mDefaults.pos_ranges[5]) | ||
191 | //{ | ||
192 | // mData[0] |= PART_SYS_POS_RANGES_MASK; | ||
193 | //} | ||
194 | |||
195 | //if(in->vel_ranges[0] != mDefaults.vel_ranges[0] || in->vel_ranges[1] != mDefaults.vel_ranges[1] || | ||
196 | // in->vel_ranges[2] != mDefaults.vel_ranges[2] || in->vel_ranges[3] != mDefaults.vel_ranges[3] || | ||
197 | // in->vel_ranges[4] != mDefaults.vel_ranges[4] || in->vel_ranges[5] != mDefaults.vel_ranges[5]) | ||
198 | //{ | ||
199 | // mData[0] |= PART_SYS_VEL_RANGES_MASK; | ||
200 | //} | ||
201 | |||
202 | |||
203 | if(in->diffEqAlpha[0] != mDefaults.diffEqAlpha[0] || | ||
204 | in->diffEqAlpha[1] != mDefaults.diffEqAlpha[1] || | ||
205 | in->diffEqAlpha[2] != mDefaults.diffEqAlpha[2] || | ||
206 | in->diffEqScale[0] != mDefaults.diffEqScale[0] || | ||
207 | in->diffEqScale[1] != mDefaults.diffEqScale[1] || | ||
208 | in->diffEqScale[2] != mDefaults.diffEqScale[2]) | ||
209 | { | ||
210 | mData[0] |= PART_SYS_ALPHA_SCALE_DIFF_MASK; | ||
211 | } | ||
212 | |||
213 | |||
214 | if(in->scale_range[0] != mDefaults.scale_range[0] || | ||
215 | in->scale_range[1] != mDefaults.scale_range[1] || | ||
216 | in->scale_range[2] != mDefaults.scale_range[2] || | ||
217 | in->scale_range[3] != mDefaults.scale_range[3]) | ||
218 | { | ||
219 | mData[0] |= PART_SYS_SCALE_RANGE_MASK; | ||
220 | } | ||
221 | |||
222 | |||
223 | if(in->alpha_range[0] != mDefaults.alpha_range[0] || | ||
224 | in->alpha_range[1] != mDefaults.alpha_range[1] || | ||
225 | in->alpha_range[2] != mDefaults.alpha_range[2] || | ||
226 | in->alpha_range[3] != mDefaults.alpha_range[3]) | ||
227 | { | ||
228 | mData[2] |= PART_SYS_BYTE_3_ALPHA_MASK; | ||
229 | } | ||
230 | |||
231 | if(in->vel_offset[0] != mDefaults.vel_offset[0] || | ||
232 | in->vel_offset[1] != mDefaults.vel_offset[1] || | ||
233 | in->vel_offset[2] != mDefaults.vel_offset[2]) | ||
234 | { | ||
235 | mData[0] |= PART_SYS_VEL_OFFSET_MASK; | ||
236 | } | ||
237 | |||
238 | |||
239 | if(in->mImageUuid != mDefaults.mImageUuid) | ||
240 | { | ||
241 | mData[0] |= PART_SYS_M_IMAGE_UUID_MASK; | ||
242 | } | ||
243 | |||
244 | for( i = 0; i < 8; i++) | ||
245 | { | ||
246 | if(in->mFlags[i]) | ||
247 | { | ||
248 | mData[1] |= 1<<i; | ||
249 | // llprintline("Flag \"%x\" gets byte \"%x\"\n", i<<i, in->mFlags[i]); | ||
250 | } | ||
251 | } | ||
252 | |||
253 | |||
254 | if(in->spawnRange != mDefaults.spawnRange || | ||
255 | in->spawnFrequency != mDefaults.spawnFrequency || | ||
256 | in->spawnFreqencyRange != mDefaults.spawnFreqencyRange || | ||
257 | in->spawnDirection[0] != mDefaults.spawnDirection[0] || | ||
258 | in->spawnDirection[1] != mDefaults.spawnDirection[1] || | ||
259 | in->spawnDirection[2] != mDefaults.spawnDirection[2] || | ||
260 | in->spawnDirectionRange != mDefaults.spawnDirectionRange || | ||
261 | in->spawnVelocity != mDefaults.spawnVelocity || | ||
262 | in->spawnVelocityRange != mDefaults.spawnVelocityRange) | ||
263 | { | ||
264 | mData[3] |= PART_SYS_BYTE_SPAWN_MASK; | ||
265 | } | ||
266 | |||
267 | |||
268 | if(in->windWeight != mDefaults.windWeight || | ||
269 | in->currentGravity[0] != mDefaults.currentGravity[0] || | ||
270 | in->currentGravity[1] != mDefaults.currentGravity[1] || | ||
271 | in->currentGravity[2] != mDefaults.currentGravity[2] || | ||
272 | in->gravityWeight != mDefaults.gravityWeight) | ||
273 | { | ||
274 | mData[3] |= PART_SYS_BYTE_ENVIRONMENT_MASK; | ||
275 | } | ||
276 | |||
277 | |||
278 | if(in->globalLifetime != mDefaults.globalLifetime || | ||
279 | in->individualLifetime != mDefaults.individualLifetime || | ||
280 | in->individualLifetimeRange != mDefaults.individualLifetimeRange) | ||
281 | { | ||
282 | mData[3] |= PART_SYS_BYTE_LIFESPAN_MASK; | ||
283 | } | ||
284 | |||
285 | |||
286 | if(in->speedLimit != mDefaults.speedLimit || | ||
287 | in->alphaDecay != mDefaults.alphaDecay || | ||
288 | in->scaleDecay != mDefaults.scaleDecay || | ||
289 | in->dampMotionFactor != mDefaults.dampMotionFactor) | ||
290 | { | ||
291 | mData[3] |= PART_SYS_BYTE_DECAY_DAMP_MASK; | ||
292 | } | ||
293 | |||
294 | if(in->windDiffusionFactor[0] != mDefaults.windDiffusionFactor[0] || | ||
295 | in->windDiffusionFactor[1] != mDefaults.windDiffusionFactor[1] || | ||
296 | in->windDiffusionFactor[2] != mDefaults.windDiffusionFactor[2]) | ||
297 | { | ||
298 | mData[3] |= PART_SYS_BYTE_WIND_DIFF_MASK; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | F32 floatFromTwoBytes(S8 bMant, S8 bExp) | ||
303 | { | ||
304 | F32 result = bMant; | ||
305 | while(bExp > 0) | ||
306 | { | ||
307 | result *= 2.0f; | ||
308 | bExp--; | ||
309 | } | ||
310 | while(bExp < 0) | ||
311 | { | ||
312 | result *= 0.5f; | ||
313 | bExp++; | ||
314 | } | ||
315 | return result; | ||
316 | } | ||
317 | |||
318 | void twoBytesFromFloat(F32 fIn, S8 &bMant, S8 &bExp) | ||
319 | { | ||
320 | bExp = 0; | ||
321 | if(fIn > 127.0f) | ||
322 | { | ||
323 | fIn = 127.0f; | ||
324 | } | ||
325 | if(fIn < -127.0f) | ||
326 | { | ||
327 | fIn = -127.0f; | ||
328 | } | ||
329 | while(fIn < 64 && fIn > -64 && bExp > -127) | ||
330 | { | ||
331 | fIn *= 2.0f; | ||
332 | bExp--; | ||
333 | } | ||
334 | while((fIn > 128 || fIn < -128) && bExp < 127) | ||
335 | { | ||
336 | fIn *= 0.5f; | ||
337 | bExp++; | ||
338 | } | ||
339 | bMant = (S8)fIn; | ||
340 | } | ||
341 | |||
342 | |||
343 | |||
344 | /* | ||
345 | U32 LLPartSysCompressedPacket::writeK(LLPartInitData *in, U32 startByte) | ||
346 | { | ||
347 | U32 i, kFlag, i_mod_eight; | ||
348 | S8 bMant, bExp; | ||
349 | |||
350 | kFlag = startByte; | ||
351 | |||
352 | startByte += 3; // 3 bytes contain enough room for 18 flag bits | ||
353 | mData[kFlag] = 0x00; | ||
354 | // llprintline("In the writeK\n"); | ||
355 | |||
356 | i_mod_eight = 0; | ||
357 | for(i = 0; i < 18; i++) | ||
358 | { | ||
359 | if(in->k[i] != mDefaults.k[i]) | ||
360 | { | ||
361 | |||
362 | mData[kFlag] |= 1<<i_mod_eight; | ||
363 | twoBytesFromFloat(in->k[i], bMant, bExp); | ||
364 | |||
365 | mData[startByte++] = bMant; | ||
366 | mData[startByte++] = bExp; | ||
367 | } | ||
368 | i_mod_eight++; | ||
369 | while(i_mod_eight >= 8) | ||
370 | { | ||
371 | kFlag++; | ||
372 | i_mod_eight -= 8; | ||
373 | } | ||
374 | } | ||
375 | |||
376 | return startByte; | ||
377 | }*/ | ||
378 | |||
379 | U32 LLPartSysCompressedPacket::writeKill_p(LLPartInitData *in, U32 startByte) | ||
380 | { | ||
381 | S8 bMant, bExp; | ||
382 | |||
383 | twoBytesFromFloat(in->killPlaneNormal[0], bMant, bExp); | ||
384 | mData[startByte++] = bMant; | ||
385 | mData[startByte++] = bExp; | ||
386 | twoBytesFromFloat(in->killPlaneNormal[1], bMant, bExp); | ||
387 | mData[startByte++] = bMant; | ||
388 | mData[startByte++] = bExp; | ||
389 | twoBytesFromFloat(in->killPlaneNormal[2], bMant, bExp); | ||
390 | mData[startByte++] = bMant; | ||
391 | mData[startByte++] = bExp; | ||
392 | |||
393 | twoBytesFromFloat(in->killPlaneZ, bMant, bExp); | ||
394 | mData[startByte++] = bMant; | ||
395 | mData[startByte++] = bExp; | ||
396 | twoBytesFromFloat(in->distanceDeath, bMant, bExp); | ||
397 | mData[startByte++] = bMant; | ||
398 | mData[startByte++] = bExp; | ||
399 | |||
400 | return startByte; | ||
401 | } | ||
402 | |||
403 | U32 LLPartSysCompressedPacket::writeBounce_p(LLPartInitData *in, U32 startByte) | ||
404 | { | ||
405 | S8 bMant, bExp; | ||
406 | |||
407 | twoBytesFromFloat(in->bouncePlaneNormal[0], bMant, bExp); | ||
408 | mData[startByte++] = bMant; | ||
409 | mData[startByte++] = bExp; | ||
410 | twoBytesFromFloat(in->bouncePlaneNormal[1], bMant, bExp); | ||
411 | mData[startByte++] = bMant; | ||
412 | mData[startByte++] = bExp; | ||
413 | twoBytesFromFloat(in->bouncePlaneNormal[2], bMant, bExp); | ||
414 | mData[startByte++] = bMant; | ||
415 | mData[startByte++] = bExp; | ||
416 | |||
417 | |||
418 | twoBytesFromFloat(in->bouncePlaneZ, bMant, bExp); | ||
419 | mData[startByte++] = bMant; | ||
420 | mData[startByte++] = bExp; | ||
421 | |||
422 | return startByte; | ||
423 | } | ||
424 | |||
425 | U32 LLPartSysCompressedPacket::writeBounce_b(LLPartInitData *in, U32 startByte) | ||
426 | { | ||
427 | S8 bMant, bExp; | ||
428 | twoBytesFromFloat(in->bounce_b, bMant, bExp); | ||
429 | mData[startByte++] = bMant; | ||
430 | mData[startByte++] = bExp; | ||
431 | return startByte; | ||
432 | } | ||
433 | |||
434 | //U32 LLPartSysCompressedPacket::writePos_ranges(LLPartInitData *in, U32 startByte) | ||
435 | //{ | ||
436 | // S8 tmp; | ||
437 | // int i; | ||
438 | // for(i = 0; i < 6; i++) | ||
439 | // { | ||
440 | // tmp = (S8) in->pos_ranges[i]; // float to int conversion (keep the sign) | ||
441 | // mData[startByte++] = (U8)tmp; // signed to unsigned typecast | ||
442 | // } | ||
443 | // return startByte; | ||
444 | //} | ||
445 | |||
446 | //U32 LLPartSysCompressedPacket::writeVel_ranges(LLPartInitData *in, U32 startByte) | ||
447 | //{ | ||
448 | // S8 tmp; | ||
449 | // int i; | ||
450 | // for(i = 0; i < 6; i++) | ||
451 | // { | ||
452 | // tmp = (S8) in->vel_ranges[i]; // float to int conversion (keep the sign) | ||
453 | // mData[startByte++] = (U8)tmp; // signed to unsigned typecast | ||
454 | // } | ||
455 | // return startByte; | ||
456 | //} | ||
457 | |||
458 | U32 LLPartSysCompressedPacket::writeAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte) | ||
459 | { | ||
460 | S8 bExp, bMant; | ||
461 | int i; | ||
462 | for(i = 0; i < 3; i++) | ||
463 | { | ||
464 | twoBytesFromFloat(in->diffEqAlpha[i], bMant, bExp); | ||
465 | mData[startByte++] = bMant; | ||
466 | mData[startByte++] = bExp; | ||
467 | } | ||
468 | for(i = 0; i < 3; i++) | ||
469 | { | ||
470 | twoBytesFromFloat(in->diffEqScale[i], bMant, bExp); | ||
471 | mData[startByte++] = bMant; | ||
472 | mData[startByte++] = bExp; | ||
473 | } | ||
474 | return startByte; | ||
475 | } | ||
476 | |||
477 | U32 LLPartSysCompressedPacket::writeScale_range(LLPartInitData *in, U32 startByte) | ||
478 | { | ||
479 | S8 bExp, bMant; | ||
480 | int i; | ||
481 | for(i = 0; i < 4; i++) | ||
482 | { | ||
483 | twoBytesFromFloat(in->scale_range[i], bMant, bExp); | ||
484 | mData[startByte++] = bMant; | ||
485 | mData[startByte++] = bExp; | ||
486 | } | ||
487 | return startByte; | ||
488 | } | ||
489 | |||
490 | |||
491 | U32 LLPartSysCompressedPacket::writeAlpha_range(LLPartInitData *in, U32 startByte) | ||
492 | { | ||
493 | S8 bExp, bMant; | ||
494 | int i; | ||
495 | for(i = 0; i < 4; i++) | ||
496 | { | ||
497 | twoBytesFromFloat(in->alpha_range[i], bMant, bExp); | ||
498 | mData[startByte++] = bMant; | ||
499 | mData[startByte++] = bExp; | ||
500 | } | ||
501 | return startByte; | ||
502 | } | ||
503 | |||
504 | U32 LLPartSysCompressedPacket::writeVelocityOffset(LLPartInitData *in, U32 startByte) | ||
505 | { | ||
506 | S8 bExp, bMant; | ||
507 | int i; | ||
508 | for(i = 0; i < 3; i++) | ||
509 | { | ||
510 | twoBytesFromFloat(in->vel_offset[i], bMant, bExp); | ||
511 | mData[startByte++] = bMant; | ||
512 | mData[startByte++] = bExp; | ||
513 | } | ||
514 | return startByte; | ||
515 | } | ||
516 | |||
517 | U32 LLPartSysCompressedPacket::writeUUID(LLPartInitData *in, U32 startByte) | ||
518 | { | ||
519 | U8 * bufPtr = mData + startByte; | ||
520 | if(in->mImageUuid == IMG_SHOT) { | ||
521 | mData[startByte++] = 0x01; | ||
522 | return startByte; | ||
523 | } | ||
524 | |||
525 | if(in->mImageUuid == IMG_SPARK) { | ||
526 | mData[startByte++] = 0x02; | ||
527 | return startByte; | ||
528 | } | ||
529 | |||
530 | |||
531 | if(in->mImageUuid == IMG_BIG_EXPLOSION_1) { | ||
532 | mData[startByte++] = 0x03; | ||
533 | return startByte; | ||
534 | } | ||
535 | |||
536 | if(in->mImageUuid == IMG_BIG_EXPLOSION_2) { | ||
537 | mData[startByte++] = 0x04; | ||
538 | return startByte; | ||
539 | } | ||
540 | |||
541 | |||
542 | if(in->mImageUuid == IMG_SMOKE_POOF) { | ||
543 | mData[startByte++] = 0x05; | ||
544 | return startByte; | ||
545 | } | ||
546 | |||
547 | if(in->mImageUuid == IMG_FIRE) { | ||
548 | mData[startByte++] = 0x06; | ||
549 | return startByte; | ||
550 | } | ||
551 | |||
552 | |||
553 | if(in->mImageUuid == IMG_EXPLOSION) { | ||
554 | mData[startByte++] = 0x07; | ||
555 | return startByte; | ||
556 | } | ||
557 | |||
558 | if(in->mImageUuid == IMG_EXPLOSION_2) { | ||
559 | mData[startByte++] = 0x08; | ||
560 | return startByte; | ||
561 | } | ||
562 | |||
563 | |||
564 | if(in->mImageUuid == IMG_EXPLOSION_3) { | ||
565 | mData[startByte++] = 0x09; | ||
566 | return startByte; | ||
567 | } | ||
568 | |||
569 | if(in->mImageUuid == IMG_EXPLOSION_4) { | ||
570 | mData[startByte++] = 0x0A; | ||
571 | return startByte; | ||
572 | } | ||
573 | |||
574 | mData[startByte++] = 0x00; // flag for "read whole UUID" | ||
575 | |||
576 | memcpy(bufPtr, in->mImageUuid.mData, 16); /* Flawfinder: ignore */ | ||
577 | return (startByte+16); | ||
578 | } | ||
579 | |||
580 | U32 LLPartSysCompressedPacket::writeSpawn(LLPartInitData *in, U32 startByte) | ||
581 | { | ||
582 | S8 bExp, bMant; | ||
583 | int i; | ||
584 | |||
585 | twoBytesFromFloat(in->spawnRange, bMant, bExp); | ||
586 | mData[startByte++] = bMant; | ||
587 | mData[startByte++] = bExp; | ||
588 | twoBytesFromFloat(in->spawnFrequency, bMant, bExp); | ||
589 | mData[startByte++] = bMant; | ||
590 | mData[startByte++] = bExp; | ||
591 | twoBytesFromFloat(in->spawnFreqencyRange, bMant, bExp); | ||
592 | mData[startByte++] = bMant; | ||
593 | mData[startByte++] = bExp; | ||
594 | |||
595 | |||
596 | |||
597 | for(i = 0; i < 3; i++) | ||
598 | { | ||
599 | twoBytesFromFloat(in->spawnDirection[i], bMant, bExp); | ||
600 | mData[startByte++] = bMant; | ||
601 | mData[startByte++] = bExp; | ||
602 | } | ||
603 | |||
604 | twoBytesFromFloat(in->spawnDirectionRange, bMant, bExp); | ||
605 | mData[startByte++] = bMant; | ||
606 | mData[startByte++] = bExp; | ||
607 | twoBytesFromFloat(in->spawnVelocity, bMant, bExp); | ||
608 | mData[startByte++] = bMant; | ||
609 | mData[startByte++] = bExp; | ||
610 | twoBytesFromFloat(in->spawnVelocityRange, bMant, bExp); | ||
611 | mData[startByte++] = bMant; | ||
612 | mData[startByte++] = bExp; | ||
613 | |||
614 | return startByte; | ||
615 | } | ||
616 | |||
617 | U32 LLPartSysCompressedPacket::writeEnvironment(LLPartInitData *in, U32 startByte) | ||
618 | { | ||
619 | S8 bExp, bMant; | ||
620 | int i; | ||
621 | |||
622 | twoBytesFromFloat(in->windWeight, bMant, bExp); | ||
623 | mData[startByte++] = bMant; | ||
624 | mData[startByte++] = bExp; | ||
625 | |||
626 | for(i = 0; i < 3; i++) | ||
627 | { | ||
628 | twoBytesFromFloat(in->currentGravity[i], bMant, bExp); | ||
629 | mData[startByte++] = bMant; | ||
630 | mData[startByte++] = bExp; | ||
631 | } | ||
632 | |||
633 | twoBytesFromFloat(in->gravityWeight, bMant, bExp); | ||
634 | mData[startByte++] = bMant; | ||
635 | mData[startByte++] = bExp; | ||
636 | return startByte; | ||
637 | } | ||
638 | |||
639 | U32 LLPartSysCompressedPacket::writeLifespan(LLPartInitData *in, U32 startByte) | ||
640 | { | ||
641 | S8 bExp, bMant; | ||
642 | |||
643 | twoBytesFromFloat(in->globalLifetime, bMant, bExp); | ||
644 | mData[startByte++] = bMant; | ||
645 | mData[startByte++] = bExp; | ||
646 | |||
647 | twoBytesFromFloat(in->individualLifetime, bMant, bExp); | ||
648 | mData[startByte++] = bMant; | ||
649 | mData[startByte++] = bExp; | ||
650 | |||
651 | twoBytesFromFloat(in->individualLifetimeRange, bMant, bExp); | ||
652 | mData[startByte++] = bMant; | ||
653 | mData[startByte++] = bExp; | ||
654 | |||
655 | return startByte; | ||
656 | } | ||
657 | |||
658 | |||
659 | U32 LLPartSysCompressedPacket::writeDecayDamp(LLPartInitData *in, U32 startByte) | ||
660 | { | ||
661 | S8 bExp, bMant; | ||
662 | |||
663 | twoBytesFromFloat(in->speedLimit, bMant, bExp); | ||
664 | mData[startByte++] = bMant; | ||
665 | mData[startByte++] = bExp; | ||
666 | |||
667 | twoBytesFromFloat(in->alphaDecay, bMant, bExp); | ||
668 | mData[startByte++] = bMant; | ||
669 | mData[startByte++] = bExp; | ||
670 | |||
671 | twoBytesFromFloat(in->scaleDecay, bMant, bExp); | ||
672 | mData[startByte++] = bMant; | ||
673 | mData[startByte++] = bExp; | ||
674 | |||
675 | twoBytesFromFloat(in->dampMotionFactor, bMant, bExp); | ||
676 | mData[startByte++] = bMant; | ||
677 | mData[startByte++] = bExp; | ||
678 | |||
679 | return startByte; | ||
680 | } | ||
681 | |||
682 | U32 LLPartSysCompressedPacket::writeWindDiffusionFactor(LLPartInitData *in, U32 startByte) | ||
683 | { | ||
684 | S8 bExp, bMant; | ||
685 | |||
686 | twoBytesFromFloat(in->windDiffusionFactor[0], bMant, bExp); | ||
687 | mData[startByte++] = bMant; | ||
688 | mData[startByte++] = bExp; | ||
689 | |||
690 | twoBytesFromFloat(in->windDiffusionFactor[1], bMant, bExp); | ||
691 | mData[startByte++] = bMant; | ||
692 | mData[startByte++] = bExp; | ||
693 | |||
694 | twoBytesFromFloat(in->windDiffusionFactor[2], bMant, bExp); | ||
695 | mData[startByte++] = bMant; | ||
696 | mData[startByte++] = bExp; | ||
697 | |||
698 | return startByte; | ||
699 | } | ||
700 | |||
701 | |||
702 | |||
703 | |||
704 | |||
705 | |||
706 | /* | ||
707 | U32 LLPartSysCompressedPacket::readK(LLPartInitData *in, U32 startByte) | ||
708 | { | ||
709 | U32 i, i_mod_eight, kFlag; | ||
710 | S8 bMant, bExp; // 1 bytes mantissa and exponent for a float | ||
711 | kFlag = startByte; | ||
712 | startByte += 3; // 3 bytes has enough room for 18 bits | ||
713 | |||
714 | i_mod_eight = 0; | ||
715 | for(i = 0; i < 18; i++) | ||
716 | { | ||
717 | if(mData[kFlag]&(1<<i_mod_eight)) | ||
718 | { | ||
719 | |||
720 | |||
721 | |||
722 | bMant = mData[startByte++]; | ||
723 | bExp = mData[startByte++]; | ||
724 | |||
725 | |||
726 | in->k[i] = floatFromTwoBytes(bMant, bExp); // much tighter platform-independent | ||
727 | // way to ship floats | ||
728 | |||
729 | } | ||
730 | i_mod_eight++; | ||
731 | if(i_mod_eight >= 8) | ||
732 | { | ||
733 | i_mod_eight -= 8; | ||
734 | kFlag++; | ||
735 | } | ||
736 | } | ||
737 | |||
738 | return startByte; | ||
739 | } | ||
740 | */ | ||
741 | |||
742 | U32 LLPartSysCompressedPacket::readKill_p(LLPartInitData *in, U32 startByte) | ||
743 | { | ||
744 | S8 bMant, bExp; | ||
745 | |||
746 | bMant = mData[startByte++]; | ||
747 | bExp = mData[startByte++]; | ||
748 | in->killPlaneNormal[0] = floatFromTwoBytes(bMant, bExp); | ||
749 | bMant = mData[startByte++]; | ||
750 | bExp = mData[startByte++]; | ||
751 | in->killPlaneNormal[1] = floatFromTwoBytes(bMant, bExp); | ||
752 | bMant = mData[startByte++]; | ||
753 | bExp = mData[startByte++]; | ||
754 | in->killPlaneNormal[2] = floatFromTwoBytes(bMant, bExp); | ||
755 | |||
756 | bMant = mData[startByte++]; | ||
757 | bExp = mData[startByte++]; | ||
758 | in->killPlaneZ = floatFromTwoBytes(bMant, bExp); | ||
759 | bMant = mData[startByte++]; | ||
760 | bExp = mData[startByte++]; | ||
761 | in->distanceDeath = floatFromTwoBytes(bMant, bExp); | ||
762 | |||
763 | return startByte; | ||
764 | } | ||
765 | |||
766 | U32 LLPartSysCompressedPacket::readBounce_p(LLPartInitData *in, U32 startByte) | ||
767 | { | ||
768 | |||
769 | S8 bMant, bExp; | ||
770 | |||
771 | bMant = mData[startByte++]; | ||
772 | bExp = mData[startByte++]; | ||
773 | in->bouncePlaneNormal[0] = floatFromTwoBytes(bMant, bExp); | ||
774 | bMant = mData[startByte++]; | ||
775 | bExp = mData[startByte++]; | ||
776 | in->bouncePlaneNormal[1] = floatFromTwoBytes(bMant, bExp); | ||
777 | bMant = mData[startByte++]; | ||
778 | bExp = mData[startByte++]; | ||
779 | in->bouncePlaneNormal[2] = floatFromTwoBytes(bMant, bExp); | ||
780 | |||
781 | bMant = mData[startByte++]; | ||
782 | bExp = mData[startByte++]; | ||
783 | in->bouncePlaneZ = floatFromTwoBytes(bMant, bExp); | ||
784 | |||
785 | return startByte; | ||
786 | } | ||
787 | |||
788 | U32 LLPartSysCompressedPacket::readBounce_b(LLPartInitData *in, U32 startByte) | ||
789 | { | ||
790 | S8 bMant, bExp; | ||
791 | bMant = mData[startByte++]; | ||
792 | bExp = mData[startByte++]; | ||
793 | in->bounce_b = floatFromTwoBytes(bMant, bExp); | ||
794 | return startByte; | ||
795 | } | ||
796 | |||
797 | |||
798 | //U32 LLPartSysCompressedPacket::readPos_ranges(LLPartInitData *in, U32 startByte) | ||
799 | //{ | ||
800 | // S8 tmp; | ||
801 | // int i; | ||
802 | // for(i = 0; i < 6; i++) | ||
803 | // { | ||
804 | // tmp = (S8)mData[startByte++]; | ||
805 | // in->pos_ranges[i] = tmp; | ||
806 | // } | ||
807 | // return startByte; | ||
808 | //} | ||
809 | |||
810 | //U32 LLPartSysCompressedPacket::readVel_ranges(LLPartInitData *in, U32 startByte) | ||
811 | //{ | ||
812 | // S8 tmp; | ||
813 | // int i; | ||
814 | // for(i = 0; i < 6; i++) | ||
815 | // { | ||
816 | // tmp = (S8)mData[startByte++]; | ||
817 | // in->vel_ranges[i] = tmp; | ||
818 | // } | ||
819 | // return startByte; | ||
820 | //} | ||
821 | |||
822 | |||
823 | |||
824 | U32 LLPartSysCompressedPacket::readAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte) | ||
825 | { | ||
826 | int i; | ||
827 | S8 bMant, bExp; | ||
828 | for(i = 0; i < 3; i++) | ||
829 | { | ||
830 | bMant = mData[startByte++]; | ||
831 | bExp = mData[startByte++]; | ||
832 | in->diffEqAlpha[i] = floatFromTwoBytes(bMant, bExp); | ||
833 | } | ||
834 | for(i = 0; i < 3; i++) | ||
835 | { | ||
836 | bMant = mData[startByte++]; | ||
837 | bExp = mData[startByte++]; | ||
838 | in->diffEqScale[i] = floatFromTwoBytes(bMant, bExp); | ||
839 | } | ||
840 | return startByte; | ||
841 | } | ||
842 | |||
843 | U32 LLPartSysCompressedPacket::readAlpha_range(LLPartInitData *in, U32 startByte) | ||
844 | { | ||
845 | int i; | ||
846 | S8 bMant, bExp; | ||
847 | for(i = 0; i < 4; i++) | ||
848 | { | ||
849 | bMant = mData[startByte++]; | ||
850 | bExp = mData[startByte++]; | ||
851 | in->alpha_range[i] = floatFromTwoBytes(bMant, bExp); | ||
852 | } | ||
853 | return startByte; | ||
854 | } | ||
855 | |||
856 | U32 LLPartSysCompressedPacket::readScale_range(LLPartInitData *in, U32 startByte) | ||
857 | { | ||
858 | int i; | ||
859 | S8 bMant, bExp; | ||
860 | for(i = 0; i < 4; i++) | ||
861 | { | ||
862 | bMant = mData[startByte++]; | ||
863 | bExp = mData[startByte++]; | ||
864 | in->scale_range[i] = floatFromTwoBytes(bMant, bExp); | ||
865 | } | ||
866 | return startByte; | ||
867 | } | ||
868 | |||
869 | U32 LLPartSysCompressedPacket::readVelocityOffset(LLPartInitData *in, U32 startByte) | ||
870 | { | ||
871 | int i; | ||
872 | S8 bMant, bExp; | ||
873 | for(i = 0; i < 3; i++) | ||
874 | { | ||
875 | bMant = mData[startByte++]; | ||
876 | bExp = mData[startByte++]; | ||
877 | in->vel_offset[i] = floatFromTwoBytes(bMant, bExp); | ||
878 | } | ||
879 | return startByte; | ||
880 | } | ||
881 | |||
882 | U32 LLPartSysCompressedPacket::readUUID(LLPartInitData *in, U32 startByte) | ||
883 | { | ||
884 | U8 * bufPtr = mData + startByte; | ||
885 | |||
886 | if(mData[startByte] == 0x01) | ||
887 | { | ||
888 | in->mImageUuid = IMG_SHOT; | ||
889 | return startByte+1; | ||
890 | } | ||
891 | if(mData[startByte] == 0x02) | ||
892 | { | ||
893 | in->mImageUuid = IMG_SPARK; | ||
894 | return startByte+1; | ||
895 | } | ||
896 | if(mData[startByte] == 0x03) | ||
897 | { | ||
898 | in->mImageUuid = IMG_BIG_EXPLOSION_1; | ||
899 | return startByte+1; | ||
900 | } | ||
901 | if(mData[startByte] == 0x04) | ||
902 | { | ||
903 | in->mImageUuid = IMG_BIG_EXPLOSION_2; | ||
904 | return startByte+1; | ||
905 | } | ||
906 | if(mData[startByte] == 0x05) | ||
907 | { | ||
908 | in->mImageUuid = IMG_SMOKE_POOF; | ||
909 | return startByte+1; | ||
910 | } | ||
911 | if(mData[startByte] == 0x06) | ||
912 | { | ||
913 | in->mImageUuid = IMG_FIRE; | ||
914 | return startByte+1; | ||
915 | } | ||
916 | if(mData[startByte] == 0x07) | ||
917 | { | ||
918 | in->mImageUuid = IMG_EXPLOSION; | ||
919 | return startByte+1; | ||
920 | } | ||
921 | if(mData[startByte] == 0x08) | ||
922 | { | ||
923 | in->mImageUuid = IMG_EXPLOSION_2; | ||
924 | return startByte+1; | ||
925 | } | ||
926 | if(mData[startByte] == 0x09) | ||
927 | { | ||
928 | in->mImageUuid = IMG_EXPLOSION_3; | ||
929 | return startByte+1; | ||
930 | } | ||
931 | if(mData[startByte] == 0x0A) | ||
932 | { | ||
933 | in->mImageUuid = IMG_EXPLOSION_4; | ||
934 | return startByte+1; | ||
935 | } | ||
936 | |||
937 | startByte++; // cause we actually have to read the UUID now. | ||
938 | memcpy(in->mImageUuid.mData, bufPtr, 16); /* Flawfinder: ignore */ | ||
939 | return (startByte+16); | ||
940 | } | ||
941 | |||
942 | |||
943 | |||
944 | |||
945 | U32 LLPartSysCompressedPacket::readSpawn(LLPartInitData *in, U32 startByte) | ||
946 | { | ||
947 | S8 bMant, bExp; | ||
948 | U32 i; | ||
949 | |||
950 | bMant = mData[startByte++]; | ||
951 | bExp = mData[startByte++]; | ||
952 | in->spawnRange = floatFromTwoBytes(bMant, bExp); | ||
953 | bMant = mData[startByte++]; | ||
954 | bExp = mData[startByte++]; | ||
955 | in->spawnFrequency = floatFromTwoBytes(bMant, bExp); | ||
956 | bMant = mData[startByte++]; | ||
957 | bExp = mData[startByte++]; | ||
958 | in->spawnFreqencyRange = floatFromTwoBytes(bMant, bExp); | ||
959 | |||
960 | for(i = 0; i < 3; i++) | ||
961 | { | ||
962 | bMant = mData[startByte++]; | ||
963 | bExp = mData[startByte++]; | ||
964 | in->spawnDirection[i] = floatFromTwoBytes(bMant, bExp); | ||
965 | } | ||
966 | |||
967 | bMant = mData[startByte++]; | ||
968 | bExp = mData[startByte++]; | ||
969 | in->spawnDirectionRange = floatFromTwoBytes(bMant, bExp); | ||
970 | bMant = mData[startByte++]; | ||
971 | bExp = mData[startByte++]; | ||
972 | in->spawnVelocity = floatFromTwoBytes(bMant, bExp); | ||
973 | bMant = mData[startByte++]; | ||
974 | bExp = mData[startByte++]; | ||
975 | in->spawnVelocityRange = floatFromTwoBytes(bMant, bExp); | ||
976 | |||
977 | return startByte; | ||
978 | } | ||
979 | |||
980 | U32 LLPartSysCompressedPacket::readEnvironment(LLPartInitData *in, U32 startByte) | ||
981 | { | ||
982 | S8 bMant, bExp; | ||
983 | U32 i; | ||
984 | |||
985 | |||
986 | bMant = mData[startByte++]; | ||
987 | bExp = mData[startByte++]; | ||
988 | in->windWeight = floatFromTwoBytes(bMant, bExp); | ||
989 | |||
990 | for(i = 0; i < 3; i++) | ||
991 | { | ||
992 | bMant = mData[startByte++]; | ||
993 | bExp = mData[startByte++]; | ||
994 | in->currentGravity[i] = floatFromTwoBytes(bMant, bExp); | ||
995 | } | ||
996 | |||
997 | bMant = mData[startByte++]; | ||
998 | bExp = mData[startByte++]; | ||
999 | in->gravityWeight = floatFromTwoBytes(bMant, bExp); | ||
1000 | |||
1001 | return startByte; | ||
1002 | } | ||
1003 | |||
1004 | U32 LLPartSysCompressedPacket::readLifespan(LLPartInitData *in, U32 startByte) | ||
1005 | { | ||
1006 | S8 bMant, bExp; | ||
1007 | |||
1008 | bMant = mData[startByte++]; | ||
1009 | bExp = mData[startByte++]; | ||
1010 | in->globalLifetime = floatFromTwoBytes(bMant, bExp); | ||
1011 | bMant = mData[startByte++]; | ||
1012 | bExp = mData[startByte++]; | ||
1013 | in->individualLifetime = floatFromTwoBytes(bMant, bExp); | ||
1014 | bMant = mData[startByte++]; | ||
1015 | bExp = mData[startByte++]; | ||
1016 | in->individualLifetimeRange = floatFromTwoBytes(bMant, bExp); | ||
1017 | |||
1018 | return startByte; | ||
1019 | } | ||
1020 | |||
1021 | U32 LLPartSysCompressedPacket::readDecayDamp(LLPartInitData *in, U32 startByte) | ||
1022 | { | ||
1023 | S8 bMant, bExp; | ||
1024 | |||
1025 | bMant = mData[startByte++]; | ||
1026 | bExp = mData[startByte++]; | ||
1027 | in->speedLimit = floatFromTwoBytes(bMant, bExp); | ||
1028 | bMant = mData[startByte++]; | ||
1029 | bExp = mData[startByte++]; | ||
1030 | in->alphaDecay = floatFromTwoBytes(bMant, bExp); | ||
1031 | bMant = mData[startByte++]; | ||
1032 | bExp = mData[startByte++]; | ||
1033 | in->scaleDecay = floatFromTwoBytes(bMant, bExp); | ||
1034 | bMant = mData[startByte++]; | ||
1035 | bExp = mData[startByte++]; | ||
1036 | in->dampMotionFactor = floatFromTwoBytes(bMant, bExp); | ||
1037 | |||
1038 | return startByte; | ||
1039 | } | ||
1040 | |||
1041 | U32 LLPartSysCompressedPacket::readWindDiffusionFactor(LLPartInitData *in, U32 startByte) | ||
1042 | { | ||
1043 | int i; | ||
1044 | S8 bMant, bExp; | ||
1045 | for(i = 0; i < 3; i++) | ||
1046 | { | ||
1047 | bMant = mData[startByte++]; | ||
1048 | bExp = mData[startByte++]; | ||
1049 | in->windDiffusionFactor[i] = floatFromTwoBytes(bMant, bExp); | ||
1050 | } | ||
1051 | return startByte; | ||
1052 | } | ||
1053 | |||
1054 | BOOL LLPartSysCompressedPacket::fromLLPartInitData(LLPartInitData *in, U32 &bytesUsed) | ||
1055 | { | ||
1056 | |||
1057 | writeFlagByte(in); | ||
1058 | U32 currByte = 4; | ||
1059 | |||
1060 | // llprintline("calling \"fromLLPartInitData\"\n"); | ||
1061 | |||
1062 | //if(mData[0] & PART_SYS_K_MASK) | ||
1063 | //{ | ||
1064 | // currByte = writeK(in, 3); // first 3 bytes are reserved for header data | ||
1065 | //} | ||
1066 | |||
1067 | |||
1068 | |||
1069 | if(mData[0] & PART_SYS_KILL_P_MASK) | ||
1070 | { | ||
1071 | currByte = writeKill_p(in, currByte); | ||
1072 | } | ||
1073 | |||
1074 | if(mData[0] & PART_SYS_BOUNCE_P_MASK) | ||
1075 | { | ||
1076 | currByte = writeBounce_p(in, currByte); | ||
1077 | } | ||
1078 | |||
1079 | if(mData[0] & PART_SYS_BOUNCE_B_MASK) | ||
1080 | { | ||
1081 | currByte = writeBounce_b(in, currByte); | ||
1082 | } | ||
1083 | |||
1084 | //if(mData[0] & PART_SYS_POS_RANGES_MASK) | ||
1085 | //{ | ||
1086 | // currByte = writePos_ranges(in, currByte); | ||
1087 | //} | ||
1088 | |||
1089 | //if(mData[0] & PART_SYS_VEL_RANGES_MASK) | ||
1090 | //{ | ||
1091 | // currByte = writeVel_ranges(in, currByte); | ||
1092 | //} | ||
1093 | |||
1094 | if(mData[0] & PART_SYS_ALPHA_SCALE_DIFF_MASK) | ||
1095 | { | ||
1096 | currByte = writeAlphaScaleDiffEqn_range(in, currByte); | ||
1097 | } | ||
1098 | |||
1099 | if(mData[0] & PART_SYS_SCALE_RANGE_MASK) | ||
1100 | { | ||
1101 | currByte = writeScale_range(in, currByte); | ||
1102 | } | ||
1103 | |||
1104 | if(mData[0] & PART_SYS_VEL_OFFSET_MASK) | ||
1105 | { | ||
1106 | currByte = writeVelocityOffset(in, currByte); | ||
1107 | } | ||
1108 | |||
1109 | if(mData[0] & PART_SYS_M_IMAGE_UUID_MASK) | ||
1110 | { | ||
1111 | currByte = writeUUID(in, currByte); | ||
1112 | } | ||
1113 | |||
1114 | |||
1115 | if(mData[3] & PART_SYS_BYTE_SPAWN_MASK) | ||
1116 | { | ||
1117 | currByte = writeSpawn(in, currByte); | ||
1118 | } | ||
1119 | |||
1120 | if(mData[3] & PART_SYS_BYTE_ENVIRONMENT_MASK) | ||
1121 | { | ||
1122 | currByte = writeEnvironment(in, currByte); | ||
1123 | } | ||
1124 | |||
1125 | if(mData[3] & PART_SYS_BYTE_LIFESPAN_MASK) | ||
1126 | { | ||
1127 | currByte = writeLifespan(in, currByte); | ||
1128 | } | ||
1129 | |||
1130 | if(mData[3] & PART_SYS_BYTE_DECAY_DAMP_MASK) | ||
1131 | { | ||
1132 | currByte = writeDecayDamp(in, currByte); | ||
1133 | } | ||
1134 | |||
1135 | if(mData[3] & PART_SYS_BYTE_WIND_DIFF_MASK) | ||
1136 | { | ||
1137 | currByte = writeWindDiffusionFactor(in, currByte); | ||
1138 | } | ||
1139 | |||
1140 | |||
1141 | if(mData[2] & PART_SYS_BYTE_3_ALPHA_MASK) | ||
1142 | { | ||
1143 | currByte = writeAlpha_range(in, currByte); | ||
1144 | } | ||
1145 | |||
1146 | mData[currByte++] = (U8)in->maxParticles; | ||
1147 | mData[currByte++] = (U8)in->initialParticles; | ||
1148 | |||
1149 | |||
1150 | U32 flagFlag = 1; // flag indicating which flag bytes are non-zero | ||
1151 | // yeah, I know, the name sounds funny | ||
1152 | for(U32 i = 0; i < 8; i++) | ||
1153 | { | ||
1154 | |||
1155 | // llprintline("Flag \"%x\" gets byte \"%x\"\n", flagFlag, in->mFlags[i]); | ||
1156 | if(mData[1] & flagFlag) | ||
1157 | { | ||
1158 | mData[currByte++] = in->mFlags[i]; | ||
1159 | // llprintline("and is valid...\n"); | ||
1160 | } | ||
1161 | flagFlag <<= 1; | ||
1162 | } | ||
1163 | |||
1164 | bytesUsed = mNumBytes = currByte; | ||
1165 | |||
1166 | |||
1167 | |||
1168 | // llprintline("returning from \"fromLLPartInitData\" with %d bytes\n", bytesUsed); | ||
1169 | |||
1170 | return TRUE; | ||
1171 | } | ||
1172 | |||
1173 | BOOL LLPartSysCompressedPacket::toLLPartInitData(LLPartInitData *out, U32 *bytesUsed) | ||
1174 | { | ||
1175 | U32 currByte = 4; | ||
1176 | |||
1177 | gSetInitDataDefaults(out); | ||
1178 | |||
1179 | if(mData[0] & PART_SYS_KILL_P_MASK) | ||
1180 | { | ||
1181 | currByte = readKill_p(out, currByte); | ||
1182 | } | ||
1183 | |||
1184 | if(mData[0] & PART_SYS_BOUNCE_P_MASK) | ||
1185 | { | ||
1186 | currByte = readBounce_p(out, currByte); | ||
1187 | } | ||
1188 | |||
1189 | if(mData[0] & PART_SYS_BOUNCE_B_MASK) | ||
1190 | { | ||
1191 | currByte = readBounce_b(out, currByte); | ||
1192 | } | ||
1193 | |||
1194 | if(mData[0] & PART_SYS_ALPHA_SCALE_DIFF_MASK) | ||
1195 | { | ||
1196 | currByte = readAlphaScaleDiffEqn_range(out, currByte); | ||
1197 | } | ||
1198 | |||
1199 | if(mData[0] & PART_SYS_SCALE_RANGE_MASK) | ||
1200 | { | ||
1201 | currByte = readScale_range(out, currByte); | ||
1202 | } | ||
1203 | |||
1204 | if(mData[0] & PART_SYS_VEL_OFFSET_MASK) | ||
1205 | { | ||
1206 | currByte = readVelocityOffset(out, currByte); | ||
1207 | } | ||
1208 | |||
1209 | if(mData[0] & PART_SYS_M_IMAGE_UUID_MASK) | ||
1210 | { | ||
1211 | currByte = readUUID(out, currByte); | ||
1212 | } | ||
1213 | |||
1214 | |||
1215 | if(mData[3] & PART_SYS_BYTE_SPAWN_MASK) | ||
1216 | { | ||
1217 | currByte = readSpawn(out, currByte); | ||
1218 | } | ||
1219 | |||
1220 | if(mData[3] & PART_SYS_BYTE_ENVIRONMENT_MASK) | ||
1221 | { | ||
1222 | currByte = readEnvironment(out, currByte); | ||
1223 | } | ||
1224 | |||
1225 | if(mData[3] & PART_SYS_BYTE_LIFESPAN_MASK) | ||
1226 | { | ||
1227 | currByte = readLifespan(out, currByte); | ||
1228 | } | ||
1229 | |||
1230 | if(mData[3] & PART_SYS_BYTE_DECAY_DAMP_MASK) | ||
1231 | { | ||
1232 | currByte = readDecayDamp(out, currByte); | ||
1233 | } | ||
1234 | |||
1235 | if(mData[3] & PART_SYS_BYTE_WIND_DIFF_MASK) | ||
1236 | { | ||
1237 | currByte = readWindDiffusionFactor(out, currByte); | ||
1238 | } | ||
1239 | |||
1240 | if(mData[2] & PART_SYS_BYTE_3_ALPHA_MASK) | ||
1241 | { | ||
1242 | currByte = readAlpha_range(out, currByte); | ||
1243 | } | ||
1244 | |||
1245 | out->maxParticles = mData[currByte++]; | ||
1246 | out->initialParticles = mData[currByte++]; | ||
1247 | |||
1248 | U32 flagFlag = 1; // flag indicating which flag bytes are non-zero | ||
1249 | // yeah, I know, the name sounds funny | ||
1250 | for(U32 i = 0; i < 8; i++) | ||
1251 | { | ||
1252 | flagFlag = 1<<i; | ||
1253 | |||
1254 | if((mData[1] & flagFlag)) | ||
1255 | { | ||
1256 | out->mFlags[i] = mData[currByte++]; | ||
1257 | } | ||
1258 | } | ||
1259 | |||
1260 | *bytesUsed = currByte; | ||
1261 | return TRUE; | ||
1262 | } | ||
1263 | |||
1264 | BOOL LLPartSysCompressedPacket::fromUnsignedBytes(U8 *in, U32 bytesUsed) | ||
1265 | { | ||
1266 | if ((in != NULL) && (bytesUsed <= sizeof(mData))) | ||
1267 | { | ||
1268 | memcpy(mData, in, bytesUsed); | ||
1269 | mNumBytes = bytesUsed; | ||
1270 | return TRUE; | ||
1271 | } | ||
1272 | else | ||
1273 | { | ||
1274 | llerrs << "NULL input data or number of bytes exceed mData size" << llendl; | ||
1275 | return FALSE; | ||
1276 | } | ||
1277 | } | ||
1278 | |||
1279 | |||
1280 | U32 LLPartSysCompressedPacket::bufferSize() | ||
1281 | { | ||
1282 | return mNumBytes; | ||
1283 | } | ||
1284 | |||
1285 | BOOL LLPartSysCompressedPacket::toUnsignedBytes(U8 *out) | ||
1286 | { | ||
1287 | memcpy(out, mData, mNumBytes); /* Flawfinder: ignore */ | ||
1288 | return TRUE; | ||
1289 | } | ||
1290 | |||
1291 | U8 * LLPartSysCompressedPacket::getBytePtr() | ||
1292 | { | ||
1293 | return mData; | ||
1294 | } | ||
1295 | |||
1296 | |||