* Return different values for llCloud() over time based on a cellular automation system.
* Thanks aduffy70!
0.6.5-rc1
Justin Clarke Casey 2009-04-10 14:56:58 +00:00
parent 30d012b297
commit 7c04c1e44c
2 changed files with 74 additions and 1 deletions

View File

@ -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<ICloudModule>(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)

View File

@ -746,6 +746,9 @@
; Density of cloud cover 0.0 to 1.0
density = 0.5
; update interval for the cloud cover data returned by llCloud().
; default is 1000
cloud_update_rate = 1000
[Trees]
; Enable this to allow the tree module to manage your sim trees, including growing, reproducing and dying