llcloud.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**
  2. * @file llcloud.h
  3. * @brief Declaration of viewer cloud classes
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. * Copyright (c) 2009-2024, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLCLOUD_H
  34. #define LL_LLCLOUD_H
  35. // Some ideas on how clouds should work
  36. //
  37. // Each region has a cloud layer
  38. // Each cloud layer has pre-allocated space for N clouds
  39. // The LLSky class knows the max number of clouds to render M.
  40. // All clouds use the same texture, but the tex-coords can take on 8 configurations
  41. // (four rotations, front and back)
  42. //
  43. // The sky's part
  44. // --------------
  45. // The sky knows that A clouds have been assigned to regions and there are B left over.
  46. // Divide B by number of active regions to get C.
  47. // Ask each region to add C more clouds and return total number D.
  48. // Add up all the D's to get a new A.
  49. //
  50. // The cloud layer's part
  51. // ----------------------
  52. // The cloud layer is a grid of possibility. Each grid's value represents the probablility
  53. // (0.0 to 1.0) that a cloud placement query will succeed.
  54. //
  55. // The sky asks the region to add C more clouds.
  56. // The cloud layer tries a total of E times to place clouds and returns total cloud count.
  57. //
  58. // Clouds move according to local wind velocity.
  59. // If a cloud moves out of region then it's location is sent to neighbor region
  60. // or it is allowed to drift and decay.
  61. //
  62. // The clouds in non-visible regions do not propagate every frame.
  63. // Each frame one non-visible region is allowed to propagate it's clouds
  64. // (might have to check to see if incoming cloud was already visible or not).
  65. //
  66. //
  67. #include "llframetimer.h"
  68. #include "llmath.h"
  69. #include "llpointer.h"
  70. #include "llvector3d.h"
  71. #include "llvector3.h"
  72. #include "llcolor4.h"
  73. #include "llvector4.h"
  74. constexpr U32 CLOUD_GRIDS_PER_EDGE = 16;
  75. constexpr F32 CLOUD_PUFF_WIDTH = 64.f;
  76. constexpr F32 CLOUD_PUFF_HEIGHT = 48.f;
  77. class LLWind;
  78. class LLVOClouds;
  79. class LLViewerRegion;
  80. class LLCloudLayer;
  81. class LLBitPack;
  82. class LLGroupHeader;
  83. constexpr S32 CLOUD_GROUPS_PER_EDGE = 4;
  84. class LLCloudPuff
  85. {
  86. friend class LLCloudGroup;
  87. public:
  88. LLCloudPuff();
  89. void updatePuffs(F32 dt);
  90. void updatePuffOwnership();
  91. LL_INLINE const LLVector3d& getPositionGlobal() const { return mPositionGlobal; }
  92. LL_INLINE F32 getAlpha() const { return mAlpha; }
  93. LL_INLINE U32 getLifeState() const { return mLifeState; }
  94. LL_INLINE void setLifeState(U32 state) { mLifeState = state; }
  95. LL_INLINE bool isDead() const { return mAlpha <= 0.f; }
  96. protected:
  97. F32 mAlpha;
  98. F32 mRate;
  99. LLVector3d mPositionGlobal;
  100. U32 mLifeState;
  101. };
  102. class LLCloudGroup
  103. {
  104. public:
  105. LLCloudGroup();
  106. void cleanup();
  107. LL_INLINE void setCloudLayerp(LLCloudLayer* clp) { mCloudLayerp = clp; }
  108. void setCenterRegion(F32 x, F32 y);
  109. void updatePuffs(F32 dt);
  110. void updatePuffOwnership();
  111. void updatePuffCount();
  112. bool inGroup(const LLCloudPuff& puff) const;
  113. LL_INLINE F32 getDensity() const { return mDensity; }
  114. LL_INLINE S32 getNumPuffs() const { return (S32)mCloudPuffs.size(); }
  115. LL_INLINE const LLCloudPuff& getPuff(S32 i) { return mCloudPuffs[i]; }
  116. protected:
  117. LLCloudLayer* mCloudLayerp;
  118. std::vector<LLCloudPuff> mCloudPuffs;
  119. LLPointer<LLVOClouds> mVOCloudsp;
  120. LLVector3 mCenterRegion;
  121. F32 mDensity;
  122. S32 mTargetPuffCount;
  123. // Last time altitude was checked
  124. F32 mLastAltitudeUpdate;
  125. };
  126. class LLCloudLayer
  127. {
  128. public:
  129. LLCloudLayer();
  130. ~LLCloudLayer();
  131. void create(LLViewerRegion* regionp);
  132. void destroy();
  133. void reset(); // Clears all active cloud puffs
  134. void generateDensity();
  135. void resetDensity();
  136. void updatePuffs(F32 dt);
  137. void updatePuffOwnership();
  138. void updatePuffCount();
  139. bool shouldUpdateDensity();
  140. LLCloudGroup* findCloudGroup(const LLCloudPuff& puff);
  141. void setRegion(LLViewerRegion* regionp);
  142. LL_INLINE LLViewerRegion* getRegion() const { return mRegionp; }
  143. void setWindPointer(LLWind* windp);
  144. LL_INLINE void setOriginGlobal(const LLVector3d& orig) { mOriginGlobal = orig; }
  145. LL_INLINE F32 getMetersPerEdge() const { return mMetersPerEdge; }
  146. void setBrightness(F32 brightness);
  147. void setSunColor(const LLColor4& color);
  148. // "position" is in local coordinates
  149. F32 getDensityRegion(const LLVector3& pos_region);
  150. void decompress(LLBitPack& bitpack, LLGroupHeader* group_header);
  151. LL_INLINE LLCloudLayer* getNeighbor(S32 n) const { return mNeighbors[n]; }
  152. void connectNeighbor(LLCloudLayer* cloudp, U32 direction);
  153. void disconnectNeighbor(U32 direction);
  154. void disconnectAllNeighbors();
  155. static F32 getCloudsAltitude();
  156. static bool needClassicClouds();
  157. public:
  158. LLVector3d mOriginGlobal;
  159. F32 mMetersPerEdge;
  160. F32 mMetersPerGrid;
  161. F32 mMaxAlpha; // The max cloud puff render alpha
  162. protected:
  163. LLCloudLayer* mNeighbors[4];
  164. LLWind* mWindp;
  165. LLViewerRegion* mRegionp;
  166. F32* mDensityp; // The probability density grid
  167. F32 mLastDensityUpdate; // Last time density was updated
  168. LLCloudGroup mCloudGroups[CLOUD_GROUPS_PER_EDGE][CLOUD_GROUPS_PER_EDGE];
  169. static F32 sCloudsAltitude;
  170. };
  171. #endif // LL_LLCLOUD_H