aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Terrain
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Terrain')
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs2
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs69
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs8
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs11
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs13
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs11
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs3
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs3
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs29
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs7
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs28
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs13
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs12
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs30
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs12
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs16
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs3
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs592
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs6
25 files changed, 496 insertions, 418 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs
index 36917e9..b456aa1 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/ChannelDigger.cs
@@ -64,7 +64,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
64 64
65 for (int i = 0; i < rounds; i++) 65 for (int i = 0; i < rounds; i++)
66 { 66 {
67 smoothFunction.FloodEffect(map, bitmap, 1.0); 67 smoothFunction.FloodEffect(map, bitmap, 1.0, 0, map.Width - 1, 0, map.Height - 1);
68 } 68 }
69 } 69 }
70 70
@@ -99,7 +99,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
99 } 99 }
100 } 100 }
101 101
102 raiseFunction.FloodEffect(map, bitmap, height); 102 raiseFunction.FloodEffect(map, bitmap, height, 0, map.Width - 1, 0, map.Height - 1);
103 } 103 }
104 } 104 }
105 } 105 }
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs
index dc76ad5..3222524 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/CookieCutter.cs
@@ -84,7 +84,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
84 for (y = 0; y < map.Height; y++) 84 for (y = 0; y < map.Height; y++)
85 { 85 {
86 if (cliffMask[x, y]) 86 if (cliffMask[x, y])
87 eroder.PaintEffect(map, allowMask, x, y, -1, 4, 0.1); 87 eroder.PaintEffect(map, allowMask, x, y, -1, 4, 0.1,0,map.Width - 1,0,map.Height - 1);
88 } 88 }
89 } 89 }
90 90
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
index 89087b1..80396c4 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Effects/DefaultTerrainGenerator.cs
@@ -53,4 +53,4 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Effects
53 53
54 #endregion 54 #endregion
55 } 55 }
56} \ No newline at end of file 56}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index d5c77ec..e8c719a 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -128,7 +128,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
128 colours.Save(stream, ImageFormat.Png); 128 colours.Save(stream, ImageFormat.Png);
129 } 129 }
130 130
131 public virtual void SaveFile(ITerrainChannel m_channel, string filename, 131 public virtual void SaveFile(ITerrainChannel m_channel, string filename,
132 int offsetX, int offsetY, 132 int offsetX, int offsetY,
133 int fileWidth, int fileHeight, 133 int fileWidth, int fileHeight,
134 int regionSizeX, int regionSizeY) 134 int regionSizeX, int regionSizeY)
@@ -162,13 +162,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
162 { 162 {
163 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); 163 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
164 } 164 }
165 165
166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); 166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
167 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); 167 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
168 for (int x = 0; x < regionSizeX; x++) 168 for (int x = 0; x < regionSizeX; x++)
169 for (int y = 0; y < regionSizeY; y++) 169 for (int y = 0; y < regionSizeY; y++)
170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); 170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
171 171
172 Save(newBitmap, filename); 172 Save(newBitmap, filename);
173 } 173 }
174 finally 174 finally
@@ -213,8 +213,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
213 /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> 213 /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns>
214 protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) 214 protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map)
215 { 215 {
216 // Bitmap bmp = new Bitmap(map.Width, map.Height, PixelFormat.Format24bppRgb);
216 Bitmap bmp = new Bitmap(map.Width, map.Height); 217 Bitmap bmp = new Bitmap(map.Width, map.Height);
217 218
219
218 const int pallete = 256; 220 const int pallete = 256;
219 221
220 Color[] grays = new Color[pallete]; 222 Color[] grays = new Color[pallete];
@@ -227,59 +229,24 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
227 { 229 {
228 for (int x = 0; x < map.Width; x++) 230 for (int x = 0; x < map.Width; x++)
229 { 231 {
230 // 512 is the largest possible height before colours clamp 232 // to change this, loading also needs change
231 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1));
232
233 // Handle error conditions
234 if (colorindex > pallete - 1 || colorindex < 0)
235 bmp.SetPixel(x, map.Height - y - 1, Color.Red);
236 else
237 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
238 }
239 }
240 return bmp;
241 }
242
243 /// <summary>
244 /// Protected method, generates a coloured bitmap
245 /// image from a specified terrain channel.
246 /// </summary>
247 /// <param name="map">The terrain channel to export to bitmap</param>
248 /// <returns>A System.Drawing.Bitmap containing a coloured image</returns>
249 protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
250 {
251 int pallete;
252 Bitmap bmp;
253 Color[] colours;
254 233
255 using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png")) 234 // int colorindex = (int)map[x, y]; // one to one conversion 0 - 255m range
256 { 235 // int colorindex = (int)map[x, y] / 2; // 0 - 510 range
257 pallete = gradientmapLd.Height;
258
259 bmp = new Bitmap(map.Width, map.Height);
260 colours = new Color[pallete];
261
262 for (int i = 0; i < pallete; i++)
263 {
264 colours[i] = gradientmapLd.GetPixel(0, i);
265 }
266 }
267 236
268 for (int y = 0; y < map.Height; y++) 237 int colorindex = (int)map[x, y] * 2; // the original 0 - 127.5 range
269 {
270 for (int x = 0; x < map.Width; x++)
271 {
272 // 512 is the largest possible height before colours clamp
273 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
274 238
275 // Handle error conditions 239 // clamp it not adding the red warning
276 if (colorindex > pallete - 1 || colorindex < 0) 240 if (colorindex < 0)
277 bmp.SetPixel(x, map.Height - y - 1, Color.Red); 241 colorindex = 0;
278 else 242 else if (colorindex >= pallete)
279 bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); 243 colorindex = pallete - 1;
244 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
280 } 245 }
281 } 246 }
282 return bmp; 247 return bmp;
283 } 248 }
284 } 249 }
285} 250}
251
252
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
index be1fb24..59994e4 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
@@ -57,6 +57,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
57 57
58 public LLRAW() 58 public LLRAW()
59 { 59 {
60 }
61
62 private void BuildLookupHeightTable()
63 {
60 LookupHeightTable = new HeightmapLookupValue[256 * 256]; 64 LookupHeightTable = new HeightmapLookupValue[256 * 256];
61 65
62 for (int i = 0; i < 256; i++) 66 for (int i = 0; i < 256; i++)
@@ -186,6 +190,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
186 190
187 public void SaveStream(Stream s, ITerrainChannel map) 191 public void SaveStream(Stream s, ITerrainChannel map)
188 { 192 {
193 if (LookupHeightTable == null)
194 BuildLookupHeightTable();
195
189 using (BinaryWriter binStream = new BinaryWriter(s)) 196 using (BinaryWriter binStream = new BinaryWriter(s))
190 { 197 {
191 // Output the calculated raw 198 // Output the calculated raw
@@ -241,6 +248,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
241 } 248 }
242 } 249 }
243 } 250 }
251 LookupHeightTable = null;
244 } 252 }
245 253
246 public string FileExtension 254 public string FileExtension
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs
index 774e7b2..0c4171e 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs
@@ -33,15 +33,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 double sum = 0.0; 39 double sum = 0.0;
39 double steps = 0.0; 40 double steps = 0.0;
40 41
41 int x, y; 42 int x, y;
42 for (x = 0; x < map.Width; x++) 43 for (x = startX; x <= endX; x++)
43 { 44 {
44 for (y = 0; y < map.Height; y++) 45 for (y = startY; y <= endY; y++)
45 { 46 {
46 if (fillArea[x, y]) 47 if (fillArea[x, y])
47 { 48 {
@@ -55,9 +56,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
55 56
56 double str = 0.1 * strength; // == 0.2 in the default client 57 double str = 0.1 * strength; // == 0.2 in the default client
57 58
58 for (x = 0; x < map.Width; x++) 59 for (x = startX; x <= endX; x++)
59 { 60 {
60 for (y = 0; y < map.Height; y++) 61 for (y = startY; y <= endY; y++)
61 { 62 {
62 if (fillArea[x, y]) 63 if (fillArea[x, y])
63 map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str); 64 map[x, y] = (map[x, y] * (1.0 - str)) + (avg * str);
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs
index 3e87390..a275a86 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs
@@ -33,13 +33,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 int x; 39 int x,y;
39 for (x = 0; x < map.Width; x++) 40 for (x = startX; x <= endX; x++)
40 { 41 {
41 int y; 42 for (y = startY; y <= endY; y++)
42 for (y = 0; y < map.Height; y++)
43 { 43 {
44 if (fillArea[x, y]) 44 if (fillArea[x, y])
45 { 45 {
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
index b6c635c..d634e8b 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs
@@ -35,18 +35,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
35 { 35 {
36 #region ITerrainFloodEffect Members 36 #region ITerrainFloodEffect Members
37 37
38 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 38 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
39 int startX, int endX, int startY, int endY)
39 { 40 {
40 int x; 41 int x, y;
41 for (x = 0; x < map.Width; x++) 42 for (x = startX; x <= endX; x++)
42 { 43 {
43 int y; 44 for (y = startY; y <= endY; y++)
44 for (y = 0; y < map.Height; y++)
45 { 45 {
46 if (fillArea[x, y]) 46 if (fillArea[x, y])
47 { 47 {
48 double noise = TerrainUtil.PerlinNoise2D((double) x / map.Width, (double) y / map.Height, 8, 1.0); 48 double noise = TerrainUtil.PerlinNoise2D((double) x / map.Width, (double) y / map.Height, 8, 1.0);
49
50 map[x, y] += noise * strength; 49 map[x, y] += noise * strength;
51 } 50 }
52 } 51 }
@@ -55,4 +54,4 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
55 54
56 #endregion 55 #endregion
57 } 56 }
58} \ No newline at end of file 57}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs
index 3bdc5e7..6ccd5df 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs
@@ -33,13 +33,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 int x; 39 int x,y;
39 for (x = 0; x < map.Width; x++) 40 for (x = startX; x <= endX; x++)
40 { 41 {
41 int y; 42 for (y = startY; y <= endY; y++)
42 for (y = 0; y < map.Height; y++)
43 { 43 {
44 if (fillArea[x, y]) 44 if (fillArea[x, y])
45 { 45 {
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs
index c5527fa..4230133 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs
@@ -46,13 +46,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
46 /// <param name="map">the current heightmap</param> 46 /// <param name="map">the current heightmap</param>
47 /// <param name="fillArea">array indicating which sections of the map are to be reverted</param> 47 /// <param name="fillArea">array indicating which sections of the map are to be reverted</param>
48 /// <param name="strength">unused</param> 48 /// <param name="strength">unused</param>
49 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 49 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
50 int startX, int endX, int startY, int endY)
50 { 51 {
51 int x; 52 int x, y;
52 for (x = 0; x < map.Width; x++) 53 for (x = startX; x <= endX; x++)
53 { 54 {
54 int y; 55 for (y = startY; y <= endY; y++)
55 for (y = 0; y < map.Height; y++)
56 { 56 {
57 if (fillArea[x, y]) 57 if (fillArea[x, y])
58 { 58 {
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs
index 6b07747..6c0d60d 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs
@@ -33,16 +33,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
33 { 33 {
34 #region ITerrainFloodEffect Members 34 #region ITerrainFloodEffect Members
35 35
36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength) 36 public void FloodEffect(ITerrainChannel map, bool[,] fillArea, double strength,
37 int startX, int endX, int startY, int endY)
37 { 38 {
38 double area = strength; 39 double area = strength;
39 double step = strength / 4.0; 40 double step = strength / 4.0;
40 41
41 double[,] manipulate = new double[map.Width,map.Height]; 42 double[,] manipulate = new double[map.Width,map.Height];
42 int x, y; 43 int x, y;
43 for (x = 0; x < map.Width; x++) 44 for (x = startX; x <= endX; x++)
44 { 45 {
45 for (y = 0; y < map.Height; y++) 46 for (y = startY; y <= endY; y++)
46 { 47 {
47 if (!fillArea[x, y]) 48 if (!fillArea[x, y])
48 continue; 49 continue;
@@ -64,9 +65,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes
64 manipulate[x, y] = average / avgsteps; 65 manipulate[x, y] = average / avgsteps;
65 } 66 }
66 } 67 }
67 for (x = 0; x < map.Width; x++) 68 for (x = startX; x <= endX; x++)
68 { 69 {
69 for (y = 0; y < map.Height; y++) 70 for (y = startY; y <= endY; y++)
70 { 71 {
71 if (!fillArea[x, y]) 72 if (!fillArea[x, y])
72 continue; 73 continue;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs
index 3984a30..6324aca 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFloodEffect.cs
@@ -32,6 +32,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
32{ 32{
33 public interface ITerrainFloodEffect 33 public interface ITerrainFloodEffect
34 { 34 {
35 void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); 35 void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength,
36 int startX, int endX, int startY, int endY);
36 } 37 }
37} \ No newline at end of file 38} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs
index b73defd..d0b05e4 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs
@@ -31,6 +31,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
31{ 31{
32 public interface ITerrainPaintableEffect 32 public interface ITerrainPaintableEffect
33 { 33 {
34 void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z, double strength, double duration); 34 void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z,
35 double strength, double duration, int startX, int endX, int startY, int endY);
35 } 36 }
36} 37}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs
index 7a78cd8..7358ba3 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs
@@ -151,7 +151,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
151 151
152 #region ITerrainPaintableEffect Members 152 #region ITerrainPaintableEffect Members
153 153
154 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 154 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
155 double strength, double duration, int startX, int endX, int startY, int endY)
155 { 156 {
156 strength = TerrainUtil.MetersToSphericalStrength(strength); 157 strength = TerrainUtil.MetersToSphericalStrength(strength);
157 158
@@ -163,18 +164,23 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
163 ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); 164 ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height);
164 165
165 // Fill with rain 166 // Fill with rain
166 for (x = 0; x < water.Width; x++) 167 for (x = startX; x <= endX; x++)
167 for (y = 0; y < water.Height; y++) 168 {
168 water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); 169 for (y = startY; y <= endY; y++)
170 {
171 if (mask[x, y])
172 water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
173 }
174 }
169 175
170 for (int i = 0; i < rounds; i++) 176 for (int i = 0; i < rounds; i++)
171 { 177 {
172 // Erode underlying terrain 178 // Erode underlying terrain
173 for (x = 0; x < water.Width; x++) 179 for (x = startX; x <= endX; x++)
174 { 180 {
175 for (y = 0; y < water.Height; y++) 181 for (y = startY; y <= endY; y++)
176 { 182 {
177 if (mask[x,y]) 183 if (mask[x, y])
178 { 184 {
179 const double solConst = (1.0 / rounds); 185 const double solConst = (1.0 / rounds);
180 double sedDelta = water[x, y] * solConst; 186 double sedDelta = water[x, y] * solConst;
@@ -185,9 +191,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
185 } 191 }
186 192
187 // Move water 193 // Move water
188 for (x = 0; x < water.Width; x++) 194 for (x = startX; x <= endX; x++)
189 { 195 {
190 for (y = 0; y < water.Height; y++) 196 for (y = startY; y <= endY; y++)
191 { 197 {
192 if (water[x, y] <= 0) 198 if (water[x, y] <= 0)
193 continue; 199 continue;
@@ -296,7 +302,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
296 double sedimentDeposit = sediment[x, y] - waterCapacity; 302 double sedimentDeposit = sediment[x, y] - waterCapacity;
297 if (sedimentDeposit > 0) 303 if (sedimentDeposit > 0)
298 { 304 {
299 if (mask[x,y]) 305 if (mask[x, y])
300 { 306 {
301 sediment[x, y] -= sedimentDeposit; 307 sediment[x, y] -= sedimentDeposit;
302 map[x, y] += sedimentDeposit; 308 map[x, y] += sedimentDeposit;
@@ -309,10 +315,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
309 // Deposit any remainder (should be minimal) 315 // Deposit any remainder (should be minimal)
310 for (x = 0; x < water.Width; x++) 316 for (x = 0; x < water.Width; x++)
311 for (y = 0; y < water.Height; y++) 317 for (y = 0; y < water.Height; y++)
312 if (mask[x,y] && sediment[x, y] > 0) 318 if (mask[x, y] && sediment[x, y] > 0)
313 map[x, y] += sediment[x, y]; 319 map[x, y] += sediment[x, y];
314 } 320 }
315
316 #endregion 321 #endregion
317 } 322 }
318} 323}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs
index 9aa3dff..8937f63 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs
@@ -35,16 +35,17 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
35 { 35 {
36 #region ITerrainPaintableEffect Members 36 #region ITerrainPaintableEffect Members
37 37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
39 double strength, double duration, int startX, int endX, int startY, int endY)
39 { 40 {
40 strength = TerrainUtil.MetersToSphericalStrength(strength); 41 strength = TerrainUtil.MetersToSphericalStrength(strength);
41 42
42 int x, y; 43 int x, y;
43 44
44 // blend in map 45 // blend in map
45 for (x = 0; x < map.Width; x++) 46 for (x = startX; x <= endX; x++)
46 { 47 {
47 for (y = 0; y < map.Height; y++) 48 for (y = startY; y <= endY; y++)
48 { 49 {
49 if (!mask[x,y]) 50 if (!mask[x,y])
50 continue; 51 continue;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs
index 68145f2..bbf9407 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs
@@ -34,34 +34,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
34 { 34 {
35 #region ITerrainPaintableEffect Members 35 #region ITerrainPaintableEffect Members
36 36
37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
38 double strength, double duration, int startX, int endX, int startY, int endY)
38 { 39 {
39 int s = (int) (Math.Pow(2, strength) + 0.5); 40 int s = (int) (Math.Pow(2, strength) + 0.5);
40 41
41 int x; 42 int x, y;
42 int xFrom = (int)(rx-s+0.5);
43 int xTo = (int)(rx+s+0.5) + 1;
44 int yFrom = (int)(ry-s+0.5);
45 int yTo = (int)(ry+s+0.5) + 1;
46 43
47 if (xFrom < 0) 44 for (x = startX; x <= endX; x++)
48 xFrom = 0;
49
50 if (yFrom < 0)
51 yFrom = 0;
52
53 if (xTo > map.Width)
54 xTo = map.Width;
55
56 if (yTo > map.Width)
57 yTo = map.Width;
58
59 for (x = xFrom; x < xTo; x++)
60 { 45 {
61 int y; 46 for (y = startY; y <= endY; y++)
62 for (y = yFrom; y < yTo; y++)
63 { 47 {
64 if (!mask[x,y]) 48 if (!mask[x, y])
65 continue; 49 continue;
66 50
67 // Calculate a cos-sphere and add it to the heighmap 51 // Calculate a cos-sphere and add it to the heighmap
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
index e7df3f8..46d47b4 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs
@@ -35,17 +35,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
35 { 35 {
36 #region ITerrainPaintableEffect Members 36 #region ITerrainPaintableEffect Members
37 37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
39 double strength, double duration, int startX, int endX, int startY, int endY)
39 { 40 {
40 strength = TerrainUtil.MetersToSphericalStrength(strength); 41 strength = TerrainUtil.MetersToSphericalStrength(strength);
41 42
42 int x; 43 int x, y;
43 for (x = 0; x < map.Width; x++) 44
45 for (x = startX; x <= endX; x++)
44 { 46 {
45 int y; 47 for (y = startY; y <= endY; y++)
46 for (y = 0; y < map.Height; y++)
47 { 48 {
48 if (!mask[x,y]) 49 if (!mask[x, y])
49 continue; 50 continue;
50 51
51 // Calculate a sphere and add it to the heighmap 52 // Calculate a sphere and add it to the heighmap
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs
index b199df3..281690d 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs
@@ -152,18 +152,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
152 152
153 #region ITerrainPaintableEffect Members 153 #region ITerrainPaintableEffect Members
154 154
155 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 155 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
156 double strength, double duration, int startX, int endX, int startY, int endY)
156 { 157 {
157 strength = TerrainUtil.MetersToSphericalStrength(strength); 158 strength = TerrainUtil.MetersToSphericalStrength(strength);
158 159
159 int x; 160 int x, y;
160 161
161 for (x = 0; x < map.Width; x++) 162 for (x = startX; x <= endX; x++)
162 { 163 {
163 int y; 164 for (y = startY; y <= endY; y++)
164 for (y = 0; y < map.Height; y++)
165 { 165 {
166 if (!mask[x,y]) 166 if (!mask[x, y])
167 continue; 167 continue;
168 168
169 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 169 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs
index bd9a8a0..1b704bb 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs
@@ -35,38 +35,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
35 #region ITerrainPaintableEffect Members 35 #region ITerrainPaintableEffect Members
36 36
37 37
38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 38 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
39 double strength, double duration, int startX, int endX, int startY, int endY)
39 { 40 {
40 int s = (int) (Math.Pow(2, strength) + 0.5); 41 int s = (int) (Math.Pow(2, strength) + 0.5);
41 42
42 int x; 43 int x,y;
43 int xFrom = (int)(rx-s+0.5);
44 int xTo = (int)(rx+s+0.5) + 1;
45 int yFrom = (int)(ry-s+0.5);
46 int yTo = (int)(ry+s+0.5) + 1;
47 44
48 if (xFrom < 0) 45 for (x = startX; x <= endX; x++)
49 xFrom = 0;
50
51 if (yFrom < 0)
52 yFrom = 0;
53
54 if (xTo > map.Width)
55 xTo = map.Width;
56
57 if (yTo > map.Width)
58 yTo = map.Width;
59
60 for (x = xFrom; x < xTo; x++)
61 { 46 {
62 int y; 47 for (y = startY; y <= endY; y++)
63 for (y = yFrom; y < yTo; y++)
64 { 48 {
65 if (!mask[x,y]) 49 if (!mask[x, y])
66 continue; 50 continue;
67 51
68 // Calculate a cos-sphere and add it to the heighmap 52 // Calculate a cos-sphere and add it to the heighmap
69 double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry))); 53 double r = Math.Sqrt((x - rx) * (x - rx) + ((y - ry) * (y - ry)));
70 double z = Math.Cos(r * Math.PI / (s * 2)); 54 double z = Math.Cos(r * Math.PI / (s * 2));
71 if (z > 0.0) 55 if (z > 0.0)
72 map[x, y] += z * duration; 56 map[x, y] += z * duration;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs
index 4b28275..efc5324 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs
@@ -41,7 +41,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
41 41
42 #region ITerrainPaintableEffect Members 42 #region ITerrainPaintableEffect Members
43 43
44 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 44 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
45 double strength, double duration, int startX, int endX, int startY, int endY)
45 { 46 {
46 strength = TerrainUtil.MetersToSphericalStrength(strength); 47 strength = TerrainUtil.MetersToSphericalStrength(strength);
47 duration = 0.03; //MCP Should be read from ini file 48 duration = 0.03; //MCP Should be read from ini file
@@ -51,13 +52,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
51 if (duration < 0) 52 if (duration < 0)
52 return; 53 return;
53 54
54 int x; 55 int x,y;
55 for (x = 0; x < map.Width; x++) 56 for (x = startX; x <= endX; x++)
56 { 57 {
57 int y; 58 for (y = startY; y <= endY; y++)
58 for (y = 0; y < map.Height; y++)
59 { 59 {
60 if (!mask[x,y]) 60 if (!mask[x, y])
61 continue; 61 continue;
62 62
63 // Calculate a sphere and add it to the heighmap 63 // Calculate a sphere and add it to the heighmap
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs
index 4834c86..65dd0a6 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs
@@ -34,7 +34,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
34 { 34 {
35 #region ITerrainPaintableEffect Members 35 #region ITerrainPaintableEffect Members
36 36
37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 37 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
38 double strength, double duration, int startX, int endX, int startY, int endY)
38 { 39 {
39 strength = TerrainUtil.MetersToSphericalStrength(strength); 40 strength = TerrainUtil.MetersToSphericalStrength(strength);
40 41
@@ -47,10 +48,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
47 48
48 49
49 // compute delta map 50 // compute delta map
50 for (x = 0; x < map.Width; x++) 51 for (x = startX; x <= endX; x++)
51 { 52 {
52 for (y = 0; y < map.Height; y++) 53 for (y = startY; y <= endY; y++)
53 { 54 {
55 if (!mask[x, y])
56 continue;
57
54 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 58 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
55 59
56 if (z > 0) // add in non-zero amount 60 if (z > 0) // add in non-zero amount
@@ -73,11 +77,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
73 } 77 }
74 } 78 }
75 // blend in map 79 // blend in map
76 for (x = 0; x < map.Width; x++) 80 for (x = startX; x <= endX; x++)
77 { 81 {
78 for (y = 0; y < map.Height; y++) 82 for (y = startY; y <= endY; y++)
79 { 83 {
80 if (!mask[x,y]) 84 if (!mask[x, y])
81 continue; 85 continue;
82 86
83 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); 87 double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs
index f31c8b6..f52fe07 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs
@@ -148,16 +148,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
148 148
149 #region ITerrainPaintableEffect Members 149 #region ITerrainPaintableEffect Members
150 150
151 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) 151 public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
152 double strength, double duration, int startX, int endX, int startY, int endY)
152 { 153 {
153 strength = TerrainUtil.MetersToSphericalStrength(strength); 154 strength = TerrainUtil.MetersToSphericalStrength(strength);
154 155
155 int x; 156 int x,y;
156 157
157 for (x = 0; x < map.Width; x++) 158 for (x = startX; x <= endX; x++)
158 { 159 {
159 int y; 160 for (y = startY; y <= endY; y++)
160 for (y = 0; y < map.Height; y++)
161 { 161 {
162 if (!mask[x,y]) 162 if (!mask[x,y])
163 continue; 163 continue;
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs
index 7ebd08e..c6e992f 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModifier.cs
@@ -370,9 +370,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain
370 } 370 }
371 return mask; 371 return mask;
372 } 372 }
373
374
375 } 373 }
376
377} 374}
378 375
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index 932652c..c9aa3a3 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -29,6 +29,7 @@ using System.Collections.Generic;
29using System.IO; 29using System.IO;
30using System.Reflection; 30using System.Reflection;
31using System.Net; 31using System.Net;
32using System.Threading;
32 33
33using log4net; 34using log4net;
34using Nini.Config; 35using Nini.Config;
@@ -36,7 +37,6 @@ using Nini.Config;
36using OpenMetaverse; 37using OpenMetaverse;
37using Mono.Addins; 38using Mono.Addins;
38 39
39using OpenSim.Data;
40using OpenSim.Framework; 40using OpenSim.Framework;
41using OpenSim.Framework.Console; 41using OpenSim.Framework.Console;
42using OpenSim.Region.CoreModules.Framework.InterfaceCommander; 42using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
@@ -86,14 +86,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain
86 private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>(); 86 private readonly Dictionary<string, ITerrainLoader> m_loaders = new Dictionary<string, ITerrainLoader>();
87 private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = 87 private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects =
88 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); 88 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
89 private Dictionary<string, ITerrainEffect> m_plugineffects;
90 private Dictionary<string, ITerrainModifier> m_modifyOperations = 89 private Dictionary<string, ITerrainModifier> m_modifyOperations =
91 new Dictionary<string, ITerrainModifier>(); 90 new Dictionary<string, ITerrainModifier>();
91 private Dictionary<string, ITerrainEffect> m_plugineffects;
92 private ITerrainChannel m_channel; 92 private ITerrainChannel m_channel;
93 private ITerrainChannel m_revert; 93 private ITerrainChannel m_baked;
94 private Scene m_scene; 94 private Scene m_scene;
95 private volatile bool m_tainted; 95 private volatile bool m_tainted;
96 private readonly Stack<LandUndoState> m_undo = new Stack<LandUndoState>(5); 96
97 private String m_InitialTerrain = "pinhead-island"; 97 private String m_InitialTerrain = "pinhead-island";
98 98
99 // If true, send terrain patch updates to clients based on their view distance 99 // If true, send terrain patch updates to clients based on their view distance
@@ -107,13 +107,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain
107 private bool[,] updated; // for each patch, whether it needs to be sent to this client 107 private bool[,] updated; // for each patch, whether it needs to be sent to this client
108 private int updateCount; // number of patches that need to be sent 108 private int updateCount; // number of patches that need to be sent
109 public ScenePresence Presence; // a reference to the client to send to 109 public ScenePresence Presence; // a reference to the client to send to
110 public TerrainData Terrain; // reference to the underlying terrain 110 public bool sendAll;
111 public int sendAllcurrentX;
112 public int sendAllcurrentY;
113
114
111 public PatchUpdates(TerrainData terrData, ScenePresence pPresence) 115 public PatchUpdates(TerrainData terrData, ScenePresence pPresence)
112 { 116 {
113 updated = new bool[terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize]; 117 updated = new bool[terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize];
114 updateCount = 0; 118 updateCount = 0;
115 Presence = pPresence; 119 Presence = pPresence;
116 Terrain = terrData;
117 // Initially, send all patches to the client 120 // Initially, send all patches to the client
118 SetAll(true); 121 SetAll(true);
119 } 122 }
@@ -146,12 +149,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain
146 public void SetAll(bool state) 149 public void SetAll(bool state)
147 { 150 {
148 updateCount = 0; 151 updateCount = 0;
149 for(int xx = 0; xx < updated.GetLength(0); xx++) 152 for (int xx = 0; xx < updated.GetLength(0); xx++)
150 for(int yy = 0; yy < updated.GetLength(1); yy++) 153 for (int yy = 0; yy < updated.GetLength(1); yy++)
151 updated[xx, yy] = state; 154 updated[xx, yy] = state;
152 if (state) 155 if (state)
153 updateCount = updated.GetLength(0) * updated.GetLength(1); 156 updateCount = updated.GetLength(0) * updated.GetLength(1);
157 sendAllcurrentX = 0;
158 sendAllcurrentY = 0;
159 sendAll = true;
154 } 160 }
161
155 // Logically OR's the terrain data's patch taint map into this client's update map. 162 // Logically OR's the terrain data's patch taint map into this client's update map.
156 public void SetAll(TerrainData terrData) 163 public void SetAll(TerrainData terrData)
157 { 164 {
@@ -164,9 +171,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain
164 terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize) 171 terrData.SizeX / Constants.TerrainPatchSize, terrData.SizeY / Constants.TerrainPatchSize)
165 ); 172 );
166 } 173 }
167 for(int xx = 0; xx < terrData.SizeX; xx += Constants.TerrainPatchSize) 174
175 for (int xx = 0; xx < terrData.SizeX; xx += Constants.TerrainPatchSize)
168 { 176 {
169 for(int yy = 0; yy < terrData.SizeY; yy += Constants.TerrainPatchSize) 177 for (int yy = 0; yy < terrData.SizeY; yy += Constants.TerrainPatchSize)
170 { 178 {
171 // Only set tainted. The patch bit may be set if the patch was to be sent later. 179 // Only set tainted. The patch bit may be set if the patch was to be sent later.
172 if (terrData.IsTaintedAt(xx, yy, false)) 180 if (terrData.IsTaintedAt(xx, yy, false))
@@ -210,7 +218,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
210 if (terrainConfig != null) 218 if (terrainConfig != null)
211 { 219 {
212 m_InitialTerrain = terrainConfig.GetString("InitialTerrain", m_InitialTerrain); 220 m_InitialTerrain = terrainConfig.GetString("InitialTerrain", m_InitialTerrain);
213 m_sendTerrainUpdatesByViewDistance = terrainConfig.GetBoolean("SendTerrainUpdatesByViewDistance", m_sendTerrainUpdatesByViewDistance); 221 m_sendTerrainUpdatesByViewDistance =
222 terrainConfig.GetBoolean(
223 "SendTerrainUpdatesByViewDistance",m_sendTerrainUpdatesByViewDistance);
214 } 224 }
215 } 225 }
216 226
@@ -227,12 +237,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain
227 (int)m_scene.RegionInfo.RegionSizeY, 237 (int)m_scene.RegionInfo.RegionSizeY,
228 (int)m_scene.RegionInfo.RegionSizeZ); 238 (int)m_scene.RegionInfo.RegionSizeZ);
229 m_scene.Heightmap = m_channel; 239 m_scene.Heightmap = m_channel;
230 UpdateRevertMap(); 240
241 UpdateBakedMap();
231 } 242 }
232 else 243 else
233 { 244 {
234 m_channel = m_scene.Heightmap; 245 m_channel = m_scene.Heightmap;
235 UpdateRevertMap(); 246 UpdateBakedMap();
236 } 247 }
237 248
238 m_scene.RegisterModuleInterface<ITerrainModule>(this); 249 m_scene.RegisterModuleInterface<ITerrainModule>(this);
@@ -240,7 +251,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
240 m_scene.EventManager.OnClientClosed += EventManager_OnClientClosed; 251 m_scene.EventManager.OnClientClosed += EventManager_OnClientClosed;
241 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; 252 m_scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
242 m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick; 253 m_scene.EventManager.OnTerrainTick += EventManager_OnTerrainTick;
243 m_scene.EventManager.OnFrame += EventManager_OnFrame; 254 m_scene.EventManager.OnTerrainCheckUpdates += EventManager_TerrainCheckUpdates;
244 } 255 }
245 256
246 InstallDefaultEffects(); 257 InstallDefaultEffects();
@@ -279,7 +290,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
279 // remove the commands 290 // remove the commands
280 m_scene.UnregisterModuleCommander(m_commander.Name); 291 m_scene.UnregisterModuleCommander(m_commander.Name);
281 // remove the event-handlers 292 // remove the event-handlers
282 m_scene.EventManager.OnFrame -= EventManager_OnFrame; 293
294 m_scene.EventManager.OnTerrainCheckUpdates -= EventManager_TerrainCheckUpdates;
283 m_scene.EventManager.OnTerrainTick -= EventManager_OnTerrainTick; 295 m_scene.EventManager.OnTerrainTick -= EventManager_OnTerrainTick;
284 m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole; 296 m_scene.EventManager.OnPluginConsole -= EventManager_OnPluginConsole;
285 m_scene.EventManager.OnClientClosed -= EventManager_OnClientClosed; 297 m_scene.EventManager.OnClientClosed -= EventManager_OnClientClosed;
@@ -334,7 +346,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
334 m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height); 346 m_log.DebugFormat("[TERRAIN]: Loaded terrain, wd/ht: {0}/{1}", channel.Width, channel.Height);
335 m_scene.Heightmap = channel; 347 m_scene.Heightmap = channel;
336 m_channel = channel; 348 m_channel = channel;
337 UpdateRevertMap(); 349 UpdateBakedMap();
338 } 350 }
339 catch(NotImplementedException) 351 catch(NotImplementedException)
340 { 352 {
@@ -426,7 +438,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
426 { 438 {
427 ITerrainChannel channel = loader.Value.LoadStream(stream); 439 ITerrainChannel channel = loader.Value.LoadStream(stream);
428 m_channel.Merge(channel, displacement, radianRotation, rotationDisplacement); 440 m_channel.Merge(channel, displacement, radianRotation, rotationDisplacement);
429 UpdateRevertMap(); 441 UpdateBakedMap();
430 } 442 }
431 catch(NotImplementedException) 443 catch(NotImplementedException)
432 { 444 {
@@ -506,12 +518,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
506 518
507 // Someone diddled terrain outside the normal code paths. Set the taintedness for all clients. 519 // Someone diddled terrain outside the normal code paths. Set the taintedness for all clients.
508 // ITerrainModule.TaintTerrain() 520 // ITerrainModule.TaintTerrain()
509 public void TaintTerrain() 521 public void TaintTerrain ()
510 { 522 {
511 lock(m_perClientPatchUpdates) 523 lock (m_perClientPatchUpdates)
512 { 524 {
513 // Set the flags for all clients so the tainted patches will be sent out 525 // Set the flags for all clients so the tainted patches will be sent out
514 foreach(PatchUpdates pups in m_perClientPatchUpdates.Values) 526 foreach (PatchUpdates pups in m_perClientPatchUpdates.Values)
515 { 527 {
516 pups.SetAll(m_scene.Heightmap.GetTerrainData()); 528 pups.SetAll(m_scene.Heightmap.GetTerrainData());
517 } 529 }
@@ -521,13 +533,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
521 // ITerrainModule.PushTerrain() 533 // ITerrainModule.PushTerrain()
522 public void PushTerrain(IClientAPI pClient) 534 public void PushTerrain(IClientAPI pClient)
523 { 535 {
524 // If view distance based, set the modified patch bits and the frame event will send the updates
525 if (m_sendTerrainUpdatesByViewDistance) 536 if (m_sendTerrainUpdatesByViewDistance)
526 { 537 {
527 ScenePresence presence = m_scene.GetScenePresence(pClient.AgentId); 538 ScenePresence presence = m_scene.GetScenePresence(pClient.AgentId);
528 if (presence != null) 539 if (presence != null)
529 { 540 {
530 lock(m_perClientPatchUpdates) 541 lock (m_perClientPatchUpdates)
531 { 542 {
532 PatchUpdates pups; 543 PatchUpdates pups;
533 if (!m_perClientPatchUpdates.TryGetValue(pClient.AgentId, out pups)) 544 if (!m_perClientPatchUpdates.TryGetValue(pClient.AgentId, out pups))
@@ -536,7 +547,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain
536 pups = new PatchUpdates(m_scene.Heightmap.GetTerrainData(), presence); 547 pups = new PatchUpdates(m_scene.Heightmap.GetTerrainData(), presence);
537 m_perClientPatchUpdates.Add(presence.UUID, pups); 548 m_perClientPatchUpdates.Add(presence.UUID, pups);
538 } 549 }
539 // By setting all to modified, the next update tick will send the patches
540 pups.SetAll(true); 550 pups.SetAll(true);
541 } 551 }
542 } 552 }
@@ -547,6 +557,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
547 pClient.SendLayerData(new float[10]); 557 pClient.SendLayerData(new float[10]);
548 } 558 }
549 } 559 }
560
550 #region Plugin Loading Methods 561 #region Plugin Loading Methods
551 562
552 private void LoadPlugins() 563 private void LoadPlugins()
@@ -636,7 +647,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
636 m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere(); 647 m_painteffects[StandardTerrainEffects.Smooth] = new SmoothSphere();
637 m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere(); 648 m_painteffects[StandardTerrainEffects.Noise] = new NoiseSphere();
638 m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere(); 649 m_painteffects[StandardTerrainEffects.Flatten] = new FlattenSphere();
639 m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_revert); 650 m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_baked);
640 m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere(); 651 m_painteffects[StandardTerrainEffects.Erode] = new ErodeSphere();
641 m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere(); 652 m_painteffects[StandardTerrainEffects.Weather] = new WeatherSphere();
642 m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere(); 653 m_painteffects[StandardTerrainEffects.Olsen] = new OlsenSphere();
@@ -647,9 +658,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain
647 m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea(); 658 m_floodeffects[StandardTerrainEffects.Smooth] = new SmoothArea();
648 m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea(); 659 m_floodeffects[StandardTerrainEffects.Noise] = new NoiseArea();
649 m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea(); 660 m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea();
650 m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert); 661 m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_baked);
651 662
652 // Terrain Modifier operations 663 // Terrain Modifier operations
664
653 m_modifyOperations["min"] = new MinModifier(this); 665 m_modifyOperations["min"] = new MinModifier(this);
654 m_modifyOperations["max"] = new MaxModifier(this); 666 m_modifyOperations["max"] = new MaxModifier(this);
655 m_modifyOperations["raise"] = new RaiseModifier(this); 667 m_modifyOperations["raise"] = new RaiseModifier(this);
@@ -673,22 +685,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain
673 } 685 }
674 686
675 /// <summary> 687 /// <summary>
676 /// Saves the current state of the region into the revert map buffer. 688 /// Saves the current state of the region into the baked map buffer.
689
677 /// </summary> 690 /// </summary>
678 public void UpdateRevertMap() 691 public void UpdateBakedMap()
679 { 692 {
680 /* 693 m_baked = m_channel.MakeCopy();
681 int x; 694 m_painteffects[StandardTerrainEffects.Revert] = new RevertSphere(m_baked);
682 for (x = 0; x < m_channel.Width; x++) 695 m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_baked);
683 {
684 int y;
685 for (y = 0; y < m_channel.Height; y++)
686 {
687 m_revert[x, y] = m_channel[x, y];
688 }
689 }
690 */
691 m_revert = m_channel.MakeCopy();
692 } 696 }
693 697
694 /// <summary> 698 /// <summary>
@@ -715,11 +719,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
715 { 719 {
716 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY, 720 ITerrainChannel channel = loader.Value.LoadFile(filename, offsetX, offsetY,
717 fileWidth, fileHeight, 721 fileWidth, fileHeight,
718 (int)m_scene.RegionInfo.RegionSizeX, 722 (int) m_scene.RegionInfo.RegionSizeX,
719 (int)m_scene.RegionInfo.RegionSizeY); 723 (int) m_scene.RegionInfo.RegionSizeY);
720 m_scene.Heightmap = channel; 724 m_scene.Heightmap = channel;
721 m_channel = channel; 725 m_channel = channel;
722 UpdateRevertMap(); 726 UpdateBakedMap();
723 } 727 }
724 728
725 return; 729 return;
@@ -782,22 +786,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain
782 } 786 }
783 787
784 /// <summary> 788 /// <summary>
785 /// Called before processing of every simulation frame.
786 /// This is used to check to see of any of the terrain is tainted and, if so, schedule 789 /// This is used to check to see of any of the terrain is tainted and, if so, schedule
787 /// updates for all the presences. 790 /// updates for all the presences.
788 /// This also checks to see if there are updates that need to be sent for each presence. 791 /// This also checks to see if there are updates that need to be sent for each presence.
789 /// This is where the logic is to send terrain updates to clients. 792 /// This is where the logic is to send terrain updates to clients.
790 /// </summary> 793 /// </summary>
791 private void EventManager_OnFrame() 794 private void EventManager_TerrainCheckUpdates()
792 { 795 {
796 // this needs fixing
793 TerrainData terrData = m_channel.GetTerrainData(); 797 TerrainData terrData = m_channel.GetTerrainData();
794 798
795 bool shouldTaint = false; 799 bool shouldTaint = false;
796 for(int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize) 800 for (int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize)
797 { 801 {
798 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize) 802 for (int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
799 { 803 {
800 if (terrData.IsTaintedAt(x, y)) 804 if (terrData.IsTaintedAt(x, y,true))
801 { 805 {
802 // Found a patch that was modified. Push this flag into the clients. 806 // Found a patch that was modified. Push this flag into the clients.
803 SendToClients(terrData, x, y); 807 SendToClients(terrData, x, y);
@@ -883,11 +887,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain
883 presence.ControllingClient.OnLandUndo -= client_OnLandUndo; 887 presence.ControllingClient.OnLandUndo -= client_OnLandUndo;
884 presence.ControllingClient.OnUnackedTerrain -= client_OnUnackedTerrain; 888 presence.ControllingClient.OnUnackedTerrain -= client_OnUnackedTerrain;
885 } 889 }
886 890 lock (m_perClientPatchUpdates)
887 lock(m_perClientPatchUpdates)
888 m_perClientPatchUpdates.Remove(client); 891 m_perClientPatchUpdates.Remove(client);
889 } 892 }
890 893
891 /// <summary> 894 /// <summary>
892 /// Scan over changes in the terrain and limit height changes. This enforces the 895 /// Scan over changes in the terrain and limit height changes. This enforces the
893 /// non-estate owner limits on rate of terrain editting. 896 /// non-estate owner limits on rate of terrain editting.
@@ -898,12 +901,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
898 TerrainData terrData = m_channel.GetTerrainData(); 901 TerrainData terrData = m_channel.GetTerrainData();
899 902
900 bool wasLimited = false; 903 bool wasLimited = false;
901 for(int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize) 904 for (int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize)
902 { 905 {
903 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize) 906 for (int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
904 { 907 {
905 if (terrData.IsTaintedAt(x, y, false /* clearOnTest */)) 908 if (terrData.IsTaintedAt(x, y, false /* clearOnTest */))
906 { 909 {
907 // If we should respect the estate settings then 910 // If we should respect the estate settings then
908 // fixup and height deltas that don't respect them. 911 // fixup and height deltas that don't respect them.
909 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values. 912 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values.
@@ -926,13 +929,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain
926 float maxDelta = (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit; 929 float maxDelta = (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit;
927 930
928 // loop through the height map for this patch and compare it against 931 // loop through the height map for this patch and compare it against
929 // the revert map 932 // the baked map
930 for(int x = xStart; x < xStart + Constants.TerrainPatchSize; x++) 933 for (int x = xStart; x < xStart + Constants.TerrainPatchSize; x++)
931 { 934 {
932 for(int y = yStart; y < yStart + Constants.TerrainPatchSize; y++) 935 for(int y = yStart; y < yStart + Constants.TerrainPatchSize; y++)
933 { 936 {
934 float requestedHeight = terrData[x, y]; 937 float requestedHeight = terrData[x, y];
935 float bakedHeight = (float)m_revert[x, y]; 938 float bakedHeight = (float)m_baked[x, y];
936 float requestedDelta = requestedHeight - bakedHeight; 939 float requestedDelta = requestedHeight - bakedHeight;
937 940
938 if (requestedDelta > maxDelta) 941 if (requestedDelta > maxDelta)
@@ -953,15 +956,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain
953 956
954 private void client_OnLandUndo(IClientAPI client) 957 private void client_OnLandUndo(IClientAPI client)
955 { 958 {
956 lock(m_undo)
957 {
958 if (m_undo.Count > 0)
959 {
960 LandUndoState goback = m_undo.Pop();
961 if (goback != null)
962 goback.PlaybackState();
963 }
964 }
965 } 959 }
966 960
967 /// <summary> 961 /// <summary>
@@ -975,19 +969,19 @@ namespace OpenSim.Region.CoreModules.World.Terrain
975 if (m_sendTerrainUpdatesByViewDistance) 969 if (m_sendTerrainUpdatesByViewDistance)
976 { 970 {
977 // Add that this patch needs to be sent to the accounting for each client. 971 // Add that this patch needs to be sent to the accounting for each client.
978 lock(m_perClientPatchUpdates) 972 lock (m_perClientPatchUpdates)
979 { 973 {
980 m_scene.ForEachScenePresence(presence => 974 m_scene.ForEachScenePresence(presence =>
981 {
982 PatchUpdates thisClientUpdates;
983 if (!m_perClientPatchUpdates.TryGetValue(presence.UUID, out thisClientUpdates))
984 { 975 {
985 // There is a ScenePresence without a send patch map. Create one. 976 PatchUpdates thisClientUpdates;
986 thisClientUpdates = new PatchUpdates(terrData, presence); 977 if (!m_perClientPatchUpdates.TryGetValue(presence.UUID, out thisClientUpdates))
987 m_perClientPatchUpdates.Add(presence.UUID, thisClientUpdates); 978 {
979 // There is a ScenePresence without a send patch map. Create one.
980 thisClientUpdates = new PatchUpdates(terrData, presence);
981 m_perClientPatchUpdates.Add(presence.UUID, thisClientUpdates);
982 }
983 thisClientUpdates.SetByXY(x, y, true);
988 } 984 }
989 thisClientUpdates.SetByXY(x, y, true);
990 }
991 ); 985 );
992 } 986 }
993 } 987 }
@@ -998,7 +992,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
998 //float[] heightMap = terrData.GetFloatsSerialized(); 992 //float[] heightMap = terrData.GetFloatsSerialized();
999 float[] heightMap = new float[10]; 993 float[] heightMap = new float[10];
1000 m_scene.ForEachClient( 994 m_scene.ForEachClient(
1001 delegate(IClientAPI controller) 995 delegate (IClientAPI controller)
1002 { 996 {
1003 controller.SendLayerData(x / Constants.TerrainPatchSize, 997 controller.SendLayerData(x / Constants.TerrainPatchSize,
1004 y / Constants.TerrainPatchSize, 998 y / Constants.TerrainPatchSize,
@@ -1013,14 +1007,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1013 public int PatchX; 1007 public int PatchX;
1014 public int PatchY; 1008 public int PatchY;
1015 public float Dist; 1009 public float Dist;
1016
1017 public PatchesToSend(int pX, int pY, float pDist) 1010 public PatchesToSend(int pX, int pY, float pDist)
1018 { 1011 {
1019 PatchX = pX; 1012 PatchX = pX;
1020 PatchY = pY; 1013 PatchY = pY;
1021 Dist = pDist; 1014 Dist = pDist;
1022 } 1015 }
1023
1024 public int CompareTo(PatchesToSend other) 1016 public int CompareTo(PatchesToSend other)
1025 { 1017 {
1026 return Dist.CompareTo(other.Dist); 1018 return Dist.CompareTo(other.Dist);
@@ -1029,119 +1021,224 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1029 1021
1030 // Called each frame time to see if there are any patches to send to any of the 1022 // Called each frame time to see if there are any patches to send to any of the
1031 // ScenePresences. 1023 // ScenePresences.
1032 // We know this is only called if we are doing view distance patch sending so some
1033 // tests are not made.
1034 // Loop through all the per-client info and send any patches necessary. 1024 // Loop through all the per-client info and send any patches necessary.
1035 private void CheckSendingPatchesToClients() 1025 private void CheckSendingPatchesToClients()
1036 { 1026 {
1037 lock(m_perClientPatchUpdates) 1027 lock (m_perClientPatchUpdates)
1038 { 1028 {
1039 foreach(PatchUpdates pups in m_perClientPatchUpdates.Values) 1029 foreach (PatchUpdates pups in m_perClientPatchUpdates.Values)
1040 { 1030 {
1031 if(pups.Presence.IsDeleted)
1032 continue;
1033
1034 // throught acording to land queue free to send bytes
1035 if (!pups.Presence.ControllingClient.CanSendLayerData())
1036 continue;
1037
1041 if (pups.HasUpdates()) 1038 if (pups.HasUpdates())
1042 { 1039 {
1043 // There is something that could be sent to this client. 1040 if (m_sendTerrainUpdatesByViewDistance)
1044 List<PatchesToSend> toSend = GetModifiedPatchesInViewDistance(pups);
1045 if (toSend.Count > 0)
1046 { 1041 {
1047 // m_log.DebugFormat("{0} CheckSendingPatchesToClient: sending {1} patches to {2} in region {3}", 1042 // There is something that could be sent to this client.
1048 // LogHeader, toSend.Count, pups.Presence.Name, m_scene.RegionInfo.RegionName); 1043 List<PatchesToSend> toSend = GetModifiedPatchesInViewDistance(pups);
1049 // Sort the patches to send by the distance from the presence 1044 if (toSend.Count > 0)
1050 toSend.Sort();
1051 /* old way that sent individual patches
1052 foreach (PatchesToSend pts in toSend)
1053 { 1045 {
1054 pups.Presence.ControllingClient.SendLayerData(pts.PatchX, pts.PatchY, null); 1046 // m_log.DebugFormat("{0} CheckSendingPatchesToClient: sending {1} patches to {2} in region {3}",
1055 // presence.ControllingClient.SendLayerData(xs.ToArray(), ys.ToArray(), null, TerrainPatch.LayerType.Land); 1047 // LogHeader, toSend.Count, pups.Presence.Name, m_scene.RegionInfo.RegionName);
1056 } 1048 // Sort the patches to send by the distance from the presence
1057 */ 1049 toSend.Sort();
1058 1050 /*
1059 // new way that sends all patches to the protocol so they can be sent in one block 1051 foreach (PatchesToSend pts in toSend)
1060 int[] xPieces = new int[toSend.Count]; 1052 {
1061 int[] yPieces = new int[toSend.Count]; 1053 pups.Presence.ControllingClient.SendLayerData(pts.PatchX, pts.PatchY, null);
1062 float[] patchPieces = new float[toSend.Count * 2]; 1054 // presence.ControllingClient.SendLayerData(xs.ToArray(), ys.ToArray(), null, TerrainPatch.LayerType.Land);
1063 int pieceIndex = 0; 1055 }
1064 foreach(PatchesToSend pts in toSend) 1056 */
1065 { 1057
1066 patchPieces[pieceIndex++] = pts.PatchX; 1058 int[] xPieces = new int[toSend.Count];
1067 patchPieces[pieceIndex++] = pts.PatchY; 1059 int[] yPieces = new int[toSend.Count];
1060 float[] patchPieces = new float[toSend.Count * 2];
1061 int pieceIndex = 0;
1062 foreach (PatchesToSend pts in toSend)
1063 {
1064 patchPieces[pieceIndex++] = pts.PatchX;
1065 patchPieces[pieceIndex++] = pts.PatchY;
1066 }
1067 pups.Presence.ControllingClient.SendLayerData(-toSend.Count, 0, patchPieces);
1068 } 1068 }
1069 pups.Presence.ControllingClient.SendLayerData(-toSend.Count, 0, patchPieces); 1069 if (pups.sendAll && toSend.Count < 1024)
1070 SendAllModifiedPatchs(pups);
1070 } 1071 }
1072 else
1073 SendAllModifiedPatchs(pups);
1071 } 1074 }
1072 } 1075 }
1073 } 1076 }
1074 } 1077 }
1078 private void SendAllModifiedPatchs(PatchUpdates pups)
1079 {
1080 if (!pups.sendAll) // sanity
1081 return;
1082
1083 int limitX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize;
1084 int limitY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize;
1085
1086 if (pups.sendAllcurrentX > limitX || pups.sendAllcurrentY > limitY)
1087 {
1088 pups.sendAll = false;
1089 pups.sendAllcurrentX = 0;
1090 pups.sendAllcurrentY = 0;
1091 return;
1092 }
1093
1094 int npatchs = 0;
1095 List<PatchesToSend> patchs = new List<PatchesToSend>();
1096 int x = pups.sendAllcurrentX;
1097 int y = pups.sendAllcurrentY;
1098 // send it in the order viewer draws it
1099 // even if not best for memory scan
1100 for (; y < limitY; y++)
1101 {
1102 for (; x < limitX; x++)
1103 {
1104 if (pups.GetByPatch(x, y))
1105 {
1106 pups.SetByPatch(x, y, false);
1107 patchs.Add(new PatchesToSend(x, y, 0));
1108 if (++npatchs >= 128)
1109 {
1110 x++;
1111 break;
1112 }
1113 }
1114 }
1115 if (npatchs >= 128)
1116 break;
1117 x = 0;
1118 }
1119
1120 if (x >= limitX && y >= limitY)
1121 {
1122 pups.sendAll = false;
1123 pups.sendAllcurrentX = 0;
1124 pups.sendAllcurrentY = 0;
1125 }
1126 else
1127 {
1128 pups.sendAllcurrentX = x;
1129 pups.sendAllcurrentY = y;
1130 }
1131
1132 npatchs = patchs.Count;
1133 if (npatchs > 0)
1134 {
1135 int[] xPieces = new int[npatchs];
1136 int[] yPieces = new int[npatchs];
1137 float[] patchPieces = new float[npatchs * 2];
1138 int pieceIndex = 0;
1139 foreach (PatchesToSend pts in patchs)
1140 {
1141 patchPieces[pieceIndex++] = pts.PatchX;
1142 patchPieces[pieceIndex++] = pts.PatchY;
1143 }
1144 pups.Presence.ControllingClient.SendLayerData(-npatchs, 0, patchPieces);
1145 }
1146 }
1075 1147
1076 // Compute a list of modified patches that are within our view distance.
1077 private List<PatchesToSend> GetModifiedPatchesInViewDistance(PatchUpdates pups) 1148 private List<PatchesToSend> GetModifiedPatchesInViewDistance(PatchUpdates pups)
1078 { 1149 {
1079 List<PatchesToSend> ret = new List<PatchesToSend>(); 1150 List<PatchesToSend> ret = new List<PatchesToSend>();
1080 1151
1152 int npatchs = 0;
1153
1081 ScenePresence presence = pups.Presence; 1154 ScenePresence presence = pups.Presence;
1082 if (presence == null) 1155 if (presence == null)
1083 return ret; 1156 return ret;
1084 1157
1085 Vector3 presencePos = presence.AbsolutePosition; 1158 float minz = presence.AbsolutePosition.Z;
1086 1159 if (presence.CameraPosition.Z < minz)
1087 // Before this distance check, the whole region just showed up. Adding the distance 1160 minz = presence.CameraPosition.Z;
1088 // check causes different things to happen for the current and adjacent regions. 1161
1089 // So, to keep legacy views, if the region is legacy sized, don't do distance check. 1162 // this limit should be max terrainheight + max draw
1090 bool isLegacySizedRegion = pups.Terrain.SizeX == Constants.RegionSize && pups.Terrain.SizeY == Constants.RegionSize; 1163 if (minz > 1500f)
1091 bool shouldCheckViewDistance = m_sendTerrainUpdatesByViewDistance && !isLegacySizedRegion; 1164 return ret;
1092 1165
1093 int startX = 0; 1166 int DrawDistance = (int)presence.DrawDistance;
1094 int endX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize; 1167
1095 int startY = 0; 1168 DrawDistance = DrawDistance / Constants.TerrainPatchSize;
1096 int endY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize; 1169
1097 1170 int testposX;
1098 // The following only reduces the size of area scanned for updates. Only significant for very large varregions. 1171 int testposY;
1099 if (shouldCheckViewDistance) 1172
1100 { 1173 if (Math.Abs(presence.AbsolutePosition.X - presence.CameraPosition.X) > 30
1101 // Compute the area of patches within our draw distance 1174 || Math.Abs(presence.AbsolutePosition.Y - presence.CameraPosition.Y) > 30)
1102 startX = (((int)(presencePos.X - presence.DrawDistance)) / Constants.TerrainPatchSize) - 2; 1175 {
1103 startX = Math.Max(startX, 0); 1176 testposX = (int)presence.CameraPosition.X / Constants.TerrainPatchSize;
1104 startX = Math.Min(startX, (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize); 1177 testposY = (int)presence.CameraPosition.Y / Constants.TerrainPatchSize;
1105 startY = (((int)(presencePos.Y - presence.DrawDistance)) / Constants.TerrainPatchSize) - 2; 1178 }
1106 startY = Math.Max(startY, 0); 1179 else
1107 startY = Math.Min(startY, (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize); 1180 {
1108 endX = (((int)(presencePos.X + presence.DrawDistance)) / Constants.TerrainPatchSize) + 2; 1181 testposX = (int)presence.AbsolutePosition.X / Constants.TerrainPatchSize;
1109 endX = Math.Max(endX, 0); 1182 testposY = (int)presence.AbsolutePosition.Y / Constants.TerrainPatchSize;
1110 endX = Math.Min(endX, (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize); 1183 }
1111 endY = (((int)(presencePos.Y + presence.DrawDistance)) / Constants.TerrainPatchSize) + 2; 1184 int limitX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize;
1112 endY = Math.Max(endY, 0); 1185 int limitY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize;
1113 endY = Math.Min(endY, (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize); 1186
1114 } 1187 // Compute the area of patches within our draw distance
1115 1188 int startX = testposX - DrawDistance;
1116 // m_log.DebugFormat("{0} GetModifiedPatchesInViewDistance. rName={1}, ddist={2}, apos={3}, cpos={4}, isChild={5}, start=<{6},{7}>, end=<{8},{9}>", 1189 if (startX < 0)
1117 // LogHeader, m_scene.RegionInfo.RegionName, 1190 startX = 0;
1118 // presence.DrawDistance, presencePos, presence.CameraPosition, 1191 else if (startX >= limitX)
1119 // isLegacySizeChildRegion, 1192 startX = limitX - 1;
1120 // startX, startY, endX, endY); 1193
1121 for(int x = startX; x < endX; x++) 1194 int startY = testposY - DrawDistance;
1122 { 1195 if (startY < 0)
1123 for(int y = startY; y < endY; y++) 1196 startY = 0;
1197 else if (startY >= limitY)
1198 startY = limitY - 1;
1199
1200 int endX = testposX + DrawDistance;
1201 if (endX < 0)
1202 endX = 0;
1203 else if (endX > limitX)
1204 endX = limitX;
1205
1206 int endY = testposY + DrawDistance;
1207 if (endY < 0)
1208 endY = 0;
1209 else if (endY > limitY)
1210 endY = limitY;
1211
1212 int distx;
1213 int disty;
1214 int distsq;
1215
1216 DrawDistance *= DrawDistance;
1217
1218 for (int x = startX; x < endX; x++)
1219 {
1220 for (int y = startY; y < endY; y++)
1124 { 1221 {
1125 //Need to make sure we don't send the same ones over and over
1126 Vector3 patchPos = new Vector3(x * Constants.TerrainPatchSize, y * Constants.TerrainPatchSize, presencePos.Z);
1127 if (pups.GetByPatch(x, y)) 1222 if (pups.GetByPatch(x, y))
1128 { 1223 {
1129 //Check which has less distance, camera or avatar position, both have to be done. 1224 distx = x - testposX;
1130 //Its not a radius, its a diameter and we add 50 so that it doesn't look like it cuts off 1225 disty = y - testposY;
1131 if (!shouldCheckViewDistance 1226 distsq = distx * distx + disty * disty;
1132 || Util.DistanceLessThan(presencePos, patchPos, presence.DrawDistance + 50) 1227 if (distsq < DrawDistance)
1133 || Util.DistanceLessThan(presence.CameraPosition, patchPos, presence.DrawDistance + 50))
1134 { 1228 {
1135 //They can see it, send it to them
1136 pups.SetByPatch(x, y, false); 1229 pups.SetByPatch(x, y, false);
1137 float dist = Vector3.DistanceSquared(presencePos, patchPos); 1230 ret.Add(new PatchesToSend(x, y, (float)distsq));
1138 ret.Add(new PatchesToSend(x, y, dist)); 1231 if (npatchs++ > 1024)
1232 {
1233 y = endY;
1234 x = endX;
1235 }
1139 } 1236 }
1140 } 1237 }
1141 } 1238 }
1142 } 1239 }
1143 return ret; 1240 return ret;
1144 } 1241 }
1145 1242
1146 private void client_OnModifyTerrain(UUID user, float height, float seconds, byte size, byte action, 1243 private void client_OnModifyTerrain(UUID user, float height, float seconds, byte size, byte action,
1147 float north, float west, float south, float east, UUID agentId) 1244 float north, float west, float south, float east, UUID agentId)
@@ -1161,31 +1258,42 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1161 int zx = (int)(west + 0.5); 1258 int zx = (int)(west + 0.5);
1162 int zy = (int)(north + 0.5); 1259 int zy = (int)(north + 0.5);
1163 1260
1164 int dx; 1261 int startX = zx - n;
1165 for(dx=-n; dx<=n; dx++) 1262 if (startX < 0)
1263 startX = 0;
1264
1265 int startY = zy - n;
1266 if (startY < 0)
1267 startY = 0;
1268
1269 int endX = zx + n;
1270 if (endX >= m_channel.Width)
1271 endX = m_channel.Width - 1;
1272 int endY = zy + n;
1273 if (endY >= m_channel.Height)
1274 endY = m_channel.Height - 1;
1275
1276 int x, y;
1277
1278 for (x = startX; x <= endX; x++)
1166 { 1279 {
1167 int dy; 1280 for (y = startY; y <= endY; y++)
1168 for(dy=-n; dy<=n; dy++)
1169 { 1281 {
1170 int x = zx + dx; 1282 if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0)))
1171 int y = zy + dy;
1172 if (x >= 0 && y >= 0 && x < m_channel.Width && y < m_channel.Height)
1173 { 1283 {
1174 if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0))) 1284 allowMask[x, y] = true;
1175 { 1285 allowed = true;
1176 allowMask[x, y] = true;
1177 allowed = true;
1178 }
1179 } 1286 }
1180 } 1287 }
1181 } 1288 }
1182 if (allowed) 1289 if (allowed)
1183 { 1290 {
1184 StoreUndoState(); 1291 StoreUndoState();
1185 m_painteffects[(StandardTerrainEffects)action].PaintEffect( 1292 m_painteffects[(StandardTerrainEffects) action].PaintEffect(
1186 m_channel, allowMask, west, south, height, size, seconds); 1293 m_channel, allowMask, west, south, height, size, seconds,
1294 startX, endX, startY, endY);
1187 1295
1188 //revert changes outside estate limits 1296 //block changes outside estate limits
1189 if (!god) 1297 if (!god)
1190 EnforceEstateLimits(); 1298 EnforceEstateLimits();
1191 } 1299 }
@@ -1202,22 +1310,42 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1202 bool[,] fillArea = new bool[m_channel.Width, m_channel.Height]; 1310 bool[,] fillArea = new bool[m_channel.Width, m_channel.Height];
1203 fillArea.Initialize(); 1311 fillArea.Initialize();
1204 1312
1205 int x; 1313 int startX = (int)west;
1206 for(x = 0; x < m_channel.Width; x++) 1314 int startY = (int)south;
1315 int endX = (int)east;
1316 int endY = (int)north;
1317
1318 if (startX < 0)
1319 startX = 0;
1320 else if (startX >= m_channel.Width)
1321 startX = m_channel.Width - 1;
1322
1323 if (endX < 0)
1324 endX = 0;
1325 else if (endX >= m_channel.Width)
1326 endX = m_channel.Width - 1;
1327
1328 if (startY < 0)
1329 startY = 0;
1330 else if (startY >= m_channel.Height)
1331 startY = m_channel.Height - 1;
1332
1333 if (endY < 0)
1334 endY = 0;
1335 else if (endY >= m_channel.Height)
1336 endY = m_channel.Height - 1;
1337
1338
1339 int x, y;
1340
1341 for (x = startX; x <= endX; x++)
1207 { 1342 {
1208 int y; 1343 for (y = startY; y <= endY; y++)
1209 for(y = 0; y < m_channel.Height; y++)
1210 { 1344 {
1211 if (x < east && x > west) 1345 if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0)))
1212 { 1346 {
1213 if (y < north && y > south) 1347 fillArea[x, y] = true;
1214 { 1348 allowed = true;
1215 if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0)))
1216 {
1217 fillArea[x, y] = true;
1218 allowed = true;
1219 }
1220 }
1221 } 1349 }
1222 } 1350 }
1223 } 1351 }
@@ -1225,9 +1353,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1225 if (allowed) 1353 if (allowed)
1226 { 1354 {
1227 StoreUndoState(); 1355 StoreUndoState();
1228 m_floodeffects[(StandardTerrainEffects)action].FloodEffect(m_channel, fillArea, size); 1356 m_floodeffects[(StandardTerrainEffects)action].FloodEffect(m_channel, fillArea, size,
1357 startX, endX, startY, endY);
1229 1358
1230 //revert changes outside estate limits 1359 //block changes outside estate limits
1231 if (!god) 1360 if (!god)
1232 EnforceEstateLimits(); 1361 EnforceEstateLimits();
1233 } 1362 }
@@ -1260,37 +1389,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1260 1389
1261 private void StoreUndoState() 1390 private void StoreUndoState()
1262 { 1391 {
1263 lock(m_undo)
1264 {
1265 if (m_undo.Count > 0)
1266 {
1267 LandUndoState last = m_undo.Peek();
1268 if (last != null)
1269 {
1270 if (last.Compare(m_channel))
1271 return;
1272 }
1273 }
1274
1275 LandUndoState nUndo = new LandUndoState(this, m_channel);
1276 m_undo.Push(nUndo);
1277 }
1278 } 1392 }
1279 1393
1280 #region Console Commands 1394 #region Console Commands
1281 1395
1282 private void InterfaceLoadFile(Object[] args) 1396 private void InterfaceLoadFile(Object[] args)
1283 { 1397 {
1284 LoadFromFile((string)args[0]); 1398 LoadFromFile((string) args[0]);
1285 } 1399 }
1286 1400
1287 private void InterfaceLoadTileFile(Object[] args) 1401 private void InterfaceLoadTileFile(Object[] args)
1288 { 1402 {
1289 LoadFromFile((string)args[0], 1403 LoadFromFile((string) args[0],
1290 (int)args[1], 1404 (int) args[1],
1291 (int)args[2], 1405 (int) args[2],
1292 (int)args[3], 1406 (int) args[3],
1293 (int)args[4]); 1407 (int) args[4]);
1294 } 1408 }
1295 1409
1296 private void InterfaceSaveFile(Object[] args) 1410 private void InterfaceSaveFile(Object[] args)
@@ -1309,15 +1423,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1309 1423
1310 private void InterfaceBakeTerrain(Object[] args) 1424 private void InterfaceBakeTerrain(Object[] args)
1311 { 1425 {
1312 UpdateRevertMap(); 1426 UpdateBakedMap();
1313 } 1427 }
1314 1428
1315 private void InterfaceRevertTerrain(Object[] args) 1429 private void InterfaceRevertTerrain(Object[] args)
1316 { 1430 {
1317 int x, y; 1431 int x, y;
1318 for(x = 0; x < m_channel.Width; x++) 1432 for (x = 0; x < m_channel.Width; x++)
1319 for(y = 0; y < m_channel.Height; y++) 1433 for (y = 0; y < m_channel.Height; y++)
1320 m_channel[x, y] = m_revert[x, y]; 1434 m_channel[x, y] = m_baked[x, y];
1321 1435
1322 } 1436 }
1323 1437
@@ -1327,9 +1441,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1327 1441
1328 if (direction.ToLower().StartsWith("y")) 1442 if (direction.ToLower().StartsWith("y"))
1329 { 1443 {
1330 for(int x = 0; x < m_channel.Width; x++) 1444 for (int x = 0; x < m_channel.Width; x++)
1331 { 1445 {
1332 for(int y = 0; y < m_channel.Height / 2; y++) 1446 for (int y = 0; y < m_channel.Height / 2; y++)
1333 { 1447 {
1334 double height = m_channel[x, y]; 1448 double height = m_channel[x, y];
1335 double flippedHeight = m_channel[x, (int)m_channel.Height - 1 - y]; 1449 double flippedHeight = m_channel[x, (int)m_channel.Height - 1 - y];
@@ -1341,9 +1455,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1341 } 1455 }
1342 else if (direction.ToLower().StartsWith("x")) 1456 else if (direction.ToLower().StartsWith("x"))
1343 { 1457 {
1344 for(int y = 0; y < m_channel.Height; y++) 1458 for (int y = 0; y < m_channel.Height; y++)
1345 { 1459 {
1346 for(int x = 0; x < m_channel.Width / 2; x++) 1460 for (int x = 0; x < m_channel.Width / 2; x++)
1347 { 1461 {
1348 double height = m_channel[x, y]; 1462 double height = m_channel[x, y];
1349 double flippedHeight = m_channel[(int)m_channel.Width - 1 - x, y]; 1463 double flippedHeight = m_channel[(int)m_channel.Width - 1 - x, y];
@@ -1415,50 +1529,57 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1415 } 1529 }
1416 1530
1417 } 1531 }
1418
1419 } 1532 }
1420 1533
1421 private void InterfaceElevateTerrain(Object[] args) 1534 private void InterfaceElevateTerrain(Object[] args)
1422 { 1535 {
1536 double val = (double)args[0];
1537
1423 int x, y; 1538 int x, y;
1424 for(x = 0; x < m_channel.Width; x++) 1539 for (x = 0; x < m_channel.Width; x++)
1425 for(y = 0; y < m_channel.Height; y++) 1540 for (y = 0; y < m_channel.Height; y++)
1426 m_channel[x, y] += (double)args[0]; 1541 m_channel[x, y] += val;
1427 } 1542 }
1428 1543
1429 private void InterfaceMultiplyTerrain(Object[] args) 1544 private void InterfaceMultiplyTerrain(Object[] args)
1430 { 1545 {
1431 int x, y; 1546 int x, y;
1432 for(x = 0; x < m_channel.Width; x++) 1547 double val = (double)args[0];
1433 for(y = 0; y < m_channel.Height; y++) 1548
1434 m_channel[x, y] *= (double)args[0]; 1549 for (x = 0; x < m_channel.Width; x++)
1550 for (y = 0; y < m_channel.Height; y++)
1551 m_channel[x, y] *= val;
1435 } 1552 }
1436 1553
1437 private void InterfaceLowerTerrain(Object[] args) 1554 private void InterfaceLowerTerrain(Object[] args)
1438 { 1555 {
1439 int x, y; 1556 int x, y;
1440 for(x = 0; x < m_channel.Width; x++) 1557 double val = (double)args[0];
1441 for(y = 0; y < m_channel.Height; y++) 1558
1442 m_channel[x, y] -= (double)args[0]; 1559 for (x = 0; x < m_channel.Width; x++)
1560 for (y = 0; y < m_channel.Height; y++)
1561 m_channel[x, y] -= val;
1443 } 1562 }
1444 1563
1445 public void InterfaceFillTerrain(Object[] args) 1564 public void InterfaceFillTerrain(Object[] args)
1446 { 1565 {
1447 int x, y; 1566 int x, y;
1567 double val = (double)args[0];
1448 1568
1449 for(x = 0; x < m_channel.Width; x++) 1569 for (x = 0; x < m_channel.Width; x++)
1450 for(y = 0; y < m_channel.Height; y++) 1570 for (y = 0; y < m_channel.Height; y++)
1451 m_channel[x, y] = (double)args[0]; 1571 m_channel[x, y] = val;
1452 } 1572 }
1453 1573
1454 private void InterfaceMinTerrain(Object[] args) 1574 private void InterfaceMinTerrain(Object[] args)
1455 { 1575 {
1456 int x, y; 1576 int x, y;
1457 for(x = 0; x < m_channel.Width; x++) 1577 double val = (double)args[0];
1578 for (x = 0; x < m_channel.Width; x++)
1458 { 1579 {
1459 for(y = 0; y < m_channel.Height; y++) 1580 for(y = 0; y < m_channel.Height; y++)
1460 { 1581 {
1461 m_channel[x, y] = Math.Max((double)args[0], m_channel[x, y]); 1582 m_channel[x, y] = Math.Max(val, m_channel[x, y]);
1462 } 1583 }
1463 } 1584 }
1464 } 1585 }
@@ -1466,11 +1587,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1466 private void InterfaceMaxTerrain(Object[] args) 1587 private void InterfaceMaxTerrain(Object[] args)
1467 { 1588 {
1468 int x, y; 1589 int x, y;
1469 for(x = 0; x < m_channel.Width; x++) 1590 double val = (double)args[0];
1591 for (x = 0; x < m_channel.Width; x++)
1470 { 1592 {
1471 for(y = 0; y < m_channel.Height; y++) 1593 for(y = 0; y < m_channel.Height; y++)
1472 { 1594 {
1473 m_channel[x, y] = Math.Min((double)args[0], m_channel[x, y]); 1595 m_channel[x, y] = Math.Min(val, m_channel[x, y]);
1474 } 1596 }
1475 } 1597 }
1476 } 1598 }
@@ -1620,9 +1742,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1620 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); 1742 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double");
1621 1743
1622 Command bakeRegionCommand = 1744 Command bakeRegionCommand =
1623 new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); 1745 new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions baked map.");
1624 Command revertRegionCommand = 1746 Command revertRegionCommand =
1625 new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); 1747 new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the baked map terrain into the regions heightmap.");
1626 1748
1627 Command flipCommand = 1749 Command flipCommand =
1628 new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis"); 1750 new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis");
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs
index 29e80ef..b209b33 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs
@@ -60,7 +60,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
60 TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize); 60 TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
61 ITerrainPaintableEffect effect = new RaiseSphere(); 61 ITerrainPaintableEffect effect = new RaiseSphere();
62 62
63 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0); 63 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
64 0, midRegion - 1,0, (int)Constants.RegionSize -1);
64 Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128)."); 65 Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128).");
65 Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128)."); 66 Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128).");
66 Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128)."); 67 Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128).");
@@ -79,7 +80,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
79 } 80 }
80 effect = new LowerSphere(); 81 effect = new LowerSphere();
81 82
82 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0); 83 effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
84 0, (int)Constants.RegionSize -1,0, (int)Constants.RegionSize -1);
83 Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128)."); 85 Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
84 Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128)."); 86 Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
85 Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128)."); 87 Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128).");