aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lightshare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/lightshare.cpp')
-rw-r--r--linden/indra/newview/lightshare.cpp210
1 files changed, 205 insertions, 5 deletions
diff --git a/linden/indra/newview/lightshare.cpp b/linden/indra/newview/lightshare.cpp
index 378a755..db391f5 100644
--- a/linden/indra/newview/lightshare.cpp
+++ b/linden/indra/newview/lightshare.cpp
@@ -1,9 +1,10 @@
1/** 1/**
2 * @file lightshare.cpp 2 * @file lightshare.cpp
3 * @brief Handler for Meta7 Lightshare (region-side Windlight settings). 3 * @brief Handler for Meta7 Lightshare (region-side Windlight settings), and other methods of sharing WindLight.
4 * 4 *
5 * Copyright (c) 2010, Tom Grimshaw (Tom Meta) 5 * Copyright (c) 2010, Tom Grimshaw (Tom Meta)
6 * Copyright (c) 2010, Jacek Antonelli 6 * Copyright (c) 2010, Jacek Antonelli
7 * Copyright (c) 2012, David Seikel
7 * 8 *
8 * The source code in this file ("Source Code") is provided to you 9 * The source code in this file ("Source Code") is provided to you
9 * under the terms of the GNU General Public License, version 2.0 10 * under the terms of the GNU General Public License, version 2.0
@@ -43,6 +44,10 @@
43#include "llworld.h" 44#include "llworld.h"
44 45
45 46
47const std::string LightShare::sRegionPresetName = "(Region settings)";
48const std::string LightShare::sParcelPresetName = "(Parcel settings)";
49const std::string LightShare::sRLVPresetName = "(RLV settings)";
50
46 51
47LLWaterParamSet* LightShare::mWater = NULL; 52LLWaterParamSet* LightShare::mWater = NULL;
48LLWLParamSet* LightShare::mSky = NULL; 53LLWLParamSet* LightShare::mSky = NULL;
@@ -131,12 +136,12 @@ void LightShare::applyMaybe(LLWaterParamSet* thisWater, LLUUID* thisWaterNormal,
131 // If they are using region settings already, or LightShare is 136 // If they are using region settings already, or LightShare is
132 // always allowed, just apply the new settings, don't bother asking. 137 // always allowed, just apply the new settings, don't bother asking.
133 if( gSavedSettings.getU32("LightShareAllowed") == LIGHTSHARE_ALWAYS || 138 if( gSavedSettings.getU32("LightShareAllowed") == LIGHTSHARE_ALWAYS ||
134 (sky == LLWLParamManager::sSkyPresetName && water == LLWLParamManager::sWaterPresetName) ) 139 (sky == sRegionPresetName && water == sRegionPresetName) )
135 { 140 {
136 mSky = thisSky; 141 mSky = thisSky;
137 mWater = thisWater; 142 mWater = thisWater;
138 mWaterNormal = thisWaterNormal; 143 mWaterNormal = thisWaterNormal;
139 LLWLParamManager::apply(mWater, mWaterNormal, mSky); 144 apply(mWater, mWaterNormal, mSky, WL_SCOPE_REGION);
140 return; 145 return;
141 } 146 }
142 147
@@ -182,7 +187,7 @@ bool LightShare::applyCallback(const LLSD& notification, const LLSD& response)
182 { 187 {
183 case 0:{ 188 case 0:{
184 // "Apply" 189 // "Apply"
185 LLWLParamManager::apply(mWater, mWaterNormal, mSky); 190 apply(mWater, mWaterNormal, mSky, WL_SCOPE_REGION);
186 191
187 break; 192 break;
188 } 193 }
@@ -205,7 +210,7 @@ bool LightShare::applyCallback(const LLSD& notification, const LLSD& response)
205void LightShare::resetRegion() 210void LightShare::resetRegion()
206{ 211{
207 sIgnoreRegion = false; 212 sIgnoreRegion = false;
208 LLWorld::getInstance()->rebuildClouds(gAgent.getRegion()); 213 apply(NULL, NULL, NULL, WL_SCOPE_REGION);
209} 214}
210 215
211// static 216// static
@@ -222,6 +227,201 @@ bool LightShare::ignoreTimerHasExpired()
222 return sIgnoreTimer->hasExpired(); 227 return sIgnoreTimer->hasExpired();
223} 228}
224 229
230// TODO - have regionSet and parcelSet be arrays, so we can deal with height zones.
231static struct WLCombined userSet, regionSet, parcelSet, RLVSet;
232
233// TODO - should spread this merging stuff around,
234// so that eventually we can get rid of almost identical code for water and sky.
235// Then one of these two methods goes away.
236
237//static
238void LightShare::mergeWaterSets(LLWaterParamSet* thisSet, LLWaterParamSet* oldSet)
239{
240 for(LLSD::map_const_iterator i = thisSet->mParamValues.beginMap();
241 i != thisSet->mParamValues.endMap();
242 ++i)
243 {
244 const std::string& param = i->first;
245
246 if(i->second.isArray())
247 {
248 for (int j = 0; j < i->second.size(); j++)
249 {
250 oldSet->mParamValues[param][j] = i->second[j].asReal();
251 }
252 }
253 else if(i->second.isReal())
254 oldSet->mParamValues[param] = i->second.asReal();
255 }
256}
257
258//static
259void LightShare::mergeWLSets(LLWLParamSet* thisSet, LLWLParamSet* oldSet)
260{
261 for(LLSD::map_const_iterator i = thisSet->mParamValues.beginMap();
262 i != thisSet->mParamValues.endMap();
263 ++i)
264 {
265 const std::string& param = i->first;
266
267 if(i->second.isArray())
268 {
269 for (int j = 0; j < i->second.size(); j++)
270 {
271 oldSet->mParamValues[param][j] = i->second[j].asReal();
272 }
273 }
274 else if(i->second.isReal())
275 oldSet->mParamValues[param] = i->second.asReal();
276 }
277}
278
279//static
280void LightShare::apply(LLWaterParamSet * newWater, LLUUID *newWaterNormal, LLWLParamSet *newSky, WLScope scope)
281// TODO - Deal with day cycle stuff.
282{
283 LLWaterParamManager* waterMgr = LLWaterParamManager::instance();
284 LLWLParamManager* skyMgr = LLWLParamManager::instance();
285 LLWaterParamSet oldWaterSet = waterMgr->mCurParams;
286 LLWLParamSet oldWLSet = skyMgr->mCurParams;
287 struct WLCombined* thisSet = &userSet;
288 bool user = true;
289
290 switch(scope)
291 {
292 case WL_SCOPE_USER :
293 {
294 thisSet = &userSet;
295 thisSet->water.mName = waterMgr->mCurParams.mName;
296 thisSet->sky.mName = skyMgr->mCurParams.mName;
297 thisSet->enabled = true;
298 // Check if user selected to show the saved region or parcel settings.
299 if (newSky && (sRegionPresetName == skyMgr->mCurParams.mName))
300 thisSet->enabled = false;
301 if (newWater && (sParcelPresetName == skyMgr->mCurParams.mName))
302 thisSet->enabled = false;
303 break;
304 }
305 case WL_SCOPE_REGION :
306 {
307 thisSet = &regionSet;
308 thisSet->water.mName = sRegionPresetName;
309 thisSet->sky.mName = sRegionPresetName;
310 thisSet->enabled = (gSavedSettings.getU32("LightShareAllowed") != LIGHTSHARE_NEVER);
311 break;
312 }
313 case WL_SCOPE_PARCEL :
314 {
315 thisSet = &parcelSet;
316 thisSet->water.mName = sParcelPresetName;
317 thisSet->sky.mName = sParcelPresetName;
318 thisSet->enabled = (gSavedSettings.getU32("LightShareAllowed") != LIGHTSHARE_NEVER);
319 break;
320 }
321 case WL_SCOPE_RLV :
322 {
323 thisSet = &RLVSet;
324 thisSet->water.mName = sRLVPresetName;
325 thisSet->sky.mName = sRLVPresetName;
326 // TODO set enabled properly.
327 break;
328 }
329 }
330
331 if (newWater)
332 thisSet->water.setAll(newWater->getAll());
333 if (newWaterNormal)
334 thisSet->water.mParamValues["normalMap"] = *newWaterNormal;
335 if (newSky)
336 thisSet->sky.setAll(newSky->getAll());
337
338 if ((NULL == newWater) && (NULL == newSky))
339 thisSet->enabled = false;
340
341 F32 fade = 0; //Instant
342 bool error;
343 fade = thisSet->sky.getFloat("fade", error);
344
345 if (fade)
346 {
347 // TODO - should copy the original, then set that here.
348 // The fade should delete this copy once it's done fading.
349 // Dunno if we actually need to do any of this anyway.
350 waterMgr->removeParamSet( oldWaterSet.mName, false );
351 waterMgr->addParamSet( oldWaterSet.mName, oldWaterSet );
352 waterMgr->setNormalMapID( *newWaterNormal );
353 waterMgr->getParamSet(oldWaterSet.mName, waterMgr->mCurParams);
354 waterMgr->propagateParameters();
355
356 skyMgr->removeParamSet( oldWLSet.mName, false );
357 skyMgr->addParamSet( oldWLSet.mName, oldWLSet );
358 skyMgr->getParamSet(oldWLSet.mName, skyMgr->mCurParams);
359 skyMgr->propagateParameters();
360 }
361
362 if (regionSet.enabled)
363 {
364 waterMgr->setParamSet( regionSet.water.mName, regionSet.water );
365 skyMgr->setParamSet( regionSet.sky.mName, regionSet.sky );
366 mergeWaterSets(&(regionSet.water), &oldWaterSet);
367 mergeWLSets(&(regionSet.sky), &oldWLSet);
368 }
369 else
370 {
371 waterMgr->removeParamSet( regionSet.water.mName, false );
372 skyMgr->removeParamSet( regionSet.sky.mName, false );
373 }
374 if (parcelSet.enabled)
375 {
376 waterMgr->setParamSet( parcelSet.water.mName, parcelSet.water );
377 skyMgr->setParamSet( parcelSet.sky.mName, parcelSet.sky );
378 mergeWaterSets(&(parcelSet.water), &oldWaterSet);
379 mergeWLSets(&(parcelSet.sky), &oldWLSet);
380 }
381 else
382 {
383 waterMgr->removeParamSet( parcelSet.water.mName, false );
384 skyMgr->removeParamSet( parcelSet.sky.mName, false );
385 }
386 if (userSet.enabled)
387 {
388 mergeWaterSets(&(userSet.water), &oldWaterSet);
389 mergeWLSets(&(userSet.sky), &oldWLSet);
390 }
391 if (RLVSet.enabled)
392 {
393 mergeWaterSets(&(RLVSet.water), &oldWaterSet);
394 mergeWLSets(&(RLVSet.sky), &oldWLSet);
395 }
396
397 skyMgr->mAnimator.mIsRunning = false;
398 skyMgr->mAnimator.mUseLindenTime = false;
399 if (fade)
400 {
401 waterMgr->SetMixTime(&oldWaterSet, fade);
402 skyMgr->SetMixTime(&oldWLSet, fade);
403 }
404 else
405 {
406 if (newWater)
407 {
408 waterMgr->setParamSet( thisSet->water.mName, oldWaterSet );
409 waterMgr->setNormalMapID( *newWaterNormal );
410 waterMgr->getParamSet(thisSet->water.mName, waterMgr->mCurParams);
411 waterMgr->propagateParameters();
412 }
413
414 if (newSky)
415 {
416 skyMgr->setParamSet( thisSet->sky.mName, oldWLSet );
417 skyMgr->getParamSet(thisSet->sky.mName, skyMgr->mCurParams);
418 skyMgr->propagateParameters();
419 }
420 }
421
422 LLWorld::getInstance()->rebuildClouds(gAgent.getRegion());
423}
424
225bool LightShare::isValid() 425bool LightShare::isValid()
226{ 426{
227 return mIsValid; 427 return mIsValid;