PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmessage/llpartdata.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 238 lines | 139 code | 42 blank | 57 comment | 0 complexity | 1bfc4393b07ba37017eb49be5319bf58 MD5 | raw file
  1/** 
  2 * @file llpartdata.h
  3 * @brief Particle system data packing
  4 *
  5 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLPARTDATA_H
 28#define LL_LLPARTDATA_H
 29
 30#include "lluuid.h"
 31#include "v3math.h"
 32#include "v3dmath.h"
 33#include "v2math.h"
 34#include "v4color.h"
 35
 36class LLMessageSystem;
 37class LLDataPacker;
 38
 39const S32 PS_CUR_VERSION = 18;
 40
 41//
 42// These constants are used by the script code, not by the particle system itself
 43//
 44
 45enum LLPSScriptFlags
 46{
 47	// Flags for the different parameters of individual particles
 48	LLPS_PART_FLAGS,
 49	LLPS_PART_START_COLOR,
 50	LLPS_PART_START_ALPHA,
 51	LLPS_PART_END_COLOR,
 52	LLPS_PART_END_ALPHA,
 53	LLPS_PART_START_SCALE,
 54	LLPS_PART_END_SCALE,
 55	LLPS_PART_MAX_AGE,
 56
 57	// Flags for the different parameters of the particle source
 58	LLPS_SRC_ACCEL,
 59	LLPS_SRC_PATTERN,
 60	LLPS_SRC_INNERANGLE,
 61	LLPS_SRC_OUTERANGLE,
 62	LLPS_SRC_TEXTURE,
 63	LLPS_SRC_BURST_RATE,
 64	LLPS_SRC_BURST_DURATION,
 65	LLPS_SRC_BURST_PART_COUNT,
 66	LLPS_SRC_BURST_RADIUS,
 67	LLPS_SRC_BURST_SPEED_MIN,
 68	LLPS_SRC_BURST_SPEED_MAX,
 69	LLPS_SRC_MAX_AGE,
 70	LLPS_SRC_TARGET_UUID,
 71	LLPS_SRC_OMEGA,
 72	LLPS_SRC_ANGLE_BEGIN,
 73	LLPS_SRC_ANGLE_END
 74};
 75
 76
 77class LLPartData
 78{
 79public:
 80	LLPartData() :
 81		mFlags(0),
 82		mMaxAge(0.f),
 83		mParameter(0.f)
 84	{
 85	}
 86	BOOL unpack(LLDataPacker &dp);
 87	BOOL pack(LLDataPacker &dp);
 88	LLSD asLLSD() const;
 89	operator LLSD() const {return asLLSD(); }
 90	bool fromLLSD(LLSD& sd);
 91
 92	// Masks for the different particle flags
 93	enum
 94	{
 95		LL_PART_INTERP_COLOR_MASK =		0x01,
 96		LL_PART_INTERP_SCALE_MASK =		0x02,
 97		LL_PART_BOUNCE_MASK =			0x04,
 98		LL_PART_WIND_MASK =				0x08,
 99		LL_PART_FOLLOW_SRC_MASK =		0x10,		// Follows source, no rotation following (expensive!)
100		LL_PART_FOLLOW_VELOCITY_MASK =	0x20,		// Particles orient themselves with velocity
101		LL_PART_TARGET_POS_MASK =		0x40,
102		LL_PART_TARGET_LINEAR_MASK =	0x80,		// Particle uses a direct linear interpolation
103		LL_PART_EMISSIVE_MASK =			0x100,		// Particle is "emissive", instead of being lit
104		LL_PART_BEAM_MASK =				0x200,		// Particle is a "beam" connecting source and target
105
106		// Not implemented yet!
107		//LL_PART_RANDOM_ACCEL_MASK =		0x100,		// Particles have random acceleration
108		//LL_PART_RANDOM_VEL_MASK =		0x200,		// Particles have random velocity shifts"
109		//LL_PART_TRAIL_MASK =			0x400,		// Particles have historical "trails"
110
111		// Viewer side use only!
112		LL_PART_HUD =					0x40000000,
113		LL_PART_DEAD_MASK =				0x80000000,
114	};
115
116	void setFlags(const U32 flags);
117	void setMaxAge(const F32 max_age);
118	void setStartScale(const F32 xs, F32 ys);
119	void setEndScale(const F32 xs, F32 ys);
120	void setStartColor(const LLVector3 &rgb);
121	void setEndColor(const LLVector3 &rgb);
122	void setStartAlpha(const F32 alpha);
123	void setEndAlpha(const F32 alpha);
124
125
126	friend class LLPartSysData;
127	friend class LLViewerPartSourceScript;
128
129	// These are public because I'm really lazy...
130public:
131	U32					mFlags;						// Particle state/interpolators in effect
132	F32					mMaxAge;					// Maximum age of the particle
133	LLColor4			mStartColor;				// Start color
134	LLColor4			mEndColor;					// End color
135	LLVector2			mStartScale;				// Start scale
136	LLVector2			mEndScale;					// End scale
137
138	LLVector3			mPosOffset;					// Offset from source if using FOLLOW_SOURCE
139	F32					mParameter;					// A single floating point parameter
140};
141
142
143class LLPartSysData
144{
145public:
146	LLPartSysData();
147
148	BOOL unpack(LLDataPacker &dp);
149	BOOL pack(LLDataPacker &dp);
150
151	
152	BOOL unpackBlock(const S32 block_num);
153	BOOL packBlock();
154
155	static BOOL packNull();
156	static BOOL isNullPS(const S32 block_num); // Returns FALSE if this is a "NULL" particle system (i.e. no system)
157
158	// Different masks for effects on the source
159	enum
160	{
161		LL_PART_SRC_OBJ_REL_MASK		=	0x01,		// Accel and velocity for particles relative object rotation
162		LL_PART_USE_NEW_ANGLE			=	0x02,		// Particles uses new 'correct' angle parameters.
163	};
164
165	// The different patterns for how particles are created
166	enum
167	{
168		LL_PART_SRC_PATTERN_DROP =				0x01,
169		LL_PART_SRC_PATTERN_EXPLODE =			0x02,
170		// Not implemented fully yet
171		LL_PART_SRC_PATTERN_ANGLE =				0x04,
172		LL_PART_SRC_PATTERN_ANGLE_CONE =		0x08,
173		LL_PART_SRC_PATTERN_ANGLE_CONE_EMPTY =	0x10,
174	};
175
176
177	void setBurstSpeedMin(const F32 spd) {	mBurstSpeedMin = llclamp(spd, -100.f, 100.f); }
178	void setBurstSpeedMax(const F32 spd) {	mBurstSpeedMax = llclamp(spd, -100.f, 100.f); }
179	void setBurstRadius(const F32 rad)	 {	mBurstRadius = llclamp(rad, 0.f, 50.f); }
180	void setPartAccel(const LLVector3 &accel);
181	void setUseNewAngle()	{ mFlags |=  LL_PART_USE_NEW_ANGLE; }
182	void unsetUseNewAngle()	{ mFlags &= ~LL_PART_USE_NEW_ANGLE; }
183
184	// Since the actual particle creation rate is
185	// a combination of multiple parameters, we
186	// need to clamp it using a separate method instead of an accessor.
187	void clampSourceParticleRate();
188	
189	friend std::ostream&	 operator<<(std::ostream& s, const LLPartSysData &data);		// Stream a
190	
191public:
192	// Public because I'm lazy....
193
194	//
195	// There are two kinds of data for the particle system
196	// 1. Parameters which specify parameters of the source (mSource*)
197	// 2. Parameters which specify parameters of the particles generated by the source (mPart*)
198	//
199
200	U32		mCRC;
201	U32		mFlags;
202
203	U8		mPattern;						// Pattern for particle velocity/output
204	F32		mInnerAngle;					// Inner angle for PATTERN_ANGLE
205	F32		mOuterAngle;					// Outer angle for PATTERN_ANGLE
206	LLVector3 mAngularVelocity;				// Angular velocity for emission axis (for PATTERN_ANGLE)
207
208	F32		mBurstRate;						// How often to do a burst of particles
209	U8		mBurstPartCount;				// How many particles in a burst
210	F32		mBurstRadius;
211	F32		mBurstSpeedMin;					// Minimum particle velocity
212	F32		mBurstSpeedMax;					// Maximum particle velocity
213
214	F32		mMaxAge;						// Maximum lifetime of this particle source
215
216	LLUUID	mTargetUUID;					// Target UUID for the particle system
217
218	F32		mStartAge;						// Age at which to start the particle system (for an update after the
219											// particle system has started)
220
221
222	//
223	// These are actually particle properties, but can be mutated by the source,
224	// so are stored here instead
225	//
226	LLVector3	mPartAccel;
227	LLUUID		mPartImageID;
228
229	//
230	// The "template" partdata where we actually store the non-mutable particle parameters
231	//
232	LLPartData	mPartData;
233
234protected:
235	S32		mNumParticles;					// Number of particles generated
236};
237
238#endif // LL_LLPARTDATA_H