aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/CoreModules/World/Meta7Windlight/Meta7WindlightModule.cs245
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs8
2 files changed, 252 insertions, 1 deletions
diff --git a/OpenSim/Region/CoreModules/World/Meta7Windlight/Meta7WindlightModule.cs b/OpenSim/Region/CoreModules/World/Meta7Windlight/Meta7WindlightModule.cs
new file mode 100644
index 0000000..f180b47
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Meta7Windlight/Meta7WindlightModule.cs
@@ -0,0 +1,245 @@
1/*
2 * Copyright (c) Thomas Grimshaw and Magne Metaverse Research
3 *
4 * This module is not open source. All rights reserved.
5 * Unauthorised copying, distribution or public display is prohibited.
6 *
7 */
8
9using System;
10using System.Collections.Generic;
11using System.IO;
12using System.Reflection;
13using OpenMetaverse;
14using log4net;
15using Nini.Config;
16using OpenSim.Data;
17using OpenSim.Framework;
18using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
19using OpenSim.Region.Framework.Interfaces;
20using OpenSim.Region.Framework.Scenes;
21
22
23namespace OpenSim.Region.CoreModules.World.Meta7Windlight
24{
25 public class Meta7WindlightModule : IRegionModule, ICommandableModule
26 {
27 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
28 private readonly Commander m_commander = new Commander("windlight");
29 private Scene m_scene;
30 private static bool m_enableWindlight;
31
32 #region ICommandableModule Members
33
34 public ICommander CommandInterface
35 {
36 get { return m_commander; }
37 }
38
39 #endregion
40
41 #region IRegionModule Members
42
43 public static bool EnableWindlight
44 {
45 get
46 {
47 return m_enableWindlight;
48 }
49 set
50 {
51 }
52 }
53
54 public void Initialise(Scene scene, IConfigSource config)
55 {
56 m_scene = scene;
57 m_scene.RegisterModuleInterface<IRegionModule>(this);
58 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
59
60 // ini file settings
61 try
62 {
63 m_enableWindlight = config.Configs["Meta7Windlight"].GetBoolean("enable_windlight", false);
64 }
65 catch (Exception)
66 {
67 m_log.Debug("[WINDLIGHT]: ini failure for enable_windlight - using default");
68 }
69
70 if (m_enableWindlight)
71 {
72 m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent;
73 m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile;
74 }
75
76 InstallCommands();
77
78 m_log.Debug("[WINDLIGHT]: Initialised windlight module");
79 }
80 public void SendProfileToClient(ScenePresence presence)
81 {
82 if (m_enableWindlight)
83 {
84 if (presence.IsChildAgent == false)
85 {
86 IClientAPI client = presence.ControllingClient;
87 RegionMeta7WindlightData wl = m_scene.RegionInfo.WindlightSettings;
88 byte[] mBlock = new Byte[249];
89 int pos = 0;
90
91 wl.waterColor.ToBytes(mBlock, 0); pos += 12;
92 Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4;
93 Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4;
94 wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12;
95 Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4;
96 Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4;
97 Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4;
98 Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4;
99 Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4;
100 wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8;
101 wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8;
102 wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16;
103 wl.horizon.ToBytes(mBlock, pos); pos += 16;
104 Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4;
105 wl.blueDensity.ToBytes(mBlock, pos); pos += 16;
106 Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4;
107 Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4;
108 Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4;
109 wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16;
110 Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4;
111 wl.ambient.ToBytes(mBlock, pos); pos += 16;
112 Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4;
113 Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4;
114 Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4;
115 Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4;
116 Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4;
117 wl.cloudColor.ToBytes(mBlock, pos); pos += 16;
118 wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12;
119 Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4;
120 Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4;
121 wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12;
122 Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4;
123 Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4;
124 Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2;
125 mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++;
126 mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++;
127 mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++;
128 List<byte[]> param = new List<byte[]>();
129 param.Add(mBlock);
130
131 client.SendGenericMessage("Windlight", param);
132 }
133 }
134 else
135 {
136 //We probably don't want to spam chat with this.. probably
137 //m_log.Debug("[WINDLIGHT]: Module disabled");
138 }
139 }
140 private void EventManager_OnMakeRootAgent(ScenePresence presence)
141 {
142 m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client");
143 SendProfileToClient(presence);
144 }
145
146 private void EventManager_OnSaveNewWindlightProfile()
147 {
148 m_scene.ForEachScenePresence(SendProfileToClient);
149 }
150
151 public void PostInitialise()
152 {
153
154 }
155
156 public void Close()
157 {
158 }
159
160 public string Name
161 {
162 get { return "Meta7WindlightModule"; }
163 }
164
165 public bool IsSharedModule
166 {
167 get { return false; }
168 }
169
170 #endregion
171
172 #region events
173
174 #endregion
175
176 #region ICommandableModule Members
177
178 private void InstallCommands()
179 {
180 Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast");
181 Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin");
182 Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Enable the windlight plugin");
183
184 m_commander.RegisterCommand("load", wlload);
185 m_commander.RegisterCommand("enable", wlenable);
186 m_commander.RegisterCommand("disable", wldisable);
187
188 m_scene.RegisterModuleCommander(m_commander);
189 }
190
191 private void HandleLoad(Object[] args)
192 {
193 if (!m_enableWindlight)
194 {
195 m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first.");
196 }
197 else
198 {
199 m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database");
200 m_scene.LoadWindlightProfile();
201 m_log.InfoFormat("[WINDLIGHT]: Load complete");
202 }
203 }
204
205 private void HandleDisable(Object[] args)
206 {
207 m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled");
208 m_enableWindlight=false;
209 }
210
211 private void HandleEnable(Object[] args)
212 {
213 m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled");
214 m_enableWindlight = true;
215 }
216
217 /// <summary>
218 /// Processes commandline input. Do not call directly.
219 /// </summary>
220 /// <param name="args">Commandline arguments</param>
221 private void EventManager_OnPluginConsole(string[] args)
222 {
223 if (args[0] == "windlight")
224 {
225 if (args.Length == 1)
226 {
227 m_commander.ProcessConsoleCommand("add", new string[0]);
228 return;
229 }
230
231 string[] tmpArgs = new string[args.Length - 2];
232 int i;
233 for (i = 2; i < args.Length; i++)
234 {
235 tmpArgs[i - 2] = args[i];
236 }
237
238 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
239 }
240 }
241 #endregion
242
243 }
244}
245
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 475d775..1b275b0 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -1504,7 +1504,7 @@ namespace OpenSim.Region.Framework.Scenes
1504 { 1504 {
1505 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID); 1505 m_storageManager.DataStore.StoreTerrain(Heightmap.GetDoubles(), RegionInfo.RegionID);
1506 } 1506 }
1507 1507
1508 public void StoreWindlightProfile(RegionMeta7WindlightData wl) 1508 public void StoreWindlightProfile(RegionMeta7WindlightData wl)
1509 { 1509 {
1510 m_regInfo.WindlightSettings = wl; 1510 m_regInfo.WindlightSettings = wl;
@@ -1512,6 +1512,12 @@ namespace OpenSim.Region.Framework.Scenes
1512 m_eventManager.TriggerOnSaveNewWindlightProfile(); 1512 m_eventManager.TriggerOnSaveNewWindlightProfile();
1513 } 1513 }
1514 1514
1515 public void LoadWindlightProfile()
1516 {
1517 m_regInfo.WindlightSettings = m_storageManager.DataStore.LoadRegionWindlightSettings(RegionInfo.RegionID);
1518 m_eventManager.TriggerOnSaveNewWindlightProfile();
1519 }
1520
1515 /// <summary> 1521 /// <summary>
1516 /// Loads the World heightmap 1522 /// Loads the World heightmap
1517 /// </summary> 1523 /// </summary>