diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/llwldaycycle.cpp | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/llwldaycycle.cpp')
-rw-r--r-- | linden/indra/newview/llwldaycycle.cpp | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/linden/indra/newview/llwldaycycle.cpp b/linden/indra/newview/llwldaycycle.cpp new file mode 100644 index 0000000..4626160 --- /dev/null +++ b/linden/indra/newview/llwldaycycle.cpp | |||
@@ -0,0 +1,233 @@ | |||
1 | /** | ||
2 | * @file llwldaycycle.cpp | ||
3 | * @brief Implementation for the LLWLDayCycle class. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-2008, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | * $/LicenseInfo$ | ||
30 | */ | ||
31 | |||
32 | #include "llviewerprecompiledheaders.h" | ||
33 | |||
34 | #include "llwldaycycle.h" | ||
35 | #include "llsdserialize.h" | ||
36 | #include "llwlparammanager.h" | ||
37 | |||
38 | #include "llviewerwindow.h" | ||
39 | |||
40 | #include <map> | ||
41 | |||
42 | LLWLDayCycle::LLWLDayCycle() : mDayRate(120) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | |||
47 | LLWLDayCycle::~LLWLDayCycle() | ||
48 | { | ||
49 | } | ||
50 | |||
51 | void LLWLDayCycle::loadDayCycle(const LLString & fileName) | ||
52 | { | ||
53 | // clear the first few things | ||
54 | mTimeMap.clear(); | ||
55 | |||
56 | // now load the file | ||
57 | LLString pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, | ||
58 | "windlight/days", fileName)); | ||
59 | llinfos << "Loading DayCycle settings from " << pathName << llendl; | ||
60 | |||
61 | llifstream day_cycle_xml(pathName.c_str()); | ||
62 | if (day_cycle_xml.is_open()) | ||
63 | { | ||
64 | // load and parse it | ||
65 | LLSD day_data(LLSD::emptyArray()); | ||
66 | LLPointer<LLSDParser> parser = new LLSDXMLParser(); | ||
67 | parser->parse(day_cycle_xml, day_data, LLSDSerialize::SIZE_UNLIMITED); | ||
68 | |||
69 | // add each key | ||
70 | for(S32 i = 0; i < day_data.size(); ++i) | ||
71 | { | ||
72 | // make sure it's a two array | ||
73 | if(day_data[i].size() != 2) | ||
74 | { | ||
75 | continue; | ||
76 | } | ||
77 | |||
78 | // check each param name exists in param manager | ||
79 | bool success; | ||
80 | LLWLParamSet pset; | ||
81 | success = LLWLParamManager::instance()->getParamSet(day_data[i][1].asString(), pset); | ||
82 | if(!success) | ||
83 | { | ||
84 | // alert the user | ||
85 | LLString::format_map_t args; | ||
86 | args["[SKY]"] = day_data[i][1].asString(); | ||
87 | gViewerWindow->alertXml("WLMissingSky", args); | ||
88 | continue; | ||
89 | } | ||
90 | |||
91 | // then add the key | ||
92 | addKey((F32)day_data[i][0].asReal(), day_data[i][1].asString()); | ||
93 | } | ||
94 | |||
95 | day_cycle_xml.close(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void LLWLDayCycle::saveDayCycle(const LLString & fileName) | ||
100 | { | ||
101 | LLSD day_data(LLSD::emptyArray()); | ||
102 | |||
103 | LLString pathName(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "windlight/days", fileName)); | ||
104 | //llinfos << "Saving WindLight settings to " << pathName << llendl; | ||
105 | |||
106 | for(std::map<F32, std::string>::const_iterator mIt = mTimeMap.begin(); | ||
107 | mIt != mTimeMap.end(); | ||
108 | ++mIt) | ||
109 | { | ||
110 | LLSD key(LLSD::emptyArray()); | ||
111 | key.append(mIt->first); | ||
112 | key.append(mIt->second); | ||
113 | day_data.append(key); | ||
114 | } | ||
115 | |||
116 | std::ofstream day_cycle_xml(pathName.c_str()); | ||
117 | LLPointer<LLSDFormatter> formatter = new LLSDXMLFormatter(); | ||
118 | formatter->format(day_data, day_cycle_xml, LLSDFormatter::OPTIONS_PRETTY); | ||
119 | |||
120 | //day_cycle_xml.close(); | ||
121 | } | ||
122 | |||
123 | |||
124 | void LLWLDayCycle::clearKeys() | ||
125 | { | ||
126 | mTimeMap.clear(); | ||
127 | } | ||
128 | |||
129 | |||
130 | bool LLWLDayCycle::addKey(F32 newTime, const LLString & paramName) | ||
131 | { | ||
132 | // no adding negative time | ||
133 | if(newTime < 0) | ||
134 | { | ||
135 | newTime = 0; | ||
136 | } | ||
137 | |||
138 | // if time not being used, add it and return true | ||
139 | if(mTimeMap.find(newTime) == mTimeMap.end()) | ||
140 | { | ||
141 | mTimeMap.insert(std::pair<F32, std::string>(newTime, paramName)); | ||
142 | return true; | ||
143 | } | ||
144 | |||
145 | // otherwise, don't add, and return error | ||
146 | return false; | ||
147 | } | ||
148 | |||
149 | bool LLWLDayCycle::changeKeyTime(F32 oldTime, F32 newTime) | ||
150 | { | ||
151 | // just remove and add back | ||
152 | std::string name = mTimeMap[oldTime]; | ||
153 | |||
154 | bool stat = removeKey(oldTime); | ||
155 | if(stat == false) | ||
156 | { | ||
157 | return stat; | ||
158 | } | ||
159 | |||
160 | return addKey(newTime, name); | ||
161 | } | ||
162 | |||
163 | bool LLWLDayCycle::changeKeyParam(F32 time, const LLString & name) | ||
164 | { | ||
165 | // just remove and add back | ||
166 | // make sure param exists | ||
167 | LLWLParamSet tmp; | ||
168 | bool stat = LLWLParamManager::instance()->getParamSet(name, tmp); | ||
169 | if(stat == false) | ||
170 | { | ||
171 | return stat; | ||
172 | } | ||
173 | |||
174 | mTimeMap[time] = name; | ||
175 | return true; | ||
176 | } | ||
177 | |||
178 | |||
179 | bool LLWLDayCycle::removeKey(F32 time) | ||
180 | { | ||
181 | // look for the time. If there, erase it | ||
182 | std::map<F32, std::string>::iterator mIt = mTimeMap.find(time); | ||
183 | if(mIt != mTimeMap.end()) | ||
184 | { | ||
185 | mTimeMap.erase(mIt); | ||
186 | return true; | ||
187 | } | ||
188 | |||
189 | return false; | ||
190 | } | ||
191 | |||
192 | bool LLWLDayCycle::getKey(const LLString & name, F32& key) | ||
193 | { | ||
194 | // scroll through till we find the | ||
195 | std::map<F32, std::string>::iterator mIt = mTimeMap.begin(); | ||
196 | for(; mIt != mTimeMap.end(); ++mIt) | ||
197 | { | ||
198 | if(name == mIt->second) | ||
199 | { | ||
200 | key = mIt->first; | ||
201 | return true; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | return false; | ||
206 | } | ||
207 | |||
208 | bool LLWLDayCycle::getKeyedParam(F32 time, LLWLParamSet& param) | ||
209 | { | ||
210 | // just scroll on through till you find it | ||
211 | std::map<F32, std::string>::iterator mIt = mTimeMap.find(time); | ||
212 | if(mIt != mTimeMap.end()) | ||
213 | { | ||
214 | return LLWLParamManager::instance()->getParamSet(mIt->second, param); | ||
215 | } | ||
216 | |||
217 | // return error if not found | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | bool LLWLDayCycle::getKeyedParamName(F32 time, LLString & name) | ||
222 | { | ||
223 | // just scroll on through till you find it | ||
224 | std::map<F32, std::string>::iterator mIt = mTimeMap.find(time); | ||
225 | if(mIt != mTimeMap.end()) | ||
226 | { | ||
227 | name = mTimeMap[time]; | ||
228 | return true; | ||
229 | } | ||
230 | |||
231 | // return error if not found | ||
232 | return false; | ||
233 | } | ||