PageRenderTime 45ms CodeModel.GetById 1ms app.highlight 20ms RepoModel.GetById 20ms app.codeStats 0ms

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