From 62eaddbe14e0bf5098808294502c14a7ed4063c3 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Thu, 5 Mar 2009 04:24:22 +0000 Subject: [PATCH] Fixes Mantis #3255. Thank you kindly, MCortez, for a patch that: Changes to IWindModule interface: Change from assuming a single array of 256 Vector2 values to a lookup function that takes region x, y, z and returns a Vector3 * Changed llWind() to use new lookup method of IWindModule * Moved logic for determining the wind at a given point in the data array from llWind() to the Wind Module itself. --- .../CoreModules/World/Wind/WindModule.cs | 30 +++++++++++++++++-- .../Framework/Interfaces/IWindModule.cs | 9 +++--- .../Shared/Api/Implementation/LSL_Api.cs | 17 +++++------ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs index 0b2062b10b..b761c139e0 100644 --- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs @@ -45,7 +45,10 @@ namespace OpenSim.Region.CoreModules private Random rndnums = new Random(Environment.TickCount); private Scene m_scene = null; private bool ready = false; + + // 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(); public void Initialise(Scene scene, IConfigSource config) @@ -89,9 +92,32 @@ namespace OpenSim.Region.CoreModules get { return false; } } - public Vector2[] WindSpeeds + /// + /// 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) { - get { return windSpeeds; } + 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) + { + windVector.X = windSpeeds[y * 16 + x].X; + windVector.Y = windSpeeds[y * 16 + x].Y; + } + + + return windVector; } public void WindToClient(IClientAPI client) diff --git a/OpenSim/Region/Framework/Interfaces/IWindModule.cs b/OpenSim/Region/Framework/Interfaces/IWindModule.cs index 5b8b0ceab4..84effd0faa 100644 --- a/OpenSim/Region/Framework/Interfaces/IWindModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IWindModule.cs @@ -31,9 +31,10 @@ namespace OpenSim.Region.Framework.Interfaces { public interface IWindModule : IRegionModule { - Vector2[] WindSpeeds - { - get; - } + + /// + /// Retrieves the current wind speed at the given Region Coordinates + /// + Vector3 WindSpeed(int x, int y, int z); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index fcd94a4345..32ebc37620 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -1031,17 +1031,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); LSL_Vector wind = new LSL_Vector(0, 0, 0); IWindModule module = World.RequestModuleInterface(); - if (module != null && module.WindSpeeds != null) + if (module != null) { Vector3 pos = m_host.GetWorldPosition(); - int x = (int)((pos.X + offset.x)/ 16); - int y = (int)((pos.Y + offset.y)/ 16); - if (x < 0) x = 0; - if (x > 15) x = 15; - if (y < 0) y = 0; - if (y > 15) y = 15; - wind.x = module.WindSpeeds[y * 16 + x].X; - wind.y = module.WindSpeeds[y * 16 + x].Y; + int x = (int)(pos.X + offset.x); + int y = (int)(pos.Y + offset.y); + + Vector3 windSpeed = module.WindSpeed(x, y, 0); + + wind.x = windSpeed.X; + wind.y = windSpeed.Y; } return wind; }