From c32b19f31d4d5d0b32fcf64cce1cebd7d79b9b05 Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Thu, 26 May 2011 15:11:01 +0300 Subject: STORM-1253 WIP Implemented switching between multiple day cycles (locally and region-wide). --- indra/newview/lldaycyclemanager.cpp | 122 ++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 indra/newview/lldaycyclemanager.cpp (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp new file mode 100644 index 0000000000..c0eae8cd3c --- /dev/null +++ b/indra/newview/lldaycyclemanager.cpp @@ -0,0 +1,122 @@ +/** + * @file lldaycyclemanager.cpp + * @brief Implementation for the LLDayCycleManager class. + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "lldaycyclemanager.h" + +#include "lldiriterator.h" + +const LLDayCycleManager::dc_map_t& LLDayCycleManager::getPresets() +{ + // Refresh day cycles. + loadAllPresets(); + + return mDayCycleMap; +} + +bool LLDayCycleManager::getPreset(const std::string name, LLWLDayCycle& day_cycle) +{ + dc_map_t::const_iterator it = mDayCycleMap.find(name); + if (it == mDayCycleMap.end()) + { + return false; + } + + day_cycle = it->second; + return true; +} + +bool LLDayCycleManager::getPreset(const std::string name, LLSD& day_cycle) +{ + LLWLDayCycle dc; + if (!getPreset(name, dc)) + { + return false; + } + + day_cycle = dc.asLLSD(); + return true; +} + +// virtual +void LLDayCycleManager::initSingleton() +{ + LL_DEBUGS("Windlight") << "Loading all day cycles" << LL_ENDL; + loadAllPresets(); +} + +void LLDayCycleManager::loadAllPresets() +{ + mDayCycleMap.clear(); + + // First, load system (coming out of the box) day cycles. + loadPresets(getSysDir()); + + // Then load user presets. Note that user day cycles will modify any system ones already loaded. + loadPresets(getUserDir()); +} + +void LLDayCycleManager::loadPresets(const std::string& dir) +{ + LLDirIterator dir_iter(dir, "*.xml"); + + while (1) + { + std::string file; + if (!dir_iter.next(file)) break; // no more files + loadPreset(dir + file); + } +} + +bool LLDayCycleManager::loadPreset(const std::string& path) +{ + LLSD data = LLWLDayCycle::loadDayCycleFromPath(path); + if (data.isUndefined()) + { + LL_WARNS("Windlight") << "Error loading day cycle from " << path << LL_ENDL; + return false; + } + + std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true)); + LLWLDayCycle day_cycle; + day_cycle.loadDayCycle(data, LLEnvKey::SCOPE_LOCAL); + mDayCycleMap[name] = day_cycle; + + return true; +} + +// static +std::string LLDayCycleManager::getSysDir() +{ + return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/days", ""); +} + +// static +std::string LLDayCycleManager::getUserDir() +{ + return gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS , "windlight/days", ""); +} -- cgit v1.2.3 From 657e434fd59139436e8b97e5ecd01ca686e82269 Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Mon, 30 May 2011 22:34:56 +0300 Subject: STORM-1253 WIP New day cycle editor. Done: * Creating new local day cycles. * Editing existing local day cycles. * Deleting day cycles. To do: * Editing region day cycle, dealing with skies in region scope. * Handle teleport while editing a day cycle. * Update UI when a day cycle or sky preset gets deleted. * Make the time ctrl increase/decrease consistently. --- indra/newview/lldaycyclemanager.cpp | 62 ++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 5 deletions(-) (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp index c0eae8cd3c..e80da5ba11 100644 --- a/indra/newview/lldaycyclemanager.cpp +++ b/indra/newview/lldaycyclemanager.cpp @@ -38,7 +38,7 @@ const LLDayCycleManager::dc_map_t& LLDayCycleManager::getPresets() return mDayCycleMap; } -bool LLDayCycleManager::getPreset(const std::string name, LLWLDayCycle& day_cycle) +bool LLDayCycleManager::getPreset(const std::string name, LLWLDayCycle& day_cycle) const { dc_map_t::const_iterator it = mDayCycleMap.find(name); if (it == mDayCycleMap.end()) @@ -50,7 +50,7 @@ bool LLDayCycleManager::getPreset(const std::string name, LLWLDayCycle& day_cycl return true; } -bool LLDayCycleManager::getPreset(const std::string name, LLSD& day_cycle) +bool LLDayCycleManager::getPreset(const std::string name, LLSD& day_cycle) const { LLWLDayCycle dc; if (!getPreset(name, dc)) @@ -62,6 +62,46 @@ bool LLDayCycleManager::getPreset(const std::string name, LLSD& day_cycle) return true; } +bool LLDayCycleManager::presetExists(const std::string name) const +{ + LLWLDayCycle dummy; + return getPreset(name, dummy); +} + +bool LLDayCycleManager::isSystemPreset(const std::string& name) const +{ + return gDirUtilp->fileExists(getSysDir() + LLURI::escape(name) + ".xml"); +} + +bool LLDayCycleManager::savePreset(const std::string& name, const LLSD& data) +{ + // Save given preset. + LLWLDayCycle day; + day.loadDayCycle(data, LLEnvKey::SCOPE_LOCAL); + day.save(getUserDir() + LLURI::escape(name) + ".xml"); + + // Add it to our map. + addPreset(name, data); + return true; +} + +bool LLDayCycleManager::deletePreset(const std::string& name) +{ + std::string path; + std::string filename = LLURI::escape(name) + ".xml"; + + // Try removing specified user preset. + path = getUserDir() + filename; + if (gDirUtilp->fileExists(path)) + { + gDirUtilp->deleteFilesInDir(getUserDir(), filename); + return true; + } + + // Invalid or system preset. + return false; +} + // virtual void LLDayCycleManager::initSingleton() { @@ -102,13 +142,25 @@ bool LLDayCycleManager::loadPreset(const std::string& path) } std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true)); - LLWLDayCycle day_cycle; - day_cycle.loadDayCycle(data, LLEnvKey::SCOPE_LOCAL); - mDayCycleMap[name] = day_cycle; + addPreset(name, data); return true; } +bool LLDayCycleManager::addPreset(const std::string& name, const LLSD& data) +{ + if (name.empty()) + { + llassert(name.empty()); + return false; + } + + LLWLDayCycle day; + day.loadDayCycle(data, LLEnvKey::SCOPE_LOCAL); + mDayCycleMap[name] = day; + return false; +} + // static std::string LLDayCycleManager::getSysDir() { -- cgit v1.2.3 From 6e2c05a512f498fe10aee307308e0365536f9819 Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Wed, 1 Jun 2011 18:11:20 +0300 Subject: STORM-1253 WIP Fixed a couple of typos. --- indra/newview/lldaycyclemanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp index e80da5ba11..0cd23f5202 100644 --- a/indra/newview/lldaycyclemanager.cpp +++ b/indra/newview/lldaycyclemanager.cpp @@ -158,7 +158,7 @@ bool LLDayCycleManager::addPreset(const std::string& name, const LLSD& data) LLWLDayCycle day; day.loadDayCycle(data, LLEnvKey::SCOPE_LOCAL); mDayCycleMap[name] = day; - return false; + return true; } // static -- cgit v1.2.3 From 995a006b58f2be1d7236b32be3570b6d7250013b Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Wed, 1 Jun 2011 18:26:36 +0300 Subject: STORM-1253 WIP Update UI when a day cycle gets added or deleted. --- indra/newview/lldaycyclemanager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp index 0cd23f5202..960879c32c 100644 --- a/indra/newview/lldaycyclemanager.cpp +++ b/indra/newview/lldaycyclemanager.cpp @@ -82,6 +82,7 @@ bool LLDayCycleManager::savePreset(const std::string& name, const LLSD& data) // Add it to our map. addPreset(name, data); + mModifySignal(); return true; } @@ -95,6 +96,7 @@ bool LLDayCycleManager::deletePreset(const std::string& name) if (gDirUtilp->fileExists(path)) { gDirUtilp->deleteFilesInDir(getUserDir(), filename); + mModifySignal(); return true; } @@ -102,6 +104,11 @@ bool LLDayCycleManager::deletePreset(const std::string& name) return false; } +boost::signals2::connection LLDayCycleManager::setModifyCallback(const modify_signal_t::slot_type& cb) +{ + return mModifySignal.connect(cb); +} + // virtual void LLDayCycleManager::initSingleton() { -- cgit v1.2.3 From 0a2406b494bed489da02f27852d916790b412ab5 Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Tue, 7 Jun 2011 13:53:15 +0300 Subject: STORM-1255 WIP Changed a comment and a warning message. --- indra/newview/lldaycyclemanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp index 960879c32c..2e622d002c 100644 --- a/indra/newview/lldaycyclemanager.cpp +++ b/indra/newview/lldaycyclemanager.cpp @@ -144,7 +144,7 @@ bool LLDayCycleManager::loadPreset(const std::string& path) LLSD data = LLWLDayCycle::loadDayCycleFromPath(path); if (data.isUndefined()) { - LL_WARNS("Windlight") << "Error loading day cycle from " << path << LL_ENDL; + llwarns << "Error loading day cycle from " << path << llendl; return false; } -- cgit v1.2.3 From 497c0983bb013cb65b6faf10045ea7b62511cc55 Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Tue, 7 Jun 2011 14:23:10 +0300 Subject: STORM-1253 WIP Fixed a potential bug: removing a day cycle didn't remove it from internal data structures. --- indra/newview/lldaycyclemanager.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp index 2e622d002c..07a9a72e68 100644 --- a/indra/newview/lldaycyclemanager.cpp +++ b/indra/newview/lldaycyclemanager.cpp @@ -88,20 +88,25 @@ bool LLDayCycleManager::savePreset(const std::string& name, const LLSD& data) bool LLDayCycleManager::deletePreset(const std::string& name) { - std::string path; - std::string filename = LLURI::escape(name) + ".xml"; + // Remove it from the map. + dc_map_t::iterator it = mDayCycleMap.find(name); + if (it == mDayCycleMap.end()) + { + LL_WARNS("Windlight") << "No day cycle named " << name << LL_ENDL; + return false; + } + mDayCycleMap.erase(it); - // Try removing specified user preset. - path = getUserDir() + filename; - if (gDirUtilp->fileExists(path)) + // Remove from the filesystem. + std::string filename = LLURI::escape(name) + ".xml"; + if (gDirUtilp->fileExists(getUserDir() + filename)) { gDirUtilp->deleteFilesInDir(getUserDir(), filename); - mModifySignal(); - return true; } - // Invalid or system preset. - return false; + // Signal interested parties. + mModifySignal(); + return true; } boost::signals2::connection LLDayCycleManager::setModifyCallback(const modify_signal_t::slot_type& cb) -- cgit v1.2.3 From 7151a4e6b02f02155387fc595034a42aebd7ec9c Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Tue, 7 Jun 2011 17:41:26 +0300 Subject: STORM-1255 WIP Consistency pass on sky presets removal. * Update all related floaters when a sky preset gets removed. * Don't allow removing skies referenced by (local) day cycles. * Other minor fixes. --- indra/newview/lldaycyclemanager.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp index 07a9a72e68..ab442d7c83 100644 --- a/indra/newview/lldaycyclemanager.cpp +++ b/indra/newview/lldaycyclemanager.cpp @@ -109,6 +109,22 @@ bool LLDayCycleManager::deletePreset(const std::string& name) return true; } +bool LLDayCycleManager::isSkyPresetReferenced(const std::string& preset_name) const +{ + // We're traversing local day cycles, they can only reference local skies. + LLWLParamKey key(preset_name, LLEnvKey::SCOPE_LOCAL); + + for (dc_map_t::const_iterator it = mDayCycleMap.begin(); it != mDayCycleMap.end(); ++it) + { + if (it->second.hasReferencesTo(key)) + { + return true; + } + } + + return false; +} + boost::signals2::connection LLDayCycleManager::setModifyCallback(const modify_signal_t::slot_type& cb) { return mModifySignal.connect(cb); -- cgit v1.2.3 From ab431d1774d5b282836a3327dd0bfa8b3b91632b Mon Sep 17 00:00:00 2001 From: Vadim ProductEngine Date: Tue, 14 Jun 2011 18:04:29 +0300 Subject: STORM-1305 WIP User day cycles now go first in all lists. --- indra/newview/lldaycyclemanager.cpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'indra/newview/lldaycyclemanager.cpp') diff --git a/indra/newview/lldaycyclemanager.cpp b/indra/newview/lldaycyclemanager.cpp index ab442d7c83..347a467a8b 100644 --- a/indra/newview/lldaycyclemanager.cpp +++ b/indra/newview/lldaycyclemanager.cpp @@ -30,12 +30,40 @@ #include "lldiriterator.h" -const LLDayCycleManager::dc_map_t& LLDayCycleManager::getPresets() +void LLDayCycleManager::getPresetNames(preset_name_list_t& names) const { - // Refresh day cycles. - loadAllPresets(); + names.clear(); + + for (dc_map_t::const_iterator it = mDayCycleMap.begin(); it != mDayCycleMap.end(); ++it) + { + names.push_back(it->first); + } +} + +void LLDayCycleManager::getPresetNames(preset_name_list_t& user, preset_name_list_t& sys) const +{ + user.clear(); + sys.clear(); - return mDayCycleMap; + for (dc_map_t::const_iterator it = mDayCycleMap.begin(); it != mDayCycleMap.end(); ++it) + { + const std::string& name = it->first; + + if (isSystemPreset(name)) + { + sys.push_back(name); + } + else + { + user.push_back(name); + } + } +} + +void LLDayCycleManager::getUserPresetNames(preset_name_list_t& user) const +{ + preset_name_list_t sys; // unused + getPresetNames(user, sys); } bool LLDayCycleManager::getPreset(const std::string name, LLWLDayCycle& day_cycle) const -- cgit v1.2.3