diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs index 6af40507f3..65691fe304 100644 --- a/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs +++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/ConfigurableWind.cs @@ -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); @@ -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) diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs index fcb0c10e1b..d2ff7b332d 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 2f401bf2dd..9f13d90176 100644 --- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs @@ -51,6 +51,7 @@ namespace OpenSim.Region.CoreModules //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; @@ -160,7 +161,7 @@ namespace OpenSim.Region.CoreModules m_scene.RegisterModuleInterface(this); // Generate initial wind values - GenWindPos(); + GenWind(); // Mark Module Ready for duty m_ready = true; @@ -416,67 +417,63 @@ 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(); + m_inUpdate = true; + Util.FireAndForget(delegate + { + try + { + if(GenWind()) + windSpeeds = m_activeWindPlugin.WindLLClientArray(); - SendWindAllClients(); + m_scene.ForEachRootClient(delegate(IClientAPI client) + { + client.SendWindData(windSpeeds); + }); + + } + finally + { + m_inUpdate = false; + } + }, + null, "WindModuleUpdate"); } /* - public void OnAgentEnteredRegion(ScenePresence avatar) - { - 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); - } - } -*/ private void SendWindAllClients() { - if (m_ready) - { - if (m_scene.GetRootAgentCount() > 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; - } + if (!m_ready || m_scene.GetRootAgentCount() == 0) + return; - m_scene.ForEachRootClient(delegate(IClientAPI client) - { - client.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; } + + m_scene.ForEachRootClient(delegate(IClientAPI client) + { + client.SendWindData(windSpeeds); + }); } +*/ /// - /// 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) { // Tell Wind Plugin to update it's wind data - m_activeWindPlugin.WindUpdate(m_frame); + return m_activeWindPlugin.WindUpdate(m_frame); } + return false; } } } diff --git a/OpenSim/Region/Framework/Interfaces/IWindModelPlugin.cs b/OpenSim/Region/Framework/Interfaces/IWindModelPlugin.cs index 16b6024442..b4bc15c25c 100644 --- a/OpenSim/Region/Framework/Interfaces/IWindModelPlugin.cs +++ b/OpenSim/Region/Framework/Interfaces/IWindModelPlugin.cs @@ -53,7 +53,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// Update wind. /// - void WindUpdate(uint frame); + bool WindUpdate(uint frame); /// /// Returns the wind vector at the given local region coordinates.