PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewerpartsim.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 203 lines | 123 code | 49 blank | 31 comment | 2 complexity | 7c0c5e6bb84f653f9250c7d2299fbf9c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerpartsim.h
  3. * @brief LLViewerPart class header file
  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_LLVIEWERPARTSIM_H
  27. #define LL_LLVIEWERPARTSIM_H
  28. #include "lldarrayptr.h"
  29. #include "llframetimer.h"
  30. #include "llpointer.h"
  31. #include "llpartdata.h"
  32. #include "llviewerpartsource.h"
  33. class LLViewerTexture;
  34. class LLViewerPart;
  35. class LLViewerRegion;
  36. class LLViewerTexture;
  37. class LLVOPartGroup;
  38. typedef void (*LLVPCallback)(LLViewerPart &part, const F32 dt);
  39. ///////////////////
  40. //
  41. // An individual particle
  42. //
  43. class LLViewerPart : public LLPartData
  44. {
  45. public:
  46. ~LLViewerPart();
  47. public:
  48. LLViewerPart();
  49. void init(LLPointer<LLViewerPartSource> sourcep, LLViewerTexture *imagep, LLVPCallback cb);
  50. U32 mPartID; // Particle ID used primarily for moving between groups
  51. F32 mLastUpdateTime; // Last time the particle was updated
  52. F32 mSkipOffset; // Offset against current group mSkippedTime
  53. LLVPCallback mVPCallback; // Callback function for more complicated behaviors
  54. LLPointer<LLViewerPartSource> mPartSourcep; // Particle source used for this object
  55. // Current particle state (possibly used for rendering)
  56. LLPointer<LLViewerTexture> mImagep;
  57. LLVector3 mPosAgent;
  58. LLVector3 mVelocity;
  59. LLVector3 mAccel;
  60. LLColor4 mColor;
  61. LLVector2 mScale;
  62. static U32 sNextPartID;
  63. };
  64. class LLViewerPartGroup
  65. {
  66. public:
  67. LLViewerPartGroup(const LLVector3 &center,
  68. const F32 box_radius,
  69. bool hud);
  70. virtual ~LLViewerPartGroup();
  71. void cleanup();
  72. BOOL addPart(LLViewerPart* part, const F32 desired_size = -1.f);
  73. void updateParticles(const F32 lastdt);
  74. BOOL posInGroup(const LLVector3 &pos, const F32 desired_size = -1.f);
  75. void shift(const LLVector3 &offset);
  76. typedef std::vector<LLViewerPart*> part_list_t;
  77. part_list_t mParticles;
  78. const LLVector3 &getCenterAgent() const { return mCenterAgent; }
  79. S32 getCount() const { return (S32) mParticles.size(); }
  80. LLViewerRegion *getRegion() const { return mRegionp; }
  81. void removeParticlesByID(const U32 source_id);
  82. LLPointer<LLVOPartGroup> mVOPartGroupp;
  83. BOOL mUniformParticles;
  84. U32 mID;
  85. F32 mSkippedTime;
  86. bool mHud;
  87. protected:
  88. LLVector3 mCenterAgent;
  89. F32 mBoxRadius;
  90. LLVector3 mMinObjPos;
  91. LLVector3 mMaxObjPos;
  92. LLViewerRegion *mRegionp;
  93. };
  94. class LLViewerPartSim : public LLSingleton<LLViewerPartSim>
  95. {
  96. public:
  97. LLViewerPartSim();
  98. virtual ~LLViewerPartSim(){}
  99. void destroyClass();
  100. typedef std::vector<LLViewerPartGroup *> group_list_t;
  101. typedef std::vector<LLPointer<LLViewerPartSource> > source_list_t;
  102. void shift(const LLVector3 &offset);
  103. void updateSimulation();
  104. void addPartSource(LLPointer<LLViewerPartSource> sourcep);
  105. void cleanupRegion(LLViewerRegion *regionp);
  106. BOOL shouldAddPart(); // Just decides whether this particle should be added or not (for particle count capping)
  107. F32 maxRate() // Return maximum particle generation rate
  108. {
  109. if (sParticleCount >= MAX_PART_COUNT)
  110. {
  111. return 1.f;
  112. }
  113. if (sParticleCount > PART_THROTTLE_THRESHOLD*sMaxParticleCount)
  114. {
  115. return (((F32)sParticleCount/(F32)sMaxParticleCount)-PART_THROTTLE_THRESHOLD)*PART_THROTTLE_RESCALE;
  116. }
  117. return 0.f;
  118. }
  119. F32 getRefRate() { return sParticleAdaptiveRate; }
  120. F32 getBurstRate() {return sParticleBurstRate; }
  121. void addPart(LLViewerPart* part);
  122. void updatePartBurstRate() ;
  123. void clearParticlesByID(const U32 system_id);
  124. void clearParticlesByOwnerID(const LLUUID& task_id);
  125. void removeLastCreatedSource();
  126. const source_list_t* getParticleSystemList() const { return &mViewerPartSources; }
  127. friend class LLViewerPartGroup;
  128. BOOL aboveParticleLimit() const { return sParticleCount > sMaxParticleCount; }
  129. static void setMaxPartCount(const S32 max_parts) { sMaxParticleCount = max_parts; }
  130. static S32 getMaxPartCount() { return sMaxParticleCount; }
  131. static void incPartCount(const S32 count) { sParticleCount += count; }
  132. static void decPartCount(const S32 count) { sParticleCount -= count; }
  133. U32 mID;
  134. protected:
  135. LLViewerPartGroup *createViewerPartGroup(const LLVector3 &pos_agent, const F32 desired_size, bool hud);
  136. LLViewerPartGroup *put(LLViewerPart* part);
  137. group_list_t mViewerPartGroups;
  138. source_list_t mViewerPartSources;
  139. LLFrameTimer mSimulationTimer;
  140. static S32 sMaxParticleCount;
  141. static S32 sParticleCount;
  142. static F32 sParticleAdaptiveRate;
  143. static F32 sParticleBurstRate;
  144. static const S32 MAX_PART_COUNT;
  145. static const F32 PART_THROTTLE_THRESHOLD;
  146. static const F32 PART_THROTTLE_RESCALE;
  147. static const F32 PART_ADAPT_RATE_MULT;
  148. static const F32 PART_ADAPT_RATE_MULT_RECIP;
  149. //debug use only
  150. public:
  151. static S32 sParticleCount2;
  152. static void checkParticleCount(U32 size = 0) ;
  153. };
  154. #endif // LL_LLVIEWERPARTSIM_H