Thank you kindly, MCortez for a patch that:
With some support from HomerH, this patch adds support for Wind Model plugins via the mono.Addin framework. * Adds console & OSSL access to Wind Parameters * Adds plug-in support for custom wind models * Provides two example Wind Model plug-ins Documentation for the wind module is temporarily located at http://code.google.com/p/flotsam/wiki/CoreWindModule [^] -- will move this documentation to http://opensimulator.org [^] after the patch has been committed.0.6.5-rc1
parent
54ccca1e2c
commit
54a27f9f5c
|
@ -0,0 +1,12 @@
|
|||
<Addin id="WindModule.Default.WindModels" version="1.0">
|
||||
<Runtime>
|
||||
<Import assembly="OpenSim.Region.CoreModules.dll"/>
|
||||
</Runtime>
|
||||
<Dependencies>
|
||||
<Addin id="OpenSim" version="0.5" />
|
||||
</Dependencies>
|
||||
<Extension path = "/OpenSim/WindModule">
|
||||
<WindModel id="ConfigurableWind" type="OpenSim.Region.CoreModules.World.Wind.Plugins.ConfigurableWind" />
|
||||
<WindModel id="SimpleRandomWind" type="OpenSim.Region.CoreModules.World.Wind.Plugins.SimpleRandomWind" />
|
||||
</Extension>
|
||||
</Addin>
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Brief description of this plugin's wind model
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to the wind configuration, if any.
|
||||
/// </summary>
|
||||
void WindConfig(Scene scene, IConfig windConfig);
|
||||
|
||||
/// <summary>
|
||||
/// Update wind.
|
||||
/// </summary>
|
||||
void WindUpdate(uint frame);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the wind vector at the given local region coordinates.
|
||||
/// </summary>
|
||||
Vector3 WindSpeed(float x, float y, float z);
|
||||
|
||||
/// <summary>
|
||||
/// Generate a 16 x 16 Vector2 array of wind speeds for LL* based viewers
|
||||
/// </summary>
|
||||
/// <returns>Must return a Vector2[256]</returns>
|
||||
Vector2[] WindLLClientArray();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a list of parameter/description pairs.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Dictionary<string, string> WindParams();
|
||||
|
||||
/// <summary>
|
||||
/// Set the specified parameter
|
||||
/// </summary>
|
||||
void WindParamSet(string param, float value);
|
||||
|
||||
/// <summary>
|
||||
/// Get the specified parameter
|
||||
/// </summary>
|
||||
float WindParamGet(string param);
|
||||
|
||||
}
|
||||
}
|
|
@ -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<string, string> WindParams()
|
||||
{
|
||||
Dictionary<string, string> Params = new Dictionary<string, string>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -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<string, string> WindParams()
|
||||
{
|
||||
Dictionary<string, string> Params = new Dictionary<string, string>();
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
}
|
|
@ -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<string, IWindModelPlugin> m_availableWindPlugins = new Dictionary<string, IWindModelPlugin>();
|
||||
|
||||
// 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<UUID, ulong> m_rootAgents = new Dictionary<UUID, ulong>();
|
||||
#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<IWindModule>(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 <plugin> <param> [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<string, string> 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<IWindModule>(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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base console command handler, only used if a person specifies the base command with now options
|
||||
/// </summary>
|
||||
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.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to change the active wind model plugin
|
||||
/// </summary>
|
||||
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 <parameter> <value>");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to change plugin parameters.
|
||||
/// </summary>
|
||||
private void HandleConsoleParamCommand(string module, string[] cmdparams)
|
||||
{
|
||||
ValidateConsole();
|
||||
|
||||
// wind <plugin> <param> [value]
|
||||
if ((cmdparams.Length != 4)
|
||||
&& (cmdparams.Length != 3))
|
||||
{
|
||||
m_log.Info("[WIND] Usage: wind <plugin> <param> [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
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the wind speed at the given region coordinate. This
|
||||
/// implimentation ignores Z.
|
||||
/// </summary>
|
||||
/// <param name="x">0...255</param>
|
||||
/// <param name="y">0...255</param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
return windVector;
|
||||
}
|
||||
|
||||
public void WindToClient(IClientAPI client)
|
||||
else
|
||||
{
|
||||
if (m_ready)
|
||||
{
|
||||
//if (!sunFixed)
|
||||
//GenWindPos(); // Generate shared values once
|
||||
client.SendWindData(windSpeeds);
|
||||
return new Vector3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void WindParamSet(string plugin, string param, float value)
|
||||
{
|
||||
if (m_availableWindPlugins.ContainsKey(plugin))
|
||||
{
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Called on each frame update. Updates the wind model and clients as necessary.
|
||||
/// </summary>
|
||||
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<ScenePresence> avatars = m_scene.GetAvatars();
|
||||
foreach (ScenePresence avatar in avatars)
|
||||
GenWindPos();
|
||||
|
||||
SendWindAllClients();
|
||||
}
|
||||
|
||||
public void OnAgentEnteredRegion(ScenePresence avatar)
|
||||
{
|
||||
if (!avatar.IsChildAgent)
|
||||
if (m_ready)
|
||||
{
|
||||
if (m_activeWindPlugin != null)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// set estate settings for region access to sun position
|
||||
//m_scene.RegionInfo.RegionSettings.SunVector = Position;
|
||||
//m_scene.RegionInfo.EstateSettings.sunHour = GetLindenEstateHourFromCurrentTime();
|
||||
private void SendWindAllClients()
|
||||
{
|
||||
if (m_ready)
|
||||
{
|
||||
List<ScenePresence> 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;
|
||||
}
|
||||
|
||||
public void ForceWindUpdateToAllClients()
|
||||
{
|
||||
GenWindPos(); // Generate shared values once
|
||||
|
||||
List<ScenePresence> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,5 +36,20 @@ namespace OpenSim.Region.Framework.Interfaces
|
|||
/// Retrieves the current wind speed at the given Region Coordinates
|
||||
/// </summary>
|
||||
Vector3 WindSpeed(int x, int y, int z);
|
||||
|
||||
/// <summary>
|
||||
/// Set Wind Plugin Parameter
|
||||
/// </summary>
|
||||
void WindParamSet(string plugin, string param, float value);
|
||||
|
||||
/// <summary>
|
||||
/// Get Wind Plugin Parameter
|
||||
/// </summary>
|
||||
float WindParamGet(string plugin, string param);
|
||||
|
||||
/// <summary>
|
||||
/// Current active wind model plugin or String.Empty
|
||||
/// </summary>
|
||||
string WindActiveModelPluginName { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IWindModule>();
|
||||
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<IWindModule>();
|
||||
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<IWindModule>();
|
||||
if (module != null)
|
||||
{
|
||||
return module.WindParamGet(plugin, param);
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public double osList2Double(LSL_Types.list src, int index)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -12,4 +12,7 @@
|
|||
<ExtensionPoint path="/OpenSim/AssetClient" name="Region Asset Cache Server Interface Plugin-point">
|
||||
<ExtensionNode name="AssetClient" type="OpenSim.Framework.PluginExtensionNode" objectType="OpenSim.Framework.IAssetServer"/>
|
||||
</ExtensionPoint>
|
||||
<ExtensionPoint path="/OpenSim/WindModule" name="Wind Module Plugins for wind models">
|
||||
<ExtensionNode name="WindModel" type="Mono.Addins.TypeExtensionNode" objectType="OpenSim.Region.CoreModules.World.Wind.IWindModelPlugin"/>
|
||||
</ExtensionPoint>
|
||||
</Addin>
|
||||
|
|
|
@ -1167,7 +1167,11 @@
|
|||
<Reference name="log4net.dll"/>
|
||||
<Reference name="DotNetOpenMail.dll"/>
|
||||
|
||||
<!-- To allow regions to have mono addins -->
|
||||
<Reference name="Mono.Addins.dll" />
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.addin.xml" path="Resources" buildAction="EmbeddedResource" recurse="true"/>
|
||||
<Match pattern="*.cs" recurse="true">
|
||||
<Exclude name="Tests" pattern="Tests" />
|
||||
<Exclude name="TerrainDefaultEffects" pattern="World/Terrain/DefaultEffects" />
|
||||
|
@ -3214,3 +3218,4 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue