29 using System.Collections.Generic;
30 using System.Reflection;
32 using OpenSim.Framework;
33 using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
34 using OpenSim.Region.Framework.Interfaces;
35 using OpenSim.Region.Framework.Scenes;
40 namespace OpenSim.
Region.CoreModules.
World.LightShare
42 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"LightShareModule")]
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private Scene m_scene;
48 private static bool m_enableWindlight;
50 #region ICommandableModule Members
54 get {
return m_commander; }
59 #region INonSharedRegionModule Members
65 m_enableWindlight = config.Configs[
"LightShare"].GetBoolean(
"enable_windlight",
false);
69 m_log.Debug(
"[WINDLIGHT]: ini failure for enable_windlight - using default");
72 m_log.DebugFormat(
"[WINDLIGHT]: windlight module {0}", (m_enableWindlight ?
"enabled" :
"disabled"));
77 if (!m_enableWindlight)
82 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
84 m_scene.EventManager.OnMakeRootAgent += EventManager_OnMakeRootAgent;
85 m_scene.EventManager.OnSaveNewWindlightProfile += EventManager_OnSaveNewWindlightProfile;
86 m_scene.EventManager.OnSendNewWindlightProfileTargeted += EventManager_OnSendNewWindlightProfileTargeted;
87 m_scene.LoadWindlightProfile();
94 if (!m_enableWindlight)
97 m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole;
99 m_scene.EventManager.OnMakeRootAgent -= EventManager_OnMakeRootAgent;
100 m_scene.EventManager.OnSaveNewWindlightProfile -= EventManager_OnSaveNewWindlightProfile;
101 m_scene.EventManager.OnSendNewWindlightProfileTargeted -= EventManager_OnSendNewWindlightProfileTargeted;
112 get {
return "LightShareModule"; }
119 public Type ReplaceableInterface
126 public static bool EnableWindlight
130 return m_enableWindlight;
141 byte[] mBlock =
new Byte[249];
144 wl.waterColor.ToBytes(mBlock, 0); pos += 12;
145 Utils.FloatToBytes(wl.waterFogDensityExponent).CopyTo(mBlock, pos); pos += 4;
146 Utils.FloatToBytes(wl.underwaterFogModifier).CopyTo(mBlock, pos); pos += 4;
147 wl.reflectionWaveletScale.ToBytes(mBlock, pos); pos += 12;
148 Utils.FloatToBytes(wl.fresnelScale).CopyTo(mBlock, pos); pos += 4;
149 Utils.FloatToBytes(wl.fresnelOffset).CopyTo(mBlock, pos); pos += 4;
150 Utils.FloatToBytes(wl.refractScaleAbove).CopyTo(mBlock, pos); pos += 4;
151 Utils.FloatToBytes(wl.refractScaleBelow).CopyTo(mBlock, pos); pos += 4;
152 Utils.FloatToBytes(wl.blurMultiplier).CopyTo(mBlock, pos); pos += 4;
153 wl.bigWaveDirection.ToBytes(mBlock, pos); pos += 8;
154 wl.littleWaveDirection.ToBytes(mBlock, pos); pos += 8;
155 wl.normalMapTexture.ToBytes(mBlock, pos); pos += 16;
156 wl.horizon.ToBytes(mBlock, pos); pos += 16;
157 Utils.FloatToBytes(wl.hazeHorizon).CopyTo(mBlock, pos); pos += 4;
158 wl.blueDensity.ToBytes(mBlock, pos); pos += 16;
159 Utils.FloatToBytes(wl.hazeDensity).CopyTo(mBlock, pos); pos += 4;
160 Utils.FloatToBytes(wl.densityMultiplier).CopyTo(mBlock, pos); pos += 4;
161 Utils.FloatToBytes(wl.distanceMultiplier).CopyTo(mBlock, pos); pos += 4;
162 wl.sunMoonColor.ToBytes(mBlock, pos); pos += 16;
163 Utils.FloatToBytes(wl.sunMoonPosition).CopyTo(mBlock, pos); pos += 4;
164 wl.ambient.ToBytes(mBlock, pos); pos += 16;
165 Utils.FloatToBytes(wl.eastAngle).CopyTo(mBlock, pos); pos += 4;
166 Utils.FloatToBytes(wl.sunGlowFocus).CopyTo(mBlock, pos); pos += 4;
167 Utils.FloatToBytes(wl.sunGlowSize).CopyTo(mBlock, pos); pos += 4;
168 Utils.FloatToBytes(wl.sceneGamma).CopyTo(mBlock, pos); pos += 4;
169 Utils.FloatToBytes(wl.starBrightness).CopyTo(mBlock, pos); pos += 4;
170 wl.cloudColor.ToBytes(mBlock, pos); pos += 16;
171 wl.cloudXYDensity.ToBytes(mBlock, pos); pos += 12;
172 Utils.FloatToBytes(wl.cloudCoverage).CopyTo(mBlock, pos); pos += 4;
173 Utils.FloatToBytes(wl.cloudScale).CopyTo(mBlock, pos); pos += 4;
174 wl.cloudDetailXYDensity.ToBytes(mBlock, pos); pos += 12;
175 Utils.FloatToBytes(wl.cloudScrollX).CopyTo(mBlock, pos); pos += 4;
176 Utils.FloatToBytes(wl.cloudScrollY).CopyTo(mBlock, pos); pos += 4;
177 Utils.UInt16ToBytes(wl.maxAltitude).CopyTo(mBlock, pos); pos += 2;
178 mBlock[pos] = Convert.ToByte(wl.cloudScrollXLock); pos++;
179 mBlock[pos] = Convert.ToByte(wl.cloudScrollYLock); pos++;
180 mBlock[pos] = Convert.ToByte(wl.drawClassicClouds); pos++;
181 List<byte[]> param =
new List<byte[]>();
188 SendProfileToClient(client, m_scene.RegionInfo.WindlightSettings);
196 if (m_enableWindlight)
198 if (m_scene.RegionInfo.WindlightSettings.valid)
200 List<byte[]> param = compileWindlightSettings(wl);
201 client.SendGenericMessage(
"Windlight", UUID.Random(), param);
205 List<byte[]> param =
new List<byte[]>();
206 client.SendGenericMessage(
"WindlightReset", UUID.Random(), param);
211 private void EventManager_OnMakeRootAgent(
ScenePresence presence)
213 if (m_enableWindlight && m_scene.RegionInfo.WindlightSettings.valid)
214 m_log.Debug(
"[WINDLIGHT]: Sending windlight scene to new client");
218 private void EventManager_OnSendNewWindlightProfileTargeted(
RegionLightShareData wl, UUID pUUID)
221 m_scene.TryGetClient(pUUID, out client);
222 SendProfileToClient(client, wl);
225 private void EventManager_OnSaveNewWindlightProfile()
227 m_scene.ForEachRootClient(SendProfileToClient);
232 #region ICommandableModule Members
234 private void InstallCommands()
240 m_commander.RegisterCommand(
"load", wlload);
241 m_commander.RegisterCommand(
"enable", wlenable);
242 m_commander.RegisterCommand(
"disable", wldisable);
244 m_scene.RegisterModuleCommander(m_commander);
247 private void HandleLoad(Object[] args)
249 if (!m_enableWindlight)
251 m_log.InfoFormat(
"[WINDLIGHT]: Cannot load windlight profile, module disabled. Use 'windlight enable' first.");
255 m_log.InfoFormat(
"[WINDLIGHT]: Loading Windlight profile from database");
256 m_scene.LoadWindlightProfile();
257 m_log.InfoFormat(
"[WINDLIGHT]: Load complete");
261 private void HandleDisable(Object[] args)
263 m_log.InfoFormat(
"[WINDLIGHT]: Plugin now disabled");
264 m_enableWindlight =
false;
267 private void HandleEnable(Object[] args)
269 m_log.InfoFormat(
"[WINDLIGHT]: Plugin now enabled");
270 m_enableWindlight =
true;
277 private void EventManager_OnPluginConsole(
string[] args)
279 if (args[0] ==
"windlight")
281 if (args.Length == 1)
283 m_commander.ProcessConsoleCommand(
"add",
new string[0]);
287 string[] tmpArgs =
new string[args.Length - 2];
289 for (i = 2; i < args.Length; i++)
291 tmpArgs[i - 2] = args[i];
294 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
IClientAPI ControllingClient
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void SendProfileToClient(IClientAPI client, RegionLightShareData wl)
A single function call encapsulated in a class which enforces arguments when passing around as Object...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
A class to enable modules to register console and script commands, which enforces typing and valid in...
void SendProfileToClient(IClientAPI client)
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...