aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lightshare.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2010-07-27 04:08:19 -0500
committerJacek Antonelli2010-08-01 00:30:59 -0500
commite4475e45edde706332718908b1ebbef924c44b4f (patch)
tree496e051b768f1b1344b96418bba773f577c3b298 /linden/indra/newview/lightshare.cpp
parentFixed a Linden typo that made the object cache useless. (SNOW-783) (diff)
downloadmeta-impy-e4475e45edde706332718908b1ebbef924c44b4f.zip
meta-impy-e4475e45edde706332718908b1ebbef924c44b4f.tar.gz
meta-impy-e4475e45edde706332718908b1ebbef924c44b4f.tar.bz2
meta-impy-e4475e45edde706332718908b1ebbef924c44b4f.tar.xz
Refactored a bunch of messy LightShare code.
Diffstat (limited to 'linden/indra/newview/lightshare.cpp')
-rw-r--r--linden/indra/newview/lightshare.cpp302
1 files changed, 302 insertions, 0 deletions
diff --git a/linden/indra/newview/lightshare.cpp b/linden/indra/newview/lightshare.cpp
new file mode 100644
index 0000000..24d4139
--- /dev/null
+++ b/linden/indra/newview/lightshare.cpp
@@ -0,0 +1,302 @@
1/**
2 * @file lightshare.cpp
3 * @brief Handler for Meta7 Lightshare (region-side Windlight settings).
4 *
5 * Copyright (c) 2010, Tom Meta / Meta7
6 * Copyright (c) 2010, Jacek Antonelli
7 *
8 * 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 * ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in
11 * this distribution, or online at
12 * http://secondlifegrid.net/programs/open_source/licensing/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at
18 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29
30#include "lightshare.h"
31
32#include "linden_common.h"
33
34#include "lluuid.h"
35#include "llviewercontrol.h"
36#include "llwaterparammanager.h"
37#include "llwaterparamset.h"
38#include "llwlparammanager.h"
39#include "llwlparamset.h"
40#include "message.h"
41#include "meta7windlight.h"
42
43
44// The names of the presets where the region settings are stored.
45const std::string WindlightMessage::sWaterPresetName = "(Region settings)";
46const std::string WindlightMessage::sSkyPresetName = "(Region settings)";
47
48
49WindlightMessage::WindlightMessage( LLMessageSystem* msg ) :
50 mPacket(NULL),
51 mWater(NULL),
52 mSky(NULL),
53 mWaterNormal(NULL),
54 mIsValid(false)
55{
56 std::string method;
57 msg->getStringFast(_PREHASH_MethodData, _PREHASH_Method, method);
58
59 if( method != "Windlight" )
60 {
61 return; // Wrong message type, somehow.
62 }
63
64 S32 size = msg->getSizeFast(_PREHASH_ParamList, 0,
65 _PREHASH_Parameter);
66
67 if( size < 0 || 250 < size )
68 {
69 return; // Too small or too big.
70 }
71
72 // Unpack and process the message's binary payload.
73 char buf[250];
74 msg->getBinaryDataFast(_PREHASH_ParamList,
75 _PREHASH_Parameter,
76 buf, size, 0, 249);
77
78 mWater = new LLWaterParamSet();
79 mSky = new LLWLParamSet();
80 mWaterNormal = LLUUID();
81
82 process_packet(&buf[0]);
83 process_water();
84 process_sky();
85
86 // *TODO: Actually validate the settings.
87 mIsValid = true;
88}
89
90
91WindlightMessage::~WindlightMessage()
92{
93 delete mWater;
94 delete mSky;
95}
96
97
98// static
99void WindlightMessage::processWindlight(LLMessageSystem* msg, void**)
100{
101 if( gSavedSettings.getBOOL("UseServersideWindlightSettings") )
102 {
103 WindlightMessage wl = WindlightMessage(msg);
104 if( wl.isValid() )
105 {
106 wl.apply();
107 }
108 }
109}
110
111
112bool WindlightMessage::apply()
113{
114 LLWaterParamManager* water_mgr = LLWaterParamManager::instance();
115 LLWLParamManager* sky_mgr = LLWLParamManager::instance();
116
117 mWater->mName = sWaterPresetName;
118 water_mgr->removeParamSet( sWaterPresetName, false );
119 water_mgr->addParamSet( sWaterPresetName, *mWater );
120 water_mgr->savePreset( sWaterPresetName );
121 water_mgr->loadPreset( sWaterPresetName, true );
122 water_mgr->setNormalMapID( mWaterNormal );
123
124 mSky->mName = sSkyPresetName;
125 sky_mgr->mAnimator.mIsRunning = false;
126 sky_mgr->mAnimator.mUseLindenTime = false;
127 sky_mgr->removeParamSet( sSkyPresetName, false );
128 sky_mgr->addParamSet( sSkyPresetName, *mSky );
129 sky_mgr->savePreset( sSkyPresetName );
130 sky_mgr->loadPreset( sSkyPresetName, true );
131
132 return true;
133}
134
135
136bool WindlightMessage::isValid()
137{
138 return mIsValid;
139}
140
141
142void WindlightMessage::process_packet( char* buf )
143{
144 // *FIXME: Horrible idea, fragile, not byte-order or endian
145 // safe, no validation, etc. etc. -Jacek
146 mPacket = (Meta7WindlightPacket*)buf;
147}
148
149
150void WindlightMessage::process_water()
151{
152 mWater->set("waterFogColor",
153 mPacket->waterColor.red / 256.f,
154 mPacket->waterColor.green / 256.f,
155 mPacket->waterColor.blue / 256.f);
156
157 mWater->set("waterFogDensity",
158 pow(2.0f, mPacket->waterFogDensityExponent));
159
160 mWater->set("underWaterFogMod", mPacket->underwaterFogModifier);
161
162 mWater->set("normScale",
163 mPacket->reflectionWaveletScale.X,
164 mPacket->reflectionWaveletScale.Y,
165 mPacket->reflectionWaveletScale.Z);
166
167 mWater->set("fresnelScale", mPacket->fresnelScale);
168 mWater->set("fresnelOffset", mPacket->fresnelOffset);
169 mWater->set("scaleAbove", mPacket->refractScaleAbove);
170 mWater->set("scaleBelow", mPacket->refractScaleBelow);
171 mWater->set("blurMultiplier", mPacket->blurMultiplier);
172
173 mWater->set("wave1Dir",
174 mPacket->littleWaveDirection.X,
175 mPacket->littleWaveDirection.Y);
176
177 mWater->set("wave2Dir",
178 mPacket->bigWaveDirection.X,
179 mPacket->bigWaveDirection.Y);
180
181
182 // Format a UUID string from a block of raw bytes. Ugh.
183 std::string uuid = llformat(
184 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
185 (U8)(mPacket->normalMapTexture[0]),
186 (U8)(mPacket->normalMapTexture[1]),
187 (U8)(mPacket->normalMapTexture[2]),
188 (U8)(mPacket->normalMapTexture[3]),
189 (U8)(mPacket->normalMapTexture[4]),
190 (U8)(mPacket->normalMapTexture[5]),
191 (U8)(mPacket->normalMapTexture[6]),
192 (U8)(mPacket->normalMapTexture[7]),
193 (U8)(mPacket->normalMapTexture[8]),
194 (U8)(mPacket->normalMapTexture[9]),
195 (U8)(mPacket->normalMapTexture[10]),
196 (U8)(mPacket->normalMapTexture[11]),
197 (U8)(mPacket->normalMapTexture[12]),
198 (U8)(mPacket->normalMapTexture[13]),
199 (U8)(mPacket->normalMapTexture[14]),
200 (U8)(mPacket->normalMapTexture[15]));
201
202 mWaterNormal.set(uuid);
203}
204
205
206void WindlightMessage::process_sky()
207{
208 mSky->setSunAngle(F_TWO_PI * mPacket->sunMoonPosiiton);
209 mSky->setEastAngle(F_TWO_PI * mPacket->eastAngle);
210
211 mSky->set("sunlight_color",
212 mPacket->sunMoonColor.red * 3.0f,
213 mPacket->sunMoonColor.green * 3.0f,
214 mPacket->sunMoonColor.blue * 3.0f,
215 mPacket->sunMoonColor.alpha * 3.0f);
216
217 mSky->set("ambient",
218 mPacket->ambient.red * 3.0f,
219 mPacket->ambient.green * 3.0f,
220 mPacket->ambient.blue * 3.0f,
221 mPacket->ambient.alpha * 3.0f);
222
223 mSky->set("blue_horizon",
224 mPacket->horizon.red * 2.0f,
225 mPacket->horizon.green *2.0f,
226 mPacket->horizon.blue * 2.0f,
227 mPacket->horizon.alpha * 2.0f);
228
229 mSky->set("blue_density",
230 mPacket->blueDensity.red * 2.0f,
231 mPacket->blueDensity.green * 2.0f,
232 mPacket->blueDensity.blue * 2.0f,
233 mPacket->blueDensity.alpha * 2.0f);
234
235 mSky->set("haze_horizon",
236 mPacket->hazeHorizon,
237 mPacket->hazeHorizon,
238 mPacket->hazeHorizon,
239 1.f);
240
241 mSky->set("haze_density",
242 mPacket->hazeDensity,
243 0.f, 0.f, 1.f);
244
245 mSky->set("cloud_shadow",
246 mPacket->cloudCoverage,
247 0.f, 0.f, 1.f);
248
249 mSky->set("density_multiplier",
250 mPacket->densityMultiplier / 1000.0f,
251 0.f, 0.f, 1.f);
252
253 mSky->set("distance_multiplier",
254 mPacket->distanceMultiplier,
255 0.f, 0.f, 1.f);
256
257 mSky->set("max_y",
258 (F32)mPacket->maxAltitude,
259 0.f, 0.f, 1.f);
260
261 mSky->set("cloud_color",
262 mPacket->cloudColor.red,
263 mPacket->cloudColor.green,
264 mPacket->cloudColor.blue,
265 mPacket->cloudColor.alpha);
266
267 mSky->set("cloud_pos_density1",
268 mPacket->cloudXYDensity.X,
269 mPacket->cloudXYDensity.Y,
270 mPacket->cloudXYDensity.Z,
271 1.f);
272
273 mSky->set("cloud_pos_density2",
274 mPacket->cloudDetailXYDensity.X,
275 mPacket->cloudDetailXYDensity.Y,
276 mPacket->cloudDetailXYDensity.Z,
277 1.f);
278
279 mSky->set("cloud_scale",
280 mPacket->cloudScale,
281 0.f, 0.f, 1.f);
282
283 mSky->set("gamma",
284 mPacket->sceneGamma,
285 0.f, 0.f, 1.f);
286
287 mSky->set("glow",
288 (2 - mPacket->sunGlowSize) * 20,
289 0.f,
290 -mPacket->sunGlowFocus * 5,
291 1.f);
292
293 mSky->setCloudScrollX(mPacket->cloudScrollX + 10.0f);
294 mSky->setCloudScrollY(mPacket->cloudScrollY + 10.0f);
295
296 mSky->setEnableCloudScrollX(!mPacket->cloudScrollXLock);
297 mSky->setEnableCloudScrollY(!mPacket->cloudScrollYLock);
298
299 mSky->setStarBrightness(mPacket->starBrightness);
300}
301
302