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