From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 19 May 2019 21:24:15 +1000 Subject: Dump OpenSim 0.9.0.1 into it's own branch. --- .../World/Wind/Plugins/ConfigurableWind.cs | 19 +++-- .../World/Wind/Plugins/SimpleRandomWind.cs | 21 +++--- .../Region/CoreModules/World/Wind/WindModule.cs | 88 ++++++++-------------- 3 files changed, 52 insertions(+), 76 deletions(-) (limited to 'OpenSim/Region/CoreModules/World/Wind') diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs index 6af4050..a2b44df 100644 --- a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs +++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs @@ -50,7 +50,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins 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 float m_rateChange = 1.0f; // private Vector2 m_curPredominateWind = new Vector2(); @@ -70,7 +70,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins public void Initialise() { - + } #endregion @@ -103,7 +103,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins } } - public void WindUpdate(uint frame) + public bool WindUpdate(uint frame) { double avgAng = m_avgDirection * (Math.PI/180.0f); double varDir = m_varDirection * (Math.PI/180.0f); @@ -111,7 +111,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins // Prevailing wind algorithm // Inspired by Kanker Greenacre - // TODO: + // 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.0f; @@ -125,10 +125,8 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins 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; - - + if (windSpeed < 0) + windSpeed = -windSpeed; m_curPredominateWind.X = (float)Math.Cos(windDir); m_curPredominateWind.Y = (float)Math.Sin(windDir); @@ -144,6 +142,7 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins m_windSpeeds[y * 16 + x] = m_curPredominateWind; } } + return true; } public Vector3 WindSpeed(float fX, float fY, float fZ) @@ -158,9 +157,9 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins public string Description { - get + get { - return "Provides a predominate wind direction that can change within configured variances for direction and speed."; + return "Provides a predominate wind direction that can change within configured variances for direction and speed."; } } diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs index fcb0c10..d2ff7b3 100644 --- a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs +++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs @@ -82,22 +82,23 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins } } - public void WindUpdate(uint frame) + public bool WindUpdate(uint frame) { //Make sure our object is valid (we haven't been disposed of yet) - if (m_windSpeeds != null) + if (m_windSpeeds == null) + return false; + + for (int y = 0; y < 16; y++) { - for (int y = 0; y < 16; y++) + for (int x = 0; x < 16; x++) { - 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; - } + 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; } } + return true; } public Vector3 WindSpeed(float fX, float fY, float fZ) diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs index 35014f5..a1fff62 100644 --- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs @@ -46,11 +46,13 @@ namespace OpenSim.Region.CoreModules private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private uint m_frame = 0; - private uint m_frameLastUpdateClientArray = 0; + private int m_dataVersion = 0; + private int m_regionID = 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 bool m_inUpdate = false; private bool m_enabled = false; private IConfig m_windConfig; @@ -96,7 +98,6 @@ namespace OpenSim.Region.CoreModules m_scene = scene; m_frame = 0; - // Register all the Wind Model Plug-ins foreach (IWindModelPlugin windPlugin in AddinManager.GetExtensionObjects("/OpenSim/WindModule", false)) { @@ -118,7 +119,6 @@ namespace OpenSim.Region.CoreModules } } - // if the plug-in wasn't found, default to no wind. if (m_activeWindPlugin == null) { @@ -154,14 +154,14 @@ namespace OpenSim.Region.CoreModules // 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 + // Register the wind module m_scene.RegisterModuleInterface(this); // Generate initial wind values - GenWindPos(); - + GenWind(); + // hopefully this will not be the same for all regions on same instance + m_dataVersion = (int)m_scene.AllocateLocalId(); // Mark Module Ready for duty m_ready = true; } @@ -184,7 +184,7 @@ namespace OpenSim.Region.CoreModules // Remove our hooks m_scene.EventManager.OnFrame -= WindUpdate; - m_scene.EventManager.OnMakeRootAgent -= OnAgentEnteredRegion; +// m_scene.EventManager.OnMakeRootAgent -= OnAgentEnteredRegion; } @@ -351,7 +351,7 @@ namespace OpenSim.Region.CoreModules #region IWindModule Methods /// - /// Retrieve the wind speed at the given region coordinate. This + /// Retrieve the wind speed at the given region coordinate. This /// implimentation ignores Z. /// /// 0...255 @@ -396,7 +396,7 @@ namespace OpenSim.Region.CoreModules public string WindActiveModelPluginName { - get + get { if (m_activeWindPlugin != null) { @@ -416,67 +416,43 @@ namespace OpenSim.Region.CoreModules /// public void WindUpdate() { - if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready) - { + if ((!m_ready || m_inUpdate || (m_frame++ % m_frameUpdateRate) != 0)) return; - } - - GenWindPos(); - - SendWindAllClients(); - } - public void OnAgentEnteredRegion(ScenePresence avatar) - { - if (m_ready) + m_inUpdate = true; + Util.FireAndForget(delegate { - if (m_activeWindPlugin != null) + try { - // 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)) + GenWind(); + m_scene.ForEachClient(delegate(IClientAPI client) { - windSpeeds = m_activeWindPlugin.WindLLClientArray(); - m_frameLastUpdateClientArray = m_frame; - } - } - - avatar.ControllingClient.SendWindData(windSpeeds); - } - } + client.SendWindData(m_dataVersion, windSpeeds); + }); - private void SendWindAllClients() - { - if (m_ready) - { - if (m_scene.GetRootAgentCount() > 0) + } + finally { - // 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; - } - - m_scene.ForEachRootClient(delegate(IClientAPI client) - { - client.SendWindData(windSpeeds); - }); + m_inUpdate = false; } - } + }, + null, "WindModuleUpdate"); } + /// - /// Calculate the sun's orbital position and its velocity. + /// Calculate new wind + /// returns false if no change /// - private void GenWindPos() + private bool GenWind() { - if (m_activeWindPlugin != null) + if (m_activeWindPlugin != null && m_activeWindPlugin.WindUpdate(m_frame)) { - // Tell Wind Plugin to update it's wind data - m_activeWindPlugin.WindUpdate(m_frame); + windSpeeds = m_activeWindPlugin.WindLLClientArray(); + m_dataVersion++; + return true; } + return false; } } } -- cgit v1.1