aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llpartdata.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/llpartdata.cpp
parentREADME.txt (diff)
downloadmeta-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 '')
-rw-r--r--linden/indra/llmessage/llpartdata.cpp326
1 files changed, 326 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llpartdata.cpp b/linden/indra/llmessage/llpartdata.cpp
new file mode 100644
index 0000000..11969d0
--- /dev/null
+++ b/linden/indra/llmessage/llpartdata.cpp
@@ -0,0 +1,326 @@
1/**
2 * @file llpartdata.cpp
3 * @brief Particle system data packing
4 *
5 * Copyright (c) 2003-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "linden_common.h"
29
30#include "llpartdata.h"
31#include "message.h"
32
33#include "lldatapacker.h"
34#include "v4coloru.h"
35
36#include "llsdutil.h"
37
38
39const S32 PS_PART_DATA_BLOCK_SIZE = 4 + 2 + 4 + 4 + 2 + 2; // 18
40const S32 PS_DATA_BLOCK_SIZE = 68 + PS_PART_DATA_BLOCK_SIZE; // 68 + 18 = 86
41
42
43const F32 MAX_PART_SCALE = 4.f;
44
45BOOL LLPartData::pack(LLDataPacker &dp)
46{
47 LLColor4U coloru;
48 dp.packU32(mFlags, "pdflags");
49 dp.packFixed(mMaxAge, "pdmaxage", FALSE, 8, 8);
50 coloru.setVec(mStartColor);
51 dp.packColor4U(coloru, "pdstartcolor");
52 coloru.setVec(mEndColor);
53 dp.packColor4U(coloru, "pdendcolor");
54 dp.packFixed(mStartScale.mV[0], "pdstartscalex", FALSE, 3, 5);
55 dp.packFixed(mStartScale.mV[1], "pdstartscaley", FALSE, 3, 5);
56 dp.packFixed(mEndScale.mV[0], "pdendscalex", FALSE, 3, 5);
57 dp.packFixed(mEndScale.mV[1], "pdendscaley", FALSE, 3, 5);
58 return TRUE;
59}
60
61LLSD LLPartData::asLLSD() const
62{
63 LLSD sd = LLSD();
64 sd["pdflags"] = ll_sd_from_U32(mFlags);
65 sd["pdmaxage"] = mMaxAge;
66 sd["pdstartcolor"] = ll_sd_from_color4(mStartColor);
67 sd["pdendcolor"] = ll_sd_from_color4(mEndColor);
68 sd["pdstartscale"] = ll_sd_from_vector2(mStartScale);
69 sd["pdendscale"] = ll_sd_from_vector2(mEndScale);
70 return sd;
71}
72
73bool LLPartData::fromLLSD(LLSD& sd)
74{
75 mFlags = ll_U32_from_sd(sd["pdflags"]);
76 mMaxAge = (F32)sd["pdmaxage"].asReal();
77 mStartColor = ll_color4_from_sd(sd["pdstartcolor"]);
78 mEndColor = ll_color4_from_sd(sd["pdendcolor"]);
79 mStartScale = ll_vector2_from_sd(sd["pdstartscale"]);
80 mEndScale = ll_vector2_from_sd(sd["pdendscale"]);
81 return true;
82}
83
84
85BOOL LLPartData::unpack(LLDataPacker &dp)
86{
87 LLColor4U coloru;
88
89 dp.unpackU32(mFlags, "pdflags");
90 dp.unpackFixed(mMaxAge, "pdmaxage", FALSE, 8, 8);
91
92 dp.unpackColor4U(coloru, "pdstartcolor");
93 mStartColor.setVec(coloru);
94 dp.unpackColor4U(coloru, "pdendcolor");
95 mEndColor.setVec(coloru);
96 dp.unpackFixed(mStartScale.mV[0], "pdstartscalex", FALSE, 3, 5);
97 dp.unpackFixed(mStartScale.mV[1], "pdstartscaley", FALSE, 3, 5);
98 dp.unpackFixed(mEndScale.mV[0], "pdendscalex", FALSE, 3, 5);
99 dp.unpackFixed(mEndScale.mV[1], "pdendscaley", FALSE, 3, 5);
100 return TRUE;
101}
102
103
104void LLPartData::setFlags(const U32 flags)
105{
106 mFlags = flags;
107}
108
109
110void LLPartData::setMaxAge(const F32 max_age)
111{
112 mMaxAge = llclamp(max_age, 0.f, 30.f);
113}
114
115
116void LLPartData::setStartScale(const F32 xs, const F32 ys)
117{
118 mStartScale.mV[VX] = llmin(xs, MAX_PART_SCALE);
119 mStartScale.mV[VY] = llmin(ys, MAX_PART_SCALE);
120}
121
122
123void LLPartData::setEndScale(const F32 xs, const F32 ys)
124{
125 mEndScale.mV[VX] = llmin(xs, MAX_PART_SCALE);
126 mEndScale.mV[VY] = llmin(ys, MAX_PART_SCALE);
127}
128
129
130void LLPartData::setStartColor(const LLVector3 &rgb)
131{
132 mStartColor.setVec(rgb.mV[0], rgb.mV[1], rgb.mV[2]);
133}
134
135
136void LLPartData::setEndColor(const LLVector3 &rgb)
137{
138 mEndColor.setVec(rgb.mV[0], rgb.mV[1], rgb.mV[2]);
139}
140
141void LLPartData::setStartAlpha(const F32 alpha)
142{
143 mStartColor.mV[3] = alpha;
144}
145void LLPartData::setEndAlpha(const F32 alpha)
146{
147 mEndColor.mV[3] = alpha;
148}
149
150
151LLPartSysData::LLPartSysData()
152{
153 mCRC = 0;
154 mPartData.mFlags = 0;
155 mPartData.mStartColor = LLColor4(1.f, 1.f, 1.f, 1.f);
156 mPartData.mEndColor = LLColor4(1.f, 1.f, 1.f, 1.f);
157 mPartData.mStartScale = LLVector2(1.f, 1.f);
158 mPartData.mEndScale = LLVector2(1.f, 1.f);
159 mPartData.mMaxAge = 10.0;
160
161 mMaxAge = 0.0;
162 mStartAge = 0.0;
163 mPattern = LL_PART_SRC_PATTERN_DROP; // Pattern for particle velocity
164 mInnerAngle = 0.0; // Inner angle of PATTERN_ANGLE_*
165 mOuterAngle = 0.0; // Outer angle of PATTERN_ANGLE_*
166 mBurstRate = 0.1f; // How often to do a burst of particles
167 mBurstPartCount = 1; // How many particles in a burst
168 mBurstSpeedMin = 1.f; // Minimum particle velocity
169 mBurstSpeedMax = 1.f; // Maximum particle velocity
170 mBurstRadius = 0.f;
171}
172
173
174BOOL LLPartSysData::pack(LLDataPacker &dp)
175{
176 dp.packU32(mCRC, "pscrc");
177 dp.packU32(mFlags, "psflags");
178 dp.packU8(mPattern, "pspattern");
179 dp.packFixed(mMaxAge, "psmaxage", FALSE, 8, 8);
180 dp.packFixed(mStartAge, "psstartage", FALSE, 8, 8);
181 dp.packFixed(mInnerAngle, "psinnerangle", FALSE, 3, 5);
182 dp.packFixed(mOuterAngle, "psouterangle", FALSE, 3, 5);
183 dp.packFixed(mBurstRate, "psburstrate", FALSE, 8, 8);
184 dp.packFixed(mBurstRadius, "psburstradius", FALSE, 8, 8);
185 dp.packFixed(mBurstSpeedMin, "psburstspeedmin", FALSE, 8, 8);
186 dp.packFixed(mBurstSpeedMax, "psburstspeedmax", FALSE, 8, 8);
187 dp.packU8(mBurstPartCount, "psburstpartcount");
188
189 dp.packFixed(mAngularVelocity.mV[0], "psangvelx", TRUE, 8, 7);
190 dp.packFixed(mAngularVelocity.mV[1], "psangvely", TRUE, 8, 7);
191 dp.packFixed(mAngularVelocity.mV[2], "psangvelz", TRUE, 8, 7);
192
193 dp.packFixed(mPartAccel.mV[0], "psaccelx", TRUE, 8, 7);
194 dp.packFixed(mPartAccel.mV[1], "psaccely", TRUE, 8, 7);
195 dp.packFixed(mPartAccel.mV[2], "psaccelz", TRUE, 8, 7);
196
197 dp.packUUID(mPartImageID, "psuuid");
198 dp.packUUID(mTargetUUID, "pstargetuuid");
199 mPartData.pack(dp);
200 return TRUE;
201}
202
203
204BOOL LLPartSysData::unpack(LLDataPacker &dp)
205{
206 dp.unpackU32(mCRC, "pscrc");
207 dp.unpackU32(mFlags, "psflags");
208 dp.unpackU8(mPattern, "pspattern");
209 dp.unpackFixed(mMaxAge, "psmaxage", FALSE, 8, 8);
210 dp.unpackFixed(mStartAge, "psstartage", FALSE, 8, 8);
211 dp.unpackFixed(mInnerAngle, "psinnerangle", FALSE, 3, 5);
212 dp.unpackFixed(mOuterAngle, "psouterangle", FALSE, 3, 5);
213 dp.unpackFixed(mBurstRate, "psburstrate", FALSE, 8, 8);
214 mBurstRate = llmax(0.01f, mBurstRate);
215 dp.unpackFixed(mBurstRadius, "psburstradius", FALSE, 8, 8);
216 dp.unpackFixed(mBurstSpeedMin, "psburstspeedmin", FALSE, 8, 8);
217 dp.unpackFixed(mBurstSpeedMax, "psburstspeedmax", FALSE, 8, 8);
218 dp.unpackU8(mBurstPartCount, "psburstpartcount");
219
220 dp.unpackFixed(mAngularVelocity.mV[0], "psangvelx", TRUE, 8, 7);
221 dp.unpackFixed(mAngularVelocity.mV[1], "psangvely", TRUE, 8, 7);
222 dp.unpackFixed(mAngularVelocity.mV[2], "psangvelz", TRUE, 8, 7);
223
224 dp.unpackFixed(mPartAccel.mV[0], "psaccelx", TRUE, 8, 7);
225 dp.unpackFixed(mPartAccel.mV[1], "psaccely", TRUE, 8, 7);
226 dp.unpackFixed(mPartAccel.mV[2], "psaccelz", TRUE, 8, 7);
227
228 dp.unpackUUID(mPartImageID, "psuuid");
229 dp.unpackUUID(mTargetUUID, "pstargetuuid");
230 mPartData.unpack(dp);
231 return TRUE;
232}
233
234
235BOOL LLPartSysData::isNullPS(const S32 block_num)
236{
237 U8 ps_data_block[PS_DATA_BLOCK_SIZE];
238 U32 crc;
239
240 S32 size;
241 // Check size of block
242 size = gMessageSystem->getSize("ObjectData", block_num, "PSBlock");
243
244 if (!size)
245 {
246 return TRUE;
247 }
248 else if (size != PS_DATA_BLOCK_SIZE)
249 {
250 llwarns << "PSBlock is wrong size for particle system data - got " << size << ", expecting " << PS_DATA_BLOCK_SIZE << llendl;
251 return TRUE;
252 }
253 gMessageSystem->getBinaryData("ObjectData", "PSBlock", ps_data_block, PS_DATA_BLOCK_SIZE, block_num, PS_DATA_BLOCK_SIZE);
254
255 LLDataPackerBinaryBuffer dp(ps_data_block, PS_DATA_BLOCK_SIZE);
256 dp.unpackU32(crc, "crc");
257
258 if (crc == 0)
259 {
260 return TRUE;
261 }
262 return FALSE;
263}
264
265
266//static
267BOOL LLPartSysData::packNull()
268{
269 U8 ps_data_block[PS_DATA_BLOCK_SIZE];
270 gMessageSystem->addBinaryData("PSBlock", ps_data_block, 0);
271 return TRUE;
272}
273
274
275BOOL LLPartSysData::packBlock()
276{
277 U8 ps_data_block[PS_DATA_BLOCK_SIZE];
278
279 LLDataPackerBinaryBuffer dp(ps_data_block, PS_DATA_BLOCK_SIZE);
280 pack(dp);
281
282 // Add to message
283 gMessageSystem->addBinaryData("PSBlock", ps_data_block, PS_DATA_BLOCK_SIZE);
284
285 return TRUE;
286}
287
288
289BOOL LLPartSysData::unpackBlock(const S32 block_num)
290{
291 U8 ps_data_block[PS_DATA_BLOCK_SIZE];
292
293 // Check size of block
294 S32 size = gMessageSystem->getSize("ObjectData", block_num, "PSBlock");
295
296 if (size != PS_DATA_BLOCK_SIZE)
297 {
298 llwarns << "PSBlock is wrong size for particle system data - got " << size << ", expecting " << PS_DATA_BLOCK_SIZE << llendl;
299 return FALSE;
300 }
301
302 // Get from message
303 gMessageSystem->getBinaryData("ObjectData", "PSBlock", ps_data_block, PS_DATA_BLOCK_SIZE, block_num, PS_DATA_BLOCK_SIZE);
304
305 LLDataPackerBinaryBuffer dp(ps_data_block, PS_DATA_BLOCK_SIZE);
306 unpack(dp);
307
308 return TRUE;
309}
310
311void LLPartSysData::clampSourceParticleRate()
312{
313 F32 particle_rate = 0;
314 particle_rate = mBurstPartCount/mBurstRate;
315 if (particle_rate > 256.f)
316 {
317 mBurstPartCount = llfloor(((F32)mBurstPartCount)*(256.f/particle_rate));
318 }
319}
320
321void LLPartSysData::setPartAccel(const LLVector3 &accel)
322{
323 mPartAccel.mV[VX] = llclamp(accel.mV[VX], -100.f, 100.f);
324 mPartAccel.mV[VY] = llclamp(accel.mV[VY], -100.f, 100.f);
325 mPartAccel.mV[VZ] = llclamp(accel.mV[VZ], -100.f, 100.f);
326}