/indra/newview/llenvmanager.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 277 lines · 171 code · 48 blank · 58 comment · 1 complexity · 36d727748419fec52b0373221100c464 MD5 · raw file

  1. /**
  2. * @file llenvmanager.h
  3. * @brief Declaration of classes managing WindLight and water settings.
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, 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_LLENVMANAGER_H
  27. #define LL_LLENVMANAGER_H
  28. #include "llmemory.h"
  29. #include "llsd.h"
  30. class LLWLParamManager;
  31. class LLWaterParamManager;
  32. class LLWLAnimator;
  33. // generic key
  34. struct LLEnvKey
  35. {
  36. public:
  37. // Note: enum ordering is important; for example, a region-level floater (1) will see local and region (all values that are <=)
  38. typedef enum e_scope
  39. {
  40. SCOPE_LOCAL, // 0
  41. SCOPE_REGION//, // 1
  42. // SCOPE_ESTATE, // 2
  43. // etc.
  44. } EScope;
  45. };
  46. class LLEnvironmentSettings
  47. {
  48. public:
  49. LLEnvironmentSettings() :
  50. mWLDayCycle(LLSD::emptyMap()),
  51. mSkyMap(LLSD::emptyMap()),
  52. mWaterParams(LLSD::emptyMap()),
  53. mDayTime(0.f)
  54. {}
  55. LLEnvironmentSettings(const LLSD& dayCycle, const LLSD& skyMap, const LLSD& waterParams, F64 dayTime) :
  56. mWLDayCycle(dayCycle),
  57. mSkyMap(skyMap),
  58. mWaterParams(waterParams),
  59. mDayTime(dayTime)
  60. {}
  61. ~LLEnvironmentSettings() {}
  62. void saveParams(const LLSD& dayCycle, const LLSD& skyMap, const LLSD& waterParams, F64 dayTime)
  63. {
  64. mWLDayCycle = dayCycle;
  65. mSkyMap = skyMap;
  66. mWaterParams = waterParams;
  67. mDayTime = dayTime;
  68. }
  69. const LLSD& getWLDayCycle() const
  70. {
  71. return mWLDayCycle;
  72. }
  73. const LLSD& getWaterParams() const
  74. {
  75. return mWaterParams;
  76. }
  77. const LLSD& getSkyMap() const
  78. {
  79. return mSkyMap;
  80. }
  81. F64 getDayTime() const
  82. {
  83. return mDayTime;
  84. }
  85. bool isEmpty() const
  86. {
  87. return mWLDayCycle.size() == 0;
  88. }
  89. void clear()
  90. {
  91. *this = LLEnvironmentSettings();
  92. }
  93. LLSD makePacket(const LLSD& metadata) const
  94. {
  95. LLSD full_packet = LLSD::emptyArray();
  96. // 0: metadata
  97. full_packet.append(metadata);
  98. // 1: day cycle
  99. full_packet.append(mWLDayCycle);
  100. // 2: map of sky setting names to sky settings (as LLSD)
  101. full_packet.append(mSkyMap);
  102. // 3: water params
  103. full_packet.append(mWaterParams);
  104. return full_packet;
  105. }
  106. private:
  107. LLSD mWLDayCycle, mWaterParams, mSkyMap;
  108. F64 mDayTime;
  109. };
  110. /**
  111. * User environment preferences.
  112. */
  113. class LLEnvPrefs
  114. {
  115. public:
  116. LLEnvPrefs() : mUseRegionSettings(true), mUseDayCycle(true) {}
  117. bool getUseRegionSettings() const { return mUseRegionSettings; }
  118. bool getUseDayCycle() const { return mUseDayCycle; }
  119. bool getUseFixedSky() const { return !getUseDayCycle(); }
  120. std::string getWaterPresetName() const;
  121. std::string getSkyPresetName() const;
  122. std::string getDayCycleName() const;
  123. void setUseRegionSettings(bool val);
  124. void setUseWaterPreset(const std::string& name);
  125. void setUseSkyPreset(const std::string& name);
  126. void setUseDayCycle(const std::string& name);
  127. bool mUseRegionSettings;
  128. bool mUseDayCycle;
  129. std::string mWaterPresetName;
  130. std::string mSkyPresetName;
  131. std::string mDayCycleName;
  132. };
  133. /**
  134. * Setting:
  135. * 1. Use region settings.
  136. * 2. Use my setting: <water preset> + <fixed_sky>|<day_cycle>
  137. */
  138. class LLEnvManagerNew : public LLSingleton<LLEnvManagerNew>
  139. {
  140. LOG_CLASS(LLEnvManagerNew);
  141. public:
  142. typedef boost::signals2::signal<void()> prefs_change_signal_t;
  143. typedef boost::signals2::signal<void()> region_settings_change_signal_t;
  144. typedef boost::signals2::signal<void()> region_change_signal_t;
  145. typedef boost::signals2::signal<void(bool)> region_settings_applied_signal_t;
  146. LLEnvManagerNew();
  147. // getters to access user env. preferences
  148. bool getUseRegionSettings() const;
  149. bool getUseDayCycle() const;
  150. bool getUseFixedSky() const;
  151. std::string getWaterPresetName() const;
  152. std::string getSkyPresetName() const;
  153. std::string getDayCycleName() const;
  154. /// @return cached env. settings of the current region.
  155. const LLEnvironmentSettings& getRegionSettings() const;
  156. /**
  157. * Set new region settings without uploading them to the region.
  158. *
  159. * The override will be reset when the changes are applied to the region (=uploaded)
  160. * or user teleports to another region.
  161. */
  162. void setRegionSettings(const LLEnvironmentSettings& new_settings);
  163. // Change environment w/o changing user preferences.
  164. bool usePrefs();
  165. bool useDefaults();
  166. bool useRegionSettings();
  167. bool useWaterPreset(const std::string& name);
  168. bool useWaterParams(const LLSD& params);
  169. bool useSkyPreset(const std::string& name);
  170. bool useSkyParams(const LLSD& params);
  171. bool useDayCycle(const std::string& name, LLEnvKey::EScope scope);
  172. bool useDayCycleParams(const LLSD& params, LLEnvKey::EScope scope, F32 time = 0.5);
  173. // setters for user env. preferences
  174. void setUseRegionSettings(bool val);
  175. void setUseWaterPreset(const std::string& name);
  176. void setUseSkyPreset(const std::string& name);
  177. void setUseDayCycle(const std::string& name);
  178. void setUserPrefs(
  179. const std::string& water_preset,
  180. const std::string& sky_preset,
  181. const std::string& day_cycle_preset,
  182. bool use_fixed_sky,
  183. bool use_region_settings);
  184. // debugging methods
  185. void dumpUserPrefs();
  186. void dumpPresets();
  187. // Misc.
  188. void requestRegionSettings();
  189. bool sendRegionSettings(const LLEnvironmentSettings& new_settings);
  190. boost::signals2::connection setPreferencesChangeCallback(const prefs_change_signal_t::slot_type& cb);
  191. boost::signals2::connection setRegionSettingsChangeCallback(const region_settings_change_signal_t::slot_type& cb);
  192. boost::signals2::connection setRegionChangeCallback(const region_change_signal_t::slot_type& cb);
  193. boost::signals2::connection setRegionSettingsAppliedCallback(const region_settings_applied_signal_t::slot_type& cb);
  194. static bool canEditRegionSettings(); /// @return true if we have access to editing region environment
  195. static const std::string getScopeString(LLEnvKey::EScope scope);
  196. // Public callbacks.
  197. void onRegionCrossing();
  198. void onTeleport();
  199. void onRegionSettingsResponse(const LLSD& content);
  200. void onRegionSettingsApplyResponse(bool ok);
  201. private:
  202. friend class LLSingleton<LLEnvManagerNew>;
  203. /*virtual*/ void initSingleton();
  204. void loadUserPrefs();
  205. void saveUserPrefs();
  206. void updateSkyFromPrefs();
  207. void updateWaterFromPrefs(bool interpolate);
  208. void updateManagersFromPrefs(bool interpolate);
  209. bool useRegionSky();
  210. bool useRegionWater();
  211. bool useDefaultSky();
  212. bool useDefaultWater();
  213. void onRegionChange(bool interpolate);
  214. /// Emitted when user environment preferences change.
  215. prefs_change_signal_t mUsePrefsChangeSignal;
  216. /// Emitted when region environment settings update comes.
  217. region_settings_change_signal_t mRegionSettingsChangeSignal;
  218. /// Emitted when agent region changes. Move to LLAgent?
  219. region_change_signal_t mRegionChangeSignal;
  220. /// Emitted when agent region changes. Move to LLAgent?
  221. region_settings_applied_signal_t mRegionSettingsAppliedSignal;
  222. LLEnvPrefs mUserPrefs; /// User environment preferences.
  223. LLEnvironmentSettings mCachedRegionPrefs; /// Cached region environment settings.
  224. LLEnvironmentSettings mNewRegionPrefs; /// Not-yet-uploaded modified region env. settings.
  225. bool mInterpNextChangeMessage; /// Interpolate env. settings on next region change.
  226. LLUUID mCurRegionUUID; /// To avoid duplicated region env. settings requests.
  227. LLUUID mLastReceivedID; /// Id of last received region env. settings.
  228. };
  229. #endif // LL_LLENVMANAGER_H