PageRenderTime 147ms CodeModel.GetById 19ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLPARTDATA_H
  27. #define LL_LLPARTDATA_H
  28. #include "lluuid.h"
  29. #include "v3math.h"
  30. #include "v3dmath.h"
  31. #include "v2math.h"
  32. #include "v4color.h"
  33. class LLMessageSystem;
  34. class LLDataPacker;
  35. const S32 PS_CUR_VERSION = 18;
  36. //
  37. // These constants are used by the script code, not by the particle system itself
  38. //
  39. enum LLPSScriptFlags
  40. {
  41. // Flags for the different parameters of individual particles
  42. LLPS_PART_FLAGS,
  43. LLPS_PART_START_COLOR,
  44. LLPS_PART_START_ALPHA,
  45. LLPS_PART_END_COLOR,
  46. LLPS_PART_END_ALPHA,
  47. LLPS_PART_START_SCALE,
  48. LLPS_PART_END_SCALE,
  49. LLPS_PART_MAX_AGE,
  50. // Flags for the different parameters of the particle source
  51. LLPS_SRC_ACCEL,
  52. LLPS_SRC_PATTERN,
  53. LLPS_SRC_INNERANGLE,
  54. LLPS_SRC_OUTERANGLE,
  55. LLPS_SRC_TEXTURE,
  56. LLPS_SRC_BURST_RATE,
  57. LLPS_SRC_BURST_DURATION,
  58. LLPS_SRC_BURST_PART_COUNT,
  59. LLPS_SRC_BURST_RADIUS,
  60. LLPS_SRC_BURST_SPEED_MIN,
  61. LLPS_SRC_BURST_SPEED_MAX,
  62. LLPS_SRC_MAX_AGE,
  63. LLPS_SRC_TARGET_UUID,
  64. LLPS_SRC_OMEGA,
  65. LLPS_SRC_ANGLE_BEGIN,
  66. LLPS_SRC_ANGLE_END
  67. };
  68. class LLPartData
  69. {
  70. public:
  71. LLPartData() :
  72. mFlags(0),
  73. mMaxAge(0.f),
  74. mParameter(0.f)
  75. {
  76. }
  77. BOOL unpack(LLDataPacker &dp);
  78. BOOL pack(LLDataPacker &dp);
  79. LLSD asLLSD() const;
  80. operator LLSD() const {return asLLSD(); }
  81. bool fromLLSD(LLSD& sd);
  82. // Masks for the different particle flags
  83. enum
  84. {
  85. LL_PART_INTERP_COLOR_MASK = 0x01,
  86. LL_PART_INTERP_SCALE_MASK = 0x02,
  87. LL_PART_BOUNCE_MASK = 0x04,
  88. LL_PART_WIND_MASK = 0x08,
  89. LL_PART_FOLLOW_SRC_MASK = 0x10, // Follows source, no rotation following (expensive!)
  90. LL_PART_FOLLOW_VELOCITY_MASK = 0x20, // Particles orient themselves with velocity
  91. LL_PART_TARGET_POS_MASK = 0x40,
  92. LL_PART_TARGET_LINEAR_MASK = 0x80, // Particle uses a direct linear interpolation
  93. LL_PART_EMISSIVE_MASK = 0x100, // Particle is "emissive", instead of being lit
  94. LL_PART_BEAM_MASK = 0x200, // Particle is a "beam" connecting source and target
  95. // Not implemented yet!
  96. //LL_PART_RANDOM_ACCEL_MASK = 0x100, // Particles have random acceleration
  97. //LL_PART_RANDOM_VEL_MASK = 0x200, // Particles have random velocity shifts"
  98. //LL_PART_TRAIL_MASK = 0x400, // Particles have historical "trails"
  99. // Viewer side use only!
  100. LL_PART_HUD = 0x40000000,
  101. LL_PART_DEAD_MASK = 0x80000000,
  102. };
  103. void setFlags(const U32 flags);
  104. void setMaxAge(const F32 max_age);
  105. void setStartScale(const F32 xs, F32 ys);
  106. void setEndScale(const F32 xs, F32 ys);
  107. void setStartColor(const LLVector3 &rgb);
  108. void setEndColor(const LLVector3 &rgb);
  109. void setStartAlpha(const F32 alpha);
  110. void setEndAlpha(const F32 alpha);
  111. friend class LLPartSysData;
  112. friend class LLViewerPartSourceScript;
  113. // These are public because I'm really lazy...
  114. public:
  115. U32 mFlags; // Particle state/interpolators in effect
  116. F32 mMaxAge; // Maximum age of the particle
  117. LLColor4 mStartColor; // Start color
  118. LLColor4 mEndColor; // End color
  119. LLVector2 mStartScale; // Start scale
  120. LLVector2 mEndScale; // End scale
  121. LLVector3 mPosOffset; // Offset from source if using FOLLOW_SOURCE
  122. F32 mParameter; // A single floating point parameter
  123. };
  124. class LLPartSysData
  125. {
  126. public:
  127. LLPartSysData();
  128. BOOL unpack(LLDataPacker &dp);
  129. BOOL pack(LLDataPacker &dp);
  130. BOOL unpackBlock(const S32 block_num);
  131. BOOL packBlock();
  132. static BOOL packNull();
  133. static BOOL isNullPS(const S32 block_num); // Returns FALSE if this is a "NULL" particle system (i.e. no system)
  134. // Different masks for effects on the source
  135. enum
  136. {
  137. LL_PART_SRC_OBJ_REL_MASK = 0x01, // Accel and velocity for particles relative object rotation
  138. LL_PART_USE_NEW_ANGLE = 0x02, // Particles uses new 'correct' angle parameters.
  139. };
  140. // The different patterns for how particles are created
  141. enum
  142. {
  143. LL_PART_SRC_PATTERN_DROP = 0x01,
  144. LL_PART_SRC_PATTERN_EXPLODE = 0x02,
  145. // Not implemented fully yet
  146. LL_PART_SRC_PATTERN_ANGLE = 0x04,
  147. LL_PART_SRC_PATTERN_ANGLE_CONE = 0x08,
  148. LL_PART_SRC_PATTERN_ANGLE_CONE_EMPTY = 0x10,
  149. };
  150. void setBurstSpeedMin(const F32 spd) { mBurstSpeedMin = llclamp(spd, -100.f, 100.f); }
  151. void setBurstSpeedMax(const F32 spd) { mBurstSpeedMax = llclamp(spd, -100.f, 100.f); }
  152. void setBurstRadius(const F32 rad) { mBurstRadius = llclamp(rad, 0.f, 50.f); }
  153. void setPartAccel(const LLVector3 &accel);
  154. void setUseNewAngle() { mFlags |= LL_PART_USE_NEW_ANGLE; }
  155. void unsetUseNewAngle() { mFlags &= ~LL_PART_USE_NEW_ANGLE; }
  156. // Since the actual particle creation rate is
  157. // a combination of multiple parameters, we
  158. // need to clamp it using a separate method instead of an accessor.
  159. void clampSourceParticleRate();
  160. friend std::ostream& operator<<(std::ostream& s, const LLPartSysData &data); // Stream a
  161. public:
  162. // Public because I'm lazy....
  163. //
  164. // There are two kinds of data for the particle system
  165. // 1. Parameters which specify parameters of the source (mSource*)
  166. // 2. Parameters which specify parameters of the particles generated by the source (mPart*)
  167. //
  168. U32 mCRC;
  169. U32 mFlags;
  170. U8 mPattern; // Pattern for particle velocity/output
  171. F32 mInnerAngle; // Inner angle for PATTERN_ANGLE
  172. F32 mOuterAngle; // Outer angle for PATTERN_ANGLE
  173. LLVector3 mAngularVelocity; // Angular velocity for emission axis (for PATTERN_ANGLE)
  174. F32 mBurstRate; // How often to do a burst of particles
  175. U8 mBurstPartCount; // How many particles in a burst
  176. F32 mBurstRadius;
  177. F32 mBurstSpeedMin; // Minimum particle velocity
  178. F32 mBurstSpeedMax; // Maximum particle velocity
  179. F32 mMaxAge; // Maximum lifetime of this particle source
  180. LLUUID mTargetUUID; // Target UUID for the particle system
  181. F32 mStartAge; // Age at which to start the particle system (for an update after the
  182. // particle system has started)
  183. //
  184. // These are actually particle properties, but can be mutated by the source,
  185. // so are stored here instead
  186. //
  187. LLVector3 mPartAccel;
  188. LLUUID mPartImageID;
  189. //
  190. // The "template" partdata where we actually store the non-mutable particle parameters
  191. //
  192. LLPartData mPartData;
  193. protected:
  194. S32 mNumParticles; // Number of particles generated
  195. };
  196. #endif // LL_LLPARTDATA_H