PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llmessage/partsyspacket.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 261 lines | 132 code | 38 blank | 91 comment | 0 complexity | 270cc45ee99811b0ddbbee708085330c MD5 | raw file
  1/** 
  2 * @file partsyspacket.h
  3 * @brief Object for packing particle system initialization parameters
  4 * before sending them over the network
  5 *
  6 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_PARTSYSPACKET_H
 29#define LL_PARTSYSPACKET_H
 30
 31#include "lluuid.h"
 32
 33// Particle system stuff
 34
 35const U64 PART_SYS_MAX_TIME_IN_USEC = 1000000;  //  1 second, die not quite near instantaneously
 36
 37
 38// this struct is for particle system initialization parameters 
 39// I'm breaking some rules here, but I need a storage structure to hold initialization data
 40//	for these things.  Sorry guys, they're not simple enough (yet) to avoid this cleanly 
 41struct LLPartInitData {
 42	// please do not add functions to this class -- data only!
 43	//F32 k[18];     // first 9 --> x,y,z  last 9 --> scale, alpha, rot
 44	//F32 kill_p[6]; // last one is for particles that die when they reach a spherical bounding radius 
 45	//F32 kill_plane[3]; 
 46	//F32 bounce_p[5]; 
 47	F32 bounce_b; // recently changed
 48	// no need to store orientation and position here, as they're sent over seperately
 49	//F32 pos_ranges[6]; 
 50	//F32 vel_ranges[6];
 51	F32 scale_range[4];
 52	F32 alpha_range[4];
 53	F32 vel_offset[3];	//new - more understandable!
 54
 55	F32 mDistBeginFadeout; // for fadeout LOD optimization 
 56	F32 mDistEndFadeout;
 57	
 58	LLUUID mImageUuid;
 59	//U8 n; // number of particles 
 60	U8 mFlags[8]; // for miscellaneous data --> its interpretation can change at my whim!
 61	U8 createMe; // do I need to be created? or has the work allready been done?
 62	//ActionFlag is now mFlags[PART_SYS_ACTION_BYTE]
 63	//Spawn point is initially object creation center
 64
 65	F32 diffEqAlpha[3];
 66	F32 diffEqScale[3];
 67
 68	U8	maxParticles;
 69		//How many particles exist at any time within the system?
 70	U8	initialParticles;
 71		//How many particles exist when the system is created?
 72	F32	killPlaneZ;
 73		//For simplicity assume the XY plane, so this sets an altitude at which to die
 74	F32 killPlaneNormal[3]; 
 75		//Normal if not planar XY
 76	F32	bouncePlaneZ;
 77		//For simplicity assume the XY plane, so this sets an altitude at which to bounce
 78	F32 bouncePlaneNormal[3]; 
 79		//Normal if not planar XY
 80	F32	spawnRange;
 81		//Range of emission points about the mSpawnPoint
 82	F32	spawnFrequency;
 83		//Required if the system is to spawn new particles.
 84		//This variable determines the time after a particle dies when it is respawned.
 85	F32	spawnFreqencyRange;
 86		//Determines the random range of time until a new particle is spawned.
 87	F32	spawnDirection[3];
 88		//Direction vector giving the mean direction in which particles are spawned
 89	F32	spawnDirectionRange;
 90		//Direction limiting the angular range of emissions about the mean direction. 1.0f means everywhere, 0.0f means uni-directional
 91	F32	spawnVelocity;
 92		//The mean speed at which particles are emitted
 93	F32	spawnVelocityRange;
 94		//The range of speeds about the mean at which particles are emitted.
 95	F32	speedLimit;
 96		//Used to constrain particle maximum velocity
 97	F32	windWeight;
 98		//How much of an effect does wind have
 99	F32	currentGravity[3];
100		//Gravity direction used in update calculations
101	F32	gravityWeight;
102		//How much of an effect does gravity have
103	F32	globalLifetime;
104		//If particles re-spawn, a system can exist forever.
105		//If (ActionFlags & PART_SYS_GLOBAL_DIE) is TRUE this variable is used to determine how long the system lasts.
106	F32	individualLifetime;
107		//How long does each particle last if nothing else happens to it
108	F32	individualLifetimeRange;
109		//Range of variation in individual lifetimes
110	F32	alphaDecay;
111		//By what factor does alpha decrease as the lifetime of a particle is approached.
112	F32	scaleDecay;
113		//By what factor does scale decrease as the lifetime of a particle is approached.
114	F32	distanceDeath;
115		//With the increased functionality, particle systems can expand to indefinite size
116		//(e.g. wind can chaotically move particles into a wide spread).
117		//To avoid particles exceeding normal object size constraints,
118		//set the PART_SYS_DISTANCE_DEATH flag, and set a distance value here, representing a radius around the spawn point.
119	F32	dampMotionFactor;
120		//How much to damp motion
121	F32 windDiffusionFactor[3];
122		//Change the size and alpha of particles as wind speed increases (scale gets bigger, alpha smaller)
123};
124
125// constants for setting flag values
126// BYTES are in range 0-8, bits are in range 2^0 - 2^8 and can only be powers of two
127const int PART_SYS_NO_Z_BUFFER_BYTE = 0; // option to turn off z-buffer when rendering
128const int PART_SYS_NO_Z_BUFFER_BIT = 2;  // particle systems -- 
129// I advise against using this, as it looks bad in every case I've tried
130
131const int PART_SYS_SLOW_ANIM_BYTE = 0; // slow animation down by a factor of 10
132const int PART_SYS_SLOW_ANIM_BIT = 1;  // useful for tweaking anims during debugging
133
134const int PART_SYS_FOLLOW_VEL_BYTE = 0; // indicates whether to orient sprites towards
135const int PART_SYS_FOLLOW_VEL_BIT = 4;  // their velocity vector -- default is FALSE
136
137const int PART_SYS_IS_LIGHT_BYTE = 0;   // indicates whether a particular particle system
138const int PART_SYS_IS_LIGHT_BIT = 8;    // is also a light object -- for andrew
139// should deprecate this once there is a general method for setting light properties of objects
140
141const int PART_SYS_SPAWN_COPY_BYTE = 0;   // indicates whether to spawn baby particle systems on 
142const int PART_SYS_SPAWN_COPY_BIT = 0x10; // particle death -- intended for smoke trails
143
144const int PART_SYS_COPY_VEL_BYTE = 0; // indicates whether baby particle systems inherit parents vel
145const int PART_SYS_COPY_VEL_BIT = 0x20; // (by default they don't)
146
147const int PART_SYS_INVISIBLE_BYTE = 0; // optional -- turn off display, just simulate
148const int PART_SYS_INVISIBLE_BIT = 0x40; // useful for smoke trails
149
150const int PART_SYS_ADAPT_TO_FRAMERATE_BYTE = 0;    // drop sprites from render call proportionally
151const int PART_SYS_ADAPT_TO_FRAMERATE_BIT = 0x80; // to how far we are below 60 fps
152
153
154// 26 September 2001 - not even big enough to hold all changes, so should enlarge anyway
155//const U16 MAX_PART_SYS_PACKET_SIZE = 180;
156const U16 MAX_PART_SYS_PACKET_SIZE = 256;
157
158//const U8 PART_SYS_K_MASK				= 0x01;
159const U8 PART_SYS_KILL_P_MASK			= 0x02;
160const U8 PART_SYS_BOUNCE_P_MASK			= 0x04;
161const U8 PART_SYS_BOUNCE_B_MASK			= 0x08;
162//const U8 PART_SYS_POS_RANGES_MASK		= 0x10;
163//const U8 PART_SYS_VEL_RANGES_MASK		= 0x20;
164const U8 PART_SYS_VEL_OFFSET_MASK		= 0x10;	//re-use one of the original slots now commented out
165const U8 PART_SYS_ALPHA_SCALE_DIFF_MASK = 0x20;	//re-use one of the original slots now commented out
166const U8 PART_SYS_SCALE_RANGE_MASK		= 0x40;
167const U8 PART_SYS_M_IMAGE_UUID_MASK		= 0x80;
168const U8 PART_SYS_BYTE_3_ALPHA_MASK		= 0x01; // wrapped around, didn't we?
169
170const U8 PART_SYS_BYTE_SPAWN_MASK		= 0x01;
171const U8 PART_SYS_BYTE_ENVIRONMENT_MASK	= 0x02;
172const U8 PART_SYS_BYTE_LIFESPAN_MASK	= 0x04;
173const U8 PART_SYS_BYTE_DECAY_DAMP_MASK	= 0x08;
174const U8 PART_SYS_BYTE_WIND_DIFF_MASK	= 0x10;
175
176
177// 26 September 2001 - new constants for  mActionFlags
178const int PART_SYS_ACTION_BYTE = 1;
179const U8 PART_SYS_SPAWN 						= 0x01;
180const U8 PART_SYS_BOUNCE 						= 0x02;
181const U8 PART_SYS_AFFECTED_BY_WIND 				= 0x04;
182const U8 PART_SYS_AFFECTED_BY_GRAVITY			= 0x08;
183const U8 PART_SYS_EVALUATE_WIND_PER_PARTICLE 	= 0x10; 
184const U8 PART_SYS_DAMP_MOTION 					= 0x20;
185const U8 PART_SYS_WIND_DIFFUSION 				= 0x40;
186
187// 26 September 2001 - new constants for  mKillFlags
188const int PART_SYS_KILL_BYTE = 2;
189const U8 PART_SYS_KILL_PLANE					= 0x01;
190const U8 PART_SYS_GLOBAL_DIE 					= 0x02;  
191const U8 PART_SYS_DISTANCE_DEATH 				= 0x04;
192const U8 PART_SYS_TIME_DEATH 					= 0x08;
193
194
195// global, because the sim-side also calls it in the LLPartInitDataFactory
196
197
198void gSetInitDataDefaults(LLPartInitData *setMe);
199
200class LLPartSysCompressedPacket
201{
202public:
203	LLPartSysCompressedPacket();
204	~LLPartSysCompressedPacket();
205	BOOL	fromLLPartInitData(LLPartInitData *in, U32 &bytesUsed);
206	BOOL	toLLPartInitData(LLPartInitData *out, U32 *bytesUsed);
207	BOOL	fromUnsignedBytes(U8 *in, U32 bytesUsed);
208	BOOL	toUnsignedBytes(U8 *out);
209	U32		bufferSize();
210	U8		*getBytePtr();
211
212protected:
213	U8 mData[MAX_PART_SYS_PACKET_SIZE];
214	U32 mNumBytes;
215	LLPartInitData mDefaults; //  this is intended to hold default LLPartInitData values
216	//                            please do not modify it
217	LLPartInitData mWorkingCopy; // uncompressed data I'm working with
218
219protected:
220	// private functions (used only to break up code)
221	void	writeFlagByte(LLPartInitData *in);
222	//U32		writeK(LLPartInitData *in, U32 startByte);
223	U32		writeKill_p(LLPartInitData *in, U32 startByte);
224	U32		writeBounce_p(LLPartInitData *in, U32 startByte);
225	U32		writeBounce_b(LLPartInitData *in, U32 startByte);
226	//U32		writePos_ranges(LLPartInitData *in, U32 startByte);
227	//U32		writeVel_ranges(LLPartInitData *in, U32 startByte);
228	U32		writeAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte);
229	U32		writeScale_range(LLPartInitData *in, U32 startByte);
230	U32		writeAlpha_range(LLPartInitData *in, U32 startByte);
231	U32		writeUUID(LLPartInitData *in, U32 startByte);
232
233	U32		writeVelocityOffset(LLPartInitData *in, U32 startByte);
234	U32		writeSpawn(LLPartInitData *in, U32 startByte);	//all spawn data
235	U32		writeEnvironment(LLPartInitData *in, U32 startByte);	//wind and gravity
236	U32		writeLifespan(LLPartInitData *in, U32 startByte);	//lifespan data - individual and global
237	U32		writeDecayDamp(LLPartInitData *in, U32 startByte);	//alpha and scale, and motion damp
238	U32		writeWindDiffusionFactor(LLPartInitData *in, U32 startByte);
239
240	
241	//U32		readK(LLPartInitData *in, U32 startByte);
242	U32		readKill_p(LLPartInitData *in, U32 startByte);
243	U32		readBounce_p(LLPartInitData *in, U32 startByte);
244	U32		readBounce_b(LLPartInitData *in, U32 startByte);
245	//U32		readPos_ranges(LLPartInitData *in, U32 startByte);
246	//U32		readVel_ranges(LLPartInitData *in, U32 startByte);
247	U32		readAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte);
248	U32		readScale_range(LLPartInitData *in, U32 startByte);
249	U32		readAlpha_range(LLPartInitData *in, U32 startByte);
250	U32		readUUID(LLPartInitData *in, U32 startByte);
251
252	U32		readVelocityOffset(LLPartInitData *in, U32 startByte);
253	U32		readSpawn(LLPartInitData *in, U32 startByte);	//all spawn data
254	U32		readEnvironment(LLPartInitData *in, U32 startByte);	//wind and gravity
255	U32		readLifespan(LLPartInitData *in, U32 startByte);	//lifespan data - individual and global
256	U32		readDecayDamp(LLPartInitData *in, U32 startByte);	//alpha and scale, and motion damp
257	U32		readWindDiffusionFactor(LLPartInitData *in, U32 startByte);
258};
259
260#endif
261