PageRenderTime 26ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

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