aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/Effects/CookieCutter.cs27
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/Effects/DefaultTerrainGenerator.cs10
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GIF.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs35
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs24
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs22
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/PNG.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs27
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/TIFF.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs16
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs12
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs7
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs7
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs4
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RevertArea.cs6
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs73
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs4
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/ITerrainModule.cs5
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs71
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs26
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs16
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs4
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs20
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs4
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs14
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs17
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs110
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs642
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs24
35 files changed, 678 insertions, 591 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/Effects/CookieCutter.cs b/OpenSim/Region/Environment/Modules/Terrain/Effects/CookieCutter.cs
index 8e51d40..6d41eba 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/Effects/CookieCutter.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/Effects/CookieCutter.cs
@@ -25,26 +25,24 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic;
29using System.Text;
30using OpenSim.Region.Environment.Modules.Terrain;
31using OpenSim.Region.Environment.Interfaces; 28using OpenSim.Region.Environment.Interfaces;
32using OpenSim.Framework; 29using OpenSim.Region.Environment.Modules.Terrain.FloodBrushes;
30using OpenSim.Region.Environment.Modules.Terrain.PaintBrushes;
33 31
34namespace OpenSim.Region.Environment.Modules.Terrain.Effects 32namespace OpenSim.Region.Environment.Modules.Terrain.Effects
35{ 33{
36 class CookieCutter : ITerrainEffect 34 internal class CookieCutter : ITerrainEffect
37 { 35 {
38 #region ITerrainEffect Members 36 #region ITerrainEffect Members
39 37
40 public void RunEffect(ITerrainChannel map) 38 public void RunEffect(ITerrainChannel map)
41 { 39 {
42 FloodBrushes.SmoothArea smooth = new FloodBrushes.SmoothArea(); 40 SmoothArea smooth = new SmoothArea();
43 ITerrainPaintableEffect eroder = new PaintBrushes.WeatherSphere(); 41 ITerrainPaintableEffect eroder = new WeatherSphere();
44 42
45 bool[,] cliffMask = new bool[map.Width, map.Height]; 43 bool[,] cliffMask = new bool[map.Width,map.Height];
46 bool[,] channelMask = new bool[map.Width, map.Height]; 44 bool[,] channelMask = new bool[map.Width,map.Height];
47 bool[,] smoothMask = new bool[map.Width, map.Height]; 45 bool[,] smoothMask = new bool[map.Width,map.Height];
48 46
49 Console.WriteLine("S1"); 47 Console.WriteLine("S1");
50 48
@@ -98,7 +96,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.Effects
98 //smooth.FloodEffect(map, smoothMask, 4.0); 96 //smooth.FloodEffect(map, smoothMask, 4.0);
99 } 97 }
100 98
101 private static void SetLowerChannel(ITerrainChannel map, bool[,] cliffMask, bool[,] channelMask, int x, int y, int numChannels, int channelWidth, int mapSize, int rp) 99 #endregion
100
101 private static void SetLowerChannel(ITerrainChannel map, bool[,] cliffMask, bool[,] channelMask, int x, int y, int numChannels, int channelWidth,
102 int mapSize, int rp)
102 { 103 {
103 for (int i = 0; i < numChannels; i++) 104 for (int i = 0; i < numChannels; i++)
104 { 105 {
@@ -119,7 +120,5 @@ namespace OpenSim.Region.Environment.Modules.Terrain.Effects
119 } 120 }
120 } 121 }
121 } 122 }
122
123 #endregion
124 } 123 }
125} 124} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/Effects/DefaultTerrainGenerator.cs b/OpenSim/Region/Environment/Modules/Terrain/Effects/DefaultTerrainGenerator.cs
index 4f91ee5..2327275 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/Effects/DefaultTerrainGenerator.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/Effects/DefaultTerrainGenerator.cs
@@ -24,16 +24,12 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30using OpenSim.Region.Environment.Modules.Terrain;
31using OpenSim.Region.Environment.Interfaces;
32using OpenSim.Framework; 27using OpenSim.Framework;
28using OpenSim.Region.Environment.Interfaces;
33 29
34namespace OpenSim.Region.Environment.Modules.Terrain.Effects 30namespace OpenSim.Region.Environment.Modules.Terrain.Effects
35{ 31{
36 class DefaultTerrainGenerator : ITerrainEffect 32 internal class DefaultTerrainGenerator : ITerrainEffect
37 { 33 {
38 #region ITerrainEffect Members 34 #region ITerrainEffect Members
39 35
@@ -56,4 +52,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.Effects
56 52
57 #endregion 53 #endregion
58 } 54 }
59} 55} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs
index cad0edf..f975872 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs
@@ -24,8 +24,8 @@
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 */
27using System;
28using System.Drawing; 27using System.Drawing;
28using System.Drawing.Imaging;
29using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders 31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
@@ -36,7 +36,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
36 /// 36 ///
37 /// Uses the System.Drawing filesystem loader. 37 /// Uses the System.Drawing filesystem loader.
38 /// </summary> 38 /// </summary>
39 class BMP : GenericSystemDrawing 39 internal class BMP : GenericSystemDrawing
40 { 40 {
41 /// <summary> 41 /// <summary>
42 /// Exports a file to a image on the disk using a System.Drawing exporter. 42 /// Exports a file to a image on the disk using a System.Drawing exporter.
@@ -47,7 +47,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
47 { 47 {
48 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 48 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
49 49
50 colours.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp); 50 colours.Save(filename, ImageFormat.Bmp);
51 } 51 }
52 52
53 /// <summary> 53 /// <summary>
@@ -59,4 +59,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
59 return "BMP"; 59 return "BMP";
60 } 60 }
61 } 61 }
62} 62} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GIF.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GIF.cs
index 7f07fd9..cf82000 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GIF.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GIF.cs
@@ -24,19 +24,19 @@
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 */
27using System;
28using System.Drawing; 27using System.Drawing;
28using System.Drawing.Imaging;
29using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders 31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
32{ 32{
33 class GIF : GenericSystemDrawing 33 internal class GIF : GenericSystemDrawing
34 { 34 {
35 public override void SaveFile(string filename, ITerrainChannel map) 35 public override void SaveFile(string filename, ITerrainChannel map)
36 { 36 {
37 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 37 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
38 38
39 colours.Save(filename, System.Drawing.Imaging.ImageFormat.Gif); 39 colours.Save(filename, ImageFormat.Gif);
40 } 40 }
41 41
42 public override string ToString() 42 public override string ToString()
@@ -44,4 +44,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
44 return "GIF"; 44 return "GIF";
45 } 45 }
46 } 46 }
47} 47} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs
index 9bcf94d..47e0e4cb 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Drawing; 29using System.Drawing;
30using System.Drawing.Imaging;
30using OpenSim.Region.Environment.Interfaces; 31using OpenSim.Region.Environment.Interfaces;
31 32
32namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders 33namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
@@ -72,6 +73,20 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
72 throw new NotImplementedException(); 73 throw new NotImplementedException();
73 } 74 }
74 75
76 /// <summary>
77 /// Exports a file to a image on the disk using a System.Drawing exporter.
78 /// </summary>
79 /// <param name="filename">The target filename</param>
80 /// <param name="map">The terrain channel being saved</param>
81 public virtual void SaveFile(string filename, ITerrainChannel map)
82 {
83 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
84
85 colours.Save(filename, ImageFormat.Png);
86 }
87
88 #endregion
89
75 public override string ToString() 90 public override string ToString()
76 { 91 {
77 return "SYS.DRAWING"; 92 return "SYS.DRAWING";
@@ -100,7 +115,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
100 for (int x = 0; x < map.Width; x++) 115 for (int x = 0; x < map.Width; x++)
101 { 116 {
102 // 512 is the largest possible height before colours clamp 117 // 512 is the largest possible height before colours clamp
103 int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); 118 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1));
104 119
105 // Handle error conditions 120 // Handle error conditions
106 if (colorindex > pallete - 1 || colorindex < 0) 121 if (colorindex > pallete - 1 || colorindex < 0)
@@ -137,7 +152,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
137 for (int x = 0; x < map.Width; x++) 152 for (int x = 0; x < map.Width; x++)
138 { 153 {
139 // 512 is the largest possible height before colours clamp 154 // 512 is the largest possible height before colours clamp
140 int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); 155 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
141 156
142 // Handle error conditions 157 // Handle error conditions
143 if (colorindex > pallete - 1 || colorindex < 0) 158 if (colorindex > pallete - 1 || colorindex < 0)
@@ -148,19 +163,5 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
148 } 163 }
149 return bmp; 164 return bmp;
150 } 165 }
151
152 /// <summary>
153 /// Exports a file to a image on the disk using a System.Drawing exporter.
154 /// </summary>
155 /// <param name="filename">The target filename</param>
156 /// <param name="map">The terrain channel being saved</param>
157 public virtual void SaveFile(string filename, ITerrainChannel map)
158 {
159 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
160
161 colours.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
162 }
163
164 #endregion
165 } 166 }
166} 167} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs
index d6430cd..f25b29b 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/JPEG.cs
@@ -26,8 +26,8 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.IO;
30using System.Drawing; 29using System.Drawing;
30using System.Drawing.Imaging;
31using OpenSim.Region.Environment.Interfaces; 31using OpenSim.Region.Environment.Interfaces;
32 32
33namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders 33namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
@@ -46,6 +46,15 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
46 throw new NotImplementedException(); 46 throw new NotImplementedException();
47 } 47 }
48 48
49 public void SaveFile(string filename, ITerrainChannel map)
50 {
51 Bitmap colours = CreateBitmapFromMap(map);
52
53 colours.Save(filename, ImageFormat.Jpeg);
54 }
55
56 #endregion
57
49 public override string ToString() 58 public override string ToString()
50 { 59 {
51 return "JPEG"; 60 return "JPEG";
@@ -70,20 +79,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
70 for (int x = 0; x < map.Width; x++) 79 for (int x = 0; x < map.Width; x++)
71 { 80 {
72 // 512 is the largest possible height before colours clamp 81 // 512 is the largest possible height before colours clamp
73 int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); 82 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
74 bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); 83 bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]);
75 } 84 }
76 } 85 }
77 return bmp; 86 return bmp;
78 } 87 }
79
80 public void SaveFile(string filename, ITerrainChannel map)
81 {
82 Bitmap colours = CreateBitmapFromMap(map);
83
84 colours.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
85 }
86
87 #endregion
88 } 88 }
89} 89} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs
index 7436dc5..fda46f0 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/LLRAW.cs
@@ -47,7 +47,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
47 { 47 {
48 for (x = 0; x < retval.Width; x++) 48 for (x = 0; x < retval.Width; x++)
49 { 49 {
50 retval[x, y] = (double)bs.ReadByte() * ((double)bs.ReadByte() / 127.0); 50 retval[x, y] = (double) bs.ReadByte() * ((double) bs.ReadByte() / 127.0);
51 bs.ReadBytes(11); // Advance the stream to next bytes. 51 bs.ReadBytes(11); // Advance the stream to next bytes.
52 } 52 }
53 } 53 }
@@ -58,11 +58,6 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
58 return retval; 58 return retval;
59 } 59 }
60 60
61 public override string ToString()
62 {
63 return "LL/SL RAW";
64 }
65
66 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) 61 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h)
67 { 62 {
68 throw new NotImplementedException(); 63 throw new NotImplementedException();
@@ -81,7 +76,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
81 { 76 {
82 for (j = 0; j < 256; j++) 77 for (j = 0; j < 256; j++)
83 { 78 {
84 lookupHeightTable[i + (j * 256)] = ((double)i * ((double)j / 127.0)); 79 lookupHeightTable[i + (j * 256)] = ((double) i * ((double) j / 127.0));
85 } 80 }
86 } 81 }
87 82
@@ -103,9 +98,9 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
103 } 98 }
104 } 99 }
105 100
106 byte red = (byte)(index & 0xFF); 101 byte red = (byte) (index & 0xFF);
107 byte green = (byte)((index >> 8) & 0xFF); 102 byte green = (byte) ((index >> 8) & 0xFF);
108 byte blue = 20; 103 byte blue = 20;
109 byte alpha1 = 0; // Land Parcels 104 byte alpha1 = 0; // Land Parcels
110 byte alpha2 = 0; // For Sale Land 105 byte alpha2 = 0; // For Sale Land
111 byte alpha3 = 0; // Public Edit Object 106 byte alpha3 = 0; // Public Edit Object
@@ -138,5 +133,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
138 } 133 }
139 134
140 #endregion 135 #endregion
136
137 public override string ToString()
138 {
139 return "LL/SL RAW";
140 }
141 } 141 }
142} 142} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/PNG.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/PNG.cs
index d7f34ee..16f1e3c 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/PNG.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/PNG.cs
@@ -24,19 +24,19 @@
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 */
27using System;
28using System.Drawing; 27using System.Drawing;
28using System.Drawing.Imaging;
29using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders 31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
32{ 32{
33 class PNG : GenericSystemDrawing 33 internal class PNG : GenericSystemDrawing
34 { 34 {
35 public override void SaveFile(string filename, ITerrainChannel map) 35 public override void SaveFile(string filename, ITerrainChannel map)
36 { 36 {
37 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 37 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
38 38
39 colours.Save(filename, System.Drawing.Imaging.ImageFormat.Png); 39 colours.Save(filename, ImageFormat.Png);
40 } 40 }
41 41
42 public override string ToString() 42 public override string ToString()
@@ -44,4 +44,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
44 return "PNG"; 44 return "PNG";
45 } 45 }
46 } 46 }
47} 47} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
index 7575b1b..d496069 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/RAW32.cs
@@ -25,7 +25,6 @@
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;
29using System.IO; 28using System.IO;
30using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
31 30
@@ -57,11 +56,6 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
57 return retval; 56 return retval;
58 } 57 }
59 58
60 public override string ToString()
61 {
62 return "RAW32";
63 }
64
65 public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight) 59 public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
66 { 60 {
67 TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight); 61 TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);
@@ -69,7 +63,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
69 FileInfo file = new FileInfo(filename); 63 FileInfo file = new FileInfo(filename);
70 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 64 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
71 BinaryReader bs = new BinaryReader(s); 65 BinaryReader bs = new BinaryReader(s);
72 66
73 int currFileXOffset = 0; 67 int currFileXOffset = 0;
74 int currFileYOffset = 0; 68 int currFileYOffset = 0;
75 69
@@ -79,7 +73,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
79 { 73 {
80 // read a whole strip of regions 74 // read a whole strip of regions
81 int heightsToRead = sectionHeight * (fileWidth * sectionWidth); 75 int heightsToRead = sectionHeight * (fileWidth * sectionWidth);
82 bs.ReadBytes( heightsToRead * 4); // because the floats are 4 bytes in the file 76 bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file
83 currFileYOffset++; 77 currFileYOffset++;
84 } 78 }
85 79
@@ -90,13 +84,13 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
90 for (y = 0; y < sectionHeight; y++) 84 for (y = 0; y < sectionHeight; y++)
91 { 85 {
92 currFileXOffset = 0; 86 currFileXOffset = 0;
93 87
94 // if our region isn't the first X section of the areas to be landscaped, then 88 // if our region isn't the first X section of the areas to be landscaped, then
95 // advance the stream to the X start pos of our section in the file 89 // advance the stream to the X start pos of our section in the file
96 // i.e. eat X upto where we start 90 // i.e. eat X upto where we start
97 while (currFileXOffset < offsetX) 91 while (currFileXOffset < offsetX)
98 { 92 {
99 bs.ReadBytes( sectionWidth * 4); // 4 bytes = single 93 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
100 currFileXOffset++; 94 currFileXOffset++;
101 } 95 }
102 96
@@ -111,14 +105,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
111 105
112 // if our region isn't the last X section of the areas to be landscaped, then 106 // if our region isn't the last X section of the areas to be landscaped, then
113 // advance the stream to the end of this Y column 107 // advance the stream to the end of this Y column
114 while (currFileXOffset < fileWidth ) 108 while (currFileXOffset < fileWidth)
115 { 109 {
116 // eat the next regions x line 110 // eat the next regions x line
117 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single 111 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
118 currFileXOffset++; 112 currFileXOffset++;
119 } 113 }
120
121
122 } 114 }
123 115
124 bs.Close(); 116 bs.Close();
@@ -138,7 +130,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
138 { 130 {
139 for (x = 0; x < map.Width; x++) 131 for (x = 0; x < map.Width; x++)
140 { 132 {
141 bs.Write((float)map[x, y]); 133 bs.Write((float) map[x, y]);
142 } 134 }
143 } 135 }
144 136
@@ -147,5 +139,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
147 } 139 }
148 140
149 #endregion 141 #endregion
142
143 public override string ToString()
144 {
145 return "RAW32";
146 }
150 } 147 }
151} 148} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/TIFF.cs
index 8eb53fc..39c2428 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/TIFF.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/TIFF.cs
@@ -24,19 +24,19 @@
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 */
27using System;
28using System.Drawing; 27using System.Drawing;
28using System.Drawing.Imaging;
29using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders 31namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
32{ 32{
33 class TIFF : GenericSystemDrawing 33 internal class TIFF : GenericSystemDrawing
34 { 34 {
35 public override void SaveFile(string filename, ITerrainChannel map) 35 public override void SaveFile(string filename, ITerrainChannel map)
36 { 36 {
37 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 37 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
38 38
39 colours.Save(filename, System.Drawing.Imaging.ImageFormat.Tiff); 39 colours.Save(filename, ImageFormat.Tiff);
40 } 40 }
41 41
42 public override string ToString() 42 public override string ToString()
@@ -44,4 +44,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
44 return "TIFF"; 44 return "TIFF";
45 } 45 }
46 } 46 }
47} 47} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
index 6a3c354..9f9edbc 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
@@ -37,7 +37,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
37 /// Built from specification at 37 /// Built from specification at
38 /// http://www.planetside.co.uk/terragen/dev/tgterrain.html 38 /// http://www.planetside.co.uk/terragen/dev/tgterrain.html
39 /// </summary> 39 /// </summary>
40 class Terragen : ITerrainLoader 40 internal class Terragen : ITerrainLoader
41 { 41 {
42 #region ITerrainLoader Members 42 #region ITerrainLoader Members
43 43
@@ -84,7 +84,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
84 { 84 {
85 for (y = 0; y < h; y++) 85 for (y = 0; y < h; y++)
86 { 86 {
87 retval[x, y] = (double)baseHeight + (double)bs.ReadInt16() * (double)heightScale / 65536.0; 87 retval[x, y] = (double) baseHeight + (double) bs.ReadInt16() * (double) heightScale / 65536.0;
88 } 88 }
89 } 89 }
90 break; 90 break;
@@ -107,16 +107,16 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
107 throw new NotImplementedException(); 107 throw new NotImplementedException();
108 } 108 }
109 109
110 public override string ToString()
111 {
112 return "Terragen";
113 }
114
115 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) 110 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h)
116 { 111 {
117 throw new NotImplementedException(); 112 throw new NotImplementedException();
118 } 113 }
119 114
120 #endregion 115 #endregion
116
117 public override string ToString()
118 {
119 return "Terragen";
120 }
121 } 121 }
122} 122} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs
index 76abc36..1e0b151 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/FlattenArea.cs
@@ -25,10 +25,6 @@
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;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Environment.Modules.Terrain;
32using OpenSim.Region.Environment.Interfaces; 28using OpenSim.Region.Environment.Interfaces;
33 29
34namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes 30namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
@@ -41,14 +37,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
41 { 37 {
42 double sum = 0.0; 38 double sum = 0.0;
43 double steps = 0.0; 39 double steps = 0.0;
44 double avg = 0.0; 40 double avg;
45 41
46 int x, y; 42 int x, y;
47 for (x = 0; x < map.Width; x++) 43 for (x = 0; x < map.Width; x++)
48 { 44 {
49 for (y = 0; y < map.Height; y++) 45 for (y = 0; y < map.Height; y++)
50 { 46 {
51 if (fillArea[x, y] == true) 47 if (fillArea[x, y])
52 { 48 {
53 sum += map[x, y]; 49 sum += map[x, y];
54 steps += 1.0; 50 steps += 1.0;
@@ -64,7 +60,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
64 { 60 {
65 for (y = 0; y < map.Height; y++) 61 for (y = 0; y < map.Height; y++)
66 { 62 {
67 if (fillArea[x, y] == true) 63 if (fillArea[x, y])
68 map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); 64 map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str);
69 } 65 }
70 } 66 }
@@ -72,4 +68,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
72 68
73 #endregion 69 #endregion
74 } 70 }
75} 71} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs
index 4bb7ab1..410d0cf 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/LowerArea.cs
@@ -35,12 +35,13 @@ namespace OpenSim.Region.Environment.Modules.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] == true) 44 if (fillArea[x, y])
44 { 45 {
45 map[x, y] -= strength; 46 map[x, y] -= strength;
46 } 47 }
@@ -50,4 +51,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
50 51
51 #endregion 52 #endregion
52 } 53 }
53} 54} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs
index 284ce42..2ea1b90 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/NoiseArea.cs
@@ -25,6 +25,7 @@
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 OpenSim.Framework;
28using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
29 30
30namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes 31namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
@@ -40,9 +41,9 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
40 { 41 {
41 for (y = 0; y < map.Height; y++) 42 for (y = 0; y < map.Height; y++)
42 { 43 {
43 if (fillArea[x, y] == true) 44 if (fillArea[x, y])
44 { 45 {
45 double noise = TerrainUtil.PerlinNoise2D((double)x / (double)Framework.Constants.RegionSize, (double)y / (double)Framework.Constants.RegionSize, 8, 1.0); 46 double noise = TerrainUtil.PerlinNoise2D((double) x / Constants.RegionSize, (double) y / Constants.RegionSize, 8, 1.0);
46 47
47 map[x, y] += noise * strength; 48 map[x, y] += noise * strength;
48 } 49 }
@@ -52,4 +53,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
52 53
53 #endregion 54 #endregion
54 } 55 }
55} 56} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs
index 7a9a3e5..4ea06c8 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RaiseArea.cs
@@ -40,7 +40,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
40 { 40 {
41 for (y = 0; y < map.Height; y++) 41 for (y = 0; y < map.Height; y++)
42 { 42 {
43 if (fillArea[x, y] == true) 43 if (fillArea[x, y])
44 { 44 {
45 map[x, y] += strength; 45 map[x, y] += strength;
46 } 46 }
@@ -50,4 +50,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
50 50
51 #endregion 51 #endregion
52 } 52 }
53} 53} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RevertArea.cs
index 45f2d83..198b309 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RevertArea.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/RevertArea.cs
@@ -31,7 +31,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
31{ 31{
32 public class RevertArea : ITerrainFloodEffect 32 public class RevertArea : ITerrainFloodEffect
33 { 33 {
34 ITerrainChannel m_revertmap; 34 private readonly ITerrainChannel m_revertmap;
35 35
36 public RevertArea(ITerrainChannel revertmap) 36 public RevertArea(ITerrainChannel revertmap)
37 { 37 {
@@ -47,7 +47,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
47 { 47 {
48 for (y = 0; y < map.Height; y++) 48 for (y = 0; y < map.Height; y++)
49 { 49 {
50 if (fillArea[x, y] == true) 50 if (fillArea[x, y])
51 { 51 {
52 map[x, y] = (map[x, y] * (1.0 - strength)) + (m_revertmap[x, y] * strength); 52 map[x, y] = (map[x, y] * (1.0 - strength)) + (m_revertmap[x, y] * strength);
53 } 53 }
@@ -57,4 +57,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
57 57
58 #endregion 58 #endregion
59 } 59 }
60} 60} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs
index ba4943d..49d8883 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/FloodBrushes/SmoothArea.cs
@@ -31,39 +31,6 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
31{ 31{
32 public class SmoothArea : ITerrainFloodEffect 32 public class SmoothArea : ITerrainFloodEffect
33 { 33 {
34 private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
35 {
36 int w = map.Width;
37 int h = map.Height;
38
39 if (x > w - 2.0)
40 x = w - 2.0;
41 if (y > h - 2.0)
42 y = h - 2.0;
43 if (x < 0.0)
44 x = 0.0;
45 if (y < 0.0)
46 y = 0.0;
47
48 int stepSize = 1;
49 double h00 = map[(int)x, (int)y];
50 double h10 = map[(int)x + stepSize, (int)y];
51 double h01 = map[(int)x, (int)y + stepSize];
52 double h11 = map[(int)x + stepSize, (int)y + stepSize];
53 double h1 = h00;
54 double h2 = h10;
55 double h3 = h01;
56 double h4 = h11;
57 double a00 = h1;
58 double a10 = h2 - h1;
59 double a01 = h3 - h1;
60 double a11 = h1 - h2 - h3 + h4;
61 double partialx = x - (int)x;
62 double partialz = y - (int)y;
63 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
64 return hi;
65 }
66
67 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
68 35
69 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength)
@@ -71,9 +38,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
71 double area = strength; 38 double area = strength;
72 double step = strength / 4.0; 39 double step = strength / 4.0;
73 40
74 double[,] manipulate = new double[map.Width, map.Height]; 41 double[,] manipulate = new double[map.Width,map.Height];
75 int x, y; 42 int x, y;
76 double n, l;
77 for (x = 0; x < map.Width; x++) 43 for (x = 0; x < map.Width; x++)
78 { 44 {
79 for (y = 0; y < map.Height; y++) 45 for (y = 0; y < map.Height; y++)
@@ -84,8 +50,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
84 double average = 0.0; 50 double average = 0.0;
85 int avgsteps = 0; 51 int avgsteps = 0;
86 52
53 double n;
87 for (n = 0.0 - area; n < area; n += step) 54 for (n = 0.0 - area; n < area; n += step)
88 { 55 {
56 double l;
89 for (l = 0.0 - area; l < area; l += step) 57 for (l = 0.0 - area; l < area; l += step)
90 { 58 {
91 avgsteps++; 59 avgsteps++;
@@ -109,5 +77,38 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FloodBrushes
109 } 77 }
110 78
111 #endregion 79 #endregion
80
81 private static double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
82 {
83 int w = map.Width;
84 int h = map.Height;
85
86 if (x > w - 2.0)
87 x = w - 2.0;
88 if (y > h - 2.0)
89 y = h - 2.0;
90 if (x < 0.0)
91 x = 0.0;
92 if (y < 0.0)
93 y = 0.0;
94
95 int stepSize = 1;
96 double h00 = map[(int) x, (int) y];
97 double h10 = map[(int) x + stepSize, (int) y];
98 double h01 = map[(int) x, (int) y + stepSize];
99 double h11 = map[(int) x + stepSize, (int) y + stepSize];
100 double h1 = h00;
101 double h2 = h10;
102 double h3 = h01;
103 double h4 = h11;
104 double a00 = h1;
105 double a10 = h2 - h1;
106 double a01 = h3 - h1;
107 double a11 = h1 - h2 - h3 + h4;
108 double partialx = x - (int) x;
109 double partialz = y - (int) y;
110 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
111 return hi;
112 }
112 } 113 }
113} 114} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs
index 5063e46..96e92f2 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainEffect.cs
@@ -33,4 +33,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain
33 { 33 {
34 void RunEffect(ITerrainChannel map); 34 void RunEffect(ITerrainChannel map);
35 } 35 }
36} 36} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs
index e866876..7d33bf8 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainFloodEffect.cs
@@ -25,8 +25,8 @@
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 OpenSim.Region.Environment.Interfaces;
29using System; 28using System;
29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain 31namespace OpenSim.Region.Environment.Modules.Terrain
32{ 32{
@@ -34,4 +34,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain
34 { 34 {
35 void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); 35 void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength);
36 } 36 }
37} 37} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs
index 2c391df..992ed1e 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainLoader.cs
@@ -35,4 +35,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain
35 ITerrainChannel LoadFile(string filename, int fileStartX, int fileStartY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight); 35 ITerrainChannel LoadFile(string filename, int fileStartX, int fileStartY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight);
36 void SaveFile(string filename, ITerrainChannel map); 36 void SaveFile(string filename, ITerrainChannel map);
37 } 37 }
38} 38} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainModule.cs
index 3d00b2d..9e79d17 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/ITerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainModule.cs
@@ -1,9 +1,8 @@
1using System; 1namespace OpenSim.Region.Environment.Modules.Terrain
2namespace OpenSim.Region.Environment.Modules.Terrain
3{ 2{
4 public interface ITerrainModule 3 public interface ITerrainModule
5 { 4 {
6 void LoadFromFile(string filename); 5 void LoadFromFile(string filename);
7 void SaveToFile(string filename); 6 void SaveToFile(string filename);
8 } 7 }
9} 8} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs b/OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs
index f2edff6..07fcb72 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/ITerrainPaintableEffect.cs
@@ -33,4 +33,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain
33 { 33 {
34 void PaintEffect(ITerrainChannel map, double x, double y, double strength, double duration); 34 void PaintEffect(ITerrainChannel map, double x, double y, double strength, double duration);
35 } 35 }
36} 36} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
index 96b5d52..763735f 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
@@ -26,20 +26,40 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
30using System.Drawing; 29using System.Drawing;
31using libsecondlife;
32using Nini.Config; 30using Nini.Config;
33using OpenSim.Framework; 31using OpenJPEGNet;
34using OpenSim.Region.Environment.Interfaces; 32using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes; 33using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.Environment.Modules.ModuleFramework;
37 34
38namespace OpenSim.Region.Environment.Modules.Terrain 35namespace OpenSim.Region.Environment.Modules.Terrain
39{ 36{
40 class MapImageModule : IMapImageGenerator, IRegionModule 37 internal class MapImageModule : IMapImageGenerator, IRegionModule
41 { 38 {
42 private Scene m_scene; 39 private Scene m_scene;
40
41 #region IMapImageGenerator Members
42
43 public byte[] WriteJpeg2000Image(string gradientmap)
44 {
45 byte[] imageData = null;
46
47 Bitmap bmp = TerrainToBitmap(gradientmap);
48
49 try
50 {
51 imageData = OpenJPEG.EncodeFromImage(bmp, true);
52 }
53 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
54 {
55 Console.WriteLine("Failed generating terrain map: " + e);
56 }
57
58 return imageData;
59 }
60
61 #endregion
62
43 #region IRegionModule Members 63 #region IRegionModule Members
44 64
45 public void Initialise(Scene scene, IConfigSource source) 65 public void Initialise(Scene scene, IConfigSource source)
@@ -66,24 +86,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
66 get { return false; } 86 get { return false; }
67 } 87 }
68 88
69 89 #endregion
70 public byte[] WriteJpeg2000Image(string gradientmap)
71 {
72 byte[] imageData = null;
73
74 Bitmap bmp = TerrainToBitmap(gradientmap);
75
76 try
77 {
78 imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true);
79 }
80 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
81 {
82 Console.WriteLine("Failed generating terrain map: " + e.ToString());
83 }
84
85 return imageData;
86 }
87 90
88 private void ShadeBuildings(ref Bitmap map) 91 private void ShadeBuildings(ref Bitmap map)
89 { 92 {
@@ -95,18 +98,20 @@ namespace OpenSim.Region.Environment.Modules.Terrain
95 { 98 {
96 if (entity is SceneObjectGroup) 99 if (entity is SceneObjectGroup)
97 { 100 {
98 SceneObjectGroup sog = (SceneObjectGroup)entity; 101 SceneObjectGroup sog = (SceneObjectGroup) entity;
99 102
100 foreach (SceneObjectPart primitive in sog.Children.Values) 103 foreach (SceneObjectPart primitive in sog.Children.Values)
101 { 104 {
102 int x, y, w, h, dx, dy; 105 int x, y, w, h;
103 x = (int)(primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); 106 x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
104 y = (int)(primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); 107 y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
105 w = (int)primitive.Scale.X; 108 w = (int) primitive.Scale.X;
106 h = (int)primitive.Scale.Y; 109 h = (int) primitive.Scale.Y;
107 110
111 int dx;
108 for (dx = x; dx < x + w; dx++) 112 for (dx = x; dx < x + w; dx++)
109 { 113 {
114 int dy;
110 for (dy = y; dy < y + h; dy++) 115 for (dy = y; dy < y + h; dy++)
111 { 116 {
112 if (x < 0 || y < 0) 117 if (x < 0 || y < 0)
@@ -117,8 +122,6 @@ namespace OpenSim.Region.Environment.Modules.Terrain
117 map.SetPixel(dx, dy, Color.DarkGray); 122 map.SetPixel(dx, dy, Color.DarkGray);
118 } 123 }
119 } 124 }
120
121
122 } 125 }
123 } 126 }
124 } 127 }
@@ -148,7 +151,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
148 for (int x = 0; x < copy.Width; x++) 151 for (int x = 0; x < copy.Width; x++)
149 { 152 {
150 // 512 is the largest possible height before colours clamp 153 // 512 is the largest possible height before colours clamp
151 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));
152 155
153 // Handle error conditions 156 // Handle error conditions
154 if (colorindex > pallete - 1 || colorindex < 0) 157 if (colorindex > pallete - 1 || colorindex < 0)
@@ -161,7 +164,5 @@ namespace OpenSim.Region.Environment.Modules.Terrain
161 return bmp; 164 return bmp;
162 } 165 }
163 } 166 }
164
165 #endregion
166 } 167 }
167} 168} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs
index a8942dc..cfb1f60 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/ErodeSphere.cs
@@ -25,8 +25,8 @@
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 OpenSim.Region.Environment.Interfaces;
29using System; 28using System;
29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes 31namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
32{ 32{
@@ -35,18 +35,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
35 /// </summary> 35 /// </summary>
36 public class ErodeSphere : ITerrainPaintableEffect 36 public class ErodeSphere : ITerrainPaintableEffect
37 { 37 {
38 NeighbourSystem type = NeighbourSystem.Moore; // Parameter 38 private double rainHeight = 0.2;
39 39 private int rounds = 10;
40 double rainHeight = 0.2; 40 private NeighbourSystem type = NeighbourSystem.Moore; // Parameter
41 int rounds = 10; 41 private double waterSaturation = 0.30; // Can carry 1% of water in height
42 double waterSaturation = 0.30; // Can carry 1% of water in height
43 42
44 #region Supporting Functions 43 #region Supporting Functions
45 private enum NeighbourSystem
46 {
47 Moore,
48 VonNeumann
49 } ;
50 44
51 private int[] Neighbours(NeighbourSystem type, int index) 45 private int[] Neighbours(NeighbourSystem type, int index)
52 { 46 {
@@ -146,6 +140,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
146 return coord; 140 return coord;
147 } 141 }
148 142
143 private enum NeighbourSystem
144 {
145 Moore,
146 VonNeumann
147 } ;
148
149 #endregion 149 #endregion
150 150
151 #region ITerrainPaintableEffect Members 151 #region ITerrainPaintableEffect Members
@@ -266,7 +266,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
266 // Calculate how much water we can move 266 // Calculate how much water we can move
267 double waterMin = Math.Min(water[x, y], altitudeDelta); 267 double waterMin = Math.Min(water[x, y], altitudeDelta);
268 double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]]) 268 double waterDelta = waterMin * ((water[coords[0], coords[1]] + map[coords[0], coords[1]])
269 / altitudeTotal); 269 / altitudeTotal);
270 270
271 double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]); 271 double sedimentDelta = sediment[x, y] * (waterDelta / water[x, y]);
272 272
@@ -309,4 +309,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
309 309
310 #endregion 310 #endregion
311 } 311 }
312} 312} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
index 9bfb981..d907ed2 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/FlattenSphere.cs
@@ -31,12 +31,6 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
31{ 31{
32 public class FlattenSphere : ITerrainPaintableEffect 32 public class FlattenSphere : ITerrainPaintableEffect
33 { 33 {
34 private double SphericalFactor(double x, double y, double rx, double ry, double size)
35 {
36 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
37 return z;
38 }
39
40// TODO: unused 34// TODO: unused
41// private double GetBilinearInterpolate(double x, double y, ITerrainChannel map) 35// private double GetBilinearInterpolate(double x, double y, ITerrainChannel map)
42// { 36// {
@@ -78,7 +72,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
78 strength = TerrainUtil.MetersToSphericalStrength(strength); 72 strength = TerrainUtil.MetersToSphericalStrength(strength);
79 73
80 int x, y; 74 int x, y;
81 double[,] tweak = new double[map.Width, map.Height]; 75 double[,] tweak = new double[map.Width,map.Height];
82 76
83 double area = strength; 77 double area = strength;
84 double step = strength / 4.0; 78 double step = strength / 4.0;
@@ -123,5 +117,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
123 } 117 }
124 118
125 #endregion 119 #endregion
120
121 private double SphericalFactor(double x, double y, double rx, double ry, double size)
122 {
123 double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
124 return z;
125 }
126 } 126 }
127} 127} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
index 9185b5d..ead1a49 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/LowerSphere.cs
@@ -64,4 +64,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
64 64
65 #endregion 65 #endregion
66 } 66 }
67} 67} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
index 9b45b34..e3babbf 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/NoiseSphere.cs
@@ -57,7 +57,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
57 z *= z; 57 z *= z;
58 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); 58 z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry));
59 59
60 double noise = TerrainUtil.PerlinNoise2D((double)x / (double)Framework.Constants.RegionSize, (double)y / (double)Framework.Constants.RegionSize, 8, 1.0); 60 double noise = TerrainUtil.PerlinNoise2D((double) x / (double) Constants.RegionSize, (double) y / (double) Constants.RegionSize, 8, 1.0);
61 61
62 if (z > 0.0) 62 if (z > 0.0)
63 map[x, y] += noise * z * duration; 63 map[x, y] += noise * z * duration;
@@ -67,4 +67,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
67 67
68 #endregion 68 #endregion
69 } 69 }
70} 70} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
index 23dea8a..153fc15 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/OlsenSphere.cs
@@ -25,8 +25,8 @@
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 OpenSim.Region.Environment.Interfaces;
29using System; 28using System;
29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes 31namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
32{ 32{
@@ -38,16 +38,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
38 /// </summary> 38 /// </summary>
39 public class OlsenSphere : ITerrainPaintableEffect 39 public class OlsenSphere : ITerrainPaintableEffect
40 { 40 {
41 NeighbourSystem type = NeighbourSystem.Moore; // Parameter 41 private double nConst = 1024.0;
42 42 private NeighbourSystem type = NeighbourSystem.Moore; // Parameter
43 double nConst = 1024.0;
44 43
45 #region Supporting Functions 44 #region Supporting Functions
46 private enum NeighbourSystem
47 {
48 Moore,
49 VonNeumann
50 } ;
51 45
52 private int[] Neighbours(NeighbourSystem type, int index) 46 private int[] Neighbours(NeighbourSystem type, int index)
53 { 47 {
@@ -153,6 +147,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
153 return z; 147 return z;
154 } 148 }
155 149
150 private enum NeighbourSystem
151 {
152 Moore,
153 VonNeumann
154 } ;
155
156 #endregion 156 #endregion
157 157
158 #region ITerrainPaintableEffect Members 158 #region ITerrainPaintableEffect Members
@@ -222,4 +222,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
222 222
223 #endregion 223 #endregion
224 } 224 }
225} 225} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
index f90c407..8d61a7e 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RaiseSphere.cs
@@ -64,4 +64,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
64 64
65 #endregion 65 #endregion
66 } 66 }
67} 67} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs
index 382c756..ee0edb5 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/RevertSphere.cs
@@ -32,7 +32,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
32{ 32{
33 public class RevertSphere : ITerrainPaintableEffect 33 public class RevertSphere : ITerrainPaintableEffect
34 { 34 {
35 ITerrainChannel m_revertmap; 35 private ITerrainChannel m_revertmap;
36 36
37 public RevertSphere(ITerrainChannel revertmap) 37 public RevertSphere(ITerrainChannel revertmap)
38 { 38 {
@@ -79,4 +79,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
79 79
80 #endregion 80 #endregion
81 } 81 }
82} 82} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
index db5fb72..86a01cc 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/SmoothSphere.cs
@@ -38,24 +38,24 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
38 strength = TerrainUtil.MetersToSphericalStrength(strength); 38 strength = TerrainUtil.MetersToSphericalStrength(strength);
39 39
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; 43 double n, l;
44 double area = strength; 44 double area = strength;
45 double step = strength / 4.0; 45 double step = strength / 4.0;
46 46
47 // compute delta map 47 // compute delta map
48 for (x = 0; x < map.Width; x++) 48 for (x = 0; x < map.Width; x++)
49 { 49 {
50 for (y = 0; y < map.Height; y++) 50 for (y = 0; y < map.Height; y++)
51 { 51 {
52 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 52 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
53 53
54 if (z > 0) // add in non-zero amount 54 if (z > 0) // add in non-zero amount
55 { 55 {
56 double average = 0.0; 56 double average = 0.0;
57 int avgsteps = 0; 57 int avgsteps = 0;
58 58
59 for (n = 0.0 - area; n < area; n += step) 59 for (n = 0.0 - area; n < area; n += step)
60 { 60 {
61 for (l = 0.0 - area; l < area; l += step) 61 for (l = 0.0 - area; l < area; l += step)
@@ -74,7 +74,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
74 for (y = 0; y < map.Height; y++) 74 for (y = 0; y < map.Height; y++)
75 { 75 {
76 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 76 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
77 77
78 if (z > 0) // add in non-zero amount 78 if (z > 0) // add in non-zero amount
79 { 79 {
80 double da = z; 80 double da = z;
@@ -90,4 +90,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
90 90
91 #endregion 91 #endregion
92 } 92 }
93} 93} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
index 79c9c63..f46ba8f 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/PaintBrushes/WeatherSphere.cs
@@ -34,15 +34,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
34 /// </summary> 34 /// </summary>
35 public class WeatherSphere : ITerrainPaintableEffect 35 public class WeatherSphere : ITerrainPaintableEffect
36 { 36 {
37 NeighbourSystem type = NeighbourSystem.Moore; // Parameter 37 private double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required.
38 double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required. 38 private NeighbourSystem type = NeighbourSystem.Moore; // Parameter
39 39
40 #region Supporting Functions 40 #region Supporting Functions
41 private enum NeighbourSystem
42 {
43 Moore,
44 VonNeumann
45 } ;
46 41
47 private int[] Neighbours(NeighbourSystem type, int index) 42 private int[] Neighbours(NeighbourSystem type, int index)
48 { 43 {
@@ -142,6 +137,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
142 return coord; 137 return coord;
143 } 138 }
144 139
140 private enum NeighbourSystem
141 {
142 Moore,
143 VonNeumann
144 } ;
145
145 #endregion 146 #endregion
146 147
147 #region ITerrainPaintableEffect Members 148 #region ITerrainPaintableEffect Members
@@ -203,4 +204,4 @@ namespace OpenSim.Region.Environment.Modules.Terrain.PaintBrushes
203 204
204 #endregion 205 #endregion
205 } 206 }
206} 207} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs
index 01f6bdf..1344715 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainChannel.cs
@@ -35,34 +35,70 @@ namespace OpenSim.Region.Environment.Modules.Terrain
35 /// </summary> 35 /// </summary>
36 public class TerrainChannel : ITerrainChannel 36 public class TerrainChannel : ITerrainChannel
37 { 37 {
38 private readonly bool[,] taint;
38 private double[,] map; 39 private double[,] map;
39 private bool[,] taint;
40 40
41 public int Width 41 public TerrainChannel()
42 { 42 {
43 get { return map.GetLength(0); } 43 map = new double[Constants.RegionSize,Constants.RegionSize];
44 taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16];
45
46 int x;
47 for (x = 0; x < Constants.RegionSize; x++)
48 {
49 int y;
50 for (y = 0; y < Constants.RegionSize; y++)
51 {
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;
54 if (map[x, y] < spherFac)
55 {
56 map[x, y] = spherFac;
57 }
58 }
59 }
44 } 60 }
45 61
46 public int Height 62 public TerrainChannel(double[,] import)
47 { 63 {
48 get { return map.GetLength(1); } 64 map = import;
65 taint = new bool[import.GetLength(0),import.GetLength(1)];
49 } 66 }
50 67
51 public TerrainChannel Copy() 68 public TerrainChannel(bool createMap)
52 { 69 {
53 TerrainChannel copy = new TerrainChannel(false); 70 if (createMap)
54 copy.map = (double[,])this.map.Clone(); 71 {
72 map = new double[Constants.RegionSize,Constants.RegionSize];
73 taint = new bool[Constants.RegionSize / 16,Constants.RegionSize / 16];
74 }
75 }
55 76
56 return copy; 77 public TerrainChannel(int w, int h)
78 {
79 map = new double[w,h];
80 taint = new bool[w / 16,h / 16];
81 }
82
83 #region ITerrainChannel Members
84
85 public int Width
86 {
87 get { return map.GetLength(0); }
88 }
89
90 public int Height
91 {
92 get { return map.GetLength(1); }
57 } 93 }
58 94
59 public ITerrainChannel MakeCopy() 95 public ITerrainChannel MakeCopy()
60 { 96 {
61 TerrainChannel copy = new TerrainChannel(false); 97 TerrainChannel copy = new TerrainChannel(false);
62 copy.map = (double[,])this.map.Clone(); 98 copy.map = (double[,]) map.Clone();
63 99
64 return copy; 100 return copy;
65 } 101 }
66 102
67 public float[] GetFloatsSerialised() 103 public float[] GetFloatsSerialised()
68 { 104 {
@@ -71,7 +107,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
71 107
72 for (i = 0; i < Width * Height; i++) 108 for (i = 0; i < Width * Height; i++)
73 { 109 {
74 heights[i] = (float)map[i % Width, i / Width]; 110 heights[i] = (float) map[i % Width, i / Width];
75 } 111 }
76 112
77 return heights; 113 return heights;
@@ -84,10 +120,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
84 120
85 public double this[int x, int y] 121 public double this[int x, int y]
86 { 122 {
87 get 123 get { return map[x, y]; }
88 {
89 return map[x, y];
90 }
91 set 124 set
92 { 125 {
93 if (map[x, y] != value) 126 if (map[x, y] != value)
@@ -100,7 +133,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
100 133
101 public bool Tainted(int x, int y) 134 public bool Tainted(int x, int y)
102 { 135 {
103 if (taint[x / 16, y / 16] != false) 136 if (taint[x / 16, y / 16])
104 { 137 {
105 taint[x / 16, y / 16] = false; 138 taint[x / 16, y / 16] = false;
106 return true; 139 return true;
@@ -111,45 +144,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain
111 } 144 }
112 } 145 }
113 146
114 public TerrainChannel() 147 #endregion
115 {
116 map = new double[Constants.RegionSize, Constants.RegionSize];
117 taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16];
118 148
119 int x, y; 149 public TerrainChannel Copy()
120 for (x = 0; x < Constants.RegionSize; x++)
121 {
122 for (y = 0; y < Constants.RegionSize; y++)
123 {
124 map[x, y] = TerrainUtil.PerlinNoise2D(x, y, 3, 0.25) * 10;
125 double spherFac = TerrainUtil.SphericalFactor(x, y, Constants.RegionSize / 2, Constants.RegionSize / 2, 50) * 0.01;
126 if (map[x, y] < spherFac)
127 {
128 map[x, y] = spherFac;
129 }
130 }
131 }
132 }
133
134 public TerrainChannel(double[,] import)
135 {
136 map = import;
137 taint = new bool[import.GetLength(0), import.GetLength(1)];
138 }
139
140 public TerrainChannel(bool createMap)
141 { 150 {
142 if (createMap) 151 TerrainChannel copy = new TerrainChannel(false);
143 { 152 copy.map = (double[,]) map.Clone();
144 map = new double[Constants.RegionSize, Constants.RegionSize];
145 taint = new bool[Constants.RegionSize / 16, Constants.RegionSize / 16];
146 }
147 }
148 153
149 public TerrainChannel(int w, int h) 154 return copy;
150 {
151 map = new double[w, h];
152 taint = new bool[w / 16, h / 16];
153 } 155 }
154 } 156 }
155} 157} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
index 27bfb36..987c3d0 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
@@ -27,18 +27,29 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing; 30using System.IO;
31using System.Reflection;
31using libsecondlife; 32using libsecondlife;
33using log4net;
32using Nini.Config; 34using Nini.Config;
33using OpenSim.Framework; 35using OpenSim.Framework;
34using OpenSim.Region.Environment.Interfaces; 36using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.Environment.Modules.ModuleFramework; 37using OpenSim.Region.Environment.Modules.ModuleFramework;
38using OpenSim.Region.Environment.Modules.Terrain.Effects;
39using OpenSim.Region.Environment.Modules.Terrain.FileLoaders;
40using OpenSim.Region.Environment.Modules.Terrain.FloodBrushes;
41using OpenSim.Region.Environment.Modules.Terrain.PaintBrushes;
42using OpenSim.Region.Environment.Scenes;
37 43
38namespace OpenSim.Region.Environment.Modules.Terrain 44namespace OpenSim.Region.Environment.Modules.Terrain
39{ 45{
40 public class TerrainModule : IRegionModule, ICommandableModule, OpenSim.Region.Environment.Modules.Terrain.ITerrainModule 46 public class TerrainModule : IRegionModule, ICommandableModule, ITerrainModule
41 { 47 {
48 #region StandardTerrainEffects enum
49
50 /// <summary>
51 /// A standard set of terrain brushes and effects recognised by viewers
52 /// </summary>
42 public enum StandardTerrainEffects : byte 53 public enum StandardTerrainEffects : byte
43 { 54 {
44 Flatten = 0, 55 Flatten = 0,
@@ -54,68 +65,100 @@ namespace OpenSim.Region.Environment.Modules.Terrain
54 Olsen = 253 65 Olsen = 253
55 } 66 }
56 67
57 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 68 #endregion
58 69
59 private Commander m_commander = new Commander("Terrain"); 70 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
60 71
61 private Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = 72 private readonly Commander m_commander = new Commander("Terrain");
62 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); 73
63 private Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects = 74 private readonly Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects =
64 new Dictionary<StandardTerrainEffects, ITerrainFloodEffect>(); 75 new Dictionary<StandardTerrainEffects, ITerrainFloodEffect>();
65 private Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>();
66 Scene m_scene;
67 ITerrainChannel m_channel;
68 ITerrainChannel m_revert;
69 bool m_tainted = false;
70 private IConfigSource m_gConfig;
71 76
72 private void InstallDefaultEffects() 77 private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>();
73 {
74 // Draggable Paint Brush Effects
75 m_painteffects[StandardTerrainEffects.Raise] = new PaintBrushes.RaiseSphere();
76 m_painteffects[StandardTerrainEffects.Lower] = new PaintBrushes.LowerSphere();
77 m_painteffects[StandardTerrainEffects.Smooth] = new PaintBrushes.SmoothSphere();
78 m_painteffects[StandardTerrainEffects.Noise] = new PaintBrushes.NoiseSphere();
79 m_painteffects[StandardTerrainEffects.Flatten] = new PaintBrushes.FlattenSphere();
80 m_painteffects[StandardTerrainEffects.Revert] = new PaintBrushes.RevertSphere(m_revert);
81 m_painteffects[StandardTerrainEffects.Erode] = new PaintBrushes.ErodeSphere();
82 m_painteffects[StandardTerrainEffects.Weather] = new PaintBrushes.WeatherSphere();
83 m_painteffects[StandardTerrainEffects.Olsen] = new PaintBrushes.OlsenSphere();
84 78
85 // Area of effect selection effects 79 private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects =
86 m_floodeffects[StandardTerrainEffects.Raise] = new FloodBrushes.RaiseArea(); 80 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
87 m_floodeffects[StandardTerrainEffects.Lower] = new FloodBrushes.LowerArea();
88 m_floodeffects[StandardTerrainEffects.Smooth] = new FloodBrushes.SmoothArea();
89 m_floodeffects[StandardTerrainEffects.Noise] = new FloodBrushes.NoiseArea();
90 m_floodeffects[StandardTerrainEffects.Flatten] = new FloodBrushes.FlattenArea();
91 m_floodeffects[StandardTerrainEffects.Revert] = new FloodBrushes.RevertArea(m_revert);
92 81
93 // Filesystem load/save loaders 82 private ITerrainChannel m_channel;
94 m_loaders[".r32"] = new FileLoaders.RAW32(); 83 private ITerrainChannel m_revert;
95 m_loaders[".f32"] = m_loaders[".r32"]; 84 private Scene m_scene;
96 m_loaders[".ter"] = new FileLoaders.Terragen(); 85 private bool m_tainted = false;
97 m_loaders[".raw"] = new FileLoaders.LLRAW(); 86
98 m_loaders[".jpg"] = new FileLoaders.JPEG(); 87 #region ICommandableModule Members
99 m_loaders[".jpeg"] = m_loaders[".jpg"]; 88
100 m_loaders[".bmp"] = new FileLoaders.BMP(); 89 public ICommander CommandInterface
101 m_loaders[".png"] = new FileLoaders.PNG(); 90 {
102 m_loaders[".gif"] = new FileLoaders.GIF(); 91 get { return m_commander; }
103 m_loaders[".tif"] = new FileLoaders.TIFF();
104 m_loaders[".tiff"] = m_loaders[".tif"];
105 } 92 }
106 93
107 public void UpdateRevertMap() 94 #endregion
95
96 #region IRegionModule Members
97
98 /// <summary>
99 /// Creates and initialises a terrain module for a region
100 /// </summary>
101 /// <param name="scene">Region initialising</param>
102 /// <param name="config">Config for the region</param>
103 public void Initialise(Scene scene, IConfigSource config)
108 { 104 {
109 int x, y; 105 m_scene = scene;
110 for (x = 0; x < m_channel.Width; x++) 106
107 // Install terrain module in the simulator
108 if (m_scene.Heightmap == null)
111 { 109 {
112 for (y = 0; y < m_channel.Height; y++) 110 lock (m_scene)
113 { 111 {
114 m_revert[x, y] = m_channel[x, y]; 112 m_channel = new TerrainChannel();
113 m_scene.Heightmap = m_channel;
114 m_revert = new TerrainChannel();
115 UpdateRevertMap();
115 } 116 }
116 } 117 }
118 else
119 {
120 m_channel = m_scene.Heightmap;
121 m_revert = new TerrainChannel();
122 UpdateRevertMap();
123 }
124
125 m_scene.RegisterModuleInterface<ITerrainModule>(this);
126 m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
127 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
128 m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick;
129 }
130
131 /// <summary>
132 /// Enables terrain module when called
133 /// </summary>
134 public void PostInitialise()
135 {
136 InstallDefaultEffects();
137 InstallInterfaces();
138 }
139
140 public void Close()
141 {
142 }
143
144 public string Name
145 {
146 get { return "TerrainModule"; }
117 } 147 }
118 148
149 public bool IsSharedModule
150 {
151 get { return false; }
152 }
153
154 #endregion
155
156 #region ITerrainModule Members
157
158 /// <summary>
159 /// Loads a terrain file from disk and installs it in the scene.
160 /// </summary>
161 /// <param name="filename">Filename to terrain file. Type is determined by extension.</param>
119 public void LoadFromFile(string filename) 162 public void LoadFromFile(string filename)
120 { 163 {
121 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) 164 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
@@ -133,12 +176,14 @@ namespace OpenSim.Region.Environment.Modules.Terrain
133 } 176 }
134 catch (NotImplementedException) 177 catch (NotImplementedException)
135 { 178 {
136 m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value.ToString() + " parser does not support file loading. (May be save only)"); 179 m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value +
180 " parser does not support file loading. (May be save only)");
137 return; 181 return;
138 } 182 }
139 catch (System.IO.FileNotFoundException) 183 catch (FileNotFoundException)
140 { 184 {
141 m_log.Error("[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)"); 185 m_log.Error(
186 "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)");
142 return; 187 return;
143 } 188 }
144 } 189 }
@@ -149,10 +194,97 @@ namespace OpenSim.Region.Environment.Modules.Terrain
149 m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format."); 194 m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format.");
150 } 195 }
151 196
197 /// <summary>
198 /// Saves the current heightmap to a specified file.
199 /// </summary>
200 /// <param name="filename">The destination filename</param>
201 public void SaveToFile(string filename)
202 {
203 try
204 {
205 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
206 {
207 if (filename.EndsWith(loader.Key))
208 {
209 loader.Value.SaveFile(filename, m_channel);
210 return;
211 }
212 }
213 }
214 catch (NotImplementedException)
215 {
216 m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented.");
217 }
218 }
219
220 #endregion
221
222 /// <summary>
223 /// Installs into terrain module the standard suite of brushes
224 /// </summary>
225 private void InstallDefaultEffects()
226 {
227 // Draggable Paint Brush Effects
228 m_painteffects[StandardTerrainEffects.Raise] = new RaiseSphere();
229 m_painteffects[StandardTerrainEffects.Lower] = new LowerSphere();
230 m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere();
231 m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere();
232 m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere();
233 m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_revert);
234 m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere();
235 m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere();
236 m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere();
237
238 // Area of effect selection effects
239 m_floodeffects[StandardTerrainEffects.Raise] = new RaiseArea();
240 m_floodeffects[StandardTerrainEffects.Lower] = new LowerArea();
241 m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea();
242 m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea();
243 m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea();
244 m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert);
245
246 // Filesystem load/save loaders
247 m_loaders[".r32"] = new RAW32();
248 m_loaders[".f32"] = m_loaders[".r32"];
249 m_loaders[".ter"] = new Terragen();
250 m_loaders[".raw"] = new LLRAW();
251 m_loaders[".jpg"] = new JPEG();
252 m_loaders[".jpeg"] = m_loaders[".jpg"];
253 m_loaders[".bmp"] = new BMP();
254 m_loaders[".png"] = new PNG();
255 m_loaders[".gif"] = new GIF();
256 m_loaders[".tif"] = new TIFF();
257 m_loaders[".tiff"] = m_loaders[".tif"];
258 }
259
260 /// <summary>
261 /// Saves the current state of the region into the revert map buffer.
262 /// </summary>
263 public void UpdateRevertMap()
264 {
265 int x;
266 for (x = 0; x < m_channel.Width; x++)
267 {
268 int y;
269 for (y = 0; y < m_channel.Height; y++)
270 {
271 m_revert[x, y] = m_channel[x, y];
272 }
273 }
274 }
275
276 /// <summary>
277 /// Loads a tile from a larger terrain file and installs it into the region.
278 /// </summary>
279 /// <param name="filename">The terrain file to load</param>
280 /// <param name="fileWidth">The width of the file in units</param>
281 /// <param name="fileHeight">The height of the file in units</param>
282 /// <param name="fileStartX">Where to begin our slice</param>
283 /// <param name="fileStartY">Where to begin our slice</param>
152 public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY) 284 public void LoadFromFile(string filename, int fileWidth, int fileHeight, int fileStartX, int fileStartY)
153 { 285 {
154 int offsetX = (int)m_scene.RegionInfo.RegionLocX - fileStartX; 286 int offsetX = (int) m_scene.RegionInfo.RegionLocX - fileStartX;
155 int offsetY = (int)m_scene.RegionInfo.RegionLocY - fileStartY; 287 int offsetY = (int) m_scene.RegionInfo.RegionLocY - fileStartY;
156 288
157 if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight) 289 if (offsetX >= 0 && offsetX < fileWidth && offsetY >= 0 && offsetY < fileHeight)
158 { 290 {
@@ -164,7 +296,9 @@ namespace OpenSim.Region.Environment.Modules.Terrain
164 lock (m_scene) 296 lock (m_scene)
165 { 297 {
166 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY, 298 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY,
167 fileWidth, fileHeight, (int)Constants.RegionSize, (int)Constants.RegionSize); 299 fileWidth, fileHeight,
300 (int) Constants.RegionSize,
301 (int) Constants.RegionSize);
168 m_scene.Heightmap = channel; 302 m_scene.Heightmap = channel;
169 m_channel = channel; 303 m_channel = channel;
170 UpdateRevertMap(); 304 UpdateRevertMap();
@@ -175,61 +309,137 @@ namespace OpenSim.Region.Environment.Modules.Terrain
175 } 309 }
176 } 310 }
177 311
178 public void SaveToFile(string filename) 312 /// <summary>
313 /// Performs updates to the region periodically, synchronising physics and other heightmap aware sections
314 /// </summary>
315 private void EventManager_OnTerrainTick()
179 { 316 {
180 try 317 if (m_tainted)
181 { 318 {
182 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) 319 m_tainted = false;
183 { 320 m_scene.PhysicsScene.SetTerrain(m_channel.GetFloatsSerialised());
184 if (filename.EndsWith(loader.Key)) 321 m_scene.SaveTerrain();
185 { 322 m_scene.CreateTerrainTexture(true);
186 loader.Value.SaveFile(filename, m_channel);
187 return;
188 }
189 }
190 } 323 }
191 catch (NotImplementedException) 324 }
325
326 /// <summary>
327 /// Processes commandline input. Do not call directly.
328 /// </summary>
329 /// <param name="args">Commandline arguments</param>
330 private void EventManager_OnPluginConsole(string[] args)
331 {
332 if (args[0] == "terrain")
192 { 333 {
193 m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented."); 334 string[] tmpArgs = new string[args.Length - 2];
335 int i;
336 for (i = 2; i < args.Length; i++)
337 tmpArgs[i - 2] = args[i];
338
339 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
194 } 340 }
195 } 341 }
196 342
197 public void Initialise(Scene scene, IConfigSource config) 343 /// <summary>
344 /// Installs terrain brush hook to IClientAPI
345 /// </summary>
346 /// <param name="client"></param>
347 private void EventManager_OnNewClient(IClientAPI client)
198 { 348 {
199 m_scene = scene; 349 client.OnModifyTerrain += client_OnModifyTerrain;
200 m_gConfig = config; 350 }
201 351
202 // Install terrain module in the simulator 352 /// <summary>
203 if (m_scene.Heightmap == null) 353 /// Checks to see if the terrain has been modified since last check
354 /// </summary>
355 private void CheckForTerrainUpdates()
356 {
357 bool shouldTaint = false;
358 float[] serialised = m_channel.GetFloatsSerialised();
359 int x;
360 for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize)
204 { 361 {
205 lock (m_scene) 362 int y;
363 for (y = 0; y < m_channel.Height; y += Constants.TerrainPatchSize)
206 { 364 {
207 m_channel = new TerrainChannel(); 365 if (m_channel.Tainted(x, y))
208 m_scene.Heightmap = m_channel; 366 {
209 m_revert = new TerrainChannel(); 367 SendToClients(serialised, x, y);
210 UpdateRevertMap(); 368 shouldTaint = true;
369 }
211 } 370 }
212 } 371 }
213 else 372 if (shouldTaint)
214 { 373 {
215 m_channel = m_scene.Heightmap; 374 m_tainted = true;
216 m_revert = new TerrainChannel();
217 UpdateRevertMap();
218 } 375 }
376 }
219 377
220 m_scene.RegisterModuleInterface<ITerrainModule>(this); 378 /// <summary>
221 m_scene.EventManager.OnNewClient += EventManager_OnNewClient; 379 /// Sends a copy of the current terrain to the scenes clients
222 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; 380 /// </summary>
223 m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick; 381 /// <param name="serialised">A copy of the terrain as a 1D float array of size w*h</param>
382 /// <param name="x">The patch corner to send</param>
383 /// <param name="y">The patch corner to send</param>
384 private void SendToClients(float[] serialised, int x, int y)
385 {
386 m_scene.ForEachClient(
387 delegate(IClientAPI controller) { controller.SendLayerData(x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised); });
224 } 388 }
225 389
226 void EventManager_OnTerrainTick() 390 private void client_OnModifyTerrain(float height, float seconds, byte size, byte action, float north, float west,
391 float south, float east, IClientAPI remoteClient)
227 { 392 {
228 if (m_tainted) 393 // Not a good permissions check, if in area mode, need to check the entire area.
394 if (m_scene.PermissionsMngr.CanTerraform(remoteClient.AgentId, new LLVector3(north, west, 0)))
229 { 395 {
230 m_tainted = false; 396 if (north == south && east == west)
231 m_scene.PhysicsScene.SetTerrain(m_channel.GetFloatsSerialised()); 397 {
232 m_scene.SaveTerrain(); 398 if (m_painteffects.ContainsKey((StandardTerrainEffects) action))
399 {
400 m_painteffects[(StandardTerrainEffects) action].PaintEffect(
401 m_channel, west, south, size, seconds);
402
403 CheckForTerrainUpdates();
404 }
405 else
406 {
407 m_log.Debug("Unknown terrain brush type " + action);
408 }
409 }
410 else
411 {
412 if (m_floodeffects.ContainsKey((StandardTerrainEffects) action))
413 {
414 bool[,] fillArea = new bool[m_channel.Width,m_channel.Height];
415 fillArea.Initialize();
416
417 int x;
418 for (x = 0; x < m_channel.Width; x++)
419 {
420 int y;
421 for (y = 0; y < m_channel.Height; y++)
422 {
423 if (x < east && x > west)
424 {
425 if (y < north && y > south)
426 {
427 fillArea[x, y] = true;
428 }
429 }
430 }
431 }
432
433 m_floodeffects[(StandardTerrainEffects) action].FloodEffect(
434 m_channel, fillArea, size);
435
436 CheckForTerrainUpdates();
437 }
438 else
439 {
440 m_log.Debug("Unknown terrain flood type " + action);
441 }
442 }
233 } 443 }
234 } 444 }
235 445
@@ -237,23 +447,23 @@ namespace OpenSim.Region.Environment.Modules.Terrain
237 447
238 private void InterfaceLoadFile(Object[] args) 448 private void InterfaceLoadFile(Object[] args)
239 { 449 {
240 LoadFromFile((string)args[0]); 450 LoadFromFile((string) args[0]);
241 CheckForTerrainUpdates(); 451 CheckForTerrainUpdates();
242 } 452 }
243 453
244 private void InterfaceLoadTileFile(Object[] args) 454 private void InterfaceLoadTileFile(Object[] args)
245 { 455 {
246 LoadFromFile((string)args[0], 456 LoadFromFile((string) args[0],
247 (int)args[1], 457 (int) args[1],
248 (int)args[2], 458 (int) args[2],
249 (int)args[3], 459 (int) args[3],
250 (int)args[4]); 460 (int) args[4]);
251 CheckForTerrainUpdates(); 461 CheckForTerrainUpdates();
252 } 462 }
253 463
254 private void InterfaceSaveFile(Object[] args) 464 private void InterfaceSaveFile(Object[] args)
255 { 465 {
256 SaveToFile((string)args[0]); 466 SaveToFile((string) args[0]);
257 } 467 }
258 468
259 private void InterfaceBakeTerrain(Object[] args) 469 private void InterfaceBakeTerrain(Object[] args)
@@ -276,7 +486,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
276 int x, y; 486 int x, y;
277 for (x = 0; x < m_channel.Width; x++) 487 for (x = 0; x < m_channel.Width; x++)
278 for (y = 0; y < m_channel.Height; y++) 488 for (y = 0; y < m_channel.Height; y++)
279 m_channel[x, y] += (double)args[0]; 489 m_channel[x, y] += (double) args[0];
280 CheckForTerrainUpdates(); 490 CheckForTerrainUpdates();
281 } 491 }
282 492
@@ -285,7 +495,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
285 int x, y; 495 int x, y;
286 for (x = 0; x < m_channel.Width; x++) 496 for (x = 0; x < m_channel.Width; x++)
287 for (y = 0; y < m_channel.Height; y++) 497 for (y = 0; y < m_channel.Height; y++)
288 m_channel[x, y] *= (double)args[0]; 498 m_channel[x, y] *= (double) args[0];
289 CheckForTerrainUpdates(); 499 CheckForTerrainUpdates();
290 } 500 }
291 501
@@ -294,7 +504,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
294 int x, y; 504 int x, y;
295 for (x = 0; x < m_channel.Width; x++) 505 for (x = 0; x < m_channel.Width; x++)
296 for (y = 0; y < m_channel.Height; y++) 506 for (y = 0; y < m_channel.Height; y++)
297 m_channel[x, y] -= (double)args[0]; 507 m_channel[x, y] -= (double) args[0];
298 CheckForTerrainUpdates(); 508 CheckForTerrainUpdates();
299 } 509 }
300 510
@@ -304,7 +514,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
304 514
305 for (x = 0; x < m_channel.Width; x++) 515 for (x = 0; x < m_channel.Width; x++)
306 for (y = 0; y < m_channel.Height; y++) 516 for (y = 0; y < m_channel.Height; y++)
307 m_channel[x, y] = (double)args[0]; 517 m_channel[x, y] = (double) args[0];
308 CheckForTerrainUpdates(); 518 CheckForTerrainUpdates();
309 } 519 }
310 520
@@ -312,12 +522,13 @@ namespace OpenSim.Region.Environment.Modules.Terrain
312 { 522 {
313 double max = Double.MinValue; 523 double max = Double.MinValue;
314 double min = double.MaxValue; 524 double min = double.MaxValue;
315 double avg = 0; 525 double avg;
316 double sum = 0; 526 double sum = 0;
317 527
318 int x, y; 528 int x;
319 for (x = 0; x < m_channel.Width; x++) 529 for (x = 0; x < m_channel.Width; x++)
320 { 530 {
531 int y;
321 for (y = 0; y < m_channel.Height; y++) 532 for (y = 0; y < m_channel.Height; y++)
322 { 533 {
323 sum += m_channel[x, y]; 534 sum += m_channel[x, y];
@@ -336,11 +547,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain
336 547
337 private void InterfaceEnableExperimentalBrushes(Object[] args) 548 private void InterfaceEnableExperimentalBrushes(Object[] args)
338 { 549 {
339 if ((bool)args[0]) 550 if ((bool) args[0])
340 { 551 {
341 m_painteffects[StandardTerrainEffects.Revert] = new PaintBrushes.WeatherSphere(); 552 m_painteffects[StandardTerrainEffects.Revert] = new WeatherSphere();
342 m_painteffects[StandardTerrainEffects.Flatten] = new PaintBrushes.OlsenSphere(); 553 m_painteffects[StandardTerrainEffects.Flatten] = new OlsenSphere();
343 m_painteffects[StandardTerrainEffects.Smooth] = new PaintBrushes.ErodeSphere(); 554 m_painteffects[StandardTerrainEffects.Smooth] = new ErodeSphere();
344 } 555 }
345 else 556 else
346 { 557 {
@@ -350,7 +561,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
350 561
351 private void InterfacePerformEffectTest(Object[] args) 562 private void InterfacePerformEffectTest(Object[] args)
352 { 563 {
353 Effects.CookieCutter cookie = new OpenSim.Region.Environment.Modules.Terrain.Effects.CookieCutter(); 564 CookieCutter cookie = new CookieCutter();
354 cookie.RunEffect(m_channel); 565 cookie.RunEffect(m_channel);
355 } 566 }
356 567
@@ -358,46 +569,69 @@ namespace OpenSim.Region.Environment.Modules.Terrain
358 { 569 {
359 // Load / Save 570 // Load / Save
360 string supportedFileExtensions = ""; 571 string supportedFileExtensions = "";
361 foreach (KeyValuePair<string,ITerrainLoader> loader in m_loaders) 572 foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders)
362 supportedFileExtensions += " " + loader.Key + " (" + loader.Value.ToString() + ")"; 573 supportedFileExtensions += " " + loader.Key + " (" + loader.Value + ")";
363 574
364 Command loadFromFileCommand = new Command("load", InterfaceLoadFile, "Loads a terrain from a specified file."); 575 Command loadFromFileCommand =
365 loadFromFileCommand.AddArgument("filename", "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + supportedFileExtensions, "String"); 576 new Command("load", InterfaceLoadFile, "Loads a terrain from a specified file.");
366 577 loadFromFileCommand.AddArgument("filename",
367 Command saveToFileCommand = new Command("save", InterfaceSaveFile, "Saves the current heightmap to a specified file."); 578 "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " +
368 saveToFileCommand.AddArgument("filename", "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " + supportedFileExtensions, "String"); 579 supportedFileExtensions, "String");
369 580
370 Command loadFromTileCommand = new Command("load-tile", InterfaceLoadTileFile, "Loads a terrain from a section of a larger file."); 581 Command saveToFileCommand =
371 loadFromTileCommand.AddArgument("filename", "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + supportedFileExtensions, "String"); 582 new Command("save", InterfaceSaveFile, "Saves the current heightmap to a specified file.");
583 saveToFileCommand.AddArgument("filename",
584 "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " +
585 supportedFileExtensions, "String");
586
587 Command loadFromTileCommand =
588 new Command("load-tile", InterfaceLoadTileFile, "Loads a terrain from a section of a larger file.");
589 loadFromTileCommand.AddArgument("filename",
590 "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " +
591 supportedFileExtensions, "String");
372 loadFromTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer"); 592 loadFromTileCommand.AddArgument("file width", "The width of the file in tiles", "Integer");
373 loadFromTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer"); 593 loadFromTileCommand.AddArgument("file height", "The height of the file in tiles", "Integer");
374 loadFromTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file", "Integer"); 594 loadFromTileCommand.AddArgument("minimum X tile", "The X region coordinate of the first section on the file",
375 loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file", "Integer"); 595 "Integer");
596 loadFromTileCommand.AddArgument("minimum Y tile", "The Y region coordinate of the first section on the file",
597 "Integer");
376 598
377 // Terrain adjustments 599 // Terrain adjustments
378 Command fillRegionCommand = new Command("fill", InterfaceFillTerrain, "Fills the current heightmap with a specified value."); 600 Command fillRegionCommand =
379 fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.", "Double"); 601 new Command("fill", InterfaceFillTerrain, "Fills the current heightmap with a specified value.");
602 fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.",
603 "Double");
380 604
381 Command elevateCommand = new Command("elevate", InterfaceElevateTerrain, "Raises the current heightmap by the specified amount."); 605 Command elevateCommand =
606 new Command("elevate", InterfaceElevateTerrain, "Raises the current heightmap by the specified amount.");
382 elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double"); 607 elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double");
383 608
384 Command lowerCommand = new Command("lower", InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount."); 609 Command lowerCommand =
610 new Command("lower", InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount.");
385 lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double"); 611 lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double");
386 612
387 Command multiplyCommand = new Command("multiply", InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified."); 613 Command multiplyCommand =
614 new Command("multiply", InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified.");
388 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); 615 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double");
389 616
390 Command bakeRegionCommand = new Command("bake", InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); 617 Command bakeRegionCommand =
391 Command revertRegionCommand = new Command("revert", InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); 618 new Command("bake", InterfaceBakeTerrain, "Saves the current terrain into the regions revert map.");
619 Command revertRegionCommand =
620 new Command("revert", InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap.");
392 621
393 // Debug 622 // Debug
394 Command showDebugStatsCommand = new Command("stats", InterfaceShowDebugStats, "Shows some information about the regions heightmap for debugging purposes."); 623 Command showDebugStatsCommand =
624 new Command("stats", InterfaceShowDebugStats,
625 "Shows some information about the regions heightmap for debugging purposes.");
395 626
396 Command experimentalBrushesCommand = new Command("newbrushes", InterfaceEnableExperimentalBrushes, "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); 627 Command experimentalBrushesCommand =
628 new Command("newbrushes", InterfaceEnableExperimentalBrushes,
629 "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time.");
397 experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean"); 630 experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean");
398 631
399 // Effects 632 // Effects
400 Command effectsTestCommand = new Command("test", InterfacePerformEffectTest, "Performs an effects module test"); 633 Command effectsTestCommand =
634 new Command("test", InterfacePerformEffectTest, "Performs an effects module test");
401 635
402 m_commander.RegisterCommand("load", loadFromFileCommand); 636 m_commander.RegisterCommand("load", loadFromFileCommand);
403 m_commander.RegisterCommand("load-tile", loadFromTileCommand); 637 m_commander.RegisterCommand("load-tile", loadFromTileCommand);
@@ -417,147 +651,5 @@ namespace OpenSim.Region.Environment.Modules.Terrain
417 } 651 }
418 652
419 #endregion 653 #endregion
420
421 void EventManager_OnPluginConsole(string[] args)
422 {
423 if (args[0] == "terrain")
424 {
425 string[] tmpArgs = new string[args.Length - 2];
426 int i = 0;
427 for (i = 2; i < args.Length; i++)
428 tmpArgs[i - 2] = args[i];
429
430 m_commander.ProcessConsoleCommand(args[1], tmpArgs);
431 }
432 }
433
434 void EventManager_OnNewClient(IClientAPI client)
435 {
436 client.OnModifyTerrain += client_OnModifyTerrain;
437 }
438
439 void CheckForTerrainUpdates()
440 {
441 bool shouldTaint = false;
442 float[] serialised = m_channel.GetFloatsSerialised();
443 int x, y;
444 for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize)
445 {
446 for (y = 0; y < m_channel.Height; y += Constants.TerrainPatchSize)
447 {
448 if (m_channel.Tainted(x, y))
449 {
450 SendToClients(serialised, x, y);
451 shouldTaint = true;
452 }
453 }
454 }
455 if (shouldTaint)
456 {
457 m_tainted = true;
458 }
459 }
460
461 private void SendToClients(float[] serialised, int x, int y)
462 {
463 m_scene.ForEachClient(delegate(IClientAPI controller)
464 {
465 controller.SendLayerData(x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize, serialised);
466 });
467 }
468
469 void client_OnModifyTerrain(float height, float seconds, byte size, byte action, float north, float west, float south, float east, IClientAPI remoteClient)
470 {
471 // Not a good permissions check, if in area mode, need to check the entire area.
472 if (m_scene.PermissionsMngr.CanTerraform(remoteClient.AgentId, new LLVector3(north, west, 0)))
473 {
474
475 if (north == south && east == west)
476 {
477 if (m_painteffects.ContainsKey((StandardTerrainEffects)action))
478 {
479 m_painteffects[(StandardTerrainEffects)action].PaintEffect(
480 m_channel, west, south, size, seconds);
481
482 bool usingTerrainModule = true;
483
484 if (usingTerrainModule)
485 {
486 CheckForTerrainUpdates();
487 }
488 }
489 else
490 {
491 m_log.Debug("Unknown terrain brush type " + action.ToString());
492 }
493 }
494 else
495 {
496 if (m_floodeffects.ContainsKey((StandardTerrainEffects)action))
497 {
498 bool[,] fillArea = new bool[m_channel.Width, m_channel.Height];
499 fillArea.Initialize();
500
501 int x, y;
502
503 for (x = 0; x < m_channel.Width; x++)
504 {
505 for (y = 0; y < m_channel.Height; y++)
506 {
507 if (x < east && x > west)
508 {
509 if (y < north && y > south)
510 {
511 fillArea[x, y] = true;
512 }
513 }
514 }
515 }
516
517 m_floodeffects[(StandardTerrainEffects)action].FloodEffect(
518 m_channel, fillArea, size);
519 bool usingTerrainModule = true;
520
521 if (usingTerrainModule)
522 {
523 CheckForTerrainUpdates();
524 }
525 }
526 else
527 {
528 m_log.Debug("Unknown terrain flood type " + action.ToString());
529 }
530 }
531 }
532 }
533
534 public void PostInitialise()
535 {
536 InstallDefaultEffects();
537 InstallInterfaces();
538 }
539
540 public void Close()
541 {
542 }
543
544 public string Name
545 {
546 get { return "TerrainModule"; }
547 }
548
549 public bool IsSharedModule
550 {
551 get { return false; }
552 }
553
554 #region ICommandable Members
555
556 public ICommander CommandInterface
557 {
558 get { return m_commander; }
559 }
560
561 #endregion
562 } 654 }
563} 655} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs
index bae171b..d4d0922 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainUtil.cs
@@ -57,10 +57,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain
57 y = 0.0; 57 y = 0.0;
58 58
59 int stepSize = 1; 59 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];
63 double h11 = map[(int)x + stepSize, (int)y + stepSize]; 63 double h11 = map[(int) x + stepSize, (int) y + stepSize];
64 double h1 = h00; 64 double h1 = h00;
65 double h2 = h10; 65 double h2 = h10;
66 double h3 = h01; 66 double h3 = h01;
@@ -69,15 +69,15 @@ namespace OpenSim.Region.Environment.Modules.Terrain
69 double a10 = h2 - h1; 69 double a10 = h2 - h1;
70 double a01 = h3 - h1; 70 double a01 = h3 - h1;
71 double a11 = h1 - h2 - h3 + h4; 71 double a11 = h1 - h2 - h3 + h4;
72 double partialx = x - (int)x; 72 double partialx = x - (int) x;
73 double partialz = y - (int)y; 73 double partialz = y - (int) y;
74 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); 74 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz);
75 return hi; 75 return hi;
76 } 76 }
77 77
78 private static double Noise(double x, double y) 78 private static double Noise(double x, double y)
79 { 79 {
80 int n = (int)x + (int)(y * 749); 80 int n = (int) x + (int) (y * 749);
81 n = (n << 13) ^ n; 81 n = (n << 13) ^ n;
82 return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); 82 return (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
83 } 83 }
@@ -97,10 +97,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain
97 97
98 private static double InterpolatedNoise(double x, double y) 98 private static double InterpolatedNoise(double x, double y)
99 { 99 {
100 int integer_X = (int)(x); 100 int integer_X = (int) (x);
101 double fractional_X = x - integer_X; 101 double fractional_X = x - integer_X;
102 102
103 int integer_Y = (int)y; 103 int integer_Y = (int) y;
104 double fractional_Y = y - integer_Y; 104 double fractional_Y = y - integer_Y;
105 105
106 double v1 = SmoothedNoise1(integer_X, integer_Y); 106 double v1 = SmoothedNoise1(integer_X, integer_Y);
@@ -122,12 +122,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain
122 122
123 for (int i = 0; i < octaves; i++) 123 for (int i = 0; i < octaves; i++)
124 { 124 {
125 frequency = System.Math.Pow(2, i); 125 frequency = Math.Pow(2, i);
126 amplitude = System.Math.Pow(persistence, i); 126 amplitude = Math.Pow(persistence, i);
127 127
128 total += InterpolatedNoise(x * frequency, y * frequency) * amplitude; 128 total += InterpolatedNoise(x * frequency, y * frequency) * amplitude;
129 } 129 }
130 return total; 130 return total;
131 } 131 }
132 } 132 }
133} 133} \ No newline at end of file