aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/LightShare/LightShareModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/LightShare/LightShareModule.cs293
1 files changed, 293 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs
new file mode 100644
index 0000000..e6cab1d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs
@@ -0,0 +1,293 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using OpenMetaverse;
33using log4net;
34using Nini.Config;
35using OpenSim.Data;
36using OpenSim.Framework;
37using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40
41
42namespace OpenSim.Region.CoreModules.World.LightShare
43{
44 public class LightShareModule : IRegionModule, ICommandableModule
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private readonly Commander m_commander = new Commander("windlight");
48 private Scene m_scene;
49 private static bool m_enableWindlight;
50
51 #region ICommandableModule Members
52
53 public ICommander CommandInterface
54 {
55 get { return m_commander; }
56 }
57
58 #endregion
59
60 #region IRegionModule Members
61
62 public static bool EnableWindlight
63 {
64 get
65 {
66 return m_enableWindlight;
67 }
68 set
69 {
70 }
71 }
72
73 public void Initialise(Scene scene, IConfigSource config)
74 {
75 m_scene = scene;
76 m_scene.RegisterModuleInterface<IRegionModule>(this);
77 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
78
79 // ini file settings
80 try
81 {
82 m_enableWindlight = config.Configs["LightShare"].GetBoolean("enable_windlight", false);
83 }
84 catch (Exception)
85 {
86 m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default");
87 }
88
89 if (m_enableWindlight)
90 {
91 m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent;
92 m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile;
93 m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted;
94 }
95
96 InstallCommands();
97
98 m_log.Debug("[WINDLIGHT]: Initialised windlight module");
99 }
100
101 private List<byte[]> compileWindlightSettings(RegionLightShareData wl)
102 {
103 byte[] mBlock = new Byte[249];
104 int pos = 0;
105
106 wl.waterColor.ToBytes(mBlock, 0); pos += 12;
107 Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4;
108 Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4;
109 wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12;
110 Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4;
111 Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4;
112 Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4;
113 Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4;
114 Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4;
115 wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8;
116 wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8;
117 wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16;
118 wl.horizon.ToBytes(mBlock, pos); pos += 16;
119 Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4;
120 wl.blueDensity.ToBytes(mBlock, pos); pos += 16;
121 Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4;
122 Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4;
123 Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4;
124 wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16;
125 Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4;
126 wl.ambient.ToBytes(mBlock, pos); pos += 16;
127 Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4;
128 Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4;
129 Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4;
130 Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4;
131 Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4;
132 wl.cloudColor.ToBytes(mBlock, pos); pos += 16;
133 wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12;
134 Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4;
135 Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4;
136 wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12;
137 Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4;
138 Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4;
139 Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2;
140 mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++;
141 mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++;
142 mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++;
143 List<byte[]> param = new List<byte[]>();
144 param.Add(mBlock);
145 return param;
146 }
147 public void SendProfileToClient(ScenePresence presence)
148 {
149 IClientAPI client = presence.ControllingClient;
150 if (m_enableWindlight)
151 {
152 if (presence.IsChildAgent == false)
153 {
154 List<byte[]> param = compileWindlightSettings(m_scene.RegionInfo.WindlightSettings);
155 client.SendGenericMessage("Windlight", param);
156 }
157 }
158 else
159 {
160 //We probably don't want to spam chat with this.. probably
161 //m_log.Debug("[WINDLIGHT]: Module disabled");
162 }
163 }
164 public void SendProfileToClient(ScenePresence presence, RegionLightShareData wl)
165 {
166 IClientAPI client = presence.ControllingClient;
167 if (m_enableWindlight)
168 {
169 if (presence.IsChildAgent == false)
170 {
171 List<byte[]> param = compileWindlightSettings(wl);
172 client.SendGenericMessage("Windlight", param);
173 }
174 }
175 else
176 {
177 //We probably don't want to spam chat with this.. probably
178 //m_log.Debug("[WINDLIGHT]: Module disabled");
179 }
180 }
181 private void EventManager_OnMakeRootAgent(ScenePresence presence)
182 {
183 m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client");
184 SendProfileToClient(presence);
185 }
186 private void EventManager_OnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID pUUID)
187 {
188 ScenePresence Sc;
189 if (m_scene.TryGetScenePresence(pUUID,out Sc))
190 {
191 SendProfileToClient(Sc,wl);
192 }
193 }
194 private void EventManager_OnSaveNewWindlightProfile()
195 {
196 m_scene.ForEachScenePresence(SendProfileToClient);
197 }
198
199 public void PostInitialise()
200 {
201
202 }
203
204 public void Close()
205 {
206 }
207
208 public string Name
209 {
210 get { return "LightShareModule"; }
211 }
212
213 public bool IsSharedModule
214 {
215 get { return false; }
216 }
217
218 #endregion
219
220 #region events
221
222 #endregion
223
224 #region ICommandableModule Members
225
226 private void InstallCommands()
227 {
228 Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast");
229 Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin");
230 Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Enable the windlight plugin");
231
232 m_commander.RegisterCommand("load", wlload);
233 m_commander.RegisterCommand("enable", wlenable);
234 m_commander.RegisterCommand("disable", wldisable);
235
236 m_scene.RegisterModuleCommander(m_commander);
237 }
238
239 private void HandleLoad(Object[] args)
240 {
241 if (!m_enableWindlight)
242 {
243 m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first.");
244 }
245 else
246 {
247 m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database");
248 m_scene.LoadWindlightProfile();
249 m_log.InfoFormat("[WINDLIGHT]: Load complete");
250 }
251 }
252
253 private void HandleDisable(Object[] args)
254 {
255 m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled");
256 m_enableWindlight=false;
257 }
258
259 private void HandleEnable(Object[] args)
260 {
261 m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled");
262 m_enableWindlight = true;
263 }
264
265 /// <summary>
266 /// Processes commandline input. Do not call directly.
267 /// </summary>
268 /// <param name="args">Commandline arguments</param>
269 private void EventManager_OnPluginConsole(string[] args)
270 {
271 if (args[0] == "windlight")
272 {
273 if (args.Length == 1)
274 {
275 m_commander.ProcessConsoleCommand("add", new string[0]);
276 return;
277 }
278
279 string[] tmpArgs = new string[args.Length - 2];
280 int i;
281 for (i = 2; i < args.Length; i++)
282 {
283 tmpArgs[i - 2] = args[i];
284 }
285
286 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
287 }
288 }
289 #endregion
290
291 }
292}
293