aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAdam Frisby2008-05-03 20:00:35 +0000
committerAdam Frisby2008-05-03 20:00:35 +0000
commit87b313792821cb842fd54b568302b6877c4e53f8 (patch)
tree446719156d1e8d8c12bc3bcd69546f04ba0d79ab
parent* Refactor: Move MoveFolder() and PurgeFolder() into CachedUserInfo (which ar... (diff)
downloadopensim-SC_OLD-87b313792821cb842fd54b568302b6877c4e53f8.zip
opensim-SC_OLD-87b313792821cb842fd54b568302b6877c4e53f8.tar.gz
opensim-SC_OLD-87b313792821cb842fd54b568302b6877c4e53f8.tar.bz2
opensim-SC_OLD-87b313792821cb842fd54b568302b6877c4e53f8.tar.xz
* Cleaned up code in Terrain, Tree and Map modules.
* Fixed a bug with Terragen loader where it would do bad things on a non 256x256 sized terrain. Now loads the array correctly. * Moved MapImageModule.cs to Modules/World/WorldMap * Changed Location.RegionHandle to use Helpers.GetUlong instead of doing it ourselves.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Location.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs61
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs9
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs30
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs12
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs15
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs19
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs17
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs5
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs28
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs5
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs3
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs16
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs7
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs6
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs9
-rw-r--r--OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs (renamed from OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs)333
28 files changed, 273 insertions, 345 deletions
diff --git a/OpenSim/Framework/Location.cs b/OpenSim/Framework/Location.cs
index a3d504c..6bc0755 100644
--- a/OpenSim/Framework/Location.cs
+++ b/OpenSim/Framework/Location.cs
@@ -1,4 +1,5 @@
1using System; 1using System;
2using libsecondlife;
2 3
3namespace OpenSim.Framework 4namespace OpenSim.Framework
4{ 5{
@@ -22,7 +23,7 @@ namespace OpenSim.Framework
22 23
23 public ulong RegionHandle 24 public ulong RegionHandle
24 { 25 {
25 get { return ((ulong) m_x << 32 & (ulong) m_y); } 26 get { return Helpers.UIntsToLong((uint) m_x, (uint) m_y); }
26 } 27 }
27 28
28 public int X 29 public int X
diff --git a/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
index 47ce258..7d9bdd9 100644
--- a/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
@@ -127,10 +127,10 @@ namespace OpenSim.Region.Environment.Modules.World.Sun
127 { 127 {
128 long m_addticks = (DateTime.Now.Ticks - m_start) * m_dilation; 128 long m_addticks = (DateTime.Now.Ticks - m_start) * m_dilation;
129 DateTime dt = new DateTime(m_start + m_addticks); 129 DateTime dt = new DateTime(m_start + m_addticks);
130 return (double) dt.Hour + ((double) dt.Minute / 60.0); 130 return dt.Hour + (dt.Minute / 60.0);
131 } 131 }
132 132
133 private LLVector3 SunPos(double hour) 133 private static LLVector3 SunPos(double hour)
134 { 134 {
135 // now we have our radian position 135 // now we have our radian position
136 double rad = (hour / m_real_day) * 2 * Math.PI - (Math.PI / 2.0); 136 double rad = (hour / m_real_day) * 2 * Math.PI - (Math.PI / 2.0);
@@ -138,62 +138,5 @@ namespace OpenSim.Region.Environment.Modules.World.Sun
138 double x = Math.Cos(rad); 138 double x = Math.Cos(rad);
139 return new LLVector3((float) x, 0f, (float) z); 139 return new LLVector3((float) x, 0f, (float) z);
140 } 140 }
141
142 // TODO: clear this out. This is here so that I remember to
143 // figure out if we need those other packet fields that I've
144 // left out so far
145 //
146 // public void SendViewerTime(int phase)
147 // {
148 // Console.WriteLine("SunPhase: {0}", phase);
149 // SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
150 // //viewertime.TimeInfo.SecPerDay = 86400;
151 // // viewertime.TimeInfo.SecPerYear = 31536000;
152 // viewertime.TimeInfo.SecPerDay = 1000;
153 // viewertime.TimeInfo.SecPerYear = 365000;
154 // viewertime.TimeInfo.SunPhase = 1;
155 // int sunPhase = (phase + 2)/2;
156 // if ((sunPhase < 6) || (sunPhase > 36))
157 // {
158 // viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
159 // Console.WriteLine("sending night");
160 // }
161 // else
162 // {
163 // if (sunPhase < 12)
164 // {
165 // sunPhase = 12;
166 // }
167 // sunPhase = sunPhase - 12;
168 //
169 // float yValue = 0.1f*(sunPhase);
170 // Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
171 // if (yValue > 1.2f)
172 // {
173 // yValue = yValue - 1.2f;
174 // }
175 // if (yValue > 1)
176 // {
177 // yValue = 1;
178 // }
179 // if (yValue < 0)
180 // {
181 // yValue = 0;
182 // }
183 // if (sunPhase < 14)
184 // {
185 // yValue = 1 - yValue;
186 // }
187 // if (sunPhase < 12)
188 // {
189 // yValue *= -1;
190 // }
191 // viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
192 // Console.WriteLine("sending sun update " + yValue);
193 // }
194 // viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
195 // viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch();
196 // // OutPacket(viewertime);
197 // }
198 } 141 }
199} \ No newline at end of file 142} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs
index a2e0c40..399287d 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/Effects/CookieCutter.cs
@@ -26,7 +26,6 @@
26 */ 26 */
27using System; 27using System;
28using OpenSim.Region.Environment.Interfaces; 28using OpenSim.Region.Environment.Interfaces;
29using OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes;
30using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes; 29using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes;
31 30
32namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects 31namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
@@ -37,7 +36,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
37 36
38 public void RunEffect(ITerrainChannel map) 37 public void RunEffect(ITerrainChannel map)
39 { 38 {
40 SmoothArea smooth = new SmoothArea();
41 ITerrainPaintableEffect eroder = new WeatherSphere(); 39 ITerrainPaintableEffect eroder = new WeatherSphere();
42 40
43 bool[,] cliffMask = new bool[map.Width,map.Height]; 41 bool[,] cliffMask = new bool[map.Width,map.Height];
@@ -60,9 +58,9 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
60 // Add a little height. (terrain should now be above water, mostly.) 58 // Add a little height. (terrain should now be above water, mostly.)
61 map[x, y] += 20; 59 map[x, y] += 20;
62 60
63 int channelsX = 4; 61 const int channelsX = 4;
64 int channelWidth = (map.Width / channelsX / 4); 62 int channelWidth = (map.Width / channelsX / 4);
65 int channelsY = 4; 63 const int channelsY = 4;
66 int channelHeight = (map.Height / channelsY / 4); 64 int channelHeight = (map.Height / channelsY / 4);
67 65
68 SetLowerChannel(map, cliffMask, channelMask, x, y, channelsX, channelWidth, map.Width, x); 66 SetLowerChannel(map, cliffMask, channelMask, x, y, channelsX, channelWidth, map.Width, x);
@@ -78,7 +76,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.Effects
78 { 76 {
79 for (y = 0; y < map.Height; y++) 77 for (y = 0; y < map.Height; y++)
80 { 78 {
81 if (cliffMask[x, y] == true) 79 if (cliffMask[x, y])
82 eroder.PaintEffect(map, x, y, 4, 0.1); 80 eroder.PaintEffect(map, x, y, 4, 0.1);
83 } 81 }
84 } 82 }
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index 9730b16..484bb89 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -61,9 +61,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
61 61
62 ITerrainChannel retval = new TerrainChannel(file.Width, file.Height); 62 ITerrainChannel retval = new TerrainChannel(file.Width, file.Height);
63 63
64 int x, y; 64 int x;
65 for (x = 0; x < file.Width; x++) 65 for (x = 0; x < file.Width; x++)
66 { 66 {
67 int y;
67 for (y = 0; y < file.Height; y++) 68 for (y = 0; y < file.Height; y++)
68 { 69 {
69 retval[x, y] = file.GetPixel(x, y).GetBrightness() * 128; 70 retval[x, y] = file.GetPixel(x, y).GetBrightness() * 128;
@@ -103,11 +104,11 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
103 /// </summary> 104 /// </summary>
104 /// <param name="map">The terrain channel to export to bitmap</param> 105 /// <param name="map">The terrain channel to export to bitmap</param>
105 /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> 106 /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns>
106 protected Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) 107 protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map)
107 { 108 {
108 Bitmap bmp = new Bitmap(map.Width, map.Height); 109 Bitmap bmp = new Bitmap(map.Width, map.Height);
109 110
110 int pallete = 256; 111 const int pallete = 256;
111 112
112 Color[] grays = new Color[pallete]; 113 Color[] grays = new Color[pallete];
113 for (int i = 0; i < grays.Length; i++) 114 for (int i = 0; i < grays.Length; i++)
@@ -138,7 +139,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
138 /// </summary> 139 /// </summary>
139 /// <param name="map">The terrain channel to export to bitmap</param> 140 /// <param name="map">The terrain channel to export to bitmap</param>
140 /// <returns>A System.Drawing.Bitmap containing a coloured image</returns> 141 /// <returns>A System.Drawing.Bitmap containing a coloured image</returns>
141 protected Bitmap CreateBitmapFromMap(ITerrainChannel map) 142 protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
142 { 143 {
143 Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); 144 Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
144 145
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs
index d58926e..628c201 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs
@@ -65,7 +65,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
65 return "JPEG"; 65 return "JPEG";
66 } 66 }
67 67
68 private Bitmap CreateBitmapFromMap(ITerrainChannel map) 68 private static Bitmap CreateBitmapFromMap(ITerrainChannel map)
69 { 69 {
70 Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); 70 Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
71 71
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs
index 5d6723f..1f6208c 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs
@@ -42,12 +42,13 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
42 FileInfo file = new FileInfo(filename); 42 FileInfo file = new FileInfo(filename);
43 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 43 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
44 BinaryReader bs = new BinaryReader(s); 44 BinaryReader bs = new BinaryReader(s);
45 int x, y; 45 int y;
46 for (y = 0; y < retval.Height; y++) 46 for (y = 0; y < retval.Height; y++)
47 { 47 {
48 int x;
48 for (x = 0; x < retval.Width; x++) 49 for (x = 0; x < retval.Width; x++)
49 { 50 {
50 retval[x, y] = (double) bs.ReadByte() * ((double) bs.ReadByte() / 127.0); 51 retval[x, y] = bs.ReadByte() * (bs.ReadByte() / 127.0);
51 bs.ReadBytes(11); // Advance the stream to next bytes. 52 bs.ReadBytes(11); // Advance the stream to next bytes.
52 } 53 }
53 } 54 }
@@ -71,18 +72,21 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
71 72
72 // Generate a smegging big lookup table to speed the operation up (it needs it) 73 // Generate a smegging big lookup table to speed the operation up (it needs it)
73 double[] lookupHeightTable = new double[65536]; 74 double[] lookupHeightTable = new double[65536];
74 int i, j, x, y; 75 int i;
76 int y;
75 for (i = 0; i < 256; i++) 77 for (i = 0; i < 256; i++)
76 { 78 {
79 int j;
77 for (j = 0; j < 256; j++) 80 for (j = 0; j < 256; j++)
78 { 81 {
79 lookupHeightTable[i + (j * 256)] = ((double) i * ((double) j / 127.0)); 82 lookupHeightTable[i + (j * 256)] = (i * (j / 127.0));
80 } 83 }
81 } 84 }
82 85
83 // Output the calculated raw 86 // Output the calculated raw
84 for (y = 0; y < map.Height; y++) 87 for (y = 0; y < map.Height; y++)
85 { 88 {
89 int x;
86 for (x = 0; x < map.Width; x++) 90 for (x = 0; x < map.Width; x++)
87 { 91 {
88 double t = map[x, y]; 92 double t = map[x, y];
@@ -100,15 +104,15 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
100 104
101 byte red = (byte) (index & 0xFF); 105 byte red = (byte) (index & 0xFF);
102 byte green = (byte) ((index >> 8) & 0xFF); 106 byte green = (byte) ((index >> 8) & 0xFF);
103 byte blue = 20; 107 const byte blue = 20;
104 byte alpha1 = 0; // Land Parcels 108 const byte alpha1 = 0;
105 byte alpha2 = 0; // For Sale Land 109 const byte alpha2 = 0;
106 byte alpha3 = 0; // Public Edit Object 110 const byte alpha3 = 0;
107 byte alpha4 = 0; // Public Edit Land 111 const byte alpha4 = 0;
108 byte alpha5 = 255; // Safe Land 112 const byte alpha5 = 255;
109 byte alpha6 = 255; // Flying Allowed 113 const byte alpha6 = 255;
110 byte alpha7 = 255; // Create Landmark 114 const byte alpha7 = 255;
111 byte alpha8 = 255; // Outside Scripts 115 const byte alpha8 = 255;
112 byte alpha9 = red; 116 byte alpha9 = red;
113 byte alpha10 = green; 117 byte alpha10 = green;
114 118
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
index fd2136c..689abcf 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
@@ -46,9 +46,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
46 FileInfo file = new FileInfo(filename); 46 FileInfo file = new FileInfo(filename);
47 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 47 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
48 BinaryReader bs = new BinaryReader(s); 48 BinaryReader bs = new BinaryReader(s);
49 int x, y; 49 int y;
50 for (y = 0; y < retval.Height; y++) 50 for (y = 0; y < retval.Height; y++)
51 { 51 {
52 int x;
52 for (x = 0; x < retval.Width; x++) 53 for (x = 0; x < retval.Width; x++)
53 { 54 {
54 retval[x, y] = bs.ReadSingle(); 55 retval[x, y] = bs.ReadSingle();
@@ -69,7 +70,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
69 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 70 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
70 BinaryReader bs = new BinaryReader(s); 71 BinaryReader bs = new BinaryReader(s);
71 72
72 int currFileXOffset = 0;
73 int currFileYOffset = 0; 73 int currFileYOffset = 0;
74 74
75 // if our region isn't on the first Y section of the areas to be landscaped, then 75 // if our region isn't on the first Y section of the areas to be landscaped, then
@@ -84,11 +84,11 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
84 84
85 // got to the Y start offset within the file of our region 85 // got to the Y start offset within the file of our region
86 // so read the file bits associated with our region 86 // so read the file bits associated with our region
87 int x, y; 87 int y;
88 // for each Y within our Y offset 88 // for each Y within our Y offset
89 for (y = 0; y < sectionHeight; y++) 89 for (y = 0; y < sectionHeight; y++)
90 { 90 {
91 currFileXOffset = 0; 91 int currFileXOffset = 0;
92 92
93 // if our region isn't the first X section of the areas to be landscaped, then 93 // if our region isn't the first X section of the areas to be landscaped, then
94 // advance the stream to the X start pos of our section in the file 94 // advance the stream to the X start pos of our section in the file
@@ -100,6 +100,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
100 } 100 }
101 101
102 // got to our X offset, so write our regions X line 102 // got to our X offset, so write our regions X line
103 int x;
103 for (x = 0; x < sectionWidth; x++) 104 for (x = 0; x < sectionWidth; x++)
104 { 105 {
105 // Read a strip and continue 106 // Read a strip and continue
@@ -130,9 +131,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
130 FileStream s = file.Open(FileMode.Create, FileAccess.Write); 131 FileStream s = file.Open(FileMode.Create, FileAccess.Write);
131 BinaryWriter bs = new BinaryWriter(s); 132 BinaryWriter bs = new BinaryWriter(s);
132 133
133 int x, y; 134 int y;
134 for (y = 0; y < map.Height; y++) 135 for (y = 0; y < map.Height; y++)
135 { 136 {
137 int x;
136 for (x = 0; x < map.Width; x++) 138 for (x = 0; x < map.Width; x++)
137 { 139 {
138 bs.Write((float) map[x, y]); 140 bs.Write((float) map[x, y]);
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
index 7cb4b00..fe36cf7 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
@@ -50,14 +50,15 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
50 BinaryReader bs = new BinaryReader(s); 50 BinaryReader bs = new BinaryReader(s);
51 51
52 bool eof = false; 52 bool eof = false;
53 if (ASCIIEncoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ") 53 if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ")
54 { 54 {
55 int w = 256;
56 int h = 256;
57
55 // Terragen file 58 // Terragen file
56 while (eof == false) 59 while (eof == false)
57 { 60 {
58 int w = 256; 61 string tmp = Encoding.ASCII.GetString(bs.ReadBytes(4));
59 int h = 256;
60 string tmp = ASCIIEncoding.ASCII.GetString(bs.ReadBytes(4));
61 switch (tmp) 62 switch (tmp)
62 { 63 {
63 case "SIZE": 64 case "SIZE":
@@ -79,12 +80,13 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
79 Int16 heightScale = bs.ReadInt16(); 80 Int16 heightScale = bs.ReadInt16();
80 Int16 baseHeight = bs.ReadInt16(); 81 Int16 baseHeight = bs.ReadInt16();
81 retval = new TerrainChannel(w, h); 82 retval = new TerrainChannel(w, h);
82 int x, y; 83 int x;
83 for (x = 0; x < w; x++) 84 for (x = 0; x < w; x++)
84 { 85 {
86 int y;
85 for (y = 0; y < h; y++) 87 for (y = 0; y < h; y++)
86 { 88 {
87 retval[x, y] = (double) baseHeight + (double) bs.ReadInt16() * (double) heightScale / 65536.0; 89 retval[x, y] = baseHeight + bs.ReadInt16() * (double) heightScale / 65536.0;
88 } 90 }
89 } 91 }
90 break; 92 break;
@@ -103,7 +105,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
103 105
104 public void SaveFile(string filename, ITerrainChannel map) 106 public void SaveFile(string filename, ITerrainChannel map)
105 { 107 {
106 char[] header = "TERRAGENTERRAIN".ToCharArray();
107 throw new NotImplementedException(); 108 throw new NotImplementedException();
108 } 109 }
109 110
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs
index 496da63..f3c8a13 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/FlattenArea.cs
@@ -37,7 +37,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
37 { 37 {
38 double sum = 0.0; 38 double sum = 0.0;
39 double steps = 0.0; 39 double steps = 0.0;
40 double avg;
41 40
42 int x, y; 41 int x, y;
43 for (x = 0; x < map.Width; x++) 42 for (x = 0; x < map.Width; x++)
@@ -52,7 +51,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
52 } 51 }
53 } 52 }
54 53
55 avg = sum / steps; 54 double avg = sum / steps;
56 55
57 double str = 0.1 * strength; // == 0.2 in the default client 56 double str = 0.1 * strength; // == 0.2 in the default client
58 57
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs
index 6c8e76e..f7c4893 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/NoiseArea.cs
@@ -36,9 +36,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
36 36
37 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 37 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
38 { 38 {
39 int x, y; 39 int x;
40 for (x = 0; x < map.Width; x++) 40 for (x = 0; x < map.Width; x++)
41 { 41 {
42 int y;
42 for (y = 0; y < map.Height; y++) 43 for (y = 0; y < map.Height; y++)
43 { 44 {
44 if (fillArea[x, y]) 45 if (fillArea[x, y])
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs
index 5cb236c..5eff3d6 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RaiseArea.cs
@@ -35,9 +35,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
37 { 37 {
38 int x, y; 38 int x;
39 for (x = 0; x < map.Width; x++) 39 for (x = 0; x < map.Width; x++)
40 { 40 {
41 int y;
41 for (y = 0; y < map.Height; y++) 42 for (y = 0; y < map.Height; y++)
42 { 43 {
43 if (fillArea[x, y]) 44 if (fillArea[x, y])
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs
index f1d9ce6..bebcae5 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/RevertArea.cs
@@ -42,9 +42,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
42 42
43 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 43 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
44 { 44 {
45 int x, y; 45 int x;
46 for (x = 0; x < map.Width; x++) 46 for (x = 0; x < map.Width; x++)
47 { 47 {
48 int y;
48 for (y = 0; y < map.Height; y++) 49 for (y = 0; y < map.Height; y++)
49 { 50 {
50 if (fillArea[x, y]) 51 if (fillArea[x, y])
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs
index d17d9cb..8fd805e 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FloodBrushes/SmoothArea.cs
@@ -92,7 +92,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FloodBrushes
92 if (y < 0.0) 92 if (y < 0.0)
93 y = 0.0; 93 y = 0.0;
94 94
95 int stepSize = 1; 95 const int stepSize = 1;
96 double h00 = map[(int) x, (int) y]; 96 double h00 = map[(int) x, (int) y];
97 double h10 = map[(int) x + stepSize, (int) y]; 97 double h10 = map[(int) x + stepSize, (int) y];
98 double h01 = map[(int) x, (int) y + stepSize]; 98 double h01 = map[(int) x, (int) y + stepSize];
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
index e036988..dae4cf8 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs
@@ -35,20 +35,20 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
35 /// </summary> 35 /// </summary>
36 public class ErodeSphere : ITerrainPaintableEffect 36 public class ErodeSphere : ITerrainPaintableEffect
37 { 37 {
38 private double rainHeight = 0.2; 38 private const double rainHeight = 0.2;
39 private int rounds = 10; 39 private const int rounds = 10;
40 private NeighbourSystem type = NeighbourSystem.Moore; // Parameter 40 private const NeighbourSystem type = NeighbourSystem.Moore;
41 private double waterSaturation = 0.30; // Can carry 1% of water in height 41 private const double waterSaturation = 0.30;
42 42
43 #region Supporting Functions 43 #region Supporting Functions
44 44
45 private int[] Neighbours(NeighbourSystem type, int index) 45 private static int[] Neighbours(NeighbourSystem neighbourType, int index)
46 { 46 {
47 int[] coord = new int[2]; 47 int[] coord = new int[2];
48 48
49 index++; 49 index++;
50 50
51 switch (type) 51 switch (neighbourType)
52 { 52 {
53 case NeighbourSystem.Moore: 53 case NeighbourSystem.Moore:
54 switch (index) 54 switch (index)
@@ -173,7 +173,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
173 { 173 {
174 for (y = 0; y < water.Height; y++) 174 for (y = 0; y < water.Height; y++)
175 { 175 {
176 double solConst = (1.0 / rounds); 176 const double solConst = (1.0 / rounds);
177 double sedDelta = water[x, y] * solConst; 177 double sedDelta = water[x, y] * solConst;
178 map[x, y] -= sedDelta; 178 map[x, y] -= sedDelta;
179 sediment[x, y] += sedDelta; 179 sediment[x, y] += sedDelta;
@@ -194,9 +194,8 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
194 double altitudeTotal = 0.0; 194 double altitudeTotal = 0.0;
195 double altitudeMe = map[x, y] + water[x, y]; 195 double altitudeMe = map[x, y] + water[x, y];
196 196
197 int NEIGHBOUR_ME = 4; 197 const int NEIGHBOUR_ME = 4;
198 198 const int NEIGHBOUR_MAX = 9;
199 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
200 199
201 for (int j = 0; j < NEIGHBOUR_MAX; j++) 200 for (int j = 0; j < NEIGHBOUR_MAX; j++)
202 { 201 {
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
index dee455f..0c4e3de 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs
@@ -39,21 +39,16 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
39 strength = TerrainUtil.MetersToSphericalStrength(strength); 39 strength = TerrainUtil.MetersToSphericalStrength(strength);
40 40
41 int x, y; 41 int x, y;
42 double[,] tweak = new double[map.Width,map.Height];
43
44 double area = strength;
45 double step = strength / 4.0;
46 42
47 double sum = 0.0; 43 double sum = 0.0;
48 double step2 = 0.0; 44 double step2 = 0.0;
49 double avg = 0.0;
50 45
51 // compute delta map 46 // compute delta map
52 for (x = 0; x < map.Width; x++) 47 for (x = 0; x < map.Width; x++)
53 { 48 {
54 for (y = 0; y < map.Height; y++) 49 for (y = 0; y < map.Height; y++)
55 { 50 {
56 double z = SphericalFactor(x, y, rx, ry, strength); 51 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
57 52
58 if (z > 0) // add in non-zero amount 53 if (z > 0) // add in non-zero amount
59 { 54 {
@@ -63,14 +58,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
63 } 58 }
64 } 59 }
65 60
66 avg = sum / step2; 61 double avg = sum / step2;
67 62
68 // blend in map 63 // blend in map
69 for (x = 0; x < map.Width; x++) 64 for (x = 0; x < map.Width; x++)
70 { 65 {
71 for (y = 0; y < map.Height; y++) 66 for (y = 0; y < map.Height; y++)
72 { 67 {
73 double z = SphericalFactor(x, y, rx, ry, strength) * duration; 68 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * duration;
74 69
75 if (z > 0) // add in non-zero amount 70 if (z > 0) // add in non-zero amount
76 { 71 {
@@ -84,11 +79,5 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
84 } 79 }
85 80
86 #endregion 81 #endregion
87
88 private double SphericalFactor(double x, double y, double rx, double ry, double size)
89 {
90 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
91 return z;
92 }
93 } 82 }
94} \ No newline at end of file 83} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
index 092bd29..202ab3b 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs
@@ -38,13 +38,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
38 { 38 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength); 39 strength = TerrainUtil.MetersToSphericalStrength(strength);
40 40
41 int x, y; 41 int x;
42 for (x = 0; x < map.Width; x++) 42 for (x = 0; x < map.Width; x++)
43 { 43 {
44 // Skip everything unlikely to be affected 44 // Skip everything unlikely to be affected
45 if (Math.Abs(x - rx) > strength * 1.1) 45 if (Math.Abs(x - rx) > strength * 1.1)
46 continue; 46 continue;
47 47
48 int y;
48 for (y = 0; y < map.Height; y++) 49 for (y = 0; y < map.Height; y++)
49 { 50 {
50 // Skip everything unlikely to be affected 51 // Skip everything unlikely to be affected
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
index 8ae583e..0824efd 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs
@@ -39,13 +39,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
39 { 39 {
40 strength = TerrainUtil.MetersToSphericalStrength(strength); 40 strength = TerrainUtil.MetersToSphericalStrength(strength);
41 41
42 int x, y; 42 int x;
43 for (x = 0; x < map.Width; x++) 43 for (x = 0; x < map.Width; x++)
44 { 44 {
45 // Skip everything unlikely to be affected 45 // Skip everything unlikely to be affected
46 if (Math.Abs(x - rx) > strength * 1.1) 46 if (Math.Abs(x - rx) > strength * 1.1)
47 continue; 47 continue;
48 48
49 int y;
49 for (y = 0; y < map.Height; y++) 50 for (y = 0; y < map.Height; y++)
50 { 51 {
51 // Skip everything unlikely to be affected 52 // Skip everything unlikely to be affected
@@ -57,7 +58,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
57 z *= z; 58 z *= z;
58 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 59 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
59 60
60 double noise = TerrainUtil.PerlinNoise2D((double) x / (double) Constants.RegionSize, (double) y / (double) Constants.RegionSize, 8, 1.0); 61 double noise = TerrainUtil.PerlinNoise2D(x / (double) Constants.RegionSize, y / (double) Constants.RegionSize, 8, 1.0);
61 62
62 if (z > 0.0) 63 if (z > 0.0)
63 map[x, y] += noise * z * duration; 64 map[x, y] += noise * z * duration;
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
index ba01a01..f2a1800 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs
@@ -38,18 +38,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
38 /// </summary> 38 /// </summary>
39 public class OlsenSphere : ITerrainPaintableEffect 39 public class OlsenSphere : ITerrainPaintableEffect
40 { 40 {
41 private double nConst = 1024.0; 41 private const double nConst = 1024.0;
42 private NeighbourSystem type = NeighbourSystem.Moore; // Parameter 42 private const NeighbourSystem type = NeighbourSystem.Moore;
43 43
44 #region Supporting Functions 44 #region Supporting Functions
45 45
46 private int[] Neighbours(NeighbourSystem type, int index) 46 private static int[] Neighbours(NeighbourSystem neighbourType, int index)
47 { 47 {
48 int[] coord = new int[2]; 48 int[] coord = new int[2];
49 49
50 index++; 50 index++;
51 51
52 switch (type) 52 switch (neighbourType)
53 { 53 {
54 case NeighbourSystem.Moore: 54 case NeighbourSystem.Moore:
55 switch (index) 55 switch (index)
@@ -141,12 +141,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
141 return coord; 141 return coord;
142 } 142 }
143 143
144 private double SphericalFactor(double x, double y, double rx, double ry, double size)
145 {
146 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
147 return z;
148 }
149
150 private enum NeighbourSystem 144 private enum NeighbourSystem
151 { 145 {
152 Moore, 146 Moore,
@@ -161,22 +155,22 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
161 { 155 {
162 strength = TerrainUtil.MetersToSphericalStrength(strength); 156 strength = TerrainUtil.MetersToSphericalStrength(strength);
163 157
164 int x, y; 158 int x;
165 159
166 for (x = 0; x < map.Width; x++) 160 for (x = 0; x < map.Width; x++)
167 { 161 {
162 int y;
168 for (y = 0; y < map.Height; y++) 163 for (y = 0; y < map.Height; y++)
169 { 164 {
170 double z = SphericalFactor(x, y, rx, ry, strength); 165 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
171 166
172 if (z > 0) // add in non-zero amount 167 if (z > 0) // add in non-zero amount
173 { 168 {
174 int NEIGHBOUR_ME = 4; 169 const int NEIGHBOUR_ME = 4;
175 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; 170 const int NEIGHBOUR_MAX = 9;
176 171
177 double max = Double.MinValue; 172 double max = Double.MinValue;
178 int loc = 0; 173 int loc = 0;
179 double cellmax = 0;
180 174
181 175
182 for (int j = 0; j < NEIGHBOUR_MAX; j++) 176 for (int j = 0; j < NEIGHBOUR_MAX; j++)
@@ -197,7 +191,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
197 if (coords[1] < 0) 191 if (coords[1] < 0)
198 continue; 192 continue;
199 193
200 cellmax = map[x, y] - map[coords[0], coords[1]]; 194 double cellmax = map[x, y] - map[coords[0], coords[1]];
201 if (cellmax > max) 195 if (cellmax > max)
202 { 196 {
203 max = cellmax; 197 max = cellmax;
@@ -206,7 +200,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
206 } 200 }
207 } 201 }
208 202
209 double T = nConst / ((map.Width + map.Height) / 2); 203 double T = nConst / ((map.Width + map.Height) / 2.0);
210 // Apply results 204 // Apply results
211 if (0 < max && max <= T) 205 if (0 < max && max <= T)
212 { 206 {
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
index 5d6f093..f5344a0 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs
@@ -38,13 +38,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
38 { 38 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength); 39 strength = TerrainUtil.MetersToSphericalStrength(strength);
40 40
41 int x, y; 41 int x;
42 for (x = 0; x < map.Width; x++) 42 for (x = 0; x < map.Width; x++)
43 { 43 {
44 // Skip everything unlikely to be affected 44 // Skip everything unlikely to be affected
45 if (Math.Abs(x - rx) > strength * 1.1) 45 if (Math.Abs(x - rx) > strength * 1.1)
46 continue; 46 continue;
47 47
48 int y;
48 for (y = 0; y < map.Height; y++) 49 for (y = 0; y < map.Height; y++)
49 { 50 {
50 // Skip everything unlikely to be affected 51 // Skip everything unlikely to be affected
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
index b47e041..3deb458 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs
@@ -32,7 +32,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
32{ 32{
33 public class RevertSphere : ITerrainPaintableEffect 33 public class RevertSphere : ITerrainPaintableEffect
34 { 34 {
35 private ITerrainChannel m_revertmap; 35 private readonly ITerrainChannel m_revertmap;
36 36
37 public RevertSphere(ITerrainChannel revertmap) 37 public RevertSphere(ITerrainChannel revertmap)
38 { 38 {
@@ -50,13 +50,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
50 if (duration < 0) 50 if (duration < 0)
51 return; 51 return;
52 52
53 int x, y; 53 int x;
54 for (x = 0; x < map.Width; x++) 54 for (x = 0; x < map.Width; x++)
55 { 55 {
56 // Skip everything unlikely to be affected 56 // Skip everything unlikely to be affected
57 if (Math.Abs(x - rx) > strength * 1.1) 57 if (Math.Abs(x - rx) > strength * 1.1)
58 continue; 58 continue;
59 59
60 int y;
60 for (y = 0; y < map.Height; y++) 61 for (y = 0; y < map.Height; y++)
61 { 62 {
62 // Skip everything unlikely to be affected 63 // Skip everything unlikely to be affected
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
index 51d5f0e..49946fd 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs
@@ -40,7 +40,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
40 int x, y; 40 int x, y;
41 double[,] tweak = new double[map.Width,map.Height]; 41 double[,] tweak = new double[map.Width,map.Height];
42 42
43 double n, l;
44 double area = strength; 43 double area = strength;
45 double step = strength / 4.0; 44 double step = strength / 4.0;
46 45
@@ -56,8 +55,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
56 double average = 0.0; 55 double average = 0.0;
57 int avgsteps = 0; 56 int avgsteps = 0;
58 57
58 double n;
59 for (n = 0.0 - area; n < area; n += step) 59 for (n = 0.0 - area; n < area; n += step)
60 { 60 {
61 double l;
61 for (l = 0.0 - area; l < area; l += step) 62 for (l = 0.0 - area; l < area; l += step)
62 { 63 {
63 avgsteps++; 64 avgsteps++;
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs
index b48beb8..753d171 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs
@@ -34,18 +34,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
34 /// </summary> 34 /// </summary>
35 public class WeatherSphere : ITerrainPaintableEffect 35 public class WeatherSphere : ITerrainPaintableEffect
36 { 36 {
37 private double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required. 37 private const double talus = 0.2;
38 private NeighbourSystem type = NeighbourSystem.Moore; // Parameter 38 private const NeighbourSystem type = NeighbourSystem.Moore;
39 39
40 #region Supporting Functions 40 #region Supporting Functions
41 41
42 private int[] Neighbours(NeighbourSystem type, int index) 42 private static int[] Neighbours(NeighbourSystem neighbourType, int index)
43 { 43 {
44 int[] coord = new int[2]; 44 int[] coord = new int[2];
45 45
46 index++; 46 index++;
47 47
48 switch (type) 48 switch (neighbourType)
49 { 49 {
50 case NeighbourSystem.Moore: 50 case NeighbourSystem.Moore:
51 switch (index) 51 switch (index)
@@ -151,19 +151,19 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes
151 { 151 {
152 strength = TerrainUtil.MetersToSphericalStrength(strength); 152 strength = TerrainUtil.MetersToSphericalStrength(strength);
153 153
154 int x, y; 154 int x;
155 155
156 for (x = 0; x < map.Width; x++) 156 for (x = 0; x < map.Width; x++)
157 { 157 {
158 int y;
158 for (y = 0; y < map.Height; y++) 159 for (y = 0; y < map.Height; y++)
159 { 160 {
160 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 161 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
161 162
162 if (z > 0) // add in non-zero amount 163 if (z > 0) // add in non-zero amount
163 { 164 {
164 int NEIGHBOUR_ME = 4; 165 const int NEIGHBOUR_ME = 4;
165 166 const int NEIGHBOUR_MAX = 9;
166 int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5;
167 167
168 for (int j = 0; j < NEIGHBOUR_MAX; j++) 168 for (int j = 0; j < NEIGHBOUR_MAX; j++)
169 { 169 {
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
index 4f7d20c..305818f 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
50 for (y = 0; y < Constants.RegionSize; y++) 50 for (y = 0; y < Constants.RegionSize; y++)
51 { 51 {
52 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10; 52 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10;
53 double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01; 53 double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2.0, Constants.RegionSize / 2.0, 50) * 0.01;
54 if (map[x, y] < spherFac) 54 if (map[x, y] < spherFac)
55 { 55 {
56 map[x, y] = spherFac; 56 map[x, y] = spherFac;
@@ -138,10 +138,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
138 taint[x / 16, y / 16] = false; 138 taint[x / 16, y / 16] = false;
139 return true; 139 return true;
140 } 140 }
141 else 141 return false;
142 {
143 return false;
144 }
145 } 142 }
146 143
147 #endregion 144 #endregion
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs
index f5c0fe4..2411de0 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainException.cs
@@ -31,7 +31,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
31{ 31{
32 public class TerrainException : Exception 32 public class TerrainException : Exception
33 { 33 {
34 public TerrainException() : base() 34 public TerrainException()
35 { 35 {
36 } 36 }
37 37
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
index eff6159..3076b52 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs
@@ -79,11 +79,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
79 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); 79 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
80 80
81 private ITerrainChannel m_channel; 81 private ITerrainChannel m_channel;
82 private Dictionary<Location, ITerrainChannel> m_channels;
83 private Dictionary<string, ITerrainEffect> m_plugineffects; 82 private Dictionary<string, ITerrainEffect> m_plugineffects;
84 private ITerrainChannel m_revert; 83 private ITerrainChannel m_revert;
85 private Scene m_scene; 84 private Scene m_scene;
86 private bool m_tainted = false; 85 private bool m_tainted;
87 86
88 #region ICommandableModule Members 87 #region ICommandableModule Members
89 88
@@ -581,7 +580,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
581 { 580 {
582 double max = Double.MinValue; 581 double max = Double.MinValue;
583 double min = double.MaxValue; 582 double min = double.MaxValue;
584 double avg;
585 double sum = 0; 583 double sum = 0;
586 584
587 int x; 585 int x;
@@ -598,7 +596,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
598 } 596 }
599 } 597 }
600 598
601 avg = sum / (m_channel.Height * m_channel.Width); 599 double avg = sum / (m_channel.Height * m_channel.Width);
602 600
603 m_log.Info("Channel " + m_channel.Width + "x" + m_channel.Height); 601 m_log.Info("Channel " + m_channel.Width + "x" + m_channel.Height);
604 m_log.Info("max/min/avg/sum: " + max + "/" + min + "/" + avg + "/" + sum); 602 m_log.Info("max/min/avg/sum: " + max + "/" + min + "/" + avg + "/" + sum);
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs
index daef6bd..4cb828e 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainUtil.cs
@@ -56,7 +56,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
56 if (y < 0.0) 56 if (y < 0.0)
57 y = 0.0; 57 y = 0.0;
58 58
59 int stepSize = 1; 59 const int stepSize = 1;
60 double h00 = map[(int) x, (int) y]; 60 double h00 = map[(int) x, (int) y];
61 double h10 = map[(int) x + stepSize, (int) y]; 61 double h10 = map[(int) x + stepSize, (int) y];
62 double h01 = map[(int) x, (int) y + stepSize]; 62 double h01 = map[(int) x, (int) y + stepSize];
@@ -116,14 +116,12 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain
116 116
117 public static double PerlinNoise2D(double x, double y, int octaves, double persistence) 117 public static double PerlinNoise2D(double x, double y, int octaves, double persistence)
118 { 118 {
119 double frequency = 0.0;
120 double amplitude = 0.0;
121 double total = 0.0; 119 double total = 0.0;
122 120
123 for (int i = 0; i < octaves; i++) 121 for (int i = 0; i < octaves; i++)
124 { 122 {
125 frequency = Math.Pow(2, i); 123 double frequency = Math.Pow(2, i);
126 amplitude = Math.Pow(persistence, i); 124 double amplitude = Math.Pow(persistence, i);
127 125
128 total += InterpolatedNoise(x * frequency, y * frequency) * amplitude; 126 total += InterpolatedNoise(x * frequency, y * frequency) * amplitude;
129 } 127 }
diff --git a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
index 4b22700..a62b78a 100644
--- a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
@@ -66,10 +66,10 @@ namespace OpenSim.Region.Environment.Modules.World.TreePopulator
66 m_trees = new List<LLUUID>(); 66 m_trees = new List<LLUUID>();
67 m_scene = scene; 67 m_scene = scene;
68 68
69 m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole); 69 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
70 70
71 Timer CalculateTrees = new Timer(m_tree_updates); 71 Timer CalculateTrees = new Timer(m_tree_updates);
72 CalculateTrees.Elapsed += new ElapsedEventHandler(CalculateTrees_Elapsed); 72 CalculateTrees.Elapsed += CalculateTrees_Elapsed;
73 CalculateTrees.Start(); 73 CalculateTrees.Start();
74 m_log.Debug("[TREES]: Initialised tree module"); 74 m_log.Debug("[TREES]: Initialised tree module");
75 } 75 }
@@ -190,10 +190,7 @@ namespace OpenSim.Region.Environment.Modules.World.TreePopulator
190 190
191 break; 191 break;
192 } 192 }
193 else 193 selectedTree.SetText(killLikelyhood.ToString(), new Vector3(1.0f, 1.0f, 1.0f), 1.0);
194 {
195 selectedTree.SetText(killLikelyhood.ToString(), new Vector3(1.0f, 1.0f, 1.0f), 1.0);
196 }
197 } 194 }
198 else 195 else
199 { 196 {
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
index fe26902..8ebe33e 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
@@ -1,168 +1,167 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Drawing; 29using System.Drawing;
30using Nini.Config; 30using Nini.Config;
31using OpenJPEGNet; 31using OpenJPEGNet;
32using OpenSim.Region.Environment.Interfaces; 32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Scenes; 33using OpenSim.Region.Environment.Scenes;
34 34
35namespace OpenSim.Region.Environment.Modules.World.Terrain 35namespace OpenSim.Region.Environment.Modules.World.WorldMap
36{ 36{
37 internal class MapImageModule : IMapImageGenerator, IRegionModule 37 internal class MapImageModule : IMapImageGenerator, IRegionModule
38 { 38 {
39 private Scene m_scene; 39 private Scene m_scene;
40 40
41 #region IMapImageGenerator Members 41 #region IMapImageGenerator Members
42 42
43 public byte[] WriteJpeg2000Image(string gradientmap) 43 public byte[] WriteJpeg2000Image(string gradientmap)
44 { 44 {
45 byte[] imageData = null; 45 byte[] imageData = null;
46 46
47 Bitmap bmp = TerrainToBitmap(gradientmap); 47 Bitmap bmp = TerrainToBitmap(gradientmap);
48 48
49 try 49 try
50 { 50 {
51 imageData = OpenJPEG.EncodeFromImage(bmp, true); 51 imageData = OpenJPEG.EncodeFromImage(bmp, true);
52 } 52 }
53 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke 53 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
54 { 54 {
55 Console.WriteLine("Failed generating terrain map: " + e); 55 Console.WriteLine("Failed generating terrain map: " + e);
56 } 56 }
57 57
58 return imageData; 58 return imageData;
59 } 59 }
60 60
61 #endregion 61 #endregion
62 62
63 #region IRegionModule Members 63 #region IRegionModule Members
64 64
65 public void Initialise(Scene scene, IConfigSource source) 65 public void Initialise(Scene scene, IConfigSource source)
66 { 66 {
67 m_scene = scene; 67 m_scene = scene;
68 m_scene.RegisterModuleInterface<IMapImageGenerator>(this); 68 m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
69 } 69 }
70 70
71 public void PostInitialise() 71 public void PostInitialise()
72 { 72 {
73 } 73 }
74 74
75 public void Close() 75 public void Close()
76 { 76 {
77 } 77 }
78 78
79 public string Name 79 public string Name
80 { 80 {
81 get { return "MapImageModule"; } 81 get { return "MapImageModule"; }
82 } 82 }
83 83
84 public bool IsSharedModule 84 public bool IsSharedModule
85 { 85 {
86 get { return false; } 86 get { return false; }
87 } 87 }
88 88
89 #endregion 89 #endregion
90 90
91 private void ShadeBuildings(ref Bitmap map) 91 private void ShadeBuildings(Bitmap map)
92 { 92 {
93 lock (map) 93 lock (map)
94 { 94 {
95 lock (m_scene.Entities) 95 lock (m_scene.Entities)
96 { 96 {
97 foreach (EntityBase entity in m_scene.Entities.Values) 97 foreach (EntityBase entity in m_scene.Entities.Values)
98 { 98 {
99 if (entity is SceneObjectGroup) 99 if (entity is SceneObjectGroup)
100 { 100 {
101 SceneObjectGroup sog = (SceneObjectGroup) entity; 101 SceneObjectGroup sog = (SceneObjectGroup) entity;
102 102
103 foreach (SceneObjectPart primitive in sog.Children.Values) 103 foreach (SceneObjectPart primitive in sog.Children.Values)
104 { 104 {
105 int x, y, w, h; 105 int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
106 x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); 106 int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
107 y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); 107 int w = (int) primitive.Scale.X;
108 w = (int) primitive.Scale.X; 108 int h = (int) primitive.Scale.Y;
109 h = (int) primitive.Scale.Y; 109
110 110 int dx;
111 int dx; 111 for (dx = x; dx < x + w; dx++)
112 for (dx = x; dx < x + w; dx++) 112 {
113 { 113 int dy;
114 int dy; 114 for (dy = y; dy < y + h; dy++)
115 for (dy = y; dy < y + h; dy++) 115 {
116 { 116 if (x < 0 || y < 0)
117 if (x < 0 || y < 0) 117 continue;
118 continue; 118 if (x >= map.Width || y >= map.Height)
119 if (x >= map.Width || y >= map.Height) 119 continue;
120 continue; 120
121 121 map.SetPixel(dx, dy, Color.DarkGray);
122 map.SetPixel(dx, dy, Color.DarkGray); 122 }
123 } 123 }
124 } 124 }
125 } 125 }
126 } 126 }
127 } 127 }
128 } 128 }
129 } 129 }
130 } 130
131 131 private Bitmap TerrainToBitmap(string gradientmap)
132 private Bitmap TerrainToBitmap(string gradientmap) 132 {
133 { 133 Bitmap gradientmapLd = new Bitmap(gradientmap);
134 Bitmap gradientmapLd = new Bitmap(gradientmap); 134
135 135 int pallete = gradientmapLd.Height;
136 int pallete = gradientmapLd.Height; 136
137 137 Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height);
138 Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); 138 Color[] colours = new Color[pallete];
139 Color[] colours = new Color[pallete]; 139
140 140 for (int i = 0; i < pallete; i++)
141 for (int i = 0; i < pallete; i++) 141 {
142 { 142 colours[i] = gradientmapLd.GetPixel(0, i);
143 colours[i] = gradientmapLd.GetPixel(0, i); 143 }
144 } 144
145 145 lock (m_scene.Heightmap)
146 lock (m_scene.Heightmap) 146 {
147 { 147 ITerrainChannel copy = m_scene.Heightmap;
148 ITerrainChannel copy = m_scene.Heightmap; 148 for (int y = 0; y < copy.Height; y++)
149 for (int y = 0; y < copy.Height; y++) 149 {
150 { 150 for (int x = 0; x < copy.Width; x++)
151 for (int x = 0; x < copy.Width; x++) 151 {
152 { 152 // 512 is the largest possible height before colours clamp
153 // 512 is the largest possible height before colours clamp 153 int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1));
154 int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); 154
155 155 // Handle error conditions
156 // Handle error conditions 156 if (colorindex > pallete - 1 || colorindex < 0)
157 if (colorindex > pallete - 1 || colorindex < 0) 157 bmp.SetPixel(x, copy.Height - y - 1, Color.Red);
158 bmp.SetPixel(x, copy.Height - y - 1, Color.Red); 158 else
159 else 159 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
160 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); 160 }
161 } 161 }
162 } 162 ShadeBuildings(bmp);
163 ShadeBuildings(ref bmp); 163 return bmp;
164 return bmp; 164 }
165 } 165 }
166 } 166 }
167 }
168} \ No newline at end of file 167} \ No newline at end of file