partsyspacket.h

Go to the documentation of this file.
00001 
00033 #ifndef LL_PARTSYSPACKET_H
00034 #define LL_PARTSYSPACKET_H
00035 
00036 #include "lluuid.h"
00037 
00038 // Particle system stuff
00039 
00040 const U64 PART_SYS_MAX_TIME_IN_USEC = 1000000;  //  1 second, die not quite near instantaneously
00041 
00042 
00043 // this struct is for particle system initialization parameters 
00044 // I'm breaking some rules here, but I need a storage structure to hold initialization data
00045 //      for these things.  Sorry guys, they're not simple enough (yet) to avoid this cleanly 
00046 struct LLPartInitData {
00047         // please do not add functions to this class -- data only!
00048         //F32 k[18];     // first 9 --> x,y,z  last 9 --> scale, alpha, rot
00049         //F32 kill_p[6]; // last one is for particles that die when they reach a spherical bounding radius 
00050         //F32 kill_plane[3]; 
00051         //F32 bounce_p[5]; 
00052         F32 bounce_b; // recently changed
00053         // no need to store orientation and position here, as they're sent over seperately
00054         //F32 pos_ranges[6]; 
00055         //F32 vel_ranges[6];
00056         F32 scale_range[4];
00057         F32 alpha_range[4];
00058         F32 vel_offset[3];      //new - more understandable!
00059 
00060         F32 mDistBeginFadeout; // for fadeout LOD optimization 
00061         F32 mDistEndFadeout;
00062         
00063         LLUUID mImageUuid;
00064         //U8 n; // number of particles 
00065         U8 mFlags[8]; // for miscellaneous data --> its interpretation can change at my whim!
00066         U8 createMe; // do I need to be created? or has the work allready been done?
00067         //ActionFlag is now mFlags[PART_SYS_ACTION_BYTE]
00068         //Spawn point is initially object creation center
00069 
00070         F32 diffEqAlpha[3];
00071         F32 diffEqScale[3];
00072 
00073         U8      maxParticles;
00074                 //How many particles exist at any time within the system?
00075         U8      initialParticles;
00076                 //How many particles exist when the system is created?
00077         F32     killPlaneZ;
00078                 //For simplicity assume the XY plane, so this sets an altitude at which to die
00079         F32 killPlaneNormal[3]; 
00080                 //Normal if not planar XY
00081         F32     bouncePlaneZ;
00082                 //For simplicity assume the XY plane, so this sets an altitude at which to bounce
00083         F32 bouncePlaneNormal[3]; 
00084                 //Normal if not planar XY
00085         F32     spawnRange;
00086                 //Range of emission points about the mSpawnPoint
00087         F32     spawnFrequency;
00088                 //Required if the system is to spawn new particles.
00089                 //This variable determines the time after a particle dies when it is respawned.
00090         F32     spawnFreqencyRange;
00091                 //Determines the random range of time until a new particle is spawned.
00092         F32     spawnDirection[3];
00093                 //Direction vector giving the mean direction in which particles are spawned
00094         F32     spawnDirectionRange;
00095                 //Direction limiting the angular range of emissions about the mean direction. 1.0f means everywhere, 0.0f means uni-directional
00096         F32     spawnVelocity;
00097                 //The mean speed at which particles are emitted
00098         F32     spawnVelocityRange;
00099                 //The range of speeds about the mean at which particles are emitted.
00100         F32     speedLimit;
00101                 //Used to constrain particle maximum velocity
00102         F32     windWeight;
00103                 //How much of an effect does wind have
00104         F32     currentGravity[3];
00105                 //Gravity direction used in update calculations
00106         F32     gravityWeight;
00107                 //How much of an effect does gravity have
00108         F32     globalLifetime;
00109                 //If particles re-spawn, a system can exist forever.
00110                 //If (ActionFlags & PART_SYS_GLOBAL_DIE) is TRUE this variable is used to determine how long the system lasts.
00111         F32     individualLifetime;
00112                 //How long does each particle last if nothing else happens to it
00113         F32     individualLifetimeRange;
00114                 //Range of variation in individual lifetimes
00115         F32     alphaDecay;
00116                 //By what factor does alpha decrease as the lifetime of a particle is approached.
00117         F32     scaleDecay;
00118                 //By what factor does scale decrease as the lifetime of a particle is approached.
00119         F32     distanceDeath;
00120                 //With the increased functionality, particle systems can expand to indefinite size
00121                 //(e.g. wind can chaotically move particles into a wide spread).
00122                 //To avoid particles exceeding normal object size constraints,
00123                 //set the PART_SYS_DISTANCE_DEATH flag, and set a distance value here, representing a radius around the spawn point.
00124         F32     dampMotionFactor;
00125                 //How much to damp motion
00126         F32 windDiffusionFactor[3];
00127                 //Change the size and alpha of particles as wind speed increases (scale gets bigger, alpha smaller)
00128 };
00129 
00130 // constants for setting flag values
00131 // BYTES are in range 0-8, bits are in range 2^0 - 2^8 and can only be powers of two
00132 const int PART_SYS_NO_Z_BUFFER_BYTE = 0; // option to turn off z-buffer when rendering
00133 const int PART_SYS_NO_Z_BUFFER_BIT = 2;  // particle systems -- 
00134 // I advise against using this, as it looks bad in every case I've tried
00135 
00136 const int PART_SYS_SLOW_ANIM_BYTE = 0; // slow animation down by a factor of 10
00137 const int PART_SYS_SLOW_ANIM_BIT = 1;  // useful for tweaking anims during debugging
00138 
00139 const int PART_SYS_FOLLOW_VEL_BYTE = 0; // indicates whether to orient sprites towards
00140 const int PART_SYS_FOLLOW_VEL_BIT = 4;  // their velocity vector -- default is FALSE
00141 
00142 const int PART_SYS_IS_LIGHT_BYTE = 0;   // indicates whether a particular particle system
00143 const int PART_SYS_IS_LIGHT_BIT = 8;    // is also a light object -- for andrew
00144 // should deprecate this once there is a general method for setting light properties of objects
00145 
00146 const int PART_SYS_SPAWN_COPY_BYTE = 0;   // indicates whether to spawn baby particle systems on 
00147 const int PART_SYS_SPAWN_COPY_BIT = 0x10; // particle death -- intended for smoke trails
00148 
00149 const int PART_SYS_COPY_VEL_BYTE = 0; // indicates whether baby particle systems inherit parents vel
00150 const int PART_SYS_COPY_VEL_BIT = 0x20; // (by default they don't)
00151 
00152 const int PART_SYS_INVISIBLE_BYTE = 0; // optional -- turn off display, just simulate
00153 const int PART_SYS_INVISIBLE_BIT = 0x40; // useful for smoke trails
00154 
00155 const int PART_SYS_ADAPT_TO_FRAMERATE_BYTE = 0;    // drop sprites from render call proportionally
00156 const int PART_SYS_ADAPT_TO_FRAMERATE_BIT = 0x80; // to how far we are below 60 fps
00157 
00158 
00159 // 26 September 2001 - not even big enough to hold all changes, so should enlarge anyway
00160 //const U16 MAX_PART_SYS_PACKET_SIZE = 180;
00161 const U16 MAX_PART_SYS_PACKET_SIZE = 256;
00162 
00163 //const U8 PART_SYS_K_MASK                              = 0x01;
00164 const U8 PART_SYS_KILL_P_MASK                   = 0x02;
00165 const U8 PART_SYS_BOUNCE_P_MASK                 = 0x04;
00166 const U8 PART_SYS_BOUNCE_B_MASK                 = 0x08;
00167 //const U8 PART_SYS_POS_RANGES_MASK             = 0x10;
00168 //const U8 PART_SYS_VEL_RANGES_MASK             = 0x20;
00169 const U8 PART_SYS_VEL_OFFSET_MASK               = 0x10; //re-use one of the original slots now commented out
00170 const U8 PART_SYS_ALPHA_SCALE_DIFF_MASK = 0x20; //re-use one of the original slots now commented out
00171 const U8 PART_SYS_SCALE_RANGE_MASK              = 0x40;
00172 const U8 PART_SYS_M_IMAGE_UUID_MASK             = 0x80;
00173 const U8 PART_SYS_BYTE_3_ALPHA_MASK             = 0x01; // wrapped around, didn't we?
00174 
00175 const U8 PART_SYS_BYTE_SPAWN_MASK               = 0x01;
00176 const U8 PART_SYS_BYTE_ENVIRONMENT_MASK = 0x02;
00177 const U8 PART_SYS_BYTE_LIFESPAN_MASK    = 0x04;
00178 const U8 PART_SYS_BYTE_DECAY_DAMP_MASK  = 0x08;
00179 const U8 PART_SYS_BYTE_WIND_DIFF_MASK   = 0x10;
00180 
00181 
00182 // 26 September 2001 - new constants for  mActionFlags
00183 const int PART_SYS_ACTION_BYTE = 1;
00184 const U8 PART_SYS_SPAWN                                                 = 0x01;
00185 const U8 PART_SYS_BOUNCE                                                = 0x02;
00186 const U8 PART_SYS_AFFECTED_BY_WIND                              = 0x04;
00187 const U8 PART_SYS_AFFECTED_BY_GRAVITY                   = 0x08;
00188 const U8 PART_SYS_EVALUATE_WIND_PER_PARTICLE    = 0x10; 
00189 const U8 PART_SYS_DAMP_MOTION                                   = 0x20;
00190 const U8 PART_SYS_WIND_DIFFUSION                                = 0x40;
00191 
00192 // 26 September 2001 - new constants for  mKillFlags
00193 const int PART_SYS_KILL_BYTE = 2;
00194 const U8 PART_SYS_KILL_PLANE                                    = 0x01;
00195 const U8 PART_SYS_GLOBAL_DIE                                    = 0x02;  
00196 const U8 PART_SYS_DISTANCE_DEATH                                = 0x04;
00197 const U8 PART_SYS_TIME_DEATH                                    = 0x08;
00198 
00199 
00200 // global, because the sim-side also calls it in the LLPartInitDataFactory
00201 
00202 
00203 void gSetInitDataDefaults(LLPartInitData *setMe);
00204 
00205 class LLPartSysCompressedPacket
00206 {
00207 public:
00208         LLPartSysCompressedPacket();
00209         ~LLPartSysCompressedPacket();
00210         BOOL    fromLLPartInitData(LLPartInitData *in, U32 &bytesUsed);
00211         BOOL    toLLPartInitData(LLPartInitData *out, U32 *bytesUsed);
00212         BOOL    fromUnsignedBytes(U8 *in, U32 bytesUsed);
00213         BOOL    toUnsignedBytes(U8 *out);
00214         U32             bufferSize();
00215         U8              *getBytePtr();
00216 
00217 protected:
00218         U8 mData[MAX_PART_SYS_PACKET_SIZE];
00219         U32 mNumBytes;
00220         LLPartInitData mDefaults; //  this is intended to hold default LLPartInitData values
00221         //                            please do not modify it
00222         LLPartInitData mWorkingCopy; // uncompressed data I'm working with
00223 
00224 protected:
00225         // private functions (used only to break up code)
00226         void    writeFlagByte(LLPartInitData *in);
00227         //U32           writeK(LLPartInitData *in, U32 startByte);
00228         U32             writeKill_p(LLPartInitData *in, U32 startByte);
00229         U32             writeBounce_p(LLPartInitData *in, U32 startByte);
00230         U32             writeBounce_b(LLPartInitData *in, U32 startByte);
00231         //U32           writePos_ranges(LLPartInitData *in, U32 startByte);
00232         //U32           writeVel_ranges(LLPartInitData *in, U32 startByte);
00233         U32             writeAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte);
00234         U32             writeScale_range(LLPartInitData *in, U32 startByte);
00235         U32             writeAlpha_range(LLPartInitData *in, U32 startByte);
00236         U32             writeUUID(LLPartInitData *in, U32 startByte);
00237 
00238         U32             writeVelocityOffset(LLPartInitData *in, U32 startByte);
00239         U32             writeSpawn(LLPartInitData *in, U32 startByte);  //all spawn data
00240         U32             writeEnvironment(LLPartInitData *in, U32 startByte);    //wind and gravity
00241         U32             writeLifespan(LLPartInitData *in, U32 startByte);       //lifespan data - individual and global
00242         U32             writeDecayDamp(LLPartInitData *in, U32 startByte);      //alpha and scale, and motion damp
00243         U32             writeWindDiffusionFactor(LLPartInitData *in, U32 startByte);
00244 
00245         
00246         //U32           readK(LLPartInitData *in, U32 startByte);
00247         U32             readKill_p(LLPartInitData *in, U32 startByte);
00248         U32             readBounce_p(LLPartInitData *in, U32 startByte);
00249         U32             readBounce_b(LLPartInitData *in, U32 startByte);
00250         //U32           readPos_ranges(LLPartInitData *in, U32 startByte);
00251         //U32           readVel_ranges(LLPartInitData *in, U32 startByte);
00252         U32             readAlphaScaleDiffEqn_range(LLPartInitData *in, U32 startByte);
00253         U32             readScale_range(LLPartInitData *in, U32 startByte);
00254         U32             readAlpha_range(LLPartInitData *in, U32 startByte);
00255         U32             readUUID(LLPartInitData *in, U32 startByte);
00256 
00257         U32             readVelocityOffset(LLPartInitData *in, U32 startByte);
00258         U32             readSpawn(LLPartInitData *in, U32 startByte);   //all spawn data
00259         U32             readEnvironment(LLPartInitData *in, U32 startByte);     //wind and gravity
00260         U32             readLifespan(LLPartInitData *in, U32 startByte);        //lifespan data - individual and global
00261         U32             readDecayDamp(LLPartInitData *in, U32 startByte);       //alpha and scale, and motion damp
00262         U32             readWindDiffusionFactor(LLPartInitData *in, U32 startByte);
00263 };
00264 
00265 #endif
00266 

Generated on Thu Jul 1 06:09:57 2010 for Second Life Viewer by  doxygen 1.4.7