diff --git a/OpenSim/Region/CoreModules/Resources/Wind.Models.addin.xml b/OpenSim/Region/CoreModules/Resources/Wind.Models.addin.xml
new file mode 100644
index 0000000000..972f795d4d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Resources/Wind.Models.addin.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OpenSim/Region/CoreModules/World/Wind/IWindModelPlugin.cs b/OpenSim/Region/CoreModules/World/Wind/IWindModelPlugin.cs
new file mode 100644
index 0000000000..29b0ed561c
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Wind/IWindModelPlugin.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+
+using Nini.Config;
+using OpenSim.Framework;
+using OpenMetaverse;
+using OpenSim.Region.Framework.Scenes;
+
+namespace OpenSim.Region.CoreModules.World.Wind
+{
+ public interface IWindModelPlugin : IPlugin
+ {
+ ///
+ /// Brief description of this plugin's wind model
+ ///
+ string Description { get; }
+
+ ///
+ /// Provides access to the wind configuration, if any.
+ ///
+ void WindConfig(Scene scene, IConfig windConfig);
+
+ ///
+ /// Update wind.
+ ///
+ void WindUpdate(uint frame);
+
+ ///
+ /// Returns the wind vector at the given local region coordinates.
+ ///
+ Vector3 WindSpeed(float x, float y, float z);
+
+ ///
+ /// Generate a 16 x 16 Vector2 array of wind speeds for LL* based viewers
+ ///
+ /// Must return a Vector2[256]
+ Vector2[] WindLLClientArray();
+
+ ///
+ /// Retrieve a list of parameter/description pairs.
+ ///
+ ///
+ Dictionary WindParams();
+
+ ///
+ /// Set the specified parameter
+ ///
+ void WindParamSet(string param, float value);
+
+ ///
+ /// Get the specified parameter
+ ///
+ float WindParamGet(string param);
+
+ }
+}
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs
new file mode 100644
index 0000000000..2f5cc316ca
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs
@@ -0,0 +1,211 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+using log4net;
+using OpenMetaverse;
+
+using OpenSim.Region.CoreModules.World.Wind;
+
+namespace OpenSim.Region.CoreModules.World.Wind.Plugins
+{
+ class ConfigurableWind : Mono.Addins.TypeExtensionNode, IWindModelPlugin
+ {
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ private Vector2[] m_windSpeeds = new Vector2[16 * 16];
+ private Random m_rndnums = new Random(Environment.TickCount);
+
+ private float m_avgStrength = 5.0f; // Average magnitude of the wind vector
+ private float m_avgDirection = 0.0f; // Average direction of the wind in degrees
+ private float m_varStrength = 5.0f; // Max Strength Variance
+ private float m_varDirection = 30.0f;// Max Direction Variance
+ private float m_rateChange = 1.0f; //
+
+ private Vector2 m_curPredominateWind = new Vector2();
+
+
+
+ #region IPlugin Members
+
+ public string Version
+ {
+ get { return "1.0.0.0"; }
+ }
+
+ public string Name
+ {
+ get { return "ConfigurableWind"; }
+ }
+
+ public void Initialise()
+ {
+
+ }
+
+ #endregion
+
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ m_windSpeeds = null;
+ }
+
+ #endregion
+
+ #region IWindModelPlugin Members
+
+ public void WindConfig(OpenSim.Region.Framework.Scenes.Scene scene, Nini.Config.IConfig windConfig)
+ {
+ if( windConfig != null )
+ {
+ // Uses strength value if avg_strength not specified
+ m_avgStrength = windConfig.GetFloat("strength", 5.0F);
+ m_avgStrength = windConfig.GetFloat("avg_strength", 5.0F);
+
+ m_avgDirection = windConfig.GetFloat("avg_direction", 0.0F);
+ m_varStrength = windConfig.GetFloat("var_strength", 5.0F);
+ m_varDirection = windConfig.GetFloat("var_direction", 30.0F);
+ m_rateChange = windConfig.GetFloat("rate_change", 1.0F);
+
+ LogSettings();
+ }
+ }
+
+ public void WindUpdate(uint frame)
+ {
+ double avgAng = m_avgDirection * (Math.PI/180.0f);
+ double varDir = m_varDirection * (Math.PI/180.0f);
+
+ // Prevailing wind algorithm
+ // Inspired by Kanker Greenacre
+
+ // TODO:
+ // * This should probably be based on in-world time.
+ // * should probably move all these local variables to class members and constants
+ double time = DateTime.Now.TimeOfDay.Seconds / 86400;
+
+ double theta = time * (2 * Math.PI) * m_rateChange;
+
+ double offset = Math.Sin(theta) * Math.Sin(theta*2) * Math.Sin(theta*9) * Math.Cos(theta*4);
+
+ double windDir = avgAng + (varDir * offset);
+
+ offset = Math.Sin(theta) * Math.Sin(theta*4) + (Math.Sin(theta*13) / 3);
+ double windSpeed = m_avgStrength + (m_varStrength * offset);
+
+ if (windSpeed<0)
+ windSpeed=0;
+
+
+
+ m_curPredominateWind.X = (float)Math.Cos(windDir);
+ m_curPredominateWind.Y = (float)Math.Sin(windDir);
+
+ m_curPredominateWind.Normalize();
+ m_curPredominateWind.X *= (float)windSpeed;
+ m_curPredominateWind.Y *= (float)windSpeed;
+
+ for (int y = 0; y < 16; y++)
+ {
+ for (int x = 0; x < 16; x++)
+ {
+ m_windSpeeds[y * 16 + x] = m_curPredominateWind;
+ }
+ }
+ }
+
+ public Vector3 WindSpeed(float fX, float fY, float fZ)
+ {
+ return new Vector3(m_curPredominateWind, 0.0f);
+ }
+
+ public Vector2[] WindLLClientArray()
+ {
+ return m_windSpeeds;
+ }
+
+ public string Description
+ {
+ get
+ {
+ return "Provides a predominate wind direction that can change within configured variances for direction and speed.";
+ }
+ }
+
+ public System.Collections.Generic.Dictionary WindParams()
+ {
+ Dictionary Params = new Dictionary();
+
+ Params.Add("avgStrength", "average wind strength");
+ Params.Add("avgDirection", "average wind direction in degrees");
+ Params.Add("varStrength", "allowable variance in wind strength");
+ Params.Add("varDirection", "allowable variance in wind direction in +/- degrees");
+ Params.Add("rateChange", "rate of change");
+
+ return Params;
+ }
+
+ public void WindParamSet(string param, float value)
+ {
+ switch (param)
+ {
+ case "avgStrength":
+ m_avgStrength = value;
+ break;
+ case "avgDirection":
+ m_avgDirection = value;
+ break;
+ case "varStrength":
+ m_varStrength = value;
+ break;
+ case "varDirection":
+ m_varDirection = value;
+ break;
+ case "rateChange":
+ m_rateChange = value;
+ break;
+ }
+ }
+
+ public float WindParamGet(string param)
+ {
+ switch (param)
+ {
+ case "avgStrength":
+ return m_avgStrength;
+ case "avgDirection":
+ return m_avgDirection;
+ case "varStrength":
+ return m_varStrength;
+ case "varDirection":
+ return m_varDirection;
+ case "rateChange":
+ return m_rateChange;
+ default:
+ throw new Exception(String.Format("Unknown {0} parameter {1}", this.Name, param));
+
+ }
+ }
+
+
+
+ #endregion
+
+
+ private void LogSettings()
+ {
+ m_log.InfoFormat("[ConfigurableWind] Average Strength : {0}", m_avgStrength);
+ m_log.InfoFormat("[ConfigurableWind] Average Direction : {0}", m_avgDirection);
+ m_log.InfoFormat("[ConfigurableWind] Varience Strength : {0}", m_varStrength);
+ m_log.InfoFormat("[ConfigurableWind] Varience Direction : {0}", m_varDirection);
+ m_log.InfoFormat("[ConfigurableWind] Rate Change : {0}", m_rateChange);
+ }
+
+ #region IWindModelPlugin Members
+
+
+ #endregion
+ }
+}
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
new file mode 100644
index 0000000000..040a3c49f8
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
@@ -0,0 +1,139 @@
+using System;
+using System.Collections.Generic;
+
+using OpenMetaverse;
+
+
+namespace OpenSim.Region.CoreModules.World.Wind.Plugins
+{
+ class SimpleRandomWind : Mono.Addins.TypeExtensionNode, IWindModelPlugin
+ {
+ private Vector2[] m_windSpeeds = new Vector2[16 * 16];
+ private float m_strength = 1.0f;
+ private Random m_rndnums = new Random(Environment.TickCount);
+
+
+ #region IPlugin Members
+
+ public string Version
+ {
+ get { return "1.0.0.0"; }
+ }
+
+ public string Name
+ {
+ get { return "SimpleRandomWind"; }
+ }
+
+ public void Initialise()
+ {
+
+ }
+
+ #endregion
+
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ m_windSpeeds = null;
+ }
+
+ #endregion
+
+ #region IWindModelPlugin Members
+
+ public void WindConfig(OpenSim.Region.Framework.Scenes.Scene scene, Nini.Config.IConfig windConfig)
+ {
+ if( windConfig != null )
+ {
+ if( windConfig.Contains("strength") )
+ {
+ m_strength = windConfig.GetFloat("strength", 1.0F);
+ }
+ }
+ }
+
+ public void WindUpdate(uint frame)
+ {
+ for (int y = 0; y < 16; y++)
+ {
+ for (int x = 0; x < 16; x++)
+ {
+ m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
+ m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
+ m_windSpeeds[y * 16 + x].X *= m_strength;
+ m_windSpeeds[y * 16 + x].Y *= m_strength;
+ }
+ }
+ }
+
+ public Vector3 WindSpeed(float fX, float fY, float fZ)
+ {
+ Vector3 windVector = new Vector3(0.0f, 0.0f, 0.0f);
+
+ int x = (int)fX / 16;
+ int y = (int)fY / 16;
+
+ if (x < 0) x = 0;
+ if (x > 15) x = 15;
+ if (y < 0) y = 0;
+ if (y > 15) y = 15;
+
+ if (m_windSpeeds != null)
+ {
+ windVector.X = m_windSpeeds[y * 16 + x].X;
+ windVector.Y = m_windSpeeds[y * 16 + x].Y;
+ }
+
+ return windVector;
+
+ }
+
+ public Vector2[] WindLLClientArray()
+ {
+ return m_windSpeeds;
+ }
+
+ public string Description
+ {
+ get
+ {
+ return "Provides a simple wind model that creates random wind of a given strength in 16m x 16m patches.";
+ }
+ }
+
+ public System.Collections.Generic.Dictionary WindParams()
+ {
+ Dictionary Params = new Dictionary();
+
+ Params.Add("strength", "wind strength");
+
+ return Params;
+ }
+
+ public void WindParamSet(string param, float value)
+ {
+ switch (param)
+ {
+ case "strength":
+ m_strength = value;
+ break;
+ }
+ }
+
+ public float WindParamGet(string param)
+ {
+ switch (param)
+ {
+ case "strength":
+ return m_strength;
+ default:
+ throw new Exception(String.Format("Unknown {0} parameter {1}", this.Name, param));
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs
index 87e6fd909c..26901a4417 100644
--- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs
+++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs
@@ -27,57 +27,125 @@
using System;
using System.Collections.Generic;
+using System.Reflection;
+using log4net;
+using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
+using OpenSim.Region.CoreModules.World.Wind;
+
namespace OpenSim.Region.CoreModules
{
public class WindModule : IWindModule
{
-// private static readonly log4net.ILog m_log
-// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- private int m_frame = 0;
- private int m_frame_mod = 150;
+ private uint m_frame = 0;
+ private uint m_frameLastUpdateClientArray = 0;
+ private int m_frameUpdateRate = 150;
private Random m_rndnums = new Random(Environment.TickCount);
private Scene m_scene = null;
private bool m_ready = false;
- private float m_strength = 1.0F;
+
private bool m_enabled = true;
+ private IWindModelPlugin m_activeWindPlugin = null;
+ private const string m_dWindPluginName = "SimpleRandomWind";
+ private Dictionary m_availableWindPlugins = new Dictionary();
+
// Simplified windSpeeds based on the fact that the client protocal tracks at a resolution of 16m
private Vector2[] windSpeeds = new Vector2[16 * 16];
- private Dictionary m_rootAgents = new Dictionary();
-
+ #region IRegion Methods
+
public void Initialise(Scene scene, IConfigSource config)
{
IConfig windConfig = config.Configs["Wind"];
+ string desiredWindPlugin = m_dWindPluginName;
if (windConfig != null)
{
m_enabled = windConfig.GetBoolean("enabled", true);
- m_strength = windConfig.GetFloat("strength", 1.0F);
+
+ m_frameUpdateRate = windConfig.GetInt("wind_update_rate", 150);
+
+ // Determine which wind model plugin is desired
+ if (windConfig.Contains("wind_plugin"))
+ {
+ desiredWindPlugin = windConfig.GetString("wind_plugin");
+ }
}
if (m_enabled)
{
+ m_log.InfoFormat("[WIND] Enabled with an update rate of {0} frames.", m_frameUpdateRate);
m_scene = scene;
m_frame = 0;
+ // Register all the Wind Model Plug-ins
+ foreach (IWindModelPlugin windPlugin in AddinManager.GetExtensionObjects("/OpenSim/WindModule"))
+ {
+ m_log.InfoFormat("[WIND] Found Plugin: {0}", windPlugin.Name);
+ m_availableWindPlugins.Add(windPlugin.Name, windPlugin);
+ }
- scene.EventManager.OnFrame += WindUpdate;
- scene.EventManager.OnMakeChildAgent += MakeChildAgent;
- scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
- scene.EventManager.OnClientClosed += ClientLoggedOut;
- scene.RegisterModuleInterface(this);
+ // Check for desired plugin
+ if (m_availableWindPlugins.ContainsKey(desiredWindPlugin))
+ {
+ m_activeWindPlugin = m_availableWindPlugins[desiredWindPlugin];
+ m_log.InfoFormat("[WIND] {0} plugin found, initializing.", desiredWindPlugin);
+
+ if (windConfig != null)
+ {
+ m_activeWindPlugin.Initialise();
+ m_activeWindPlugin.WindConfig(m_scene, windConfig);
+ }
+ }
+
+
+ // if the plug-in wasn't found, default to no wind.
+ if (m_activeWindPlugin == null)
+ {
+ m_log.ErrorFormat("[WIND] Could not find specified wind plug-in: {0}", desiredWindPlugin);
+ m_log.ErrorFormat("[WIND] Defaulting to no wind.");
+ }
+
+ // This one puts an entry in the main help screen
+ m_scene.AddCommand(this, String.Empty, "wind", "Usage: wind [value] - Get or Update Wind paramaters", null);
+
+ // This one enables the ability to type just the base command without any parameters
+ m_scene.AddCommand(this, "wind", "", "", HandleConsoleCommand);
+
+ // Get a list of the parameters for each plugin
+ foreach (IWindModelPlugin windPlugin in m_availableWindPlugins.Values)
+ {
+ m_scene.AddCommand(this, String.Format("wind base wind_plugin {0}", windPlugin.Name), String.Format("{0} - {1}", windPlugin.Name, windPlugin.Description), "", HandleConsoleBaseCommand);
+ m_scene.AddCommand(this, String.Format("wind base wind_update_rate"), "Change the wind update rate.", "", HandleConsoleBaseCommand);
+
+ foreach (KeyValuePair kvp in windPlugin.WindParams())
+ {
+ m_scene.AddCommand(this, String.Format("wind {0} {1}", windPlugin.Name, kvp.Key), String.Format("{0} : {1} - {2}", windPlugin.Name, kvp.Key, kvp.Value), "", HandleConsoleParamCommand);
+ }
+ }
+
+
+ // Register event handlers for when Avatars enter the region, and frame ticks
+ m_scene.EventManager.OnFrame += WindUpdate;
+ m_scene.EventManager.OnMakeRootAgent += OnAgentEnteredRegion;
+
+ // Register the wind module
+ m_scene.RegisterModuleInterface(this);
+
+ // Generate initial wind values
GenWindPos();
+ // Mark Module Ready for duty
m_ready = true;
}
@@ -93,12 +161,19 @@ namespace OpenSim.Region.CoreModules
if (m_enabled)
{
m_ready = false;
+
+ // REVIEW: If a region module is closed, is there a possibility that it'll re-open/initialize ??
+ m_activeWindPlugin = null;
+ foreach (IWindModelPlugin windPlugin in m_availableWindPlugins.Values)
+ {
+ windPlugin.Dispose();
+ }
+
+ m_availableWindPlugins.Clear();
+
// Remove our hooks
m_scene.EventManager.OnFrame -= WindUpdate;
- // m_scene.EventManager.OnNewClient -= SunToClient;
- m_scene.EventManager.OnMakeChildAgent -= MakeChildAgent;
- m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel;
- m_scene.EventManager.OnClientClosed -= ClientLoggedOut;
+ m_scene.EventManager.OnMakeRootAgent -= OnAgentEnteredRegion;
}
}
@@ -112,85 +187,264 @@ namespace OpenSim.Region.CoreModules
get { return false; }
}
+
+ #endregion
+
+ #region Console Commands
+ private void ValidateConsole()
+ {
+ if (m_scene.ConsoleScene() == null)
+ {
+ // FIXME: If console region is root then this will be printed by every module. Currently, there is no
+ // way to prevent this, short of making the entire module shared (which is complete overkill).
+ // One possibility is to return a bool to signal whether the module has completely handled the command
+ m_log.InfoFormat("[WIND]: Please change to a specific region in order to set Sun parameters.");
+ return;
+ }
+
+ if (m_scene.ConsoleScene() != m_scene)
+ {
+ m_log.InfoFormat("[WIND]: Console Scene is not my scene.");
+ return;
+ }
+ }
+
+ ///
+ /// Base console command handler, only used if a person specifies the base command with now options
+ ///
+ private void HandleConsoleCommand(string module, string[] cmdparams)
+ {
+ ValidateConsole();
+ m_log.Info("[WIND] The wind command can be used to change the currently active wind model plugin and update the parameters for wind plugins.");
+ }
+
+ ///
+ /// Called to change the active wind model plugin
+ ///
+ private void HandleConsoleBaseCommand(string module, string[] cmdparams)
+ {
+ ValidateConsole();
+
+ if( (cmdparams.Length != 4)
+ || !cmdparams[1].Equals("base")
+ )
+ {
+ m_log.Info("[WIND] Invalid parameters to change parameters for Wind module base, usage: wind base ");
+ return;
+ }
+
+ switch (cmdparams[2])
+ {
+ case "wind_update_rate":
+ int newRate = 1;
+
+ if (int.TryParse(cmdparams[3], out newRate))
+ {
+ m_frameUpdateRate = newRate;
+ }
+ else
+ {
+ m_log.InfoFormat("[WIND] Invalid value {0} specified for {1}", cmdparams[3], cmdparams[2]);
+ return;
+ }
+
+ break;
+ case "wind_plugin":
+ string desiredPlugin = cmdparams[3];
+
+ if (desiredPlugin.Equals(m_activeWindPlugin.Name))
+ {
+ m_log.InfoFormat("[WIND] Wind model plugin {0} is already active", cmdparams[3]);
+ return;
+ }
+
+ if (m_availableWindPlugins.ContainsKey(desiredPlugin))
+ {
+ m_activeWindPlugin = m_availableWindPlugins[cmdparams[3]];
+ m_log.InfoFormat("[WIND] {0} wind model plugin now active", m_activeWindPlugin.Name);
+ }
+ else
+ {
+ m_log.InfoFormat("[WIND] Could not find wind model plugin {0}", desiredPlugin);
+ }
+ break;
+ }
+
+ }
+
+ ///
+ /// Called to change plugin parameters.
+ ///
+ private void HandleConsoleParamCommand(string module, string[] cmdparams)
+ {
+ ValidateConsole();
+
+ // wind [value]
+ if ((cmdparams.Length != 4)
+ && (cmdparams.Length != 3))
+ {
+ m_log.Info("[WIND] Usage: wind [value]");
+ return;
+ }
+
+ string plugin = cmdparams[1];
+ string param = cmdparams[2];
+ float value = 0f;
+ if (cmdparams.Length == 4)
+ {
+ if (!float.TryParse(cmdparams[3], out value))
+ {
+ m_log.InfoFormat("[WIND] Invalid value {0}", cmdparams[3]);
+ }
+
+ try
+ {
+ WindParamSet(plugin, param, value);
+ }
+ catch (Exception e)
+ {
+ m_log.InfoFormat("[WIND] {0}", e.Message);
+ }
+ }
+ else
+ {
+ try
+ {
+ value = WindParamGet(plugin, param);
+ m_log.InfoFormat("[WIND] {0} : {1}", param, value);
+ }
+ catch (Exception e)
+ {
+ m_log.InfoFormat("[WIND] {0}", e.Message);
+ }
+ }
+
+ }
+ #endregion
+
+
+ #region IWindModule Methods
+
///
/// Retrieve the wind speed at the given region coordinate. This
/// implimentation ignores Z.
///
/// 0...255
/// 0...255
- ///
public Vector3 WindSpeed(int x, int y, int z)
{
- Vector3 windVector = new Vector3(0.0f, 0.0f, 0.0f);
-
- x /= 16;
- y /= 16;
- if (x < 0) x = 0;
- if (x > 15) x = 15;
- if (y < 0) y = 0;
- if (y > 15) y = 15;
-
- if (windSpeeds != null)
+ if (m_activeWindPlugin != null)
{
- windVector.X = windSpeeds[y * 16 + x].X;
- windVector.Y = windSpeeds[y * 16 + x].Y;
+ return m_activeWindPlugin.WindSpeed(x, y, z);
+ }
+ else
+ {
+ return new Vector3(0.0f, 0.0f, 0.0f);
}
-
-
- return windVector;
}
- public void WindToClient(IClientAPI client)
+ public void WindParamSet(string plugin, string param, float value)
{
- if (m_ready)
+ if (m_availableWindPlugins.ContainsKey(plugin))
{
- //if (!sunFixed)
- //GenWindPos(); // Generate shared values once
- client.SendWindData(windSpeeds);
+ IWindModelPlugin windPlugin = m_availableWindPlugins[plugin];
+ windPlugin.WindParamSet(param, value);
+ m_log.InfoFormat("[WIND] {0} set to {1}", param, value);
+ }
+ else
+ {
+ throw new Exception(String.Format("Could not find plugin {0}", plugin));
+ }
+
+ }
+
+ public float WindParamGet(string plugin, string param)
+ {
+ if (m_availableWindPlugins.ContainsKey(plugin))
+ {
+ IWindModelPlugin windPlugin = m_availableWindPlugins[plugin];
+ return windPlugin.WindParamGet(param);
+ }
+ else
+ {
+ throw new Exception(String.Format("Could not find plugin {0}", plugin));
}
}
+ public string WindActiveModelPluginName
+ {
+ get
+ {
+ if (m_activeWindPlugin != null)
+ {
+ return m_activeWindPlugin.Name;
+ }
+ else
+ {
+ return String.Empty;
+ }
+ }
+ }
+
+ #endregion
+
+ ///
+ /// Called on each frame update. Updates the wind model and clients as necessary.
+ ///
public void WindUpdate()
{
- if (((m_frame++ % m_frame_mod) != 0) || !m_ready)
+ if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready)
{
return;
}
- //m_log.Debug("[WIND]:Regenerating...");
- GenWindPos(); // Generate shared values once
- //int spotxp = 0;
- //int spotyp = 0;
- //int spotxm = 0;
- //int spotym = 0;
- List avatars = m_scene.GetAvatars();
- foreach (ScenePresence avatar in avatars)
+ GenWindPos();
+
+ SendWindAllClients();
+ }
+
+ public void OnAgentEnteredRegion(ScenePresence avatar)
+ {
+ if (m_ready)
{
- if (!avatar.IsChildAgent)
+ if (m_activeWindPlugin != null)
{
- avatar.ControllingClient.SendWindData(windSpeeds);
+ // Ask wind plugin to generate a LL wind array to be cached locally
+ // Try not to update this too often, as it may involve array copies
+ if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate))
+ {
+ windSpeeds = m_activeWindPlugin.WindLLClientArray();
+ m_frameLastUpdateClientArray = m_frame;
+ }
+ }
+
+ avatar.ControllingClient.SendWindData(windSpeeds);
+ }
+ }
+
+ private void SendWindAllClients()
+ {
+ if (m_ready)
+ {
+ List avatars = m_scene.GetAvatars();
+
+ if (avatars.Count > 0)
+ {
+ // Ask wind plugin to generate a LL wind array to be cached locally
+ // Try not to update this too often, as it may involve array copies
+ if (m_frame >= (m_frameLastUpdateClientArray + m_frameUpdateRate))
+ {
+ windSpeeds = m_activeWindPlugin.WindLLClientArray();
+ m_frameLastUpdateClientArray = m_frame;
+ }
+
+ foreach (ScenePresence avatar in avatars)
+ {
+ if (!avatar.IsChildAgent)
+ avatar.ControllingClient.SendWindData(windSpeeds);
+ }
}
}
-
- // set estate settings for region access to sun position
- //m_scene.RegionInfo.RegionSettings.SunVector = Position;
- //m_scene.RegionInfo.EstateSettings.sunHour = GetLindenEstateHourFromCurrentTime();
- }
-
- public void ForceWindUpdateToAllClients()
- {
- GenWindPos(); // Generate shared values once
-
- List avatars = m_scene.GetAvatars();
- foreach (ScenePresence avatar in avatars)
- {
- if (!avatar.IsChildAgent)
- avatar.ControllingClient.SendWindData(windSpeeds);
- }
-
- // set estate settings for region access to sun position
- //m_scene.RegionInfo.RegionSettings.SunVector = Position;
- //m_scene.RegionInfo.RegionSettings.SunPosition = GetLindenEstateHourFromCurrentTime();
}
///
/// Calculate the sun's orbital position and its velocity.
@@ -198,58 +452,14 @@ namespace OpenSim.Region.CoreModules
private void GenWindPos()
{
- for (int y = 0; y < 16; y++)
+ if( m_activeWindPlugin != null )
{
- for (int x = 0; x < 16; x++)
- {
- windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
- windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
- windSpeeds[y * 16 + x].X *= m_strength;
- windSpeeds[y * 16 + x].Y *= m_strength;
- }
+ // Tell Wind Plugin to update it's wind data
+ m_activeWindPlugin.WindUpdate(m_frame);
}
}
- private void ClientLoggedOut(UUID AgentId)
- {
- lock (m_rootAgents)
- {
- if (m_rootAgents.ContainsKey(AgentId))
- {
- m_rootAgents.Remove(AgentId);
- }
- }
- }
- private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
- {
- lock (m_rootAgents)
- {
- if (m_rootAgents.ContainsKey(avatar.UUID))
- {
- m_rootAgents[avatar.UUID] = avatar.RegionHandle;
- }
- else
- {
- m_rootAgents.Add(avatar.UUID, avatar.RegionHandle);
- WindToClient(avatar.ControllingClient);
- }
- }
- //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
- }
- private void MakeChildAgent(ScenePresence avatar)
- {
- lock (m_rootAgents)
- {
- if (m_rootAgents.ContainsKey(avatar.UUID))
- {
- if (m_rootAgents[avatar.UUID] == avatar.RegionHandle)
- {
- m_rootAgents.Remove(avatar.UUID);
- }
- }
- }
- }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWindModule.cs b/OpenSim/Region/Framework/Interfaces/IWindModule.cs
index 84effd0faa..fe5d3ac118 100644
--- a/OpenSim/Region/Framework/Interfaces/IWindModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWindModule.cs
@@ -36,5 +36,20 @@ namespace OpenSim.Region.Framework.Interfaces
/// Retrieves the current wind speed at the given Region Coordinates
///
Vector3 WindSpeed(int x, int y, int z);
+
+ ///
+ /// Set Wind Plugin Parameter
+ ///
+ void WindParamSet(string plugin, string param, float value);
+
+ ///
+ /// Get Wind Plugin Parameter
+ ///
+ float WindParamGet(string plugin, string param);
+
+ ///
+ /// Current active wind model plugin or String.Empty
+ ///
+ string WindActiveModelPluginName { get; }
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index c87cc44aa2..491a971c62 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -268,7 +268,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
//
// OpenSim functions
//
-
public int osTerrainSetHeight(int x, int y, double val)
{
CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
@@ -920,6 +919,50 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
+ public string osWindActiveModelPluginName()
+ {
+ CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
+ m_host.AddScriptLPS(1);
+
+ IWindModule module = World.RequestModuleInterface();
+ if (module != null)
+ {
+ return module.WindActiveModelPluginName;
+ }
+
+ return String.Empty;
+ }
+
+ public void osWindParamSet(string plugin, string param, float value)
+ {
+ CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamSet");
+ m_host.AddScriptLPS(1);
+
+ IWindModule module = World.RequestModuleInterface();
+ if (module != null)
+ {
+ try
+ {
+ module.WindParamSet(plugin, param, value);
+ }
+ catch (Exception) { }
+ }
+ }
+
+ public float osWindParamGet(string plugin, string param)
+ {
+ CheckThreatLevel(ThreatLevel.VeryLow, "osWindParamGet");
+ m_host.AddScriptLPS(1);
+
+ IWindModule module = World.RequestModuleInterface();
+ if (module != null)
+ {
+ return module.WindParamGet(plugin, param);
+ }
+
+ return 0.0f;
+ }
+
public double osList2Double(LSL_Types.list src, int index)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index a2a0fea435..533ed27f37 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -104,6 +104,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
double osSunGetParam(string param);
void osSunSetParam(string param, double value);
+ // Wind Module Functions
+ string osWindActiveModelPluginName();
+ void osWindParamSet(string plugin, string param, float value);
+ float osWindParamGet(string plugin, string param);
+
string osGetScriptEngineName();
string osGetSimulatorVersion();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index fa45836454..54ae32a948 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -87,6 +87,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
m_OSSL_Functions.osSunSetParam(param, value);
}
+ public string osWindActiveModelPluginName()
+ {
+ return m_OSSL_Functions.osWindActiveModelPluginName();
+ }
+
+ void osWindParamSet(string plugin, string param, float value)
+ {
+ m_OSSL_Functions.osWindParamSet(plugin, param, value);
+ }
+
+ float osWindParamGet(string plugin, string param)
+ {
+ return m_OSSL_Functions.osWindParamGet(plugin, param);
+ }
+
+
public double osList2Double(LSL_Types.list src, int index)
{
diff --git a/bin/OpenSim.addin.xml b/bin/OpenSim.addin.xml
index 82adfa65f3..e026e24e33 100644
--- a/bin/OpenSim.addin.xml
+++ b/bin/OpenSim.addin.xml
@@ -12,4 +12,7 @@
+
+
+
diff --git a/prebuild.xml b/prebuild.xml
index 51f7cfa32b..3acb6d4a4f 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -1166,11 +1166,15 @@
+
+
+
+
-
+
@@ -3214,3 +3218,4 @@
+