diff options
author | Melanie | 2010-03-31 04:23:51 +0100 |
---|---|---|
committer | Melanie | 2010-03-31 04:23:51 +0100 |
commit | 19ae5e5dbb3ae12907305a7fad4cd2f4952ae94c (patch) | |
tree | 68e6b86248b26d60f3aad63c2de67c4f99ff43cd /OpenSim/Region/CoreModules/LightShare/LightShareModule.cs | |
parent | Adding the configuration example (diff) | |
download | opensim-SC-19ae5e5dbb3ae12907305a7fad4cd2f4952ae94c.zip opensim-SC-19ae5e5dbb3ae12907305a7fad4cd2f4952ae94c.tar.gz opensim-SC-19ae5e5dbb3ae12907305a7fad4cd2f4952ae94c.tar.bz2 opensim-SC-19ae5e5dbb3ae12907305a7fad4cd2f4952ae94c.tar.xz |
Adding the LightShare module and scripting API. This code was written by
TomMeta and was contributed by Meta7.
Diffstat (limited to 'OpenSim/Region/CoreModules/LightShare/LightShareModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/LightShare/LightShareModule.cs | 274 |
1 files changed, 274 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..77d6e9a --- /dev/null +++ b/OpenSim/Region/CoreModules/LightShare/LightShareModule.cs | |||
@@ -0,0 +1,274 @@ | |||
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 | |||
9 | using System; | ||
10 | using System.Collections.Generic; | ||
11 | using System.IO; | ||
12 | using System.Reflection; | ||
13 | using OpenMetaverse; | ||
14 | using log4net; | ||
15 | using Nini.Config; | ||
16 | using OpenSim.Data; | ||
17 | using OpenSim.Framework; | ||
18 | using OpenSim.Region.CoreModules.Framework.InterfaceCommander; | ||
19 | using OpenSim.Region.Framework.Interfaces; | ||
20 | using OpenSim.Region.Framework.Scenes; | ||
21 | |||
22 | |||
23 | namespace OpenSim.Region.CoreModules.World.LightShare | ||
24 | { | ||
25 | public class LightShareModule : 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["LightShare"].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 | m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted; | ||
75 | } | ||
76 | |||
77 | InstallCommands(); | ||
78 | |||
79 | m_log.Debug("[WINDLIGHT]: Initialised windlight module"); | ||
80 | } | ||
81 | |||
82 | private List<byte[]> compileWindlightSettings(RegionLightShareData wl) | ||
83 | { | ||
84 | byte[] mBlock = new Byte[249]; | ||
85 | int pos = 0; | ||
86 | |||
87 | wl.waterColor.ToBytes(mBlock, 0); pos += 12; | ||
88 | Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4; | ||
89 | Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4; | ||
90 | wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12; | ||
91 | Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4; | ||
92 | Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4; | ||
93 | Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4; | ||
94 | Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4; | ||
95 | Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4; | ||
96 | wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8; | ||
97 | wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8; | ||
98 | wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16; | ||
99 | wl.horizon.ToBytes(mBlock, pos); pos += 16; | ||
100 | Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4; | ||
101 | wl.blueDensity.ToBytes(mBlock, pos); pos += 16; | ||
102 | Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4; | ||
103 | Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4; | ||
104 | Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4; | ||
105 | wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16; | ||
106 | Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4; | ||
107 | wl.ambient.ToBytes(mBlock, pos); pos += 16; | ||
108 | Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4; | ||
109 | Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4; | ||
110 | Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4; | ||
111 | Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4; | ||
112 | Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4; | ||
113 | wl.cloudColor.ToBytes(mBlock, pos); pos += 16; | ||
114 | wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12; | ||
115 | Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4; | ||
116 | Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4; | ||
117 | wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12; | ||
118 | Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4; | ||
119 | Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4; | ||
120 | Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2; | ||
121 | mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++; | ||
122 | mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++; | ||
123 | mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++; | ||
124 | List<byte[]> param = new List<byte[]>(); | ||
125 | param.Add(mBlock); | ||
126 | return param; | ||
127 | } | ||
128 | public void SendProfileToClient(ScenePresence presence) | ||
129 | { | ||
130 | IClientAPI client = presence.ControllingClient; | ||
131 | if (m_enableWindlight) | ||
132 | { | ||
133 | if (presence.IsChildAgent == false) | ||
134 | { | ||
135 | List<byte[]> param = compileWindlightSettings(m_scene.RegionInfo.WindlightSettings); | ||
136 | client.SendGenericMessage("Windlight", param); | ||
137 | } | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | //We probably don't want to spam chat with this.. probably | ||
142 | //m_log.Debug("[WINDLIGHT]: Module disabled"); | ||
143 | } | ||
144 | } | ||
145 | public void SendProfileToClient(ScenePresence presence, RegionLightShareData wl) | ||
146 | { | ||
147 | IClientAPI client = presence.ControllingClient; | ||
148 | if (m_enableWindlight) | ||
149 | { | ||
150 | if (presence.IsChildAgent == false) | ||
151 | { | ||
152 | List<byte[]> param = compileWindlightSettings(wl); | ||
153 | client.SendGenericMessage("Windlight", param); | ||
154 | } | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | //We probably don't want to spam chat with this.. probably | ||
159 | //m_log.Debug("[WINDLIGHT]: Module disabled"); | ||
160 | } | ||
161 | } | ||
162 | private void EventManager_OnMakeRootAgent(ScenePresence presence) | ||
163 | { | ||
164 | m_log.Debug("[WINDLIGHT]: Sending windlight scene to new client"); | ||
165 | SendProfileToClient(presence); | ||
166 | } | ||
167 | private void EventManager_OnSendNewWindlightProfileTargeted(RegionLightShareData wl, UUID pUUID) | ||
168 | { | ||
169 | ScenePresence Sc; | ||
170 | if (m_scene.TryGetScenePresence(pUUID,out Sc)) | ||
171 | { | ||
172 | SendProfileToClient(Sc,wl); | ||
173 | } | ||
174 | } | ||
175 | private void EventManager_OnSaveNewWindlightProfile() | ||
176 | { | ||
177 | m_scene.ForEachScenePresence(SendProfileToClient); | ||
178 | } | ||
179 | |||
180 | public void PostInitialise() | ||
181 | { | ||
182 | |||
183 | } | ||
184 | |||
185 | public void Close() | ||
186 | { | ||
187 | } | ||
188 | |||
189 | public string Name | ||
190 | { | ||
191 | get { return "LightShareModule"; } | ||
192 | } | ||
193 | |||
194 | public bool IsSharedModule | ||
195 | { | ||
196 | get { return false; } | ||
197 | } | ||
198 | |||
199 | #endregion | ||
200 | |||
201 | #region events | ||
202 | |||
203 | #endregion | ||
204 | |||
205 | #region ICommandableModule Members | ||
206 | |||
207 | private void InstallCommands() | ||
208 | { | ||
209 | Command wlload = new Command("load", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleLoad, "Load windlight profile from the database and broadcast"); | ||
210 | Command wlenable = new Command("enable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleEnable, "Enable the windlight plugin"); | ||
211 | Command wldisable = new Command("disable", CommandIntentions.COMMAND_NON_HAZARDOUS, HandleDisable, "Enable the windlight plugin"); | ||
212 | |||
213 | m_commander.RegisterCommand("load", wlload); | ||
214 | m_commander.RegisterCommand("enable", wlenable); | ||
215 | m_commander.RegisterCommand("disable", wldisable); | ||
216 | |||
217 | m_scene.RegisterModuleCommander(m_commander); | ||
218 | } | ||
219 | |||
220 | private void HandleLoad(Object[] args) | ||
221 | { | ||
222 | if (!m_enableWindlight) | ||
223 | { | ||
224 | m_log.InfoFormat("[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first."); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | m_log.InfoFormat("[WINDLIGHT]: Loading Windlight profile from database"); | ||
229 | m_scene.LoadWindlightProfile(); | ||
230 | m_log.InfoFormat("[WINDLIGHT]: Load complete"); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | private void HandleDisable(Object[] args) | ||
235 | { | ||
236 | m_log.InfoFormat("[WINDLIGHT]: Plugin now disabled"); | ||
237 | m_enableWindlight=false; | ||
238 | } | ||
239 | |||
240 | private void HandleEnable(Object[] args) | ||
241 | { | ||
242 | m_log.InfoFormat("[WINDLIGHT]: Plugin now enabled"); | ||
243 | m_enableWindlight = true; | ||
244 | } | ||
245 | |||
246 | /// <summary> | ||
247 | /// Processes commandline input. Do not call directly. | ||
248 | /// </summary> | ||
249 | /// <param name="args">Commandline arguments</param> | ||
250 | private void EventManager_OnPluginConsole(string[] args) | ||
251 | { | ||
252 | if (args[0] == "windlight") | ||
253 | { | ||
254 | if (args.Length == 1) | ||
255 | { | ||
256 | m_commander.ProcessConsoleCommand("add", new string[0]); | ||
257 | return; | ||
258 | } | ||
259 | |||
260 | string[] tmpArgs = new string[args.Length - 2]; | ||
261 | int i; | ||
262 | for (i = 2; i < args.Length; i++) | ||
263 | { | ||
264 | tmpArgs[i - 2] = args[i]; | ||
265 | } | ||
266 | |||
267 | m_commander.ProcessConsoleCommand(args[1], tmpArgs); | ||
268 | } | ||
269 | } | ||
270 | #endregion | ||
271 | |||
272 | } | ||
273 | } | ||
274 | |||