29 using System.Collections.Generic;
33 using OpenSim.Framework;
34 using OpenSim.Region.Framework.Interfaces;
35 using OpenSim.Region.Framework.Scenes;
39 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"CloudModule")]
44 private uint m_frame = 0;
45 private int m_frameUpdateRate = 1000;
46 private Random m_rndnums =
new Random(Environment.TickCount);
47 private Scene m_scene = null;
48 private bool m_ready =
false;
49 private bool m_enabled =
false;
50 private float m_cloudDensity = 1.0F;
51 private float[] cloudCover =
new float[16 * 16];
55 IConfig cloudConfig = config.Configs[
"Cloud"];
57 if (cloudConfig != null)
59 m_enabled = cloudConfig.GetBoolean(
"enabled",
false);
60 m_cloudDensity = cloudConfig.GetFloat(
"density", 0.5F);
61 m_frameUpdateRate = cloudConfig.GetInt(
"cloud_update_rate", 1000);
73 scene.EventManager.OnNewClient += CloudsToClient;
75 scene.EventManager.OnFrame += CloudUpdate;
89 m_scene.EventManager.OnNewClient -= CloudsToClient;
90 m_scene.EventManager.OnFrame -= CloudUpdate;
110 get {
return "CloudModule"; }
113 public Type ReplaceableInterface
128 if (cloudCover != null)
130 cover = cloudCover[y * 16 + x];
136 private void UpdateCloudCover()
138 float[] newCover =
new float[16 * 16];
139 int rowAbove =
new int();
140 int rowBelow =
new int();
141 int columnLeft =
new int();
142 int columnRight =
new int();
143 for (
int x = 0; x < 16; x++)
160 for (
int y = 0; y< 16; y++)
177 float neighborAverage = (cloudCover[rowBelow * 16 + columnLeft] +
178 cloudCover[y * 16 + columnLeft] +
179 cloudCover[rowAbove * 16 + columnLeft] +
180 cloudCover[rowBelow * 16 + x] +
181 cloudCover[rowAbove * 16 + x] +
182 cloudCover[rowBelow * 16 + columnRight] +
183 cloudCover[y * 16 + columnRight] +
184 cloudCover[rowAbove * 16 + columnRight] +
185 cloudCover[y * 16 + x]) / 9;
186 newCover[y * 16 + x] = ((neighborAverage / m_cloudDensity) + 0.175f) % 1.0f;
187 newCover[y * 16 + x] *= m_cloudDensity;
190 Array.Copy(newCover, cloudCover, 16 * 16);
193 private void CloudUpdate()
195 if (((m_frame++ % m_frameUpdateRate) != 0) || !m_ready || (m_cloudDensity == 0))
206 client.SendCloudData(cloudCover);
214 private void GenerateCloudCover()
216 for (
int y = 0; y < 16; y++)
218 for (
int x = 0; x < 16; x++)
220 cloudCover[y * 16 + x] = (float)(m_rndnums.NextDouble());
221 cloudCover[y * 16 + x] *= m_cloudDensity;
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
float CloudCover(int x, int y, int z)
Retrieves the cloud density at the given region coordinates
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void CloudsToClient(IClientAPI client)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...