From 7c04c1e44cbb1869e4add6afa33d69fc30a40e72 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 10 Apr 2009 14:56:58 +0000 Subject: * Apply http://opensimulator.org/mantis/view.php?id=3427 * Return different values for llCloud() over time based on a cellular automation system. * Thanks aduffy70! --- .../Region/CoreModules/World/Cloud/CloudModule.cs | 72 +++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/World/Cloud/CloudModule.cs b/OpenSim/Region/CoreModules/World/Cloud/CloudModule.cs index 98f31f6..b9c716f 100644 --- a/OpenSim/Region/CoreModules/World/Cloud/CloudModule.cs +++ b/OpenSim/Region/CoreModules/World/Cloud/CloudModule.cs @@ -39,7 +39,8 @@ namespace OpenSim.Region.CoreModules { // private static readonly log4net.ILog m_log // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - + private uint m_frame = 0; + private int m_frameUpdateRate = 1000; private Random m_rndnums = new Random(Environment.TickCount); private Scene m_scene = null; private bool m_ready = false; @@ -57,6 +58,7 @@ namespace OpenSim.Region.CoreModules { m_enabled = cloudConfig.GetBoolean("enabled", false); m_cloudDensity = cloudConfig.GetFloat("density", 0.5F); + m_frameUpdateRate = cloudConfig.GetInt("cloud_update_rate", 1000); } if (m_enabled) @@ -68,6 +70,7 @@ namespace OpenSim.Region.CoreModules scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; scene.EventManager.OnClientClosed += ClientLoggedOut; scene.RegisterModuleInterface(this); + scene.EventManager.OnFrame += CloudUpdate; GenerateCloudCover(); @@ -90,6 +93,7 @@ namespace OpenSim.Region.CoreModules m_scene.EventManager.OnMakeChildAgent -= MakeChildAgent; m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel; m_scene.EventManager.OnClientClosed -= ClientLoggedOut; + m_scene.EventManager.OnFrame -= CloudUpdate; } } @@ -122,6 +126,72 @@ namespace OpenSim.Region.CoreModules return cover; } + private void UpdateCloudCover() + { + float[] newCover = new float[16 * 16]; + int rowAbove = new int(); + int rowBelow = new int(); + int columnLeft = new int(); + int columnRight = new int(); + for (int x = 0; x < 16; x++) + { + if (x == 0) + { + columnRight = x + 1; + columnLeft = 15; + } + else if (x == 15) + { + columnRight = 0; + columnLeft = x - 1; + } + else + { + columnRight = x + 1; + columnLeft = x - 1; + } + for (int y = 0; y< 16; y++) + { + if (y == 0) + { + rowAbove = y + 1; + rowBelow = 15; + } + else if (y == 15) + { + rowAbove = 0; + rowBelow = y - 1; + } + else + { + rowAbove = y + 1; + rowBelow = y - 1; + } + float neighborAverage = (cloudCover[rowBelow * 16 + columnLeft] + + cloudCover[y * 16 + columnLeft] + + cloudCover[rowAbove * 16 + columnLeft] + + cloudCover[rowBelow * 16 + x] + + cloudCover[rowAbove * 16 + x] + + cloudCover[rowBelow * 16 + columnRight] + + cloudCover[y * 16 + columnRight] + + cloudCover[rowAbove * 16 + columnRight] + + cloudCover[y * 16 + x]) / 9; + newCover[y * 16 + x] = ((neighborAverage / m_cloudDensity) + 0.175f) % 1.0f; + newCover[y * 16 + x] *= m_cloudDensity; + } + } + Array.Copy(newCover, cloudCover, 16 * 16); + } + + private void CloudUpdate() + { + if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready || (m_cloudDensity == 0)) + { + return; + } + UpdateCloudCover(); + } + public void CloudsToClient(IClientAPI client) { if (m_ready) -- cgit v1.1