From cccca566bd2365c88cca819729c5432af9dfa52f Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Mon, 16 May 2011 17:17:01 +0300 Subject: STORM-1245 WIP Reimplementing management of local presets according to the new spec. User environment preferences are now persistent. TODO: Implement applying region env. settings. --- indra/newview/app_settings/settings.xml | 44 ++++ indra/newview/llagent.cpp | 16 ++ indra/newview/llenvmanager.cpp | 231 +++++++++++++++++++++ indra/newview/llenvmanager.h | 82 ++++++++ indra/newview/llfloaterwater.cpp | 6 +- indra/newview/llfloaterwindlight.cpp | 7 +- indra/newview/llviewermenu.cpp | 38 +--- indra/newview/llwaterparammanager.cpp | 10 +- indra/newview/llwaterparammanager.h | 3 + indra/newview/llwlhandlers.cpp | 8 + indra/newview/llwlparammanager.cpp | 52 ++++- indra/newview/llwlparammanager.h | 3 + indra/newview/skins/default/xui/en/menu_viewer.xml | 3 +- .../newview/skins/default/xui/en/notifications.xml | 11 - 14 files changed, 462 insertions(+), 52 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 3c02cd1b8c..29476b5e71 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -11333,6 +11333,50 @@ Value 1 + UseDayCycle + + Comment + Whether to use use a day cycle or a fixed sky. + Persist + 1 + Type + Boolean + Value + 1 + + WaterPresetName + + Comment + Water preset to use. May be superseded by region settings. + Persist + 1 + Type + String + Value + Default + + SkyPresetName + + Comment + Sky preset to use. May be superseded by region settings or by a day cycle (see DayCycleName). + Persist + 1 + Type + String + Value + Default + + DayCycleName + + Comment + Day cycle to use. May be superseded by region settings. + Persist + 1 + Type + String + Value + Default + UseExternalBrowser Comment diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index cb3c5319c9..38e6caa4b3 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -637,11 +637,19 @@ void LLAgent::setRegion(LLViewerRegion *regionp) bool teleport = (gAgent.getTeleportState() != LLAgent::TELEPORT_NONE); if (teleport) { +#if 0 LLEnvManager::getInstance()->notifyTP(); +#else + LLEnvManagerNew::instance().onTeleport(); +#endif } else { +#if 0 LLEnvManager::getInstance()->notifyCrossing(); +#else + LLEnvManagerNew::instance().onRegionCrossing(); +#endif } } else @@ -661,7 +669,11 @@ void LLAgent::setRegion(LLViewerRegion *regionp) LLWorld::getInstance()->updateAgentOffset(mAgentOriginGlobal); // Notify windlight managers about login +#if 0 LLEnvManager::getInstance()->notifyLogin(); +#else + LLEnvManagerNew::instance().onLogin(); +#endif } // Pass new region along to metrics components that care about this level of detail. @@ -687,8 +699,12 @@ void LLAgent::setRegion(LLViewerRegion *regionp) LLFloaterMove::sUpdateFlyingStatus(); +#if 0 // notify EnvManager that a refresh is needed LLEnvManager::instance().refreshFromStorage(LLEnvKey::SCOPE_REGION); +#else + LLEnvManagerNew::instance().onTeleport(); +#endif } diff --git a/indra/newview/llenvmanager.cpp b/indra/newview/llenvmanager.cpp index c855d8597c..49bbf1a77c 100644 --- a/indra/newview/llenvmanager.cpp +++ b/indra/newview/llenvmanager.cpp @@ -52,6 +52,8 @@ extern LLControlGroup gSavedSettings; /*virtual*/ void LLEnvManager::initSingleton() { + LL_DEBUGS("Windlight") << "Initializing LLEnvManager" << LL_ENDL; + mOrigSettingStore[LLEnvKey::SCOPE_LOCAL] = lindenDefaults(); mCurNormalScope = (gSavedSettings.getBOOL("UseEnvironmentFromRegion") ? LLEnvKey::SCOPE_REGION : LLEnvKey::SCOPE_LOCAL); mInterpNextChangeMessage = true; @@ -557,3 +559,232 @@ void LLEnvManager::dumpScopes() scope_dump = makePacket(LLEnvKey::SCOPE_REGION, LLSD()); LL_DEBUGS("Windlight") << "Region scope:" << scope_dump << LL_ENDL; } + + +//============================================================================= + +std::string LLEnvPrefs::getWaterPresetName() const +{ + if (mWaterPresetName.empty()) + { + llwarns << "Water preset name is empty" << llendl; + } + + return mWaterPresetName; +} + +std::string LLEnvPrefs::getSkyPresetName() const +{ + if (mSkyPresetName.empty()) + { + llwarns << "Sky preset name is empty" << llendl; + } + + return mSkyPresetName; +} + +std::string LLEnvPrefs::getDayCycleName() const +{ + if (mDayCycleName.empty()) + { + llwarns << "Day cycle name is empty" << llendl; + } + + return mDayCycleName; +} + +void LLEnvPrefs::setUseDefaults(bool val) +{ + mUseDefaults = val; +} + +void LLEnvPrefs::setUseWaterPreset(const std::string& name) +{ + setUseDefaults(false); + mWaterPresetName = name; +} + +void LLEnvPrefs::setUseSkyPreset(const std::string& name) +{ + setUseDefaults(false); + mUseDayCycle = false; + mSkyPresetName = name; +} + +void LLEnvPrefs::setUseDayCycle(const std::string& name) +{ + setUseDefaults(false); + mUseDayCycle = true; + mDayCycleName = name; +} + +//============================================================================= +LLEnvManagerNew::LLEnvManagerNew() +{ + mInterpNextChangeMessage = true; + + // Set default environment settings. + mUserPrefs.mUseDefaults = true; + mUserPrefs.mUseDayCycle = true; + mUserPrefs.mWaterPresetName = "Default"; + mUserPrefs.mSkyPresetName = "Default"; + mUserPrefs.mDayCycleName = "Default"; +} + +bool LLEnvManagerNew::getUseRegionSettings() const +{ + return mUserPrefs.getUseDefaults(); +} + +bool LLEnvManagerNew::getUseDayCycle() const +{ + return mUserPrefs.getUseDayCycle(); +} + +bool LLEnvManagerNew::getUseFixedSky() const +{ + return mUserPrefs.getUseFixedSky(); +} + +std::string LLEnvManagerNew::getWaterPresetName() const +{ + return mUserPrefs.getWaterPresetName(); +} + +std::string LLEnvManagerNew::getSkyPresetName() const +{ + return mUserPrefs.getSkyPresetName(); +} + +std::string LLEnvManagerNew::getDayCycleName() const +{ + return mUserPrefs.getDayCycleName(); +} + +void LLEnvManagerNew::setUseRegionSettings(bool val) +{ + mUserPrefs.setUseDefaults(val); + saveUserPrefs(); + updateManagersFromPrefs(); +} + +void LLEnvManagerNew::setUseWaterPreset(const std::string& name) +{ + if (name.empty()) + { + llwarns << "Empty water preset name passed" << llendl; + return; + } + + mUserPrefs.setUseWaterPreset(name); + saveUserPrefs(); + updateManagersFromPrefs(); +} + +void LLEnvManagerNew::setUseSkyPreset(const std::string& name) +{ + if (name.empty()) + { + llwarns << "Empty sky preset name passed" << llendl; + return; + } + + mUserPrefs.setUseSkyPreset(name); + saveUserPrefs(); + updateManagersFromPrefs(); +} + +void LLEnvManagerNew::setUseDayCycle(const std::string& name) +{ + if (name.empty()) + { + llwarns << "Empty day cycle name passed" << llendl; + return; + } + + mUserPrefs.setUseDayCycle(name); + saveUserPrefs(); + updateManagersFromPrefs(); +} + +void LLEnvManagerNew::loadUserPrefs() +{ + // operate on members directly to avoid side effects + mUserPrefs.mWaterPresetName = gSavedSettings.getString("WaterPresetName"); + mUserPrefs.mSkyPresetName = gSavedSettings.getString("SkyPresetName"); + mUserPrefs.mDayCycleName = gSavedSettings.getString("DayCycleName"); + + mUserPrefs.mUseDefaults = gSavedSettings.getBOOL("UseEnvironmentFromRegion"); + mUserPrefs.mUseDayCycle = gSavedSettings.getBOOL("UseDayCycle"); +} + +void LLEnvManagerNew::saveUserPrefs() +{ + gSavedSettings.setString("WaterPresetName", getWaterPresetName()); + gSavedSettings.setString("SkyPresetName", getSkyPresetName()); + gSavedSettings.setString("DayCycleName", getDayCycleName()); + + gSavedSettings.setBOOL("UseEnvironmentFromRegion", getUseRegionSettings()); + gSavedSettings.setBOOL("UseDayCycle", getUseDayCycle()); +} + +void LLEnvManagerNew::onRegionCrossing() +{ + LL_DEBUGS("Windlight") << "Crossed region" << LL_ENDL; + onRegionChange(true); +} + +void LLEnvManagerNew::onLogin() +{ + LL_DEBUGS("Windlight") << "Logged in" << LL_ENDL; + onRegionChange(false); +} + +void LLEnvManagerNew::onTeleport() +{ + LL_DEBUGS("Windlight") << "Teleported" << LL_ENDL; + onRegionChange(false); +} + +//-- private methods ---------------------------------------------------------- + +// virtual +void LLEnvManagerNew::initSingleton() +{ + LL_DEBUGS("Windlight") << "Initializing LLEnvManagerNew" << LL_ENDL; + + loadUserPrefs(); +} + +void LLEnvManagerNew::updateManagersFromPrefs() +{ + // *TODO: apply region settings if user preferences say to do so. + + // Apply water settings. + LLWaterParamManager::instance().applyUserPrefs(); + + // Apply sky settings. + LLWLParamManager::instance().applyUserPrefs(); +} + +void LLEnvManagerNew::sendRegionSettingsRequest() +{ +} + +void LLEnvManagerNew::onRegionChange(bool interpolate) +{ + mInterpNextChangeMessage = interpolate; + sendRegionSettingsRequest(); +} + +void LLEnvManagerNew::onRegionSettingsResponse() +{ + // 1. Refresh cached region settings. + // ... + + // 2. If using server settings, update managers. + if (mUserPrefs.getUseDefaults()) + { + updateManagersFromPrefs(); + } +} diff --git a/indra/newview/llenvmanager.h b/indra/newview/llenvmanager.h index 438fe4590d..0fd2a7e87e 100644 --- a/indra/newview/llenvmanager.h +++ b/indra/newview/llenvmanager.h @@ -126,6 +126,7 @@ private: // not thread-safe class LLEnvManager : public LLSingleton { + LOG_CLASS(LLEnvManager); public: // sets scopes (currently, only region-scope) to startup states // delay calling these until as close as possible to knowing whether the remote service is capable of holding windlight settings @@ -219,5 +220,86 @@ private: LLUUID mLastReceivedID; }; +/** + * User or region preferences. + * + * Region defaults :- use SL defaults + * User defaults :- use region defaults + */ +class LLEnvPrefs +{ +public: + LLEnvPrefs() : mUseDefaults(true), mUseDayCycle(true) {} + + bool getUseDefaults() const { return mUseDefaults; } + bool getUseDayCycle() const { return mUseDayCycle; } + bool getUseFixedSky() const { return !getUseDayCycle(); } + + std::string getWaterPresetName() const; + std::string getSkyPresetName() const; + std::string getDayCycleName() const; + + void setUseDefaults(bool val); + void setUseWaterPreset(const std::string& name); + void setUseSkyPreset(const std::string& name); + void setUseDayCycle(const std::string& name); + + bool mUseDefaults; + bool mUseDayCycle; + std::string mWaterPresetName; + std::string mSkyPresetName; + std::string mDayCycleName; +}; + +class LLRegionEnvPrefs : public LLEnvPrefs +{ + LLSD mDayCycle; +}; + +/** + * Setting: + * 1. Use region settings. + * 2. Use my setting: + | + */ +class LLEnvManagerNew : public LLSingleton +{ + LOG_CLASS(LLEnvManagerNew); +public: + LLEnvManagerNew(); + + bool getUseRegionSettings() const; + bool getUseDayCycle() const; + bool getUseFixedSky() const; + std::string getWaterPresetName() const; + std::string getSkyPresetName() const; + std::string getDayCycleName() const; + + void setUseRegionSettings(bool val); + void setUseWaterPreset(const std::string& name); + void setUseSkyPreset(const std::string& name); + void setUseDayCycle(const std::string& name); + + void loadUserPrefs(); + void saveUserPrefs(); + + void onLogin(); + void onRegionCrossing(); + void onTeleport(); + +private: + friend class LLSingleton; + /*virtual*/ void initSingleton(); + + void updateManagersFromPrefs(); + void sendRegionSettingsRequest(); + + void onRegionChange(bool interpolate); + void onRegionSettingsResponse(); + + LLEnvPrefs mUserPrefs; + LLRegionEnvPrefs mCachedRegionPrefs; + bool mInterpNextChangeMessage; +}; + #endif // LL_LLENVMANAGER_H diff --git a/indra/newview/llfloaterwater.cpp b/indra/newview/llfloaterwater.cpp index 533831f181..c32e25be41 100644 --- a/indra/newview/llfloaterwater.cpp +++ b/indra/newview/llfloaterwater.cpp @@ -98,7 +98,7 @@ BOOL LLFloaterWater::postBuild() } // set defaults on combo boxes - comboBox->selectByValue(LLSD("Default")); + comboBox->selectByValue(LLEnvManagerNew::instance().getWaterPresetName()); } // load it up initCallbacks(); @@ -654,7 +654,11 @@ void LLFloaterWater::onChangePresetName(LLUICtrl* ctrl) std::string data = ctrl->getValue().asString(); if(!data.empty()) { +#if 0 LLWaterParamManager::instance().loadPreset(data); +#else + LLEnvManagerNew::instance().setUseWaterPreset(data); +#endif syncMenu(); } } diff --git a/indra/newview/llfloaterwindlight.cpp b/indra/newview/llfloaterwindlight.cpp index 34629ec5c4..b90f576555 100644 --- a/indra/newview/llfloaterwindlight.cpp +++ b/indra/newview/llfloaterwindlight.cpp @@ -89,7 +89,8 @@ BOOL LLFloaterWindLight::postBuild() comboBox->add(LLStringUtil::null); // set defaults on combo boxes - comboBox->selectByValue(LLSD("Default")); + LLEnvManagerNew& env_mgr = LLEnvManagerNew::instance(); + comboBox->selectByValue(env_mgr.getUseFixedSky() ? env_mgr.getSkyPresetName() : LLStringUtil::null); } // add the list of presets @@ -920,7 +921,11 @@ void LLFloaterWindLight::onChangePresetName(LLUICtrl* ctrl) return; } +#if 0 LLWLParamManager::getInstance()->loadPreset(LLWLParamKey(combo_box->getSelectedValue())); +#else + LLEnvManagerNew::instance().setUseSkyPreset(LLWLParamKey(combo_box->getSelectedValue()).name); +#endif sWindLight->syncMenu(); } diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index 54fc4a2bb7..4a0e9fa766 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -7587,51 +7587,21 @@ class LLWorldEnvSettings : public view_listener_t return true; } - if (gSavedSettings.getBOOL("UseEnvironmentFromRegion")) - { - LLNotifications::instance().add("EnvLockedUsingRegion", LLSD(), LLSD()); - return true; - } - if (tod == "sunrise") { - // set the value, turn off animation - LLWLParamManager::getInstance()->mAnimator.setDayTime(0.25); - LLWLParamManager::getInstance()->mAnimator.deactivate(); - - // then call update once - LLWLParamManager::getInstance()->mAnimator.update( - LLWLParamManager::getInstance()->mCurParams); + LLEnvManagerNew::instance().setUseSkyPreset("Sunrise"); } else if (tod == "noon") { - // set the value, turn off animation - LLWLParamManager::getInstance()->mAnimator.setDayTime(0.567); - LLWLParamManager::getInstance()->mAnimator.deactivate(); - - // then call update once - LLWLParamManager::getInstance()->mAnimator.update( - LLWLParamManager::getInstance()->mCurParams); + LLEnvManagerNew::instance().setUseSkyPreset("Midday"); } else if (tod == "sunset") { - // set the value, turn off animation - LLWLParamManager::getInstance()->mAnimator.setDayTime(0.75); - LLWLParamManager::getInstance()->mAnimator.deactivate(); - - // then call update once - LLWLParamManager::getInstance()->mAnimator.update( - LLWLParamManager::getInstance()->mCurParams); + LLEnvManagerNew::instance().setUseSkyPreset("Sunset"); } else if (tod == "midnight") { - // set the value, turn off animation - LLWLParamManager::getInstance()->mAnimator.setDayTime(0.0); - LLWLParamManager::getInstance()->mAnimator.deactivate(); - - // then call update once - LLWLParamManager::getInstance()->mAnimator.update( - LLWLParamManager::getInstance()->mCurParams); + LLEnvManagerNew::instance().setUseSkyPreset("Midnight"); } else { diff --git a/indra/newview/llwaterparammanager.cpp b/indra/newview/llwaterparammanager.cpp index 4e56be5851..587249856e 100644 --- a/indra/newview/llwaterparammanager.cpp +++ b/indra/newview/llwaterparammanager.cpp @@ -256,6 +256,13 @@ void LLWaterParamManager::updateShaderUniforms(LLGLSLShader * shader) static LLFastTimer::DeclareTimer FTM_UPDATE_WATERPARAM("Update Water Params"); +void LLWaterParamManager::applyUserPrefs() +{ + std::string water = LLEnvManagerNew::instance().getWaterPresetName(); + LL_DEBUGS("Windlight") << "Loading water preset [" << water << "]" << LL_ENDL; + loadPreset(water, true); +} + void LLWaterParamManager::update(LLViewerCamera * cam) { LLFastTimer ftm(FTM_UPDATE_WATERPARAM); @@ -427,6 +434,7 @@ F32 LLWaterParamManager::getFogDensity(void) // virtual static void LLWaterParamManager::initSingleton() { + LL_DEBUGS("Windlight") << "Initializing water" << LL_ENDL; loadAllPresets(LLStringUtil::null); - getParamSet("Default", mCurParams); + applyUserPrefs(); } diff --git a/indra/newview/llwaterparammanager.h b/indra/newview/llwaterparammanager.h index 3fe0f0d861..37c04448eb 100644 --- a/indra/newview/llwaterparammanager.h +++ b/indra/newview/llwaterparammanager.h @@ -229,6 +229,9 @@ public: /// send the parameters to the shaders void propagateParameters(void); + /// apply user water preferences + void applyUserPrefs(); + /// update information for the shader void update(LLViewerCamera * cam); diff --git a/indra/newview/llwlhandlers.cpp b/indra/newview/llwlhandlers.cpp index c116265c86..de20051880 100644 --- a/indra/newview/llwlhandlers.cpp +++ b/indra/newview/llwlhandlers.cpp @@ -113,13 +113,21 @@ LLEnvironmentRequestResponder::LLEnvironmentRequestResponder() return; } +#if 0 LLEnvManager::getInstance()->processIncomingMessage(unvalidated_content, LLEnvKey::SCOPE_REGION); +#else + LL_INFOS("WindlightCaps") << "Temprarily ignoring region settings" << LL_ENDL; +#endif } /*virtual*/ void LLEnvironmentRequestResponder::error(U32 status, const std::string& reason) { LL_INFOS("WindlightCaps") << "Got an error, not using region windlight..." << LL_ENDL; +#if 0 // notify manager that region settings are undefined LLEnvManager::getInstance()->processIncomingMessage(LLSD(), LLEnvKey::SCOPE_REGION); +#else + LL_INFOS("WindlightCaps") << "Temprarily ignoring region settings" << LL_ENDL; +#endif } diff --git a/indra/newview/llwlparammanager.cpp b/indra/newview/llwlparammanager.cpp index 1da70b9557..43f0cdae93 100644 --- a/indra/newview/llwlparammanager.cpp +++ b/indra/newview/llwlparammanager.cpp @@ -580,6 +580,49 @@ void LLWLParamManager::update(LLViewerCamera * cam) } } +void LLWLParamManager::applyUserPrefs() +{ + LL_DEBUGS("Windlight") << "Applying sky prefs" << LL_ENDL; + + if (LLEnvManagerNew::instance().getUseRegionSettings()) // apply region-wide settings + { + llwarns << "Using region settings has not been implemented" << llendl; + } + else // apply user-specified settings + { + bool use_day_cycle = LLEnvManagerNew::instance().getUseDayCycle(); + + if (use_day_cycle) + { + LL_DEBUGS("Windlight") << "Loading day cycle " << LLEnvManagerNew::instance().getDayCycleName() << LL_ENDL; + mDay.loadDayCycleFromFile(LLEnvManagerNew::instance().getDayCycleName() + ".xml"); + } + else + { + // *HACK - sets cloud scrolling to what we want... fix this better in the future + std::string sky = LLEnvManagerNew::instance().getSkyPresetName(); + LL_DEBUGS("Windlight") << "Loading fixed sky " << sky << LL_ENDL; + getParamSet(LLWLParamKey(sky, LLWLParamKey::SCOPE_LOCAL), mCurParams); + } + + // Animator should be running if we're using a day cycle + // and be stopped if we want fixed sky. + if (use_day_cycle != mAnimator.getIsRunning()) + { + if (use_day_cycle) + { + LL_DEBUGS("Windlight") << "Activating animator" << LL_ENDL; + mAnimator.activate(mAnimator.getTimeType()); + } + else + { + LL_DEBUGS("Windlight") << "Deactivating animator" << LL_ENDL; + mAnimator.deactivate(); + } + } + } +} + void LLWLParamManager::resetAnimator(F32 curTime, bool run) { mAnimator.setTrack(mDay.mTimeMap, mDay.mDayRate, @@ -687,16 +730,19 @@ void LLWLParamManager::removeParamSet(const LLWLParamKey& key, bool delete_from_ // virtual static void LLWLParamManager::initSingleton() { + LL_DEBUGS("Windlight") << "Initializing sky" << LL_ENDL; + loadPresets(LLStringUtil::null); // load the day - mDay.loadDayCycleFromFile(std::string("Default.xml")); + mDay.loadDayCycleFromFile(LLEnvManagerNew::instance().getDayCycleName() + ".xml"); // *HACK - sets cloud scrolling to what we want... fix this better in the future - getParamSet(LLWLParamKey("Default", LLWLParamKey::SCOPE_LOCAL), mCurParams); + std::string sky = LLEnvManagerNew::instance().getSkyPresetName(); + getParamSet(LLWLParamKey(sky, LLWLParamKey::SCOPE_LOCAL), mCurParams); // set it to noon - resetAnimator(0.5, true); + resetAnimator(0.5, LLEnvManagerNew::instance().getUseDayCycle()); // but use linden time sets it to what the estate is mAnimator.setTimeType(LLWLAnimator::TIME_LINDEN); diff --git a/indra/newview/llwlparammanager.h b/indra/newview/llwlparammanager.h index e85227d3b3..a2327d35a8 100644 --- a/indra/newview/llwlparammanager.h +++ b/indra/newview/llwlparammanager.h @@ -235,6 +235,9 @@ public: /// update information camera dependent parameters void update(LLViewerCamera * cam); + /// apply specified params + void applyUserPrefs(); + // get where the light is pointing inline LLVector4 getLightDir(void) const; diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml index 910106a6b5..04a0350283 100644 --- a/indra/newview/skins/default/xui/en/menu_viewer.xml +++ b/indra/newview/skins/default/xui/en/menu_viewer.xml @@ -505,8 +505,9 @@ function="World.EnvSettings" parameter="midnight" /> + - -You cannot load environment presets while you are using the region's environment settings. To manually configure your environment setings, select the Environment Editor and uncheck "Use Region Environment Settings." - - -