bool LLWLParamManager::loadPreset(const std::string& path) { llifstream xml_file; std::string name(LLURI::unescape(gDirUtilp->getBaseFileName(path, true))); xml_file.open(path.c_str()); if (!xml_file) { return false; } LL_DEBUGS2("AppInit", "Shaders") << "Loading sky " << name << LL_ENDL; LLSD params_data; LLPointer<LLSDParser> parser = new LLSDXMLParser(); parser->parse(xml_file, params_data, LLSDSerialize::SIZE_UNLIMITED); xml_file.close(); LLWLParamKey key(name, LLEnvKey::SCOPE_LOCAL); if (hasParamSet(key)) { setParamSet(key, params_data); } else { addParamSet(key, params_data); } return true; }
void LLWLParamManager::loadPreset(const std::string & name,bool propagate) { // bugfix for SL-46920: preventing filenames that break stuff. char * curl_str = curl_escape(name.c_str(), name.size()); std::string escaped_filename(curl_str); curl_free(curl_str); curl_str = NULL; escaped_filename += ".xml"; std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", escaped_filename)); LL_DEBUGS2("AppInit", "Shaders") << "Loading WindLight sky setting from " << pathName << LL_ENDL; llifstream presetsXML; presetsXML.open(pathName.c_str()); // That failed, try loading from the users area instead. if(!presetsXML) { pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/skies", escaped_filename); LL_DEBUGS2("AppInit", "Shaders")<< "Loading User WindLight sky setting from " << LL_ENDL; presetsXML.open(pathName.c_str()); } if (presetsXML) { LLSD paramsData(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED); std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.find(name); if(mIt == mParamList.end()) { addParamSet(name, paramsData); } else { setParamSet(name, paramsData); } presetsXML.close(); } else { llwarns << "Can't find " << name << llendl; return; } if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } notifyObservers(); }
bool LLWLParamManager::loadPresetXML(const LLWLParamKey& key, std::istream& preset_stream) { LLSD params_data(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); if(parser->parse(preset_stream, params_data, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE) { return false; } static const char* expected_windlight_settings[] = { "ambient", "blue_density", "blue_horizon", "cloud_color", "cloud_pos_density1", "cloud_pos_density2", "cloud_scale", "cloud_scroll_rate", "cloud_shadow", "density_multiplier", "distance_multiplier", "east_angle", "enable_cloud_scroll", "gamma", "glow", "haze_density", "haze_horizon", "lightnorm", "max_y", "star_brightness", "sun_angle", "sunlight_color" }; static S32 expected_count = LL_ARRAY_SIZE(expected_windlight_settings); for(S32 i = 0; i < expected_count; ++i) { if(!params_data.has(expected_windlight_settings[i])) { LL_WARNS("WindLight") << "Attempted to load WindLight param set without " << expected_windlight_settings[i] << LL_ENDL; return false; } } if (hasParamSet(key)) { setParamSet(key, params_data); } else { addParamSet(key, params_data); } return true; }
void LLWaterParamManager::loadPreset(const std::string & name,bool propagate) { // bugfix for SL-46920: preventing filenames that break stuff. std::string escaped_filename = LLWeb::curlEscape(name); escaped_filename += ".xml"; std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", escaped_filename)); llinfos << "Loading water settings from " << pathName << llendl; std::ifstream presetsXML; presetsXML.open(pathName.c_str()); // That failed, try loading from the users area instead. if(!presetsXML) { pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", escaped_filename); llinfos << "Loading User water setting from " << pathName << llendl; presetsXML.open(pathName.c_str()); } if (presetsXML) { LLSD paramsData(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED); std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name); if(mIt == mParamList.end()) { addParamSet(name, paramsData); } else { setParamSet(name, paramsData); } presetsXML.close(); } else { llwarns << "Can't find " << name << llendl; return; } if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } }
BOOL LLWLParamManager::addParamSet(const LLWLParamKey& key, LLSD const & param) { LLWLParamSet param_set; param_set.setAll(param); return addParamSet(key, param_set); }
bool LLWLParamManager::loadPresetXML(const std::string& name, std::istream& preset_stream, bool propagate /* = false */, bool check_if_real /* = false */) { LLSD paramsData(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); if(parser->parse(preset_stream, paramsData, LLSDSerialize::SIZE_UNLIMITED) == LLSDParser::PARSE_FAILURE) { return false; } if(check_if_real) { static const char* expected_windlight_settings[] = { "ambient", "blue_density", "blue_horizon", "cloud_color", "cloud_pos_density1", "cloud_pos_density2", "cloud_scale", "cloud_scroll_rate", "cloud_shadow", "density_multiplier", "distance_multiplier", "east_angle", "enable_cloud_scroll", "gamma", "glow", "haze_density", "haze_horizon", "lightnorm", "max_y", "star_brightness", "sun_angle", "sunlight_color" }; static S32 expected_count = LL_ARRAY_SIZE(expected_windlight_settings); for(S32 i = 0; i < expected_count; ++i) { if(!paramsData.has(expected_windlight_settings[i])) { LL_WARNS("WindLight") << "Attempted to load WindLight param set without " << expected_windlight_settings[i] << LL_ENDL; return false; } } } std::map<std::string, LLWLParamSet>::iterator mIt = mParamList.find(name); if(mIt == mParamList.end()) { addParamSet(name, paramsData); } else { setParamSet(name, paramsData); } if(propagate) { getParamSet(name, mCurParams); propagateParameters(); } return true; }
BOOL LLWaterParamManager::addParamSet(const std::string& name, LLSD const & param) { LLWaterParamSet param_set; param_set.setAll(param); return addParamSet(name, param_set); }
void LLWLParamManager::loadPresets(const std::string& file_name) { // if fileName exists, use legacy loading form the big file, otherwise, search the sky // directory, and add the list if(file_name != "") { std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight", file_name)); LL_INFOS2("AppInit", "Shaders") << "Loading WindLight settings from " << path_name << LL_ENDL; llifstream presetsXML(path_name); if (presetsXML) { LLSD paramsData(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); parser->parse(presetsXML, paramsData, LLSDSerialize::SIZE_UNLIMITED); LLSD::map_const_iterator endParams = paramsData.endMap(); for(LLSD::map_const_iterator curParams = paramsData.beginMap(); curParams != endParams; ++curParams) { addParamSet(curParams->first, curParams->second); } } } // otherwise, search the sky directory and find things there else { std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", "")); LL_INFOS2("AppInit", "Shaders") << "Loading WindLight settings from " << path_name << LL_ENDL; //mParamList.clear(); bool found = true; while(found) { std::string name; found = gDirUtilp->getNextFileInDir(path_name, "*.xml", name, false); LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL; // if we have one if(found) { // bugfix for SL-46920: preventing filenames that break stuff. char * curl_str = curl_unescape(name.c_str(), name.size()); std::string unescaped_name(curl_str); curl_free(curl_str); curl_str = NULL; // not much error checking here since we're getting rid of this std::string sky_name = unescaped_name.substr(0, unescaped_name.size() - 4); std::string cur_path(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/skies", name)); LL_DEBUGS2("AppInit", "Shaders") << "Loading sky from " << cur_path << LL_ENDL; llifstream sky_xml(cur_path); if (sky_xml) { LLSD sky_data(LLSD::emptyMap()); LLPointer<LLSDParser> parser = new LLSDXMLParser(); parser->parse(sky_xml, sky_data, LLSDSerialize::SIZE_UNLIMITED); addParamSet(sky_name, sky_data); sky_xml.close(); } } } } }
void LLWLParamManager::update(LLViewerCamera * cam) { LLFastTimer ftm(LLFastTimer::FTM_UPDATE_WLPARAM); // update clouds, sun, and general mCurParams.updateCloudScrolling(); // update only if running if(mAnimator.mIsRunning) { mAnimator.update(mCurParams); } // update the shaders and the menu propagateParameters(); // sync menus if they exist if(LLFloaterWindLight::isOpen()) { LLFloaterWindLight::instance()->syncMenu(); } if(LLFloaterDayCycle::isOpen()) { LLFloaterDayCycle::instance()->syncMenu(); } if(LLFloaterEnvSettings::isOpen()) { LLFloaterEnvSettings::instance()->syncMenu(); } F32 camYaw = cam->getYaw(); stop_glerror(); // *TODO: potential optimization - this block may only need to be // executed some of the time. For example for water shaders only. { F32 camYawDelta = mSunDeltaYaw * DEG_TO_RAD; LLVector3 lightNorm3(mLightDir); lightNorm3 *= LLQuaternion(-(camYaw + camYawDelta), LLVector3(0.f, 1.f, 0.f)); mRotatedLightDir = LLVector4(lightNorm3, 0.f); LLViewerShaderMgr::shader_iter shaders_iter, end_shaders; end_shaders = LLViewerShaderMgr::instance()->endShaders(); for(shaders_iter = LLViewerShaderMgr::instance()->beginShaders(); shaders_iter != end_shaders; ++shaders_iter) { if (shaders_iter->mProgramObject != 0 && (gPipeline.canUseWindLightShaders() || shaders_iter->mShaderGroup == LLGLSLShader::SG_WATER)) { shaders_iter->mUniformsDirty = TRUE; } } } //Mix windlight settings if needed if(sNeedsMix == TRUE) { if(sMixSet == NULL) { sNeedsMix = FALSE; return; } if (wlSmoothTransitionTimer.getElapsedTimeF32() >= (sMixTime / 100)) //100 steps inbetween { wlSmoothTransitionTimer.reset(); mCurParams.mix(mCurParams, *sMixSet, sMixCount / 100);//.01 to 1.0 } sMixCount++; if((sMixCount / 100) == 1) { //All done sNeedsMix = FALSE; std::string wlSkyPresetName = "(Region settings)"; mCurParams.mName = wlSkyPresetName; removeParamSet( wlSkyPresetName, true ); addParamSet( wlSkyPresetName, mCurParams ); savePreset( wlSkyPresetName ); mAnimator.mIsRunning = false; mAnimator.mUseLindenTime = false; loadPreset( wlSkyPresetName, true ); sMixSet = NULL; } } }