aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/rlvextensions.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2009-09-04 01:56:20 -0500
committerJacek Antonelli2009-09-04 03:39:51 -0500
commit89a510de10c48ebcf82b98a962e4bf66477dcc93 (patch)
treed30f79f433badffe36a67fc155e70a0e29dd2dc4 /linden/indra/newview/rlvextensions.cpp
parentBackported 1.23 fix for animation joint assertion crash. (diff)
downloadmeta-impy-89a510de10c48ebcf82b98a962e4bf66477dcc93.zip
meta-impy-89a510de10c48ebcf82b98a962e4bf66477dcc93.tar.gz
meta-impy-89a510de10c48ebcf82b98a962e4bf66477dcc93.tar.bz2
meta-impy-89a510de10c48ebcf82b98a962e4bf66477dcc93.tar.xz
Applied Kitty Barnett's RLVa 1.0.1h (Restrained Life) patch.
Made a few non-functional changes to help it apply.
Diffstat (limited to 'linden/indra/newview/rlvextensions.cpp')
-rw-r--r--linden/indra/newview/rlvextensions.cpp454
1 files changed, 454 insertions, 0 deletions
diff --git a/linden/indra/newview/rlvextensions.cpp b/linden/indra/newview/rlvextensions.cpp
new file mode 100644
index 0000000..6f79636
--- /dev/null
+++ b/linden/indra/newview/rlvextensions.cpp
@@ -0,0 +1,454 @@
1#include "llviewerprecompiledheaders.h"
2#include "llagent.h"
3#include "llviewercontrol.h"
4#include "llviewerwindow.h"
5#include "llvoavatar.h"
6#include "llwlparammanager.h"
7
8#include "rlvextensions.h"
9#include "rlvhandler.h"
10
11// ============================================================================
12
13std::map<std::string, S16> RlvExtGetSet::m_DbgAllowed;
14
15// Checked: 2009-06-03 (RLVa-0.2.0h) | Modified: RLVa-0.2.0h
16RlvExtGetSet::RlvExtGetSet()
17{
18 if (!m_DbgAllowed.size()) // m_DbgAllowed is static and should only be initialized once
19 {
20 m_DbgAllowed.insert(std::pair<std::string, S16>("AvatarSex", DBG_READ | DBG_PSEUDO));
21 m_DbgAllowed.insert(std::pair<std::string, S16>("RenderResolutionDivisor", DBG_READ | DBG_WRITE));
22 #ifdef RLV_EXTENSION_CMD_GETSETDEBUG_EX
23 m_DbgAllowed.insert(std::pair<std::string, S16>(RLV_SETTING_FORBIDGIVETORLV, DBG_READ));
24 m_DbgAllowed.insert(std::pair<std::string, S16>(RLV_SETTING_NOSETENV, DBG_READ));
25 m_DbgAllowed.insert(std::pair<std::string, S16>("WindLightUseAtmosShaders", DBG_READ));
26 #endif // RLV_EXTENSION_CMD_GETSETDEBUG_EX
27
28 // Cache persistance of every setting
29 LLControlVariable* pSetting;
30 for (std::map<std::string, S16>::iterator itDbg = m_DbgAllowed.begin(); itDbg != m_DbgAllowed.end(); ++itDbg)
31 {
32 if ( ((pSetting = gSavedSettings.getControl(itDbg->first)) != NULL) && (pSetting->isPersisted()) )
33 itDbg->second |= DBG_PERSIST;
34 }
35 }
36}
37
38// Checked: 2009-05-17 (RLVa-0.2.0a)
39BOOL RlvExtGetSet::onForceCommand(const RlvEvent& rlvEvent)
40{
41 return processCommand(rlvEvent.getSenderID(), rlvEvent.getCommand());
42}
43
44// Checked: 2009-05-17 (RLVa-0.2.0a)
45BOOL RlvExtGetSet::onReplyCommand(const EventType& rlvEvent)
46{
47 return processCommand(rlvEvent.getSenderID(), rlvEvent.getCommand());
48}
49
50// Checked: 2009-06-18 (RLVa-0.2.1d) | Modified: RLVa-0.2.1d
51BOOL RlvExtGetSet::processCommand(const LLUUID& idObj, const RlvCommand& rlvCmd)
52{
53 std::string strBehaviour = rlvCmd.getBehaviour(), strGetSet, strSetting;
54 int idxSetting = strBehaviour.find('_');
55 if ( (strBehaviour.length() >= 6) && (-1 != idxSetting) && ((int)strBehaviour.length() > idxSetting + 1) )
56 {
57 strSetting = strBehaviour.substr(idxSetting + 1);
58 strBehaviour.erase(idxSetting); // Get rid of "_<setting>"
59
60 strGetSet = strBehaviour.substr(0, 3);
61 strBehaviour.erase(0, 3); // Get rid of get/set
62
63 if ("debug" == strBehaviour)
64 {
65 if ( ("get" == strGetSet) && (RLV_TYPE_REPLY == rlvCmd.getParamType()) )
66 {
67 rlvSendChatReply(rlvCmd.getParam(), onGetDebug(strSetting));
68 return TRUE;
69 }
70 else if ( ("set" == strGetSet) && (RLV_TYPE_FORCE == rlvCmd.getParamType()) )
71 {
72 if (!gRlvHandler.hasBehaviourExcept(RLV_BHVR_SETDEBUG, idObj))
73 onSetDebug(strSetting, rlvCmd.getOption());
74 return TRUE;
75 }
76 }
77 else if ("env" == strBehaviour)
78 {
79 if ( ("get" == strGetSet) && (RLV_TYPE_REPLY == rlvCmd.getParamType()) )
80 {
81 rlvSendChatReply(rlvCmd.getParam(), onGetEnv(strSetting));
82 return TRUE;
83 }
84 else if ( ("set" == strGetSet) && (RLV_TYPE_FORCE == rlvCmd.getParamType()) )
85 {
86 if (!gRlvHandler.hasBehaviourExcept(RLV_BHVR_SETENV, idObj))
87 onSetEnv(strSetting, rlvCmd.getOption());
88 return TRUE;
89 }
90 }
91 }
92 else if ("setrot" == rlvCmd.getBehaviour())
93 {
94 // NOTE: if <option> is invalid (or missing) altogether then RLV-1.17 will rotate to 0.0 (which is actually PI / 4)
95 F32 nAngle = 0.0f;
96 if (LLStringUtil::convertToF32(rlvCmd.getOption(), nAngle))
97 {
98 nAngle += RLV_SETROT_OFFSET;
99
100 gAgent.startCameraAnimation();
101
102 LLVector3 at(LLVector3::x_axis);
103 at.rotVec(nAngle, LLVector3::z_axis);
104 at.normalize();
105 gAgent.resetAxes(at);
106
107 return TRUE;
108 }
109 }
110 return FALSE;
111}
112
113// Checked: 2009-06-03 (RLVa-0.2.0h) | Modified: RLVa-0.2.0h
114bool RlvExtGetSet::findDebugSetting(std::string& strSetting, S16& flags)
115{
116 LLStringUtil::toLower(strSetting); // Convenience for non-RLV calls
117
118 std::string strTemp;
119 for (std::map<std::string, S16>::const_iterator itSetting = m_DbgAllowed.begin(); itSetting != m_DbgAllowed.end(); ++itSetting)
120 {
121 strTemp = itSetting->first;
122 LLStringUtil::toLower(strTemp);
123
124 if (strSetting == strTemp)
125 {
126 strSetting = itSetting->first;
127 flags = itSetting->second;
128 return true;
129 }
130 }
131 return false;
132}
133
134// Checked: 2009-06-03 (RLVa-0.2.0h) | Added: RLVa-0.2.0h
135S16 RlvExtGetSet::getDebugSettingFlags(const std::string& strSetting)
136{
137 std::map<std::string, S16>::const_iterator itSetting = m_DbgAllowed.find(strSetting);
138 return (itSetting != m_DbgAllowed.end()) ? itSetting->second : 0;
139}
140
141// Checked: 2009-06-03 (RLVa-0.2.0h) | Modified: RLVa-0.2.0h
142std::string RlvExtGetSet::onGetDebug(std::string strSetting)
143{
144 S16 dbgFlags;
145 if ( (findDebugSetting(strSetting, dbgFlags)) && ((dbgFlags & DBG_READ) == DBG_READ) )
146 {
147 if ((dbgFlags & DBG_PSEUDO) == 0)
148 {
149 LLControlVariable* pSetting = gSavedSettings.getControl(strSetting);
150 if (pSetting)
151 {
152 switch (pSetting->type())
153 {
154 case TYPE_U32:
155 return llformat("%u", gSavedSettings.getU32(strSetting));
156 case TYPE_S32:
157 return llformat("%d", gSavedSettings.getS32(strSetting));
158 case TYPE_BOOLEAN:
159 return llformat("%d", gSavedSettings.getBOOL(strSetting));
160 default:
161 RLV_ERRS << "Unexpected debug setting type" << LL_ENDL;
162 break;
163 }
164 }
165 }
166 else
167 {
168 return onGetPseudoDebug(strSetting);
169 }
170 }
171 return std::string();
172}
173
174// Checked: 2009-06-03 (RLVa-0.2.0h) | Added: RLVa-0.2.0h
175std::string RlvExtGetSet::onGetPseudoDebug(const std::string& strSetting)
176{
177 // Skip sanity checking because it's all done in RlvExtGetSet::onGetDebug() already
178 if ("AvatarSex" == strSetting)
179 {
180 if (gAgent.getAvatarObject())
181 return llformat("%d", (gAgent.getAvatarObject()->getSex() == SEX_MALE)); // [See LLFloaterCustomize::LLFloaterCustomize()]
182 }
183 return std::string();
184}
185
186// Checked: 2009-06-03 (RLVa-0.2.0h) | Modified: RLVa-0.2.0h
187void RlvExtGetSet::onSetDebug(std::string strSetting, const std::string& strValue)
188{
189 S16 dbgFlags;
190 if ( (findDebugSetting(strSetting, dbgFlags)) && ((dbgFlags & DBG_WRITE) == DBG_WRITE) )
191 {
192 if ((dbgFlags & DBG_PSEUDO) == 0)
193 {
194 LLControlVariable* pSetting = gSavedSettings.getControl(strSetting);
195 if (pSetting)
196 {
197 U32 u32Value; S32 s32Value; BOOL fValue;
198 switch (pSetting->type())
199 {
200 case TYPE_U32:
201 if (LLStringUtil::convertToU32(strValue, u32Value))
202 gSavedSettings.setU32(strSetting, u32Value);
203 break;
204 case TYPE_S32:
205 if (LLStringUtil::convertToS32(strValue, s32Value))
206 gSavedSettings.setS32(strSetting, s32Value);
207 break;
208 case TYPE_BOOLEAN:
209 if (LLStringUtil::convertToBOOL(strValue, fValue))
210 gSavedSettings.setBOOL(strSetting, fValue);
211 break;
212 default:
213 RLV_ERRS << "Unexpected debug setting type" << LL_ENDL;
214 break;
215 }
216
217 // Default settings should persist if they were marked that way, but non-default settings should never persist
218 pSetting->setPersist( (pSetting->isDefault()) ? ((dbgFlags & DBG_PERSIST) == DBG_PERSIST) : false );
219 }
220 }
221 }
222}
223
224std::string RlvExtGetSet::onGetEnv(std::string strSetting)
225{
226 LLWLParamManager* pWLParams = LLWLParamManager::instance();
227
228 F32 nValue = 0.0f;
229 if ("daytime" == strSetting)
230 {
231 nValue = (pWLParams->mAnimator.mIsRunning && pWLParams->mAnimator.mUseLindenTime) ? -1.0f : pWLParams->mAnimator.getDayTime();
232 }
233 else if ("preset" == strSetting)
234 {
235 return (pWLParams->mAnimator.mIsRunning && pWLParams->mAnimator.mUseLindenTime) ? std::string() : pWLParams->mCurParams.mName;
236 }
237 else if ("cloudcoverage" == strSetting) nValue = pWLParams->mCloudCoverage;
238 else if ("cloudscale" == strSetting) nValue = pWLParams->mCloudScale;
239 else if ("cloudscrollx" == strSetting) nValue = pWLParams->mCurParams.getCloudScrollX() - 10.0f;
240 else if ("cloudscrolly" == strSetting) nValue = pWLParams->mCurParams.getCloudScrollY() - 10.0f;
241 else if ("densitymultiplier" == strSetting) nValue = pWLParams->mDensityMult * 1000;
242 else if ("distancemultiplier" == strSetting) nValue = pWLParams->mDistanceMult;
243 else if ("eastangle" == strSetting) nValue = pWLParams->mCurParams.getEastAngle() / F_TWO_PI;
244 else if ("hazedensity" == strSetting) nValue = pWLParams->mHazeDensity.r;
245 else if ("hazehorizon" == strSetting) nValue = pWLParams->mHazeHorizon.r;
246 else if ("maxaltitude" == strSetting) nValue = pWLParams->mMaxAlt;
247 else if ("scenegamma" == strSetting) nValue = pWLParams->mWLGamma;
248 else if ("starbrightness" == strSetting) nValue = pWLParams->mCurParams.getStarBrightness();
249 else if ("sunglowfocus" == strSetting) nValue = -pWLParams->mGlow.b / 5.0f;
250 else if ("sunglowsize" == strSetting) nValue = 2 - pWLParams->mGlow.r / 20.0f;
251 else if ("sunmoonposition" == strSetting) nValue = pWLParams->mCurParams.getSunAngle() / F_TWO_PI;
252 else
253 {
254 char ch = strSetting[strSetting.length() - 1];
255 // HACK-RLVa: not entirely proper (creates new synonyms)
256 if ('x' == ch) ch = 'r';
257 else if ('y' == ch) ch = 'g';
258 else if ('d' == ch) ch = 'b';
259
260 if ( ('r' == ch) || ('g' == ch) || ('b' == ch) || ('i' == ch) )
261 {
262 WLColorControl* pColour = NULL;
263 strSetting.erase(strSetting.length() - 2, 1);
264
265 if ("ambient" == strSetting) pColour = &pWLParams->mAmbient;
266 else if ("bluedensity" == strSetting) pColour = &pWLParams->mBlueDensity;
267 else if ("bluehorizon" == strSetting) pColour = &pWLParams->mBlueHorizon;
268 else if ("sunmooncolor" == strSetting) pColour = &pWLParams->mSunlight;
269 else if ("cloudcolor" == strSetting) pColour = &pWLParams->mCloudColor;
270 else if ("cloud" == strSetting) pColour = &pWLParams->mCloudMain;
271 else if ("clouddetail" == strSetting) pColour = &pWLParams->mCloudDetail;
272
273 if (pColour)
274 {
275 if ('r' == ch) nValue = pColour->b;
276 else if ('g' == ch) nValue = pColour->b;
277 else if ('b' == ch) nValue = pColour->b;
278 else if (('i' == ch) && (pColour->hasSliderName)) nValue = pColour->i;
279
280 if (pColour->isBlueHorizonOrDensity) nValue /= 2.0f;
281 else if (pColour->isSunOrAmbientColor) nValue /= 3.0f;
282 }
283 }
284 }
285
286 return llformat("%f", nValue);
287}
288
289void RlvExtGetSet::onSetEnv(std::string strSetting, const std::string& strValue)
290{
291 LLWLParamManager* pWLParams = LLWLParamManager::instance();
292 WLFloatControl* pFloat = NULL;
293 WLColorControl* pColour = NULL;
294
295 F32 nValue = 0.0f;
296 // Sanity check - make sure strValue specifies a number for all settings except "preset"
297 if ( (rlv_handler_t::fNoSetEnv) || ( (!LLStringUtil::convertToF32(strValue, nValue)) && ("preset" != strSetting) ))
298 return;
299
300 // Not quite correct, but RLV-1.16.0 will halt the default daytime cycle on invalid commands so we need to as well
301 pWLParams->mAnimator.mIsRunning = false;
302 pWLParams->mAnimator.mUseLindenTime = false;
303
304 // See LLWorldEnvSettings::handleEvent()
305 if ("daytime" == strSetting)
306 {
307 if (0.0f <= nValue)
308 {
309 pWLParams->mAnimator.setDayTime(llmin(nValue, 1.0f));
310 pWLParams->mAnimator.update(pWLParams->mCurParams);
311 }
312 else
313 {
314 pWLParams->mAnimator.mIsRunning = true;
315 pWLParams->mAnimator.mUseLindenTime = true;
316 }
317 return;
318 }
319 // See LLFloaterWindLight::onChangePresetName()
320 else if ("preset" == strSetting)
321 {
322 pWLParams->loadPreset(strValue, true);
323 return;
324 }
325 // See LLFloaterWindLight::onStarAlphaMoved
326 else if ("starbrightness" == strSetting)
327 {
328 pWLParams->mCurParams.setStarBrightness(nValue);
329 return;
330 }
331 // See LLFloaterWindLight::onGlowRMoved() / LLFloaterWindLight::onGlowBMoved()
332 else if ( ("sunglowfocus" == strSetting) || ("sunglowsize" == strSetting) )
333 {
334 WLColorControl *pColour = &pWLParams->mGlow;
335 if ("sunglowfocus" == strSetting)
336 pColour->b = -nValue * 5;
337 else
338 pColour->r = (2 - nValue) * 20;
339
340 pColour->update(pWLParams->mCurParams);
341 pWLParams->propagateParameters();
342 return;
343 }
344 // See LLFloaterWindLight::onSunMoved()
345 else if ( ("eastangle" == strSetting) || ("sunmoonposition" == strSetting) )
346 {
347 if ("eastangle" == strSetting)
348 pWLParams->mCurParams.setEastAngle(F_TWO_PI * nValue);
349 else
350 pWLParams->mCurParams.setSunAngle(F_TWO_PI * nValue);
351
352 // TODO-RLVa: it looks like propagateParameters() will actually take care of this for us, making this redundant?
353 WLColorControl* pColour = &pWLParams->mLightnorm;
354 pColour->r = -sin(pWLParams->mCurParams.getEastAngle()) * cos(pWLParams->mCurParams.getSunAngle());
355 pColour->g = sin(pWLParams->mCurParams.getSunAngle());
356 pColour->b = cos(pWLParams->mCurParams.getEastAngle()) * cos(pWLParams->mCurParams.getSunAngle());
357 pColour->i = 1.f;
358
359 pColour->update(pWLParams->mCurParams);
360 pWLParams->propagateParameters();
361 return;
362 }
363 // See LLFloaterWindLight::onCloudScrollXMoved() / LLFloaterWindLight::onCloudScrollYMoved()
364 else if ("cloudscrollx" == strSetting)
365 {
366 pWLParams->mCurParams.setCloudScrollX(nValue + 10.0f);
367 return;
368 }
369 else if ("cloudscrolly" == strSetting)
370 {
371 pWLParams->mCurParams.setCloudScrollY(nValue + 10.0f);
372 return;
373 }
374 // See LLFloaterWindLight::onFloatControlMoved()
375 else if ("cloudcoverage" == strSetting) pFloat = &pWLParams->mCloudCoverage;
376 else if ("cloudscale" == strSetting) pFloat = &pWLParams->mCloudScale;
377 else if ("densitymultiplier" == strSetting) pFloat = &pWLParams->mDensityMult;
378 else if ("distancemultiplier" == strSetting) pFloat = &pWLParams->mDistanceMult;
379 else if ("maxaltitude" == strSetting) pFloat = &pWLParams->mMaxAlt;
380 else if ("scenegamma" == strSetting) pFloat = &pWLParams->mWLGamma;
381 // See LLFloaterWindLight::onColorControlRMoved()
382 else if ("hazedensity" == strSetting) pColour = &pWLParams->mHazeDensity;
383 else if ("hazehorizon" == strSetting) pColour = &pWLParams->mHazeHorizon;
384
385 if (pFloat)
386 {
387 pFloat->x = nValue / pFloat->mult;
388 pFloat->update(pWLParams->mCurParams);
389 pWLParams->propagateParameters();
390 return;
391 }
392 else if (pColour)
393 {
394 pColour->r = nValue;
395 pColour->update(pWLParams->mCurParams);
396 pWLParams->propagateParameters();
397 return;
398 }
399
400 // RGBI settings
401 char ch = strSetting[strSetting.length() - 1];
402 if ('x' == ch) ch = 'r';
403 else if ('y' == ch) ch = 'g';
404 else if ('d' == ch) ch = 'b';
405
406 if ( ('r' == ch) || ('g' == ch) || ('b' == ch) || ('i' == ch) )
407 {
408 strSetting.erase(strSetting.length() - 2, 1);
409
410 if ("ambient" == strSetting) pColour = &pWLParams->mAmbient;
411 else if ("bluedensity" == strSetting) pColour = &pWLParams->mBlueDensity;
412 else if ("bluehorizon" == strSetting) pColour = &pWLParams->mBlueHorizon;
413 else if ("sunmooncolor" == strSetting) pColour = &pWLParams->mSunlight;
414 else if ("cloudcolor" == strSetting) pColour = &pWLParams->mCloudColor;
415 else if ("cloud" == strSetting) pColour = &pWLParams->mCloudMain;
416 else if ("clouddetail" == strSetting) pColour = &pWLParams->mCloudDetail;
417
418 if (pColour)
419 {
420 if (pColour->isBlueHorizonOrDensity) nValue *= 2.0f;
421 else if (pColour->isSunOrAmbientColor) nValue *= 3.0f;
422
423 if ('i' == ch) // (See: LLFloaterWindLight::onColorControlIMoved)
424 {
425 if (!pColour->hasSliderName)
426 return;
427
428 F32 curMax = llmax(pColour->r, pColour->g, pColour->b);
429 if ( (0.0f == nValue) || (0.0f == curMax) )
430 pColour->r = pColour->g = pColour->b = pColour->i = nValue;
431 else
432 {
433 F32 nDelta = (nValue - curMax) / curMax;
434 pColour->r *= (1.0f + nDelta);
435 pColour->g *= (1.0f + nDelta);
436 pColour->b *= (1.0f + nDelta);
437 pColour->i = nValue;
438 }
439 }
440 else // (See: LLFloaterWindLight::onColorControlRMoved)
441 {
442 F32* pnValue = ('r' == ch) ? &pColour->r : ('g' == ch) ? &pColour->g : ('b' == ch) ? &pColour->b : NULL;
443 if (pnValue)
444 *pnValue = nValue;
445 pColour->i = llmax(pColour->r, pColour->g, pColour->b);
446 }
447
448 pColour->update(pWLParams->mCurParams);
449 pWLParams->propagateParameters();
450 }
451 }
452}
453
454// ============================================================================