aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
parent* Deleted .user file (diff)
downloadopensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs169
1 files changed, 91 insertions, 78 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
index c8c6e51..bbbb4d7 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs
@@ -29,11 +29,11 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing; 30using System.Drawing;
31using System.Drawing.Imaging; 31using System.Drawing.Imaging;
32using System.Globalization;
32using System.IO; 33using System.IO;
34using System.Threading;
33using libTerrain; 35using libTerrain;
34using OpenJPEGNet; 36using OpenJPEGNet;
35using OpenSim.Framework.Interfaces;
36using System.Globalization;
37using OpenSim.Framework; 37using OpenSim.Framework;
38 38
39namespace OpenSim.Region.Terrain 39namespace OpenSim.Region.Terrain
@@ -51,7 +51,7 @@ namespace OpenSim.Region.Terrain
51 51
52 public class TerrainEngine 52 public class TerrainEngine
53 { 53 {
54 public static System.Threading.Mutex fileIOLock = new System.Threading.Mutex(); 54 public static Mutex fileIOLock = new Mutex();
55 55
56 /// <summary> 56 /// <summary>
57 /// Plugin library for scripts 57 /// Plugin library for scripts
@@ -95,12 +95,13 @@ namespace OpenSim.Region.Terrain
95 /// </summary> 95 /// </summary>
96 public int tainted; 96 public int tainted;
97 97
98 int w, h; 98 private int w, h;
99 99
100 /// <summary> 100 /// <summary>
101 /// Used to determine what offset to use when loading singular heightmaps across multiple sims 101 /// Used to determine what offset to use when loading singular heightmaps across multiple sims
102 /// </summary> 102 /// </summary>
103 private int offsetX; 103 private int offsetX;
104
104 private int offsetY; 105 private int offsetY;
105 106
106 107
@@ -139,13 +140,13 @@ namespace OpenSim.Region.Terrain
139 140
140 public bool Tainted(int x, int y) 141 public bool Tainted(int x, int y)
141 { 142 {
142 return (heightmap.diff[x / 16, y / 16] != 0); 143 return (heightmap.diff[x/16, y/16] != 0);
143 } 144 }
144 145
145 public void ResetTaint() 146 public void ResetTaint()
146 { 147 {
147 tainted = 0; 148 tainted = 0;
148 heightmap.diff = new int[w / 16, h / 16]; 149 heightmap.diff = new int[w/16,h/16];
149 } 150 }
150 151
151 //Testing to see if moving the TerraForming packet handling code into here works well 152 //Testing to see if moving the TerraForming packet handling code into here works well
@@ -158,40 +159,40 @@ namespace OpenSim.Region.Terrain
158 /// <param name="action">The action to be performed</param> 159 /// <param name="action">The action to be performed</param>
159 /// <param name="north">Distance from the north border where the cursor is located</param> 160 /// <param name="north">Distance from the north border where the cursor is located</param>
160 /// <param name="west">Distance from the west border where the cursor is located</param> 161 /// <param name="west">Distance from the west border where the cursor is located</param>
161 public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west, IClientAPI remoteUser) 162 public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west,
163 IClientAPI remoteUser)
162 { 164 {
163
164 // Shiny. 165 // Shiny.
165 double size = (double)(1 << brushsize); 166 double size = (double) (1 << brushsize);
166 167
167 switch (action) 168 switch (action)
168 { 169 {
169 case 0: 170 case 0:
170 // flatten terrain 171 // flatten terrain
171 this.FlattenTerrain(west, north, size, (double)seconds / 5.0); 172 FlattenTerrain(west, north, size, (double) seconds/5.0);
172 break; 173 break;
173 case 1: 174 case 1:
174 // raise terrain 175 // raise terrain
175 this.RaiseTerrain(west, north, size, (double)seconds / 5.0); 176 RaiseTerrain(west, north, size, (double) seconds/5.0);
176 break; 177 break;
177 case 2: 178 case 2:
178 //lower terrain 179 //lower terrain
179 this.LowerTerrain(west, north, size, (double)seconds / 5.0); 180 LowerTerrain(west, north, size, (double) seconds/5.0);
180 break; 181 break;
181 case 3: 182 case 3:
182 // smooth terrain 183 // smooth terrain
183 this.SmoothTerrain(west, north, size, (double)seconds / 5.0); 184 SmoothTerrain(west, north, size, (double) seconds/5.0);
184 break; 185 break;
185 case 4: 186 case 4:
186 // noise 187 // noise
187 this.NoiseTerrain(west, north, size, (double)seconds / 5.0); 188 NoiseTerrain(west, north, size, (double) seconds/5.0);
188 break; 189 break;
189 case 5: 190 case 5:
190 // revert 191 // revert
191 this.RevertTerrain(west, north, size, (double)seconds / 5.0); 192 RevertTerrain(west, north, size, (double) seconds/5.0);
192 break; 193 break;
193 194
194 // CLIENT EXTENSIONS GO HERE 195 // CLIENT EXTENSIONS GO HERE
195 case 128: 196 case 128:
196 // erode-thermal 197 // erode-thermal
197 break; 198 break;
@@ -207,9 +208,9 @@ namespace OpenSim.Region.Terrain
207 { 208 {
208 for (int y = 0; y < 16; y++) 209 for (int y = 0; y < 16; y++)
209 { 210 {
210 if (this.Tainted(x * 16, y * 16)) 211 if (Tainted(x*16, y*16))
211 { 212 {
212 remoteUser.SendLayerData(x, y, this.GetHeights1D()); 213 remoteUser.SendLayerData(x, y, GetHeights1D());
213 } 214 }
214 } 215 }
215 } 216 }
@@ -249,12 +250,12 @@ namespace OpenSim.Region.Terrain
249 /// <returns>A float[65536] array containing the heightmap</returns> 250 /// <returns>A float[65536] array containing the heightmap</returns>
250 public float[] GetHeights1D() 251 public float[] GetHeights1D()
251 { 252 {
252 float[] heights = new float[w * h]; 253 float[] heights = new float[w*h];
253 int i; 254 int i;
254 255
255 for (i = 0; i < w * h; i++) 256 for (i = 0; i < w*h; i++)
256 { 257 {
257 heights[i] = (float)heightmap.map[i % w, i / w]; 258 heights[i] = (float) heightmap.map[i%w, i/w];
258 } 259 }
259 260
260 return heights; 261 return heights;
@@ -266,13 +267,13 @@ namespace OpenSim.Region.Terrain
266 /// <returns>An array of 256,256 values containing the heightmap</returns> 267 /// <returns>An array of 256,256 values containing the heightmap</returns>
267 public float[,] GetHeights2D() 268 public float[,] GetHeights2D()
268 { 269 {
269 float[,] heights = new float[w, h]; 270 float[,] heights = new float[w,h];
270 int x, y; 271 int x, y;
271 for (x = 0; x < w; x++) 272 for (x = 0; x < w; x++)
272 { 273 {
273 for (y = 0; y < h; y++) 274 for (y = 0; y < h; y++)
274 { 275 {
275 heights[x, y] = (float)heightmap.map[x, y]; 276 heights[x, y] = (float) heightmap.map[x, y];
276 } 277 }
277 } 278 }
278 return heights; 279 return heights;
@@ -294,9 +295,9 @@ namespace OpenSim.Region.Terrain
294 public void GetHeights1D(float[] heights) 295 public void GetHeights1D(float[] heights)
295 { 296 {
296 int i; 297 int i;
297 for (i = 0; i < w * h; i++) 298 for (i = 0; i < w*h; i++)
298 { 299 {
299 heightmap.map[i % w, i / w] = heights[i]; 300 heightmap.map[i%w, i/w] = heights[i];
300 } 301 }
301 302
302 tainted++; 303 tainted++;
@@ -313,7 +314,7 @@ namespace OpenSim.Region.Terrain
313 { 314 {
314 for (y = 0; y < h; y++) 315 for (y = 0; y < h; y++)
315 { 316 {
316 heightmap.Set(x, y, (double)heights[x, y]); 317 heightmap.Set(x, y, (double) heights[x, y]);
317 } 318 }
318 } 319 }
319 SaveRevertMap(); 320 SaveRevertMap();
@@ -376,28 +377,36 @@ namespace OpenSim.Region.Terrain
376 377
377 try 378 try
378 { 379 {
379
380 switch (command) 380 switch (command)
381 { 381 {
382 case "help": 382 case "help":
383 resultText += "terrain regenerate - rebuilds the sims terrain using a default algorithm\n"; 383 resultText += "terrain regenerate - rebuilds the sims terrain using a default algorithm\n";
384 resultText += "terrain hills <type> <number of hills> <min height> <max height> <island t/f> <additive t/f> <noisy t/f>\n"; 384 resultText +=
385 "terrain hills <type> <number of hills> <min height> <max height> <island t/f> <additive t/f> <noisy t/f>\n";
385 resultText += " type should be spheres, blocks, cones, or squared\n"; 386 resultText += " type should be spheres, blocks, cones, or squared\n";
386 resultText += "terrain voronoi <points> <blocksize> - generates a worley fractal with X points per block"; 387 resultText +=
388 "terrain voronoi <points> <blocksize> - generates a worley fractal with X points per block";
387 resultText += "terrain seed <seed> - sets the random seed value to <seed>\n"; 389 resultText += "terrain seed <seed> - sets the random seed value to <seed>\n";
388 resultText += "terrain load <type> <filename> - loads a terrain from disk, type can be 'F32', 'F64', 'RAW' or 'IMG'\n"; 390 resultText +=
389 resultText += "terrain save <type> <filename> - saves a terrain to disk, type can be 'F32', 'F64', 'PNG', 'RAW' or 'HIRAW'\n"; 391 "terrain load <type> <filename> - loads a terrain from disk, type can be 'F32', 'F64', 'RAW' or 'IMG'\n";
390 resultText += "terrain save grdmap <filename> <gradient map> - creates a PNG snapshot of the region using a named gradient map\n"; 392 resultText +=
391 resultText += "terrain rescale <min> <max> - rescales a terrain to be between <min> and <max> meters high\n"; 393 "terrain save <type> <filename> - saves a terrain to disk, type can be 'F32', 'F64', 'PNG', 'RAW' or 'HIRAW'\n";
394 resultText +=
395 "terrain save grdmap <filename> <gradient map> - creates a PNG snapshot of the region using a named gradient map\n";
396 resultText +=
397 "terrain rescale <min> <max> - rescales a terrain to be between <min> and <max> meters high\n";
392 resultText += "terrain fill <val> - fills a terrain at the specified height\n"; 398 resultText += "terrain fill <val> - fills a terrain at the specified height\n";
393 resultText += "terrain erode aerobic <windspeed> <pickupmin> <dropmin> <carry> <rounds> <lowest t/f> <fluid dynamics t/f>\n"; 399 resultText +=
400 "terrain erode aerobic <windspeed> <pickupmin> <dropmin> <carry> <rounds> <lowest t/f> <fluid dynamics t/f>\n";
394 resultText += "terrain erode thermal <talus> <rounds> <carry>\n"; 401 resultText += "terrain erode thermal <talus> <rounds> <carry>\n";
395 resultText += "terrain erode hydraulic <rain> <evaporation> <solubility> <frequency> <rounds>\n"; 402 resultText += "terrain erode hydraulic <rain> <evaporation> <solubility> <frequency> <rounds>\n";
396 resultText += "terrain multiply <val> - multiplies a terrain by <val>\n"; 403 resultText += "terrain multiply <val> - multiplies a terrain by <val>\n";
397 resultText += "terrain revert - reverts the terrain to the stored original\n"; 404 resultText += "terrain revert - reverts the terrain to the stored original\n";
398 resultText += "terrain bake - saves the current terrain into the revert map\n"; 405 resultText += "terrain bake - saves the current terrain into the revert map\n";
399 resultText += "terrain csfilter <filename.cs> - loads a new filter from the specified .cs file\n"; 406 resultText +=
400 resultText += "terrain jsfilter <filename.js> - loads a new filter from the specified .js file\n"; 407 "terrain csfilter <filename.cs> - loads a new filter from the specified .cs file\n";
408 resultText +=
409 "terrain jsfilter <filename.js> - loads a new filter from the specified .js file\n";
401 foreach (KeyValuePair<string, ITerrainFilter> filter in customFilters.filters) 410 foreach (KeyValuePair<string, ITerrainFilter> filter in customFilters.filters)
402 { 411 {
403 resultText += filter.Value.Help(); 412 resultText += filter.Value.Help();
@@ -466,8 +475,8 @@ namespace OpenSim.Region.Terrain
466 475
467 case "load": 476 case "load":
468 string filenameL = args[2].Replace("%name%", simName); 477 string filenameL = args[2].Replace("%name%", simName);
469 filenameL = filenameL.Replace("%x%", this.offsetX.ToString()); 478 filenameL = filenameL.Replace("%x%", offsetX.ToString());
470 filenameL = filenameL.Replace("%y%", this.offsetY.ToString()); 479 filenameL = filenameL.Replace("%y%", offsetY.ToString());
471 480
472 switch (args[1].ToLower()) 481 switch (args[1].ToLower())
473 { 482 {
@@ -499,11 +508,11 @@ namespace OpenSim.Region.Terrain
499 { 508 {
500 case "f32": 509 case "f32":
501 LoadFromFileF32(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]), 510 LoadFromFileF32(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
502 Convert.ToInt32(args[5]), Convert.ToInt32(args[6])); 511 Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
503 break; 512 break;
504 case "img": 513 case "img":
505 LoadFromFileIMG(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]), 514 LoadFromFileIMG(args[2], Convert.ToInt32(args[3]), Convert.ToInt32(args[4]),
506 Convert.ToInt32(args[5]), Convert.ToInt32(args[6])); 515 Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
507 break; 516 break;
508 default: 517 default:
509 resultText = "Unknown or unsupported image or data format"; 518 resultText = "Unknown or unsupported image or data format";
@@ -513,8 +522,8 @@ namespace OpenSim.Region.Terrain
513 522
514 case "save": 523 case "save":
515 string filename = args[2].Replace("%name%", simName); 524 string filename = args[2].Replace("%name%", simName);
516 filename = filename.Replace("%x%", this.offsetX.ToString()); 525 filename = filename.Replace("%x%", offsetX.ToString());
517 filename = filename.Replace("%y%", this.offsetY.ToString()); 526 filename = filename.Replace("%y%", offsetY.ToString());
518 527
519 switch (args[1].ToLower()) 528 switch (args[1].ToLower())
520 { 529 {
@@ -589,15 +598,20 @@ namespace OpenSim.Region.Terrain
589 { 598 {
590 case "aerobic": 599 case "aerobic":
591 // WindSpeed, PickupMinimum,DropMinimum,Carry,Rounds,Lowest 600 // WindSpeed, PickupMinimum,DropMinimum,Carry,Rounds,Lowest
592 heightmap.AerobicErosion(Convert.ToDouble(args[2]), Convert.ToDouble(args[3]), Convert.ToDouble(args[4]), Convert.ToDouble(args[5]), Convert.ToInt32(args[6]), Convert.ToBoolean(args[7]), Convert.ToBoolean(args[8])); 601 heightmap.AerobicErosion(Convert.ToDouble(args[2]), Convert.ToDouble(args[3]),
602 Convert.ToDouble(args[4]), Convert.ToDouble(args[5]),
603 Convert.ToInt32(args[6]), Convert.ToBoolean(args[7]),
604 Convert.ToBoolean(args[8]));
593 break; 605 break;
594 case "thermal": 606 case "thermal":
595 heightmap.ThermalWeathering(Convert.ToDouble(args[2]), Convert.ToInt32(args[3]), Convert.ToDouble(args[4])); 607 heightmap.ThermalWeathering(Convert.ToDouble(args[2]), Convert.ToInt32(args[3]),
608 Convert.ToDouble(args[4]));
596 break; 609 break;
597 case "hydraulic": 610 case "hydraulic":
598 Channel rainMap = new Channel(w, h); 611 Channel rainMap = new Channel(w, h);
599 rainMap.Fill(Convert.ToDouble(args[2])); 612 rainMap.Fill(Convert.ToDouble(args[2]));
600 heightmap.HydraulicErosion(rainMap, Convert.ToDouble(args[3]), Convert.ToDouble(args[4]), Convert.ToInt32(args[5]), Convert.ToInt32(args[6])); 613 heightmap.HydraulicErosion(rainMap, Convert.ToDouble(args[3]), Convert.ToDouble(args[4]),
614 Convert.ToInt32(args[5]), Convert.ToInt32(args[6]));
601 break; 615 break;
602 default: 616 default:
603 resultText = "Unknown erosion type"; 617 resultText = "Unknown erosion type";
@@ -624,8 +638,10 @@ namespace OpenSim.Region.Terrain
624 if (args.GetLength(0) > 2) 638 if (args.GetLength(0) > 2)
625 { 639 {
626 int.TryParse(args[2].ToString(), out count); 640 int.TryParse(args[2].ToString(), out count);
627 double.TryParse(args[3].ToString(), NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out sizeMin); 641 double.TryParse(args[3].ToString(), NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
628 double.TryParse(args[4].ToString(), NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, out sizeRange); 642 out sizeMin);
643 double.TryParse(args[4].ToString(), NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo,
644 out sizeRange);
629 bool.TryParse(args[5].ToString(), out island); 645 bool.TryParse(args[5].ToString(), out island);
630 bool.TryParse(args[6].ToString(), out additive); 646 bool.TryParse(args[6].ToString(), out additive);
631 bool.TryParse(args[7].ToString(), out noisy); 647 bool.TryParse(args[7].ToString(), out noisy);
@@ -669,7 +685,7 @@ namespace OpenSim.Region.Terrain
669 /// <param name="max">Maximum value of the new array</param> 685 /// <param name="max">Maximum value of the new array</param>
670 public void SetRange(float min, float max) 686 public void SetRange(float min, float max)
671 { 687 {
672 heightmap.Normalise((double)min, (double)max); 688 heightmap.Normalise((double) min, (double) max);
673 tainted++; 689 tainted++;
674 } 690 }
675 691
@@ -713,7 +729,7 @@ namespace OpenSim.Region.Terrain
713 { 729 {
714 for (x = 0; x < w; x++) 730 for (x = 0; x < w; x++)
715 { 731 {
716 heightmap.map[x, y] = (double)bs.ReadSingle(); 732 heightmap.map[x, y] = (double) bs.ReadSingle();
717 } 733 }
718 } 734 }
719 735
@@ -736,11 +752,10 @@ namespace OpenSim.Region.Terrain
736 fileIOLock.WaitOne(); 752 fileIOLock.WaitOne();
737 try 753 try
738 { 754 {
755 int sectionToLoadX = ((offsetX - lowerboundX)*w);
756 int sectionToLoadY = ((offsetY - lowerboundY)*h);
739 757
740 int sectionToLoadX = ((this.offsetX - lowerboundX) * this.w); 758 double[,] tempMap = new double[dimensionX,dimensionY];
741 int sectionToLoadY = ((this.offsetY - lowerboundY) * this.h);
742
743 double[,] tempMap = new double[dimensionX, dimensionY];
744 759
745 FileInfo file = new FileInfo(filename); 760 FileInfo file = new FileInfo(filename);
746 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 761 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
@@ -751,7 +766,7 @@ namespace OpenSim.Region.Terrain
751 { 766 {
752 for (y = 0; y < dimensionY; y++) 767 for (y = 0; y < dimensionY; y++)
753 { 768 {
754 tempMap[x, y] = (double)bs.ReadSingle(); 769 tempMap[x, y] = (double) bs.ReadSingle();
755 } 770 }
756 } 771 }
757 772
@@ -784,19 +799,19 @@ namespace OpenSim.Region.Terrain
784 /// <param name="lowerboundY">Where sim coords begin for this patch</param> 799 /// <param name="lowerboundY">Where sim coords begin for this patch</param>
785 public void LoadFromFileIMG(string filename, int dimensionX, int dimensionY, int lowerboundX, int lowerboundY) 800 public void LoadFromFileIMG(string filename, int dimensionX, int dimensionY, int lowerboundX, int lowerboundY)
786 { 801 {
787 int sectionToLoadX = ((this.offsetX - lowerboundX) * this.w); 802 int sectionToLoadX = ((offsetX - lowerboundX)*w);
788 int sectionToLoadY = ((this.offsetY - lowerboundY) * this.h); 803 int sectionToLoadY = ((offsetY - lowerboundY)*h);
789 804
790 double[,] tempMap = new double[dimensionX, dimensionY]; 805 double[,] tempMap = new double[dimensionX,dimensionY];
791 806
792 System.Drawing.Bitmap lgrBmp = new Bitmap(filename); 807 Bitmap lgrBmp = new Bitmap(filename);
793 808
794 int x, y; 809 int x, y;
795 for (x = 0; x < dimensionX; x++) 810 for (x = 0; x < dimensionX; x++)
796 { 811 {
797 for (y = 0; y < dimensionY; y++) 812 for (y = 0; y < dimensionY; y++)
798 { 813 {
799 tempMap[x, y] = (float)lgrBmp.GetPixel(x, y).GetBrightness(); 814 tempMap[x, y] = (float) lgrBmp.GetPixel(x, y).GetBrightness();
800 } 815 }
801 } 816 }
802 817
@@ -826,7 +841,7 @@ namespace OpenSim.Region.Terrain
826 { 841 {
827 for (x = 0; x < w; x++) 842 for (x = 0; x < w; x++)
828 { 843 {
829 heightmap.map[x, y] = (double)bs.ReadByte() * ((double)bs.ReadByte() / 127.0); 844 heightmap.map[x, y] = (double) bs.ReadByte()*((double) bs.ReadByte()/127.0);
830 bs.ReadBytes(11); // Advance the stream to next bytes. 845 bs.ReadBytes(11); // Advance the stream to next bytes.
831 } 846 }
832 } 847 }
@@ -875,7 +890,7 @@ namespace OpenSim.Region.Terrain
875 { 890 {
876 for (x = 0; x < w; x++) 891 for (x = 0; x < w; x++)
877 { 892 {
878 bs.Write((float)heightmap.Get(x, y)); 893 bs.Write((float) heightmap.Get(x, y));
879 } 894 }
880 } 895 }
881 896
@@ -897,27 +912,27 @@ namespace OpenSim.Region.Terrain
897 int x, y; 912 int x, y;
898 913
899 // Used for the 'green' channel. 914 // Used for the 'green' channel.
900 byte avgMultiplier = (byte)heightmap.Avg(); 915 byte avgMultiplier = (byte) heightmap.Avg();
901 byte backupMultiplier = (byte)revertmap.Avg(); 916 byte backupMultiplier = (byte) revertmap.Avg();
902 917
903 // Limit the multiplier so it can represent points >64m. 918 // Limit the multiplier so it can represent points >64m.
904 if (avgMultiplier > 196) 919 if (avgMultiplier > 196)
905 avgMultiplier = 196; 920 avgMultiplier = 196;
906 if(backupMultiplier > 196) 921 if (backupMultiplier > 196)
907 backupMultiplier = 196; 922 backupMultiplier = 196;
908 // Make sure it's at least one to prevent a div by zero 923 // Make sure it's at least one to prevent a div by zero
909 if (avgMultiplier < 1) 924 if (avgMultiplier < 1)
910 avgMultiplier = 1; 925 avgMultiplier = 1;
911 if(backupMultiplier < 1) 926 if (backupMultiplier < 1)
912 backupMultiplier = 1; 927 backupMultiplier = 1;
913 928
914 for (y = 0; y < h; y++) 929 for (y = 0; y < h; y++)
915 { 930 {
916 for (x = 0; x < h; x++) 931 for (x = 0; x < h; x++)
917 { 932 {
918 byte red = (byte)(heightmap.Get(x, y) / ((double)avgMultiplier / 128.0)); 933 byte red = (byte) (heightmap.Get(x, y)/((double) avgMultiplier/128.0));
919 byte green = avgMultiplier; 934 byte green = avgMultiplier;
920 byte blue = (byte)watermap.Get(x, y); 935 byte blue = (byte) watermap.Get(x, y);
921 byte alpha1 = 0; // Land Parcels 936 byte alpha1 = 0; // Land Parcels
922 byte alpha2 = 0; // For Sale Land 937 byte alpha2 = 0; // For Sale Land
923 byte alpha3 = 0; // Public Edit Object 938 byte alpha3 = 0; // Public Edit Object
@@ -926,7 +941,7 @@ namespace OpenSim.Region.Terrain
926 byte alpha6 = 255; // Flying Allowed 941 byte alpha6 = 255; // Flying Allowed
927 byte alpha7 = 255; // Create Landmark 942 byte alpha7 = 255; // Create Landmark
928 byte alpha8 = 255; // Outside Scripts 943 byte alpha8 = 255; // Outside Scripts
929 byte alpha9 = (byte)(revertmap.Get(x, y) / ((double)backupMultiplier / 128.0)); 944 byte alpha9 = (byte) (revertmap.Get(x, y)/((double) backupMultiplier/128.0));
930 byte alpha10 = backupMultiplier; 945 byte alpha10 = backupMultiplier;
931 946
932 binStream.Write(red); 947 binStream.Write(red);
@@ -966,7 +981,7 @@ namespace OpenSim.Region.Terrain
966 { 981 {
967 for (j = 0; j < 256; j++) 982 for (j = 0; j < 256; j++)
968 { 983 {
969 lookupHeightTable[i + (j * 256)] = ((double)i * ((double)j / 127.0)); 984 lookupHeightTable[i + (j*256)] = ((double) i*((double) j/127.0));
970 } 985 }
971 } 986 }
972 987
@@ -988,9 +1003,9 @@ namespace OpenSim.Region.Terrain
988 } 1003 }
989 } 1004 }
990 1005
991 byte red = (byte)(index & 0xFF); 1006 byte red = (byte) (index & 0xFF);
992 byte green = (byte)((index >> 8) & 0xFF); 1007 byte green = (byte) ((index >> 8) & 0xFF);
993 byte blue = (byte)watermap.Get(x, y); 1008 byte blue = (byte) watermap.Get(x, y);
994 byte alpha1 = 0; // Land Parcels 1009 byte alpha1 = 0; // Land Parcels
995 byte alpha2 = 0; // For Sale Land 1010 byte alpha2 = 0; // For Sale Land
996 byte alpha3 = 0; // Public Edit Object 1011 byte alpha3 = 0; // Public Edit Object
@@ -1140,7 +1155,7 @@ namespace OpenSim.Region.Terrain
1140 smoothed.Smooth(amount); 1155 smoothed.Smooth(amount);
1141 1156
1142 Channel mask = new Channel(); 1157 Channel mask = new Channel();
1143 mask.Raise(rx,ry,size,amount); 1158 mask.Raise(rx, ry, size, amount);
1144 1159
1145 heightmap.Blend(smoothed, mask); 1160 heightmap.Blend(smoothed, mask);
1146 } 1161 }
@@ -1221,8 +1236,7 @@ namespace OpenSim.Region.Terrain
1221 { 1236 {
1222 Bitmap bmp = TerrainToBitmap(gradientmap); 1237 Bitmap bmp = TerrainToBitmap(gradientmap);
1223 1238
1224 imageData = OpenJPEG.EncodeFromImage(bmp, true ); 1239 imageData = OpenJPEG.EncodeFromImage(bmp, true);
1225
1226 } 1240 }
1227 catch (Exception e) 1241 catch (Exception e)
1228 { 1242 {
@@ -1252,12 +1266,11 @@ namespace OpenSim.Region.Terrain
1252 for (int x = 0; x < copy.w; x++) 1266 for (int x = 0; x < copy.w; x++)
1253 { 1267 {
1254 // 512 is the largest possible height before colours clamp 1268 // 512 is the largest possible height before colours clamp
1255 int colorindex = (int)(Math.Max(Math.Min(1.0, copy.Get(x, y) / 512.0), 0.0) * (pallete - 1)); 1269 int colorindex = (int) (Math.Max(Math.Min(1.0, copy.Get(x, y)/512.0), 0.0)*(pallete - 1));
1256 bmp.SetPixel(x, y, colours[colorindex]); 1270 bmp.SetPixel(x, y, colours[colorindex]);
1257 } 1271 }
1258 } 1272 }
1259 return bmp; 1273 return bmp;
1260 } 1274 }
1261
1262 } 1275 }
1263} 1276} \ No newline at end of file