llsettingsdaycycle.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. * @file llsettingsdaycycle.h
  3. * @brief The day cycles settings asset support class.
  4. *
  5. * $LicenseInfo:firstyear=2018&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2019, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_SETTINGSDAYCYCLE_H
  33. #define LL_SETTINGSDAYCYCLE_H
  34. #include "llsettingsbase.h"
  35. class LLSettingsSky;
  36. class LLSettingsWater;
  37. class LLSettingsDay : public LLSettingsBase
  38. {
  39. protected:
  40. LOG_CLASS(LLSettingsDay);
  41. LLSettingsDay();
  42. void updateSettings() override {}
  43. public:
  44. LLSettingsDay(const LLSD& data);
  45. ~LLSettingsDay() override {}
  46. static const std::string SETTING_KEYID;
  47. static const std::string SETTING_KEYNAME;
  48. static const std::string SETTING_KEYKFRAME;
  49. static const std::string SETTING_KEYHASH;
  50. static const std::string SETTING_TRACKS;
  51. static const std::string SETTING_FRAMES;
  52. static constexpr S32 MINIMUM_DAYLENGTH = 14400; // 4 hours
  53. static constexpr S32 DEFAULT_DAYLENGTH = 14400; // 4 hours
  54. static constexpr S32 MAXIMUM_DAYLENGTH = 604800; // 7 days
  55. static constexpr S32 MINIMUM_DAYOFFSET = 0;
  56. static constexpr S32 DEFAULT_DAYOFFSET = 57600;
  57. static constexpr S32 MAXIMUM_DAYOFFSET = 86400; // 24 hours
  58. // Not constexpr because this allows to name more tracks more easily, and
  59. // possibly add new ones easily as well in the future.
  60. enum
  61. {
  62. TRACK_WATER = 0,
  63. TRACK_GROUND_LEVEL = 1,
  64. TRACK_SKY_LEVEL1 = 2,
  65. TRACK_SKY_LEVEL2 = 3,
  66. TRACK_SKY_LEVEL3 = 4,
  67. TRACK_MAX = 5 // 4 skys + 1 water
  68. };
  69. static constexpr S32 FRAME_MAX = 56;
  70. static constexpr F32 DEFAULT_FRAME_SLOP_FACTOR = 0.02501f;
  71. static const LLUUID DEFAULT_ASSET_ID;
  72. // These are alias for LLSettingsWater::ptr_t and LLSettingsSky::ptr_t
  73. // respectively. Here for definitions only.
  74. typedef std::shared_ptr<LLSettingsWater> settings_water_ptr_t;
  75. typedef std::shared_ptr<LLSettingsSky> settings_sky_ptr_t;
  76. typedef std::shared_ptr<LLSettingsDay> ptr_t;
  77. typedef std::weak_ptr<LLSettingsDay> wptr_t;
  78. typedef std::vector<F32> keyframe_list_t;
  79. typedef std::map<F32, LLSettingsBase::ptr_t> cycle_track_t;
  80. typedef cycle_track_t::iterator cycle_track_it_t;
  81. typedef cycle_track_t::reverse_iterator cycle_track_rit_t;
  82. typedef std::vector<cycle_track_t> cycle_list_t;
  83. typedef std::pair<cycle_track_it_t, cycle_track_it_t> track_bound_t;
  84. bool initialize(bool validate_frames = false);
  85. LL_INLINE void setInitialized(bool b = true) { mInitialized = b; }
  86. LLSD getSettings() const override;
  87. LL_INLINE LLSettingsType::EType getSettingsTypeValue() const override
  88. {
  89. return LLSettingsType::ST_DAYCYCLE;
  90. }
  91. LL_INLINE std::string getSettingsType() const override
  92. {
  93. return "daycycle";
  94. }
  95. // Settings status
  96. void blend(const LLSettingsBase::ptr_t&, F64) override;
  97. static LLSD defaults();
  98. // Used to build a full day cycle out of fixed sky and water settings. HB
  99. static LLSD buildCycleFromFixed(const settings_sky_ptr_t& skyp,
  100. const settings_water_ptr_t& waterp);
  101. keyframe_list_t getTrackKeyframes(S32 track);
  102. bool moveTrackKeyframe(S32 track, F32 old_frame, F32 new_frame);
  103. bool removeTrackKeyframe(S32 track, F32 frame);
  104. void setWaterAtKeyframe(const settings_water_ptr_t& water, F32 keyframe);
  105. settings_water_ptr_t getWaterAtKeyframe(F32 keyframe) const;
  106. void setSkyAtKeyframe(const settings_sky_ptr_t& sky, F32 keyframe,
  107. S32 track);
  108. settings_sky_ptr_t getSkyAtKeyframe(F32 keyframe, S32 track) const;
  109. void setSettingsAtKeyframe(const LLSettingsBase::ptr_t& settings,
  110. F32 keyframe, S32 track);
  111. LLSettingsBase::ptr_t getSettingsAtKeyframe(F32 keyframe, S32 track) const;
  112. cycle_track_t::value_type getSettingsNearKeyframe(F32 keyframe, S32 track,
  113. F32 fudge) const;
  114. void startDayCycle();
  115. cycle_track_t& getCycleTrack(S32 track);
  116. const cycle_track_t& getCycleTrackConst(S32 track) const;
  117. bool clearCycleTrack(S32 track);
  118. bool replaceCycleTrack(S32 track, const cycle_track_t& source);
  119. bool isTrackEmpty(S32 track) const;
  120. virtual settings_sky_ptr_t getDefaultSky() const = 0;
  121. virtual settings_water_ptr_t getDefaultWater() const = 0;
  122. virtual settings_sky_ptr_t buildSky(const LLSD& settings) const = 0;
  123. virtual settings_water_ptr_t buildWater(const LLSD& settings) const = 0;
  124. virtual ptr_t buildClone() const = 0;
  125. virtual ptr_t buildDeepCloneAndUncompress() const = 0;
  126. LL_INLINE LLSettingsBase::ptr_t buildDerivedClone() const override
  127. {
  128. return buildClone();
  129. }
  130. const validation_list_t& getValidationList() const override;
  131. static const validation_list_t& validationList();
  132. F32 getUpperBoundFrame(S32 track, F32 keyframe);
  133. F32 getLowerBoundFrame(S32 track, F32 keyframe);
  134. static const LLUUID& getDefaultAssetId();
  135. private:
  136. void parseFromLLSD(LLSD& data);
  137. static cycle_track_it_t getEntryAtOrBefore(cycle_track_t& track,
  138. F32 keyframe);
  139. static cycle_track_it_t getEntryAtOrAfter(cycle_track_t& track,
  140. F32 keyframe);
  141. track_bound_t getBoundingEntries(cycle_track_t& track, F32 keyframe);
  142. static bool validateDayCycleTrack(LLSD& value, U32 flags);
  143. static bool validateDayCycleFrames(LLSD& value, U32 flags);
  144. private:
  145. F64 mLastUpdateTime;
  146. cycle_list_t mDayTracks;
  147. protected:
  148. bool mInitialized;
  149. };
  150. #endif // LL_SETTINGSDAYCYCLE_H