PageRenderTime 470ms CodeModel.GetById 69ms app.highlight 305ms RepoModel.GetById 88ms app.codeStats 0ms

/indra/newview/llwlparammanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 728 lines | 507 code | 128 blank | 93 comment | 86 complexity | 25cd87b2f01ec685837ff8ebec402850 MD5 | raw file
  1/**
  2 * @file llwlparammanager.cpp
  3 * @brief Implementation for the LLWLParamManager class.
  4 *
  5 * $LicenseInfo:firstyear=2007&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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llwlparammanager.h"
 30
 31#include "pipeline.h"
 32#include "llsky.h"
 33
 34#include "lldiriterator.h"
 35#include "llfloaterreg.h"
 36#include "llsliderctrl.h"
 37#include "llspinctrl.h"
 38#include "llcheckboxctrl.h"
 39#include "lluictrlfactory.h"
 40#include "llviewercamera.h"
 41#include "llcombobox.h"
 42#include "lllineeditor.h"
 43#include "llsdserialize.h"
 44
 45#include "v4math.h"
 46#include "llviewerdisplay.h"
 47#include "llviewercontrol.h"
 48#include "llviewerwindow.h"
 49#include "lldrawpoolwater.h"
 50#include "llagent.h"
 51#include "llviewerregion.h"
 52
 53#include "lldaycyclemanager.h"
 54#include "llenvmanager.h"
 55#include "llwlparamset.h"
 56#include "llpostprocess.h"
 57
 58#include "llviewershadermgr.h"
 59#include "llglslshader.h"
 60
 61#include "curl/curl.h"
 62#include "llstreamtools.h"
 63
 64LLWLParamManager::LLWLParamManager() :
 65
 66	//set the defaults for the controls
 67	// index is from sWLUniforms in pipeline.cpp line 979
 68
 69	/// Sun Delta Terrain tweak variables.
 70	mSunDeltaYaw(180.0f),
 71	mSceneLightStrength(2.0f),
 72	mWLGamma(1.0f, "gamma"),
 73
 74	mBlueHorizon(0.25f, 0.25f, 1.0f, 1.0f, "blue_horizon", "WLBlueHorizon"),
 75	mHazeDensity(1.0f, 1.0f, 1.0f, 0.5f, "haze_density"),
 76	mBlueDensity(0.25f, 0.25f, 0.25f, 1.0f, "blue_density", "WLBlueDensity"),
 77	mDensityMult(1.0f, "density_multiplier", 1000),
 78	mHazeHorizon(1.0f, 1.0f, 1.0f, 0.5f, "haze_horizon"),
 79	mMaxAlt(4000.0f, "max_y"),
 80
 81	// Lighting
 82	mLightnorm(0.f, 0.707f, -0.707f, 1.f, "lightnorm"),
 83	mSunlight(0.5f, 0.5f, 0.5f, 1.0f, "sunlight_color", "WLSunlight"),
 84	mAmbient(0.5f, 0.75f, 1.0f, 1.19f, "ambient", "WLAmbient"),
 85	mGlow(18.0f, 0.0f, -0.01f, 1.0f, "glow"),
 86
 87	// Clouds
 88	mCloudColor(0.5f, 0.5f, 0.5f, 1.0f, "cloud_color", "WLCloudColor"),
 89	mCloudMain(0.5f, 0.5f, 0.125f, 1.0f, "cloud_pos_density1"),
 90	mCloudCoverage(0.0f, "cloud_shadow"),
 91	mCloudDetail(0.0f, 0.0f, 0.0f, 1.0f, "cloud_pos_density2"),
 92	mDistanceMult(1.0f, "distance_multiplier"),
 93	mCloudScale(0.42f, "cloud_scale"),
 94
 95	// sky dome
 96	mDomeOffset(0.96f),
 97	mDomeRadius(15000.f)
 98{
 99}
100
101LLWLParamManager::~LLWLParamManager()
102{
103}
104
105void LLWLParamManager::clearParamSetsOfScope(LLWLParamKey::EScope scope)
106{
107	if (LLWLParamKey::SCOPE_LOCAL == scope)
108	{
109		LL_WARNS("Windlight") << "Tried to clear windlight sky presets from local system!  This shouldn't be called..." << LL_ENDL;
110		return;
111	}
112
113	std::set<LLWLParamKey> to_remove;
114	for(std::map<LLWLParamKey, LLWLParamSet>::iterator iter = mParamList.begin(); iter != mParamList.end(); ++iter)
115	{
116		if(iter->first.scope == scope)
117		{
118			to_remove.insert(iter->first);
119		}
120	}
121
122	for(std::set<LLWLParamKey>::iterator iter = to_remove.begin(); iter != to_remove.end(); ++iter)
123	{
124		mParamList.erase(*iter);
125	}
126}
127
128// returns all skies referenced by the day cycle, with their final names
129// side effect: applies changes to all internal structures!
130std::map<LLWLParamKey, LLWLParamSet> LLWLParamManager::finalizeFromDayCycle(LLWLParamKey::EScope scope)
131{
132	lldebugs << "mDay before finalizing:" << llendl;
133	{
134		for (std::map<F32, LLWLParamKey>::iterator iter = mDay.mTimeMap.begin(); iter != mDay.mTimeMap.end(); ++iter)
135		{
136			LLWLParamKey& key = iter->second;
137			lldebugs << iter->first << "->" << key.name << llendl;
138		}
139	}
140
141	std::map<LLWLParamKey, LLWLParamSet> final_references;
142
143	// Move all referenced to desired scope, renaming if necessary
144	// First, save skies referenced
145	std::map<LLWLParamKey, LLWLParamSet> current_references; // all skies referenced by the day cycle, with their current names
146	// guard against skies with same name and different scopes
147	std::set<std::string> inserted_names;
148	std::map<std::string, unsigned int> conflicted_names; // integer later used as a count, for uniquely renaming conflicts
149
150	LLWLDayCycle& cycle = mDay;
151	for(std::map<F32, LLWLParamKey>::iterator iter = cycle.mTimeMap.begin();
152		iter != cycle.mTimeMap.end();
153		++iter)
154	{
155		LLWLParamKey& key = iter->second;
156		std::string desired_name = key.name;
157		replace_newlines_with_whitespace(desired_name); // already shouldn't have newlines, but just in case
158		if(inserted_names.find(desired_name) == inserted_names.end())
159		{
160			inserted_names.insert(desired_name);
161		}
162		else
163		{
164			// make exist in map
165			conflicted_names[desired_name] = 0;
166		}
167		current_references[key] = mParamList[key];
168	}
169
170	// forget all old skies in target scope, and rebuild, renaming as needed
171	clearParamSetsOfScope(scope);
172	for(std::map<LLWLParamKey, LLWLParamSet>::iterator iter = current_references.begin(); iter != current_references.end(); ++iter)
173	{
174		const LLWLParamKey& old_key = iter->first;
175
176		std::string desired_name(old_key.name);
177		replace_newlines_with_whitespace(desired_name);
178
179		LLWLParamKey new_key(desired_name, scope); // name will be replaced later if necessary
180
181		// if this sky is one with a non-unique name, rename via appending a number
182		// an existing preset of the target scope gets to keep its name
183		if (scope != old_key.scope && conflicted_names.find(desired_name) != conflicted_names.end())
184		{
185			std::string& new_name = new_key.name;
186
187			do
188			{
189				// if this executes more than once, this is an absurdly pathological case
190				// (e.g. "x" repeated twice, but "x 1" already exists, so need to use "x 2")
191				std::stringstream temp;
192				temp << desired_name << " " << (++conflicted_names[desired_name]);
193				new_name = temp.str();
194			} while (inserted_names.find(new_name) != inserted_names.end());
195
196			// yay, found one that works
197			inserted_names.insert(new_name); // track names we consume here; shouldn't be necessary due to ++int? but just in case
198
199			// *TODO factor out below into a rename()?
200
201			LL_INFOS("Windlight") << "Renamed " << old_key.name << " (scope" << old_key.scope << ") to "
202				<< new_key.name << " (scope " << new_key.scope << ")" << LL_ENDL;
203
204			// update name in sky
205			iter->second.mName = new_name;
206
207			// update keys in day cycle
208			for(std::map<F32, LLWLParamKey>::iterator frame = cycle.mTimeMap.begin(); frame != cycle.mTimeMap.end(); ++frame)
209			{
210				if (frame->second == old_key)
211				{
212					frame->second = new_key;
213				}
214			}
215
216			// add to master sky map
217			mParamList[new_key] = iter->second;
218		}
219
220		final_references[new_key] = iter->second;
221	}
222
223	lldebugs << "mDay after finalizing:" << llendl;
224	{
225		for (std::map<F32, LLWLParamKey>::iterator iter = mDay.mTimeMap.begin(); iter != mDay.mTimeMap.end(); ++iter)
226		{
227			LLWLParamKey& key = iter->second;
228			lldebugs << iter->first << "->" << key.name << llendl;
229		}
230	}
231
232	return final_references;
233}
234
235// static
236LLSD LLWLParamManager::createSkyMap(std::map<LLWLParamKey, LLWLParamSet> refs)
237{
238	LLSD skies = LLSD::emptyMap();
239	for(std::map<LLWLParamKey, LLWLParamSet>::iterator iter = refs.begin(); iter != refs.end(); ++iter)
240	{
241		skies.insert(iter->first.name, iter->second.getAll());
242	}
243	return skies;
244}
245
246void LLWLParamManager::addAllSkies(const LLWLParamKey::EScope scope, const LLSD& sky_presets)
247{
248	for(LLSD::map_const_iterator iter = sky_presets.beginMap(); iter != sky_presets.endMap(); ++iter)
249	{
250		LLWLParamSet set;
251		set.setAll(iter->second);
252		mParamList[LLWLParamKey(iter->first, scope)] = set;
253	}
254}
255
256void LLWLParamManager::refreshRegionPresets()
257{
258	// Remove all region sky presets because they may belong to a previously visited region.
259	clearParamSetsOfScope(LLEnvKey::SCOPE_REGION);
260
261	// Add all sky presets belonging to the current region.
262	addAllSkies(LLEnvKey::SCOPE_REGION, LLEnvManagerNew::instance().getRegionSettings().getSkyMap());
263}
264
265void LLWLParamManager::loadAllPresets()
266{
267	// First, load system (coming out of the box) sky presets.
268	loadPresetsFromDir(getSysDir());
269
270	// Then load user presets. Note that user day presets will modify any system ones already loaded.
271	loadPresetsFromDir(getUserDir());
272}
273
274void LLWLParamManager::loadPresetsFromDir(const std::string& dir)
275{
276	LL_INFOS2("AppInit", "Shaders") << "Loading sky presets from " << dir << LL_ENDL;
277
278	LLDirIterator dir_iter(dir, "*.xml");
279	while (1)
280	{
281		std::string file;
282		if (!dir_iter.next(file))
283		{
284			break; // no more files
285		}
286
287		std::string path = dir + file;
288		if (!loadPreset(path))
289		{
290			llwarns << "Error loading sky preset from " << path << llendl;
291		}
292	}
293}
294
295bool LLWLParamManager::loadPreset(const std::string& path)
296{
297	llifstream xml_file;
298	std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true));
299
300	xml_file.open(path.c_str());
301	if (!xml_file)
302	{
303		return false;
304	}
305
306	LL_DEBUGS2("AppInit", "Shaders") << "Loading sky " << name << LL_ENDL;
307
308	LLSD params_data;
309	LLPointer<LLSDParser> parser = new LLSDXMLParser();
310	parser->parse(xml_file, params_data, LLSDSerialize::SIZE_UNLIMITED);
311	xml_file.close();
312
313	LLWLParamKey key(name, LLEnvKey::SCOPE_LOCAL);
314	if (hasParamSet(key))
315	{
316		setParamSet(key, params_data);
317	}
318	else
319	{
320		addParamSet(key, params_data);
321	}
322
323	return true;
324}
325
326void LLWLParamManager::savePreset(LLWLParamKey key)
327{
328	llassert(key.scope == LLEnvKey::SCOPE_LOCAL && !key.name.empty());
329
330	// make an empty llsd
331	LLSD paramsData(LLSD::emptyMap());
332	std::string pathName(getUserDir() + escapeString(key.name) + ".xml");
333
334	// fill it with LLSD windlight params
335	paramsData = mParamList[key].getAll();
336
337	// write to file
338	llofstream presetsXML(pathName);
339	LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter();
340	formatter->format(paramsData, presetsXML, LLSDFormatter::OPTIONS_PRETTY);
341	presetsXML.close();
342
343	propagateParameters();
344}
345
346void LLWLParamManager::updateShaderUniforms(LLGLSLShader * shader)
347{
348	if (gPipeline.canUseWindLightShaders())
349	{
350		mCurParams.update(shader);
351	}
352
353	if (shader->mShaderGroup == LLGLSLShader::SG_DEFAULT)
354	{
355		shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, mRotatedLightDir.mV);
356		shader->uniform3fv("camPosLocal", 1, LLViewerCamera::getInstance()->getOrigin().mV);
357	} 
358
359	else if (shader->mShaderGroup == LLGLSLShader::SG_SKY)
360	{
361		shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, mClampedLightDir.mV);
362	}
363
364	shader->uniform1f("scene_light_strength", mSceneLightStrength);
365	
366}
367
368static LLFastTimer::DeclareTimer FTM_UPDATE_WLPARAM("Update Windlight Params");
369
370void LLWLParamManager::propagateParameters(void)
371{
372	LLFastTimer ftm(FTM_UPDATE_WLPARAM);
373	
374	LLVector4 sunDir;
375	LLVector4 moonDir;
376
377	// set the sun direction from SunAngle and EastAngle
378	F32 sinTheta = sin(mCurParams.getEastAngle());
379	F32 cosTheta = cos(mCurParams.getEastAngle());
380
381	F32 sinPhi = sin(mCurParams.getSunAngle());
382	F32 cosPhi = cos(mCurParams.getSunAngle());
383
384	sunDir.mV[0] = -sinTheta * cosPhi;
385	sunDir.mV[1] = sinPhi;
386	sunDir.mV[2] = cosTheta * cosPhi;
387	sunDir.mV[3] = 0;
388
389	moonDir = -sunDir;
390
391	// is the normal from the sun or the moon
392	if(sunDir.mV[1] >= 0)
393	{
394		mLightDir = sunDir;
395	}
396	else if(sunDir.mV[1] < 0 && sunDir.mV[1] > LLSky::NIGHTTIME_ELEVATION_COS)
397	{
398		// clamp v1 to 0 so sun never points up and causes weirdness on some machines
399		LLVector3 vec(sunDir.mV[0], sunDir.mV[1], sunDir.mV[2]);
400		vec.mV[1] = 0;
401		vec.normVec();
402		mLightDir = LLVector4(vec, 0.f);
403	}
404	else
405	{
406		mLightDir = moonDir;
407	}
408
409	// calculate the clamp lightnorm for sky (to prevent ugly banding in sky
410	// when haze goes below the horizon
411	mClampedLightDir = sunDir;
412
413	if (mClampedLightDir.mV[1] < -0.1f)
414	{
415		mClampedLightDir.mV[1] = -0.1f;
416	}
417
418	mCurParams.set("lightnorm", mLightDir);
419
420	// bind the variables for all shaders only if we're using WindLight
421	LLViewerShaderMgr::shader_iter shaders_iter, end_shaders;
422	end_shaders = LLViewerShaderMgr::instance()->endShaders();
423	for(shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter) 
424	{
425		if (shaders_iter->mProgramObject != 0
426			&& (gPipeline.canUseWindLightShaders()
427				|| shaders_iter->mShaderGroup == LLGLSLShader::SG_WATER))
428		{
429			shaders_iter->mUniformsDirty = TRUE;
430		}
431	}
432
433	// get the cfr version of the sun's direction
434	LLVector3 cfrSunDir(sunDir.mV[2], sunDir.mV[0], sunDir.mV[1]);
435
436	// set direction and don't allow overriding
437	gSky.setSunDirection(cfrSunDir, LLVector3(0,0,0));
438	gSky.setOverrideSun(TRUE);
439}
440
441void LLWLParamManager::update(LLViewerCamera * cam)
442{
443	LLFastTimer ftm(FTM_UPDATE_WLPARAM);
444	
445	// update clouds, sun, and general
446	mCurParams.updateCloudScrolling();
447	
448	// update only if running
449	if(mAnimator.getIsRunning()) 
450	{
451		mAnimator.update(mCurParams);
452	}
453
454	// update the shaders and the menu
455	propagateParameters();
456	
457	F32 camYaw = cam->getYaw();
458
459	stop_glerror();
460
461	// *TODO: potential optimization - this block may only need to be
462	// executed some of the time.  For example for water shaders only.
463	{
464		F32 camYawDelta = mSunDeltaYaw * DEG_TO_RAD;
465		
466		LLVector3 lightNorm3(mLightDir);
467		lightNorm3 *= LLQuaternion(-(camYaw + camYawDelta), LLVector3(0.f, 1.f, 0.f));
468		mRotatedLightDir = LLVector4(lightNorm3, 0.f);
469
470		LLViewerShaderMgr::shader_iter shaders_iter, end_shaders;
471		end_shaders = LLViewerShaderMgr::instance()->endShaders();
472		for(shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter)
473		{
474			if (shaders_iter->mProgramObject != 0
475				&& (gPipeline.canUseWindLightShaders()
476				|| shaders_iter->mShaderGroup == LLGLSLShader::SG_WATER))
477			{
478				shaders_iter->mUniformsDirty = TRUE;
479			}
480		}
481	}
482}
483
484bool LLWLParamManager::applyDayCycleParams(const LLSD& params, LLEnvKey::EScope scope, F32 time)
485{
486	mDay.loadDayCycle(params, scope);
487	resetAnimator(time, true); // set to specified time and start animator
488	return true;
489}
490
491bool LLWLParamManager::applySkyParams(const LLSD& params)
492{
493	mAnimator.deactivate();
494	mCurParams.setAll(params);
495	return true;
496}
497
498void LLWLParamManager::resetAnimator(F32 curTime, bool run)
499{
500	mAnimator.setTrack(mDay.mTimeMap, mDay.mDayRate, 
501		curTime, run);
502
503	return;
504}
505
506bool LLWLParamManager::addParamSet(const LLWLParamKey& key, LLWLParamSet& param)
507{
508	// add a new one if not one there already
509	std::map<LLWLParamKey, LLWLParamSet>::iterator mIt = mParamList.find(key);
510	if(mIt == mParamList.end()) 
511	{	
512		llassert(!key.name.empty());
513		// *TODO: validate params
514		mParamList[key] = param;
515		mPresetListChangeSignal();
516		return true;
517	}
518
519	return false;
520}
521
522BOOL LLWLParamManager::addParamSet(const LLWLParamKey& key, LLSD const & param)
523{
524	LLWLParamSet param_set;
525	param_set.setAll(param);
526	return addParamSet(key, param_set);
527}
528
529bool LLWLParamManager::getParamSet(const LLWLParamKey& key, LLWLParamSet& param)
530{
531	// find it and set it
532	std::map<LLWLParamKey, LLWLParamSet>::iterator mIt = mParamList.find(key);
533	if(mIt != mParamList.end()) 
534	{
535		param = mParamList[key];
536		param.mName = key.name;
537		return true;
538	}
539
540	return false;
541}
542
543bool LLWLParamManager::hasParamSet(const LLWLParamKey& key)
544{
545	LLWLParamSet dummy;
546	return getParamSet(key, dummy);
547}
548
549bool LLWLParamManager::setParamSet(const LLWLParamKey& key, LLWLParamSet& param)
550{
551	llassert(!key.name.empty());
552	// *TODO: validate params
553	mParamList[key] = param;
554
555	return true;
556}
557
558bool LLWLParamManager::setParamSet(const LLWLParamKey& key, const LLSD & param)
559{
560	llassert(!key.name.empty());
561	// *TODO: validate params
562
563	// quick, non robust (we won't be working with files, but assets) check
564	// this might not actually be true anymore....
565	if(!param.isMap()) 
566	{
567		return false;
568	}
569	
570	LLWLParamSet param_set;
571	param_set.setAll(param);
572	return setParamSet(key, param_set);
573}
574
575void LLWLParamManager::removeParamSet(const LLWLParamKey& key, bool delete_from_disk)
576{
577	// *NOTE: Removing a sky preset invalidates day cycles that refer to it.
578
579	if (key.scope == LLEnvKey::SCOPE_REGION)
580	{
581		llwarns << "Removing region skies not supported" << llendl;
582		llassert(key.scope == LLEnvKey::SCOPE_LOCAL);
583		return;
584	}
585
586	// remove from param list
587	std::map<LLWLParamKey, LLWLParamSet>::iterator it = mParamList.find(key);
588	if (it == mParamList.end())
589	{
590		LL_WARNS("WindLight") << "No sky preset named " << key.name << LL_ENDL;
591		return;
592	}
593
594	mParamList.erase(it);
595	mDay.removeReferencesTo(key);
596
597	// remove from file system if requested
598	if (delete_from_disk)
599	{
600		std::string path_name(getUserDir());
601		std::string escaped_name = escapeString(key.name);
602
603		if(gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml") < 1)
604		{
605			LL_WARNS("WindLight") << "Error removing sky preset " << key.name << " from disk" << LL_ENDL;
606		}
607	}
608
609	// signal interested parties
610	mPresetListChangeSignal();
611}
612
613bool LLWLParamManager::isSystemPreset(const std::string& preset_name) const
614{
615	// *TODO: file system access is excessive here.
616	return gDirUtilp->fileExists(getSysDir() + escapeString(preset_name) + ".xml");
617}
618
619void LLWLParamManager::getPresetNames(preset_name_list_t& region, preset_name_list_t& user, preset_name_list_t& sys) const
620{
621	region.clear();
622	user.clear();
623	sys.clear();
624
625	for (std::map<LLWLParamKey, LLWLParamSet>::const_iterator it = mParamList.begin(); it != mParamList.end(); it++)
626	{
627		const LLWLParamKey& key = it->first;
628		const std::string& name = key.name;
629
630		if (key.scope == LLEnvKey::SCOPE_REGION)
631		{
632			region.push_back(name);
633		}
634		else
635		{
636			if (isSystemPreset(name))
637			{
638				sys.push_back(name);
639			}
640			else
641			{
642				user.push_back(name);
643			}
644		}
645	}
646}
647
648void LLWLParamManager::getUserPresetNames(preset_name_list_t& user) const
649{
650	preset_name_list_t region, sys; // unused
651	getPresetNames(region, user, sys);
652}
653
654void LLWLParamManager::getPresetKeys(preset_key_list_t& keys) const
655{
656	keys.clear();
657
658	for (std::map<LLWLParamKey, LLWLParamSet>::const_iterator it = mParamList.begin(); it != mParamList.end(); it++)
659	{
660		keys.push_back(it->first);
661	}
662}
663
664boost::signals2::connection LLWLParamManager::setPresetListChangeCallback(const preset_list_signal_t::slot_type& cb)
665{
666	return mPresetListChangeSignal.connect(cb);
667}
668
669// virtual static
670void LLWLParamManager::initSingleton()
671{
672	LL_DEBUGS("Windlight") << "Initializing sky" << LL_ENDL;
673
674	loadAllPresets();
675
676	// load the day
677	std::string preferred_day = LLEnvManagerNew::instance().getDayCycleName();
678	if (!LLDayCycleManager::instance().getPreset(preferred_day, mDay))
679	{
680		// Fall back to default.
681		llwarns << "No day cycle named " << preferred_day << ", falling back to defaults" << llendl;
682		mDay.loadDayCycleFromFile("Default.xml");
683
684		// *TODO: Fix user preferences accordingly.
685	}
686
687	// *HACK - sets cloud scrolling to what we want... fix this better in the future
688	std::string sky = LLEnvManagerNew::instance().getSkyPresetName();
689	if (!getParamSet(LLWLParamKey(sky, LLWLParamKey::SCOPE_LOCAL), mCurParams))
690	{
691		llwarns << "No sky preset named " << sky << ", falling back to defaults" << llendl;
692		getParamSet(LLWLParamKey("Default", LLWLParamKey::SCOPE_LOCAL), mCurParams);
693
694		// *TODO: Fix user preferences accordingly.
695	}
696
697	// set it to noon
698	resetAnimator(0.5, LLEnvManagerNew::instance().getUseDayCycle());
699
700	// but use linden time sets it to what the estate is
701	mAnimator.setTimeType(LLWLAnimator::TIME_LINDEN);
702
703	LLEnvManagerNew::instance().usePrefs();
704}
705
706// static
707std::string LLWLParamManager::getSysDir()
708{
709	return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", "");
710}
711
712// static
713std::string LLWLParamManager::getUserDir()
714{
715	return gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS , "windlight/skies", "");
716}
717
718// static
719std::string LLWLParamManager::escapeString(const std::string& str)
720{
721	// Don't use LLURI::escape() because it doesn't encode '-' characters
722	// which may break handling of some system presets like "A-12AM".
723	char* curl_str = curl_escape(str.c_str(), str.size());
724	std::string escaped_str(curl_str);
725	curl_free(curl_str);
726
727	return escaped_str;
728}