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.cs633
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/Tests/TerrainTest.cs6
25 files changed, 524 insertions, 431 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..5e35d95 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;
@@ -781,39 +785,54 @@ namespace OpenSim.Region.CoreModules.World.Terrain
781 m_scene.RegionInfo.RegionName, filename, m_supportFileExtensionsForTileSave); 785 m_scene.RegionInfo.RegionName, filename, m_supportFileExtensionsForTileSave);
782 } 786 }
783 787
788
784 /// <summary> 789 /// <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 790 /// This is used to check to see of any of the terrain is tainted and, if so, schedule
787 /// updates for all the presences. 791 /// updates for all the presences.
788 /// This also checks to see if there are updates that need to be sent for each presence. 792 /// 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. 793 /// This is where the logic is to send terrain updates to clients.
790 /// </summary> 794 /// </summary>
791 private void EventManager_OnFrame() 795 /// doing it async, since currently this is 2 heavy for heartbeat
796 private void EventManager_TerrainCheckUpdates()
792 { 797 {
793 TerrainData terrData = m_channel.GetTerrainData(); 798 Util.FireAndForget(
799 EventManager_TerrainCheckUpdatesAsync);
800 }
794 801
795 bool shouldTaint = false; 802 object TerrainCheckUpdatesLock = new object();
796 for(int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize) 803
804 private void EventManager_TerrainCheckUpdatesAsync(object o)
805 {
806 // dont overlap execution
807 if(Monitor.TryEnter(TerrainCheckUpdatesLock))
797 { 808 {
798 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize) 809 // this needs fixing
810 TerrainData terrData = m_channel.GetTerrainData();
811
812 bool shouldTaint = false;
813 for (int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize)
799 { 814 {
800 if (terrData.IsTaintedAt(x, y)) 815 for (int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
801 { 816 {
802 // Found a patch that was modified. Push this flag into the clients. 817 if (terrData.IsTaintedAt(x, y,true))
803 SendToClients(terrData, x, y); 818 {
804 shouldTaint = true; 819 // Found a patch that was modified. Push this flag into the clients.
820 SendToClients(terrData, x, y);
821 shouldTaint = true;
822 }
805 } 823 }
806 } 824 }
807 }
808 825
809 // This event also causes changes to be sent to the clients 826 // This event also causes changes to be sent to the clients
810 CheckSendingPatchesToClients(); 827 CheckSendingPatchesToClients();
811 828
812 // If things changes, generate some events 829 // If things changes, generate some events
813 if (shouldTaint) 830 if (shouldTaint)
814 { 831 {
815 m_scene.EventManager.TriggerTerrainTainted(); 832 m_scene.EventManager.TriggerTerrainTainted();
816 m_tainted = true; 833 m_tainted = true;
834 }
835 Monitor.Exit(TerrainCheckUpdatesLock);
817 } 836 }
818 } 837 }
819 838
@@ -883,11 +902,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain
883 presence.ControllingClient.OnLandUndo -= client_OnLandUndo; 902 presence.ControllingClient.OnLandUndo -= client_OnLandUndo;
884 presence.ControllingClient.OnUnackedTerrain -= client_OnUnackedTerrain; 903 presence.ControllingClient.OnUnackedTerrain -= client_OnUnackedTerrain;
885 } 904 }
886 905 lock (m_perClientPatchUpdates)
887 lock(m_perClientPatchUpdates)
888 m_perClientPatchUpdates.Remove(client); 906 m_perClientPatchUpdates.Remove(client);
889 } 907 }
890 908
891 /// <summary> 909 /// <summary>
892 /// Scan over changes in the terrain and limit height changes. This enforces the 910 /// Scan over changes in the terrain and limit height changes. This enforces the
893 /// non-estate owner limits on rate of terrain editting. 911 /// non-estate owner limits on rate of terrain editting.
@@ -898,12 +916,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
898 TerrainData terrData = m_channel.GetTerrainData(); 916 TerrainData terrData = m_channel.GetTerrainData();
899 917
900 bool wasLimited = false; 918 bool wasLimited = false;
901 for(int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize) 919 for (int x = 0; x < terrData.SizeX; x += Constants.TerrainPatchSize)
902 { 920 {
903 for(int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize) 921 for (int y = 0; y < terrData.SizeY; y += Constants.TerrainPatchSize)
904 { 922 {
905 if (terrData.IsTaintedAt(x, y, false /* clearOnTest */)) 923 if (terrData.IsTaintedAt(x, y, false /* clearOnTest */))
906 { 924 {
907 // If we should respect the estate settings then 925 // If we should respect the estate settings then
908 // fixup and height deltas that don't respect them. 926 // fixup and height deltas that don't respect them.
909 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values. 927 // Note that LimitChannelChanges() modifies the TerrainChannel with the limited height values.
@@ -926,13 +944,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain
926 float maxDelta = (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit; 944 float maxDelta = (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit;
927 945
928 // loop through the height map for this patch and compare it against 946 // loop through the height map for this patch and compare it against
929 // the revert map 947 // the baked map
930 for(int x = xStart; x < xStart + Constants.TerrainPatchSize; x++) 948 for (int x = xStart; x < xStart + Constants.TerrainPatchSize; x++)
931 { 949 {
932 for(int y = yStart; y < yStart + Constants.TerrainPatchSize; y++) 950 for(int y = yStart; y < yStart + Constants.TerrainPatchSize; y++)
933 { 951 {
934 float requestedHeight = terrData[x, y]; 952 float requestedHeight = terrData[x, y];
935 float bakedHeight = (float)m_revert[x, y]; 953 float bakedHeight = (float)m_baked[x, y];
936 float requestedDelta = requestedHeight - bakedHeight; 954 float requestedDelta = requestedHeight - bakedHeight;
937 955
938 if (requestedDelta > maxDelta) 956 if (requestedDelta > maxDelta)
@@ -953,15 +971,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain
953 971
954 private void client_OnLandUndo(IClientAPI client) 972 private void client_OnLandUndo(IClientAPI client)
955 { 973 {
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 } 974 }
966 975
967 /// <summary> 976 /// <summary>
@@ -975,19 +984,19 @@ namespace OpenSim.Region.CoreModules.World.Terrain
975 if (m_sendTerrainUpdatesByViewDistance) 984 if (m_sendTerrainUpdatesByViewDistance)
976 { 985 {
977 // Add that this patch needs to be sent to the accounting for each client. 986 // Add that this patch needs to be sent to the accounting for each client.
978 lock(m_perClientPatchUpdates) 987 lock (m_perClientPatchUpdates)
979 { 988 {
980 m_scene.ForEachScenePresence(presence => 989 m_scene.ForEachScenePresence(presence =>
981 {
982 PatchUpdates thisClientUpdates;
983 if (!m_perClientPatchUpdates.TryGetValue(presence.UUID, out thisClientUpdates))
984 { 990 {
985 // There is a ScenePresence without a send patch map. Create one. 991 PatchUpdates thisClientUpdates;
986 thisClientUpdates = new PatchUpdates(terrData, presence); 992 if (!m_perClientPatchUpdates.TryGetValue(presence.UUID, out thisClientUpdates))
987 m_perClientPatchUpdates.Add(presence.UUID, thisClientUpdates); 993 {
994 // There is a ScenePresence without a send patch map. Create one.
995 thisClientUpdates = new PatchUpdates(terrData, presence);
996 m_perClientPatchUpdates.Add(presence.UUID, thisClientUpdates);
997 }
998 thisClientUpdates.SetByXY(x, y, true);
988 } 999 }
989 thisClientUpdates.SetByXY(x, y, true);
990 }
991 ); 1000 );
992 } 1001 }
993 } 1002 }
@@ -998,7 +1007,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
998 //float[] heightMap = terrData.GetFloatsSerialized(); 1007 //float[] heightMap = terrData.GetFloatsSerialized();
999 float[] heightMap = new float[10]; 1008 float[] heightMap = new float[10];
1000 m_scene.ForEachClient( 1009 m_scene.ForEachClient(
1001 delegate(IClientAPI controller) 1010 delegate (IClientAPI controller)
1002 { 1011 {
1003 controller.SendLayerData(x / Constants.TerrainPatchSize, 1012 controller.SendLayerData(x / Constants.TerrainPatchSize,
1004 y / Constants.TerrainPatchSize, 1013 y / Constants.TerrainPatchSize,
@@ -1013,14 +1022,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1013 public int PatchX; 1022 public int PatchX;
1014 public int PatchY; 1023 public int PatchY;
1015 public float Dist; 1024 public float Dist;
1016
1017 public PatchesToSend(int pX, int pY, float pDist) 1025 public PatchesToSend(int pX, int pY, float pDist)
1018 { 1026 {
1019 PatchX = pX; 1027 PatchX = pX;
1020 PatchY = pY; 1028 PatchY = pY;
1021 Dist = pDist; 1029 Dist = pDist;
1022 } 1030 }
1023
1024 public int CompareTo(PatchesToSend other) 1031 public int CompareTo(PatchesToSend other)
1025 { 1032 {
1026 return Dist.CompareTo(other.Dist); 1033 return Dist.CompareTo(other.Dist);
@@ -1029,119 +1036,224 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1029 1036
1030 // Called each frame time to see if there are any patches to send to any of the 1037 // Called each frame time to see if there are any patches to send to any of the
1031 // ScenePresences. 1038 // 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. 1039 // Loop through all the per-client info and send any patches necessary.
1035 private void CheckSendingPatchesToClients() 1040 private void CheckSendingPatchesToClients()
1036 { 1041 {
1037 lock(m_perClientPatchUpdates) 1042 lock (m_perClientPatchUpdates)
1038 { 1043 {
1039 foreach(PatchUpdates pups in m_perClientPatchUpdates.Values) 1044 foreach (PatchUpdates pups in m_perClientPatchUpdates.Values)
1040 { 1045 {
1046 if(pups.Presence.IsDeleted)
1047 continue;
1048
1049 // limit rate acording to udp land queue state
1050 if (!pups.Presence.ControllingClient.CanSendLayerData())
1051 continue;
1052
1041 if (pups.HasUpdates()) 1053 if (pups.HasUpdates())
1042 { 1054 {
1043 // There is something that could be sent to this client. 1055 if (m_sendTerrainUpdatesByViewDistance)
1044 List<PatchesToSend> toSend = GetModifiedPatchesInViewDistance(pups);
1045 if (toSend.Count > 0)
1046 { 1056 {
1047 // m_log.DebugFormat("{0} CheckSendingPatchesToClient: sending {1} patches to {2} in region {3}", 1057 // There is something that could be sent to this client.
1048 // LogHeader, toSend.Count, pups.Presence.Name, m_scene.RegionInfo.RegionName); 1058 List<PatchesToSend> toSend = GetModifiedPatchesInViewDistance(pups);
1049 // Sort the patches to send by the distance from the presence 1059 if (toSend.Count > 0)
1050 toSend.Sort();
1051 /* old way that sent individual patches
1052 foreach (PatchesToSend pts in toSend)
1053 { 1060 {
1054 pups.Presence.ControllingClient.SendLayerData(pts.PatchX, pts.PatchY, null); 1061 // 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); 1062 // LogHeader, toSend.Count, pups.Presence.Name, m_scene.RegionInfo.RegionName);
1056 } 1063 // Sort the patches to send by the distance from the presence
1057 */ 1064 toSend.Sort();
1058 1065 /*
1059 // new way that sends all patches to the protocol so they can be sent in one block 1066 foreach (PatchesToSend pts in toSend)
1060 int[] xPieces = new int[toSend.Count]; 1067 {
1061 int[] yPieces = new int[toSend.Count]; 1068 pups.Presence.ControllingClient.SendLayerData(pts.PatchX, pts.PatchY, null);
1062 float[] patchPieces = new float[toSend.Count * 2]; 1069 // presence.ControllingClient.SendLayerData(xs.ToArray(), ys.ToArray(), null, TerrainPatch.LayerType.Land);
1063 int pieceIndex = 0; 1070 }
1064 foreach(PatchesToSend pts in toSend) 1071 */
1065 { 1072
1066 patchPieces[pieceIndex++] = pts.PatchX; 1073 int[] xPieces = new int[toSend.Count];
1067 patchPieces[pieceIndex++] = pts.PatchY; 1074 int[] yPieces = new int[toSend.Count];
1075 float[] patchPieces = new float[toSend.Count * 2];
1076 int pieceIndex = 0;
1077 foreach (PatchesToSend pts in toSend)
1078 {
1079 patchPieces[pieceIndex++] = pts.PatchX;
1080 patchPieces[pieceIndex++] = pts.PatchY;
1081 }
1082 pups.Presence.ControllingClient.SendLayerData(-toSend.Count, 0, patchPieces);
1068 } 1083 }
1069 pups.Presence.ControllingClient.SendLayerData(-toSend.Count, 0, patchPieces); 1084 if (pups.sendAll && toSend.Count < 1024)
1085 SendAllModifiedPatchs(pups);
1070 } 1086 }
1087 else
1088 SendAllModifiedPatchs(pups);
1071 } 1089 }
1072 } 1090 }
1073 } 1091 }
1074 } 1092 }
1093 private void SendAllModifiedPatchs(PatchUpdates pups)
1094 {
1095 if (!pups.sendAll) // sanity
1096 return;
1097
1098 int limitX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize;
1099 int limitY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize;
1100
1101 if (pups.sendAllcurrentX >= limitX && pups.sendAllcurrentY >= limitY)
1102 {
1103 pups.sendAll = false;
1104 pups.sendAllcurrentX = 0;
1105 pups.sendAllcurrentY = 0;
1106 return;
1107 }
1108
1109 int npatchs = 0;
1110 List<PatchesToSend> patchs = new List<PatchesToSend>();
1111 int x = pups.sendAllcurrentX;
1112 int y = pups.sendAllcurrentY;
1113 // send it in the order viewer draws it
1114 // even if not best for memory scan
1115 for (; y < limitY; y++)
1116 {
1117 for (; x < limitX; x++)
1118 {
1119 if (pups.GetByPatch(x, y))
1120 {
1121 pups.SetByPatch(x, y, false);
1122 patchs.Add(new PatchesToSend(x, y, 0));
1123 if (++npatchs >= 128)
1124 {
1125 x++;
1126 break;
1127 }
1128 }
1129 }
1130 if (npatchs >= 128)
1131 break;
1132 x = 0;
1133 }
1134
1135 if (x >= limitX && y >= limitY)
1136 {
1137 pups.sendAll = false;
1138 pups.sendAllcurrentX = 0;
1139 pups.sendAllcurrentY = 0;
1140 }
1141 else
1142 {
1143 pups.sendAllcurrentX = x;
1144 pups.sendAllcurrentY = y;
1145 }
1146
1147 npatchs = patchs.Count;
1148 if (npatchs > 0)
1149 {
1150 int[] xPieces = new int[npatchs];
1151 int[] yPieces = new int[npatchs];
1152 float[] patchPieces = new float[npatchs * 2];
1153 int pieceIndex = 0;
1154 foreach (PatchesToSend pts in patchs)
1155 {
1156 patchPieces[pieceIndex++] = pts.PatchX;
1157 patchPieces[pieceIndex++] = pts.PatchY;
1158 }
1159 pups.Presence.ControllingClient.SendLayerData(-npatchs, 0, patchPieces);
1160 }
1161 }
1075 1162
1076 // Compute a list of modified patches that are within our view distance.
1077 private List<PatchesToSend> GetModifiedPatchesInViewDistance(PatchUpdates pups) 1163 private List<PatchesToSend> GetModifiedPatchesInViewDistance(PatchUpdates pups)
1078 { 1164 {
1079 List<PatchesToSend> ret = new List<PatchesToSend>(); 1165 List<PatchesToSend> ret = new List<PatchesToSend>();
1080 1166
1167 int npatchs = 0;
1168
1081 ScenePresence presence = pups.Presence; 1169 ScenePresence presence = pups.Presence;
1082 if (presence == null) 1170 if (presence == null)
1083 return ret; 1171 return ret;
1084 1172
1085 Vector3 presencePos = presence.AbsolutePosition; 1173 float minz = presence.AbsolutePosition.Z;
1086 1174 if (presence.CameraPosition.Z < minz)
1087 // Before this distance check, the whole region just showed up. Adding the distance 1175 minz = presence.CameraPosition.Z;
1088 // check causes different things to happen for the current and adjacent regions. 1176
1089 // So, to keep legacy views, if the region is legacy sized, don't do distance check. 1177 // this limit should be max terrainheight + max draw
1090 bool isLegacySizedRegion = pups.Terrain.SizeX == Constants.RegionSize && pups.Terrain.SizeY == Constants.RegionSize; 1178 if (minz > 1500f)
1091 bool shouldCheckViewDistance = m_sendTerrainUpdatesByViewDistance && !isLegacySizedRegion; 1179 return ret;
1092 1180
1093 int startX = 0; 1181 int DrawDistance = (int)presence.DrawDistance;
1094 int endX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize; 1182
1095 int startY = 0; 1183 DrawDistance = DrawDistance / Constants.TerrainPatchSize;
1096 int endY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize; 1184
1097 1185 int testposX;
1098 // The following only reduces the size of area scanned for updates. Only significant for very large varregions. 1186 int testposY;
1099 if (shouldCheckViewDistance) 1187
1100 { 1188 if (Math.Abs(presence.AbsolutePosition.X - presence.CameraPosition.X) > 30
1101 // Compute the area of patches within our draw distance 1189 || Math.Abs(presence.AbsolutePosition.Y - presence.CameraPosition.Y) > 30)
1102 startX = (((int)(presencePos.X - presence.DrawDistance)) / Constants.TerrainPatchSize) - 2; 1190 {
1103 startX = Math.Max(startX, 0); 1191 testposX = (int)presence.CameraPosition.X / Constants.TerrainPatchSize;
1104 startX = Math.Min(startX, (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize); 1192 testposY = (int)presence.CameraPosition.Y / Constants.TerrainPatchSize;
1105 startY = (((int)(presencePos.Y - presence.DrawDistance)) / Constants.TerrainPatchSize) - 2; 1193 }
1106 startY = Math.Max(startY, 0); 1194 else
1107 startY = Math.Min(startY, (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize); 1195 {
1108 endX = (((int)(presencePos.X + presence.DrawDistance)) / Constants.TerrainPatchSize) + 2; 1196 testposX = (int)presence.AbsolutePosition.X / Constants.TerrainPatchSize;
1109 endX = Math.Max(endX, 0); 1197 testposY = (int)presence.AbsolutePosition.Y / Constants.TerrainPatchSize;
1110 endX = Math.Min(endX, (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize); 1198 }
1111 endY = (((int)(presencePos.Y + presence.DrawDistance)) / Constants.TerrainPatchSize) + 2; 1199 int limitX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize;
1112 endY = Math.Max(endY, 0); 1200 int limitY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize;
1113 endY = Math.Min(endY, (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize); 1201
1114 } 1202 // Compute the area of patches within our draw distance
1115 1203 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}>", 1204 if (startX < 0)
1117 // LogHeader, m_scene.RegionInfo.RegionName, 1205 startX = 0;
1118 // presence.DrawDistance, presencePos, presence.CameraPosition, 1206 else if (startX >= limitX)
1119 // isLegacySizeChildRegion, 1207 startX = limitX - 1;
1120 // startX, startY, endX, endY); 1208
1121 for(int x = startX; x < endX; x++) 1209 int startY = testposY - DrawDistance;
1122 { 1210 if (startY < 0)
1123 for(int y = startY; y < endY; y++) 1211 startY = 0;
1212 else if (startY >= limitY)
1213 startY = limitY - 1;
1214
1215 int endX = testposX + DrawDistance;
1216 if (endX < 0)
1217 endX = 0;
1218 else if (endX > limitX)
1219 endX = limitX;
1220
1221 int endY = testposY + DrawDistance;
1222 if (endY < 0)
1223 endY = 0;
1224 else if (endY > limitY)
1225 endY = limitY;
1226
1227 int distx;
1228 int disty;
1229 int distsq;
1230
1231 DrawDistance *= DrawDistance;
1232
1233 for (int x = startX; x < endX; x++)
1234 {
1235 for (int y = startY; y < endY; y++)
1124 { 1236 {
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)) 1237 if (pups.GetByPatch(x, y))
1128 { 1238 {
1129 //Check which has less distance, camera or avatar position, both have to be done. 1239 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 1240 disty = y - testposY;
1131 if (!shouldCheckViewDistance 1241 distsq = distx * distx + disty * disty;
1132 || Util.DistanceLessThan(presencePos, patchPos, presence.DrawDistance + 50) 1242 if (distsq < DrawDistance)
1133 || Util.DistanceLessThan(presence.CameraPosition, patchPos, presence.DrawDistance + 50))
1134 { 1243 {
1135 //They can see it, send it to them
1136 pups.SetByPatch(x, y, false); 1244 pups.SetByPatch(x, y, false);
1137 float dist = Vector3.DistanceSquared(presencePos, patchPos); 1245 ret.Add(new PatchesToSend(x, y, (float)distsq));
1138 ret.Add(new PatchesToSend(x, y, dist)); 1246 if (npatchs++ > 1024)
1247 {
1248 y = endY;
1249 x = endX;
1250 }
1139 } 1251 }
1140 } 1252 }
1141 } 1253 }
1142 } 1254 }
1143 return ret; 1255 return ret;
1144 } 1256 }
1145 1257
1146 private void client_OnModifyTerrain(UUID user, float height, float seconds, byte size, byte action, 1258 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) 1259 float north, float west, float south, float east, UUID agentId)
@@ -1161,31 +1273,42 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1161 int zx = (int)(west + 0.5); 1273 int zx = (int)(west + 0.5);
1162 int zy = (int)(north + 0.5); 1274 int zy = (int)(north + 0.5);
1163 1275
1164 int dx; 1276 int startX = zx - n;
1165 for(dx=-n; dx<=n; dx++) 1277 if (startX < 0)
1278 startX = 0;
1279
1280 int startY = zy - n;
1281 if (startY < 0)
1282 startY = 0;
1283
1284 int endX = zx + n;
1285 if (endX >= m_channel.Width)
1286 endX = m_channel.Width - 1;
1287 int endY = zy + n;
1288 if (endY >= m_channel.Height)
1289 endY = m_channel.Height - 1;
1290
1291 int x, y;
1292
1293 for (x = startX; x <= endX; x++)
1166 { 1294 {
1167 int dy; 1295 for (y = startY; y <= endY; y++)
1168 for(dy=-n; dy<=n; dy++)
1169 { 1296 {
1170 int x = zx + dx; 1297 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 { 1298 {
1174 if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0))) 1299 allowMask[x, y] = true;
1175 { 1300 allowed = true;
1176 allowMask[x, y] = true;
1177 allowed = true;
1178 }
1179 } 1301 }
1180 } 1302 }
1181 } 1303 }
1182 if (allowed) 1304 if (allowed)
1183 { 1305 {
1184 StoreUndoState(); 1306 StoreUndoState();
1185 m_painteffects[(StandardTerrainEffects)action].PaintEffect( 1307 m_painteffects[(StandardTerrainEffects) action].PaintEffect(
1186 m_channel, allowMask, west, south, height, size, seconds); 1308 m_channel, allowMask, west, south, height, size, seconds,
1309 startX, endX, startY, endY);
1187 1310
1188 //revert changes outside estate limits 1311 //block changes outside estate limits
1189 if (!god) 1312 if (!god)
1190 EnforceEstateLimits(); 1313 EnforceEstateLimits();
1191 } 1314 }
@@ -1202,22 +1325,42 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1202 bool[,] fillArea = new bool[m_channel.Width, m_channel.Height]; 1325 bool[,] fillArea = new bool[m_channel.Width, m_channel.Height];
1203 fillArea.Initialize(); 1326 fillArea.Initialize();
1204 1327
1205 int x; 1328 int startX = (int)west;
1206 for(x = 0; x < m_channel.Width; x++) 1329 int startY = (int)south;
1330 int endX = (int)east;
1331 int endY = (int)north;
1332
1333 if (startX < 0)
1334 startX = 0;
1335 else if (startX >= m_channel.Width)
1336 startX = m_channel.Width - 1;
1337
1338 if (endX < 0)
1339 endX = 0;
1340 else if (endX >= m_channel.Width)
1341 endX = m_channel.Width - 1;
1342
1343 if (startY < 0)
1344 startY = 0;
1345 else if (startY >= m_channel.Height)
1346 startY = m_channel.Height - 1;
1347
1348 if (endY < 0)
1349 endY = 0;
1350 else if (endY >= m_channel.Height)
1351 endY = m_channel.Height - 1;
1352
1353
1354 int x, y;
1355
1356 for (x = startX; x <= endX; x++)
1207 { 1357 {
1208 int y; 1358 for (y = startY; y <= endY; y++)
1209 for(y = 0; y < m_channel.Height; y++)
1210 { 1359 {
1211 if (x < east && x > west) 1360 if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0)))
1212 { 1361 {
1213 if (y < north && y > south) 1362 fillArea[x, y] = true;
1214 { 1363 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 } 1364 }
1222 } 1365 }
1223 } 1366 }
@@ -1225,9 +1368,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1225 if (allowed) 1368 if (allowed)
1226 { 1369 {
1227 StoreUndoState(); 1370 StoreUndoState();
1228 m_floodeffects[(StandardTerrainEffects)action].FloodEffect(m_channel, fillArea, size); 1371 m_floodeffects[(StandardTerrainEffects)action].FloodEffect(m_channel, fillArea, size,
1372 startX, endX, startY, endY);
1229 1373
1230 //revert changes outside estate limits 1374 //block changes outside estate limits
1231 if (!god) 1375 if (!god)
1232 EnforceEstateLimits(); 1376 EnforceEstateLimits();
1233 } 1377 }
@@ -1260,37 +1404,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1260 1404
1261 private void StoreUndoState() 1405 private void StoreUndoState()
1262 { 1406 {
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 } 1407 }
1279 1408
1280 #region Console Commands 1409 #region Console Commands
1281 1410
1282 private void InterfaceLoadFile(Object[] args) 1411 private void InterfaceLoadFile(Object[] args)
1283 { 1412 {
1284 LoadFromFile((string)args[0]); 1413 LoadFromFile((string) args[0]);
1285 } 1414 }
1286 1415
1287 private void InterfaceLoadTileFile(Object[] args) 1416 private void InterfaceLoadTileFile(Object[] args)
1288 { 1417 {
1289 LoadFromFile((string)args[0], 1418 LoadFromFile((string) args[0],
1290 (int)args[1], 1419 (int) args[1],
1291 (int)args[2], 1420 (int) args[2],
1292 (int)args[3], 1421 (int) args[3],
1293 (int)args[4]); 1422 (int) args[4]);
1294 } 1423 }
1295 1424
1296 private void InterfaceSaveFile(Object[] args) 1425 private void InterfaceSaveFile(Object[] args)
@@ -1309,15 +1438,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1309 1438
1310 private void InterfaceBakeTerrain(Object[] args) 1439 private void InterfaceBakeTerrain(Object[] args)
1311 { 1440 {
1312 UpdateRevertMap(); 1441 UpdateBakedMap();
1313 } 1442 }
1314 1443
1315 private void InterfaceRevertTerrain(Object[] args) 1444 private void InterfaceRevertTerrain(Object[] args)
1316 { 1445 {
1317 int x, y; 1446 int x, y;
1318 for(x = 0; x < m_channel.Width; x++) 1447 for (x = 0; x < m_channel.Width; x++)
1319 for(y = 0; y < m_channel.Height; y++) 1448 for (y = 0; y < m_channel.Height; y++)
1320 m_channel[x, y] = m_revert[x, y]; 1449 m_channel[x, y] = m_baked[x, y];
1321 1450
1322 } 1451 }
1323 1452
@@ -1327,9 +1456,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1327 1456
1328 if (direction.ToLower().StartsWith("y")) 1457 if (direction.ToLower().StartsWith("y"))
1329 { 1458 {
1330 for(int x = 0; x < m_channel.Width; x++) 1459 for (int x = 0; x < m_channel.Width; x++)
1331 { 1460 {
1332 for(int y = 0; y < m_channel.Height / 2; y++) 1461 for (int y = 0; y < m_channel.Height / 2; y++)
1333 { 1462 {
1334 double height = m_channel[x, y]; 1463 double height = m_channel[x, y];
1335 double flippedHeight = m_channel[x, (int)m_channel.Height - 1 - y]; 1464 double flippedHeight = m_channel[x, (int)m_channel.Height - 1 - y];
@@ -1341,9 +1470,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1341 } 1470 }
1342 else if (direction.ToLower().StartsWith("x")) 1471 else if (direction.ToLower().StartsWith("x"))
1343 { 1472 {
1344 for(int y = 0; y < m_channel.Height; y++) 1473 for (int y = 0; y < m_channel.Height; y++)
1345 { 1474 {
1346 for(int x = 0; x < m_channel.Width / 2; x++) 1475 for (int x = 0; x < m_channel.Width / 2; x++)
1347 { 1476 {
1348 double height = m_channel[x, y]; 1477 double height = m_channel[x, y];
1349 double flippedHeight = m_channel[(int)m_channel.Width - 1 - x, y]; 1478 double flippedHeight = m_channel[(int)m_channel.Width - 1 - x, y];
@@ -1415,50 +1544,57 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1415 } 1544 }
1416 1545
1417 } 1546 }
1418
1419 } 1547 }
1420 1548
1421 private void InterfaceElevateTerrain(Object[] args) 1549 private void InterfaceElevateTerrain(Object[] args)
1422 { 1550 {
1551 double val = (double)args[0];
1552
1423 int x, y; 1553 int x, y;
1424 for(x = 0; x < m_channel.Width; x++) 1554 for (x = 0; x < m_channel.Width; x++)
1425 for(y = 0; y < m_channel.Height; y++) 1555 for (y = 0; y < m_channel.Height; y++)
1426 m_channel[x, y] += (double)args[0]; 1556 m_channel[x, y] += val;
1427 } 1557 }
1428 1558
1429 private void InterfaceMultiplyTerrain(Object[] args) 1559 private void InterfaceMultiplyTerrain(Object[] args)
1430 { 1560 {
1431 int x, y; 1561 int x, y;
1432 for(x = 0; x < m_channel.Width; x++) 1562 double val = (double)args[0];
1433 for(y = 0; y < m_channel.Height; y++) 1563
1434 m_channel[x, y] *= (double)args[0]; 1564 for (x = 0; x < m_channel.Width; x++)
1565 for (y = 0; y < m_channel.Height; y++)
1566 m_channel[x, y] *= val;
1435 } 1567 }
1436 1568
1437 private void InterfaceLowerTerrain(Object[] args) 1569 private void InterfaceLowerTerrain(Object[] args)
1438 { 1570 {
1439 int x, y; 1571 int x, y;
1440 for(x = 0; x < m_channel.Width; x++) 1572 double val = (double)args[0];
1441 for(y = 0; y < m_channel.Height; y++) 1573
1442 m_channel[x, y] -= (double)args[0]; 1574 for (x = 0; x < m_channel.Width; x++)
1575 for (y = 0; y < m_channel.Height; y++)
1576 m_channel[x, y] -= val;
1443 } 1577 }
1444 1578
1445 public void InterfaceFillTerrain(Object[] args) 1579 public void InterfaceFillTerrain(Object[] args)
1446 { 1580 {
1447 int x, y; 1581 int x, y;
1582 double val = (double)args[0];
1448 1583
1449 for(x = 0; x < m_channel.Width; x++) 1584 for (x = 0; x < m_channel.Width; x++)
1450 for(y = 0; y < m_channel.Height; y++) 1585 for (y = 0; y < m_channel.Height; y++)
1451 m_channel[x, y] = (double)args[0]; 1586 m_channel[x, y] = val;
1452 } 1587 }
1453 1588
1454 private void InterfaceMinTerrain(Object[] args) 1589 private void InterfaceMinTerrain(Object[] args)
1455 { 1590 {
1456 int x, y; 1591 int x, y;
1457 for(x = 0; x < m_channel.Width; x++) 1592 double val = (double)args[0];
1593 for (x = 0; x < m_channel.Width; x++)
1458 { 1594 {
1459 for(y = 0; y < m_channel.Height; y++) 1595 for(y = 0; y < m_channel.Height; y++)
1460 { 1596 {
1461 m_channel[x, y] = Math.Max((double)args[0], m_channel[x, y]); 1597 m_channel[x, y] = Math.Max(val, m_channel[x, y]);
1462 } 1598 }
1463 } 1599 }
1464 } 1600 }
@@ -1466,11 +1602,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1466 private void InterfaceMaxTerrain(Object[] args) 1602 private void InterfaceMaxTerrain(Object[] args)
1467 { 1603 {
1468 int x, y; 1604 int x, y;
1469 for(x = 0; x < m_channel.Width; x++) 1605 double val = (double)args[0];
1606 for (x = 0; x < m_channel.Width; x++)
1470 { 1607 {
1471 for(y = 0; y < m_channel.Height; y++) 1608 for(y = 0; y < m_channel.Height; y++)
1472 { 1609 {
1473 m_channel[x, y] = Math.Min((double)args[0], m_channel[x, y]); 1610 m_channel[x, y] = Math.Min(val, m_channel[x, y]);
1474 } 1611 }
1475 } 1612 }
1476 } 1613 }
@@ -1620,9 +1757,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1620 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); 1757 multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double");
1621 1758
1622 Command bakeRegionCommand = 1759 Command bakeRegionCommand =
1623 new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); 1760 new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions baked map.");
1624 Command revertRegionCommand = 1761 Command revertRegionCommand =
1625 new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); 1762 new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the baked map terrain into the regions heightmap.");
1626 1763
1627 Command flipCommand = 1764 Command flipCommand =
1628 new Command("flip", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFlipTerrain, "Flips the current terrain about the X or Y axis"); 1765 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).");