summaryrefslogtreecommitdiff
path: root/indra/newview/llwaterparammanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llwaterparammanager.cpp')
-rw-r--r--indra/newview/llwaterparammanager.cpp332
1 files changed, 142 insertions, 190 deletions
diff --git a/indra/newview/llwaterparammanager.cpp b/indra/newview/llwaterparammanager.cpp
index 67bb965f99..1a98d4c6c2 100644
--- a/indra/newview/llwaterparammanager.cpp
+++ b/indra/newview/llwaterparammanager.cpp
@@ -54,12 +54,9 @@
#include "llwlparammanager.h"
#include "llwaterparamset.h"
-#include "llfloaterwater.h"
#include "curl/curl.h"
-LLWaterParamManager * LLWaterParamManager::sInstance = NULL;
-
LLWaterParamManager::LLWaterParamManager() :
mFogColor(22.f/255.f, 43.f/255.f, 54.f/255.f, 0.0f, 0.0f, "waterFogColor", "WaterFogColor"),
mFogDensity(4, "waterFogDensity", 2),
@@ -73,8 +70,6 @@ LLWaterParamManager::LLWaterParamManager() :
mWave1Dir(.5f, .5f, "wave1Dir"),
mWave2Dir(.5f, .5f, "wave2Dir"),
mDensitySliderValue(1.0f),
- mPrevFogDensity(16.0f), // 2^4
- mPrevFogColor(22.f/255.f, 43.f/255.f, 54.f/255.f, 0.0f),
mWaterFogKS(1.0f)
{
}
@@ -83,131 +78,73 @@ LLWaterParamManager::~LLWaterParamManager()
{
}
-void LLWaterParamManager::loadAllPresets(const std::string& file_name)
+void LLWaterParamManager::loadAllPresets()
{
- std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", ""));
- LL_DEBUGS2("AppInit", "Shaders") << "Loading Default water settings from " << path_name << LL_ENDL;
-
- bool found = true;
- LLDirIterator app_settings_iter(path_name, "*.xml");
- while(found)
- {
- std::string name;
- found = app_settings_iter.next(name);
- if(found)
- {
-
- name=name.erase(name.length()-4);
+ // First, load system (coming out of the box) water presets.
+ loadPresetsFromDir(getSysDir());
- // 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;
-
- LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL;
- loadPreset(unescaped_name,FALSE);
- }
- }
+ // Then load user presets. Note that user day presets will modify any system ones already loaded.
+ loadPresetsFromDir(getUserDir());
+}
- // And repeat for user presets, note the user presets will modify any system presets already loaded
+void LLWaterParamManager::loadPresetsFromDir(const std::string& dir)
+{
+ LL_INFOS2("AppInit", "Shaders") << "Loading water presets from " << dir << LL_ENDL;
- std::string path_name2(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", ""));
- LL_DEBUGS2("AppInit", "Shaders") << "Loading User water settings from " << path_name2 << LL_ENDL;
-
- found = true;
- LLDirIterator user_settings_iter(path_name2, "*.xml");
- while(found)
+ LLDirIterator dir_iter(dir, "*.xml");
+ while (1)
{
- std::string name;
- found = user_settings_iter.next(name);
- if(found)
+ std::string file;
+ if (!dir_iter.next(file))
{
- name=name.erase(name.length()-4);
-
- // 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;
+ break; // no more files
+ }
- LL_DEBUGS2("AppInit", "Shaders") << "name: " << name << LL_ENDL;
- loadPreset(unescaped_name,FALSE);
+ std::string path = dir + file;
+ if (!loadPreset(path))
+ {
+ llwarns << "Error loading water preset from " << path << llendl;
}
}
-
}
-void LLWaterParamManager::loadPreset(const std::string & name,bool propagate)
+bool LLWaterParamManager::loadPreset(const std::string& path)
{
- // 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";
+ llifstream xml_file;
+ std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true));
- std::string pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", escaped_filename));
- LL_DEBUGS2("AppInit", "Shaders") << "Loading water settings from " << pathName << LL_ENDL;
-
- llifstream presetsXML;
- presetsXML.open(pathName.c_str());
-
- // That failed, try loading from the users area instead.
- if(!presetsXML)
+ xml_file.open(path.c_str());
+ if (!xml_file)
{
- pathName=gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", escaped_filename);
- LL_DEBUGS2("AppInit", "Shaders") << "Loading User water setting from " << pathName << LL_ENDL;
- presetsXML.clear();
- presetsXML.open(pathName.c_str());
+ return false;
}
- if (presetsXML)
- {
- LLSD paramsData(LLSD::emptyMap());
+ LL_DEBUGS2("AppInit", "Shaders") << "Loading water " << name << LL_ENDL;
- LLPointer<LLSDParser> parser = new LLSDXMLParser();
+ LLSD params_data;
+ LLPointer<LLSDParser> parser = new LLSDXMLParser();
+ parser->parse(xml_file, params_data, LLSDSerialize::SIZE_UNLIMITED);
+ xml_file.close();
- 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
+ if (hasParamSet(name))
{
- llwarns << "Can't find " << name << llendl;
- return;
+ setParamSet(name, params_data);
}
-
- if(propagate)
+ else
{
- getParamSet(name, mCurParams);
- propagateParameters();
+ addParamSet(name, params_data);
}
-}
+
+ return true;
+}
void LLWaterParamManager::savePreset(const std::string & name)
{
- // 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";
+ llassert(!name.empty());
// make an empty llsd
LLSD paramsData(LLSD::emptyMap());
- std::string pathName(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", escaped_filename));
+ std::string pathName(getUserDir() + LLURI::escape(name) + ".xml");
// fill it with LLSD windlight params
paramsData = mParamList[name].getAll();
@@ -221,7 +158,6 @@ void LLWaterParamManager::savePreset(const std::string & name)
propagateParameters();
}
-
void LLWaterParamManager::propagateParameters(void)
{
// bind the variables only if we're using shaders
@@ -251,7 +187,7 @@ void LLWaterParamManager::updateShaderUniforms(LLGLSLShader * shader)
{
if (shader->mShaderGroup == LLGLSLShader::SG_WATER)
{
- shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, LLWLParamManager::instance()->getRotatedLightDir().mV);
+ shader->uniform4fv(LLViewerShaderMgr::LIGHTNORM, 1, LLWLParamManager::getInstance()->getRotatedLightDir().mV);
shader->uniform3fv("camPosLocal", 1, LLViewerCamera::getInstance()->getOrigin().mV);
shader->uniform4fv("waterFogColor", 1, LLDrawPoolWater::sWaterFogColor.mV);
shader->uniform4fv("waterPlane", 1, mWaterPlane.mV);
@@ -261,36 +197,33 @@ void LLWaterParamManager::updateShaderUniforms(LLGLSLShader * shader)
}
}
-static LLFastTimer::DeclareTimer FTM_UPDATE_WLPARAM("Update Windlight Params");
-
-void LLWaterParamManager::update(LLViewerCamera * cam)
+void LLWaterParamManager::applyParams(const LLSD& params, bool interpolate)
{
- LLFastTimer ftm(FTM_UPDATE_WLPARAM);
-
- // update the shaders and the menu
- propagateParameters();
-
- // If water fog color has been changed, save it.
- if (mPrevFogColor != mFogColor)
+ if (params.size() == 0)
{
- gSavedSettings.setColor4("WaterFogColor", mFogColor);
- mPrevFogColor = mFogColor;
+ llwarns << "Undefined water params" << llendl;
+ return;
}
- // If water fog density has been changed, save it.
- if (mPrevFogDensity != mFogDensity)
+ if (interpolate)
{
- gSavedSettings.setF32("WaterFogDensity", mFogDensity);
- mPrevFogDensity = mFogDensity;
+ LLWLParamManager::getInstance()->mAnimator.startInterpolation(params);
}
-
- // sync menus if they exist
- LLFloaterWater* waterfloater = LLFloaterReg::findTypedInstance<LLFloaterWater>("env_water");
- if(waterfloater)
+ else
{
- waterfloater->syncMenu();
+ mCurParams.setAll(params);
}
+}
+static LLFastTimer::DeclareTimer FTM_UPDATE_WATERPARAM("Update Water Params");
+
+void LLWaterParamManager::update(LLViewerCamera * cam)
+{
+ LLFastTimer ftm(FTM_UPDATE_WATERPARAM);
+
+ // update the shaders and the menu
+ propagateParameters();
+
// only do this if we're dealing with shaders
if(gPipeline.canUseVertexShaders())
{
@@ -339,26 +272,14 @@ void LLWaterParamManager::update(LLViewerCamera * cam)
}
}
-// static
-void LLWaterParamManager::initClass(void)
-{
- instance();
-}
-
-// static
-void LLWaterParamManager::cleanupClass(void)
-{
- delete sInstance;
- sInstance = NULL;
-}
-
bool LLWaterParamManager::addParamSet(const std::string& name, LLWaterParamSet& param)
{
// add a new one if not one there already
- std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
+ preset_map_t::iterator mIt = mParamList.find(name);
if(mIt == mParamList.end())
{
mParamList[name] = param;
+ mPresetListChangeSignal();
return true;
}
@@ -367,23 +288,15 @@ bool LLWaterParamManager::addParamSet(const std::string& name, LLWaterParamSet&
BOOL LLWaterParamManager::addParamSet(const std::string& name, LLSD const & param)
{
- // add a new one if not one there already
- std::map<std::string, LLWaterParamSet>::const_iterator finder = mParamList.find(name);
- if(finder == mParamList.end())
- {
- mParamList[name].setAll(param);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
+ LLWaterParamSet param_set;
+ param_set.setAll(param);
+ return addParamSet(name, param_set);
}
bool LLWaterParamManager::getParamSet(const std::string& name, LLWaterParamSet& param)
{
// find it and set it
- std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
+ preset_map_t::iterator mIt = mParamList.find(name);
if(mIt != mParamList.end())
{
param = mParamList[name];
@@ -394,6 +307,12 @@ bool LLWaterParamManager::getParamSet(const std::string& name, LLWaterParamSet&
return false;
}
+bool LLWaterParamManager::hasParamSet(const std::string& name)
+{
+ LLWaterParamSet dummy;
+ return getParamSet(name, dummy);
+}
+
bool LLWaterParamManager::setParamSet(const std::string& name, LLWaterParamSet& param)
{
mParamList[name] = param;
@@ -417,29 +336,74 @@ bool LLWaterParamManager::setParamSet(const std::string& name, const LLSD & para
bool LLWaterParamManager::removeParamSet(const std::string& name, bool delete_from_disk)
{
// remove from param list
- std::map<std::string, LLWaterParamSet>::iterator mIt = mParamList.find(name);
- if(mIt != mParamList.end())
+ preset_map_t::iterator it = mParamList.find(name);
+ if (it == mParamList.end())
{
- mParamList.erase(mIt);
+ LL_WARNS("WindLight") << "No water preset named " << name << LL_ENDL;
+ return false;
}
- if(delete_from_disk)
- {
+ mParamList.erase(it);
- std::string path_name(gDirUtilp->getExpandedFilename( LL_PATH_USER_SETTINGS , "windlight/water", ""));
-
- // use full curl escaped name
- char * curl_str = curl_escape(name.c_str(), name.size());
- std::string escaped_name(curl_str);
- curl_free(curl_str);
- curl_str = NULL;
-
- gDirUtilp->deleteFilesInDir(path_name, escaped_name + ".xml");
+ // remove from file system if requested
+ if (delete_from_disk)
+ {
+ if (gDirUtilp->deleteFilesInDir(getUserDir(), LLURI::escape(name) + ".xml") < 1)
+ {
+ LL_WARNS("WindLight") << "Error removing water preset " << name << " from disk" << LL_ENDL;
+ }
}
+ // signal interested parties
+ mPresetListChangeSignal();
return true;
}
+bool LLWaterParamManager::isSystemPreset(const std::string& preset_name) const
+{
+ // *TODO: file system access is excessive here.
+ return gDirUtilp->fileExists(getSysDir() + LLURI::escape(preset_name) + ".xml");
+}
+
+void LLWaterParamManager::getPresetNames(preset_name_list_t& presets) const
+{
+ presets.clear();
+
+ for (preset_map_t::const_iterator it = mParamList.begin(); it != mParamList.end(); ++it)
+ {
+ presets.push_back(it->first);
+ }
+}
+
+void LLWaterParamManager::getPresetNames(preset_name_list_t& user_presets, preset_name_list_t& system_presets) const
+{
+ user_presets.clear();
+ system_presets.clear();
+
+ for (preset_map_t::const_iterator it = mParamList.begin(); it != mParamList.end(); ++it)
+ {
+ if (isSystemPreset(it->first))
+ {
+ system_presets.push_back(it->first);
+ }
+ else
+ {
+ user_presets.push_back(it->first);
+ }
+ }
+}
+
+void LLWaterParamManager::getUserPresetNames(preset_name_list_t& user_presets) const
+{
+ preset_name_list_t dummy;
+ getPresetNames(user_presets, dummy);
+}
+
+boost::signals2::connection LLWaterParamManager::setPresetListChangeCallback(const preset_list_signal_t::slot_type& cb)
+{
+ return mPresetListChangeSignal.connect(cb);
+}
+
F32 LLWaterParamManager::getFogDensity(void)
{
bool err;
@@ -458,34 +422,22 @@ F32 LLWaterParamManager::getFogDensity(void)
return fogDensity;
}
-// static
-LLWaterParamManager * LLWaterParamManager::instance()
+// virtual static
+void LLWaterParamManager::initSingleton()
{
- if(NULL == sInstance)
- {
- sInstance = new LLWaterParamManager();
-
- sInstance->loadAllPresets(LLStringUtil::null);
-
- sInstance->getParamSet("Default", sInstance->mCurParams);
- sInstance->initOverrides();
- }
+ LL_DEBUGS("Windlight") << "Initializing water" << LL_ENDL;
+ loadAllPresets();
+ LLEnvManagerNew::instance().usePrefs();
+}
- return sInstance;
+// static
+std::string LLWaterParamManager::getSysDir()
+{
+ return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/water", "");
}
-void LLWaterParamManager::initOverrides()
+// static
+std::string LLWaterParamManager::getUserDir()
{
- // Override fog color from the current preset with the saved setting.
- LLColor4 fog_color_override = gSavedSettings.getColor4("WaterFogColor");
- mFogColor = fog_color_override;
- mPrevFogColor = fog_color_override;
- mCurParams.set("waterFogColor", fog_color_override);
-
- // Do the same with fog density.
- F32 fog_density = gSavedSettings.getF32("WaterFogDensity");
- mPrevFogDensity = fog_density;
- mFogDensity = fog_density;
- mCurParams.set("waterFogDensity", fog_density);
- setDensitySliderValue(mFogDensity.mExp);
+ return gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS , "windlight/water", "");
}