aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-04-25 22:37:58 +0100
committerJustin Clark-Casey (justincc)2014-04-25 22:56:25 +0100
commit904baa6da6107c3aabfae45d977491b97c22a6ef (patch)
tree4e4b146d7000b37043da76a91e0673f9b0a2e79f /OpenSim
parentRestore overload mode accidentally disabled in a prior commit. Add a new (diff)
downloadopensim-SC-904baa6da6107c3aabfae45d977491b97c22a6ef.zip
opensim-SC-904baa6da6107c3aabfae45d977491b97c22a6ef.tar.gz
opensim-SC-904baa6da6107c3aabfae45d977491b97c22a6ef.tar.bz2
opensim-SC-904baa6da6107c3aabfae45d977491b97c22a6ef.tar.xz
Fix issue where terrain height values > 327 caused chaotic spiked terrain.
Per http://wiki.secondlife.com/wiki/Tips_for_Creating_Heightfields_and_Details_on_Terrain_RAW_Files#Notes_for_Creating_Height_Field_Maps_for_Second_Life terrain heights up to 508 are possible on the LL grid (and were available on previous releases of OpenSimulator). The obvious way to allow both this and equivalent -z values, is to rewiden the internal terrain height storage from short to int. The memory tradeoff is most noticeable on the maximum 8192x8192 var region (equiv to 1024 normal regions), where it adds 128mb to resident use (128k on a normal region) This is still better than the double used in previous releases. This does not affect physics or data storage since they already use float and double respectively. This may not be the final solution if we actually want to sacrifice -z, >327 or something else. Relates to http://opensimulator.org/mantis/view.php?id=7076
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/TerrainData.cs34
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainChannel.cs4
2 files changed, 19 insertions, 19 deletions
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs
index 25f9ca6..6b1be4e 100644
--- a/OpenSim/Framework/TerrainData.cs
+++ b/OpenSim/Framework/TerrainData.cs
@@ -72,8 +72,8 @@ namespace OpenSim.Framework
72 return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob); 72 return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob);
73 } 73 }
74 74
75 // return a special compressed representation of the heightmap in shorts 75 // return a special compressed representation of the heightmap in ints
76 public abstract short[] GetCompressedMap(); 76 public abstract int[] GetCompressedMap();
77 public abstract float CompressionFactor { get; } 77 public abstract float CompressionFactor { get; }
78 78
79 public abstract float[] GetFloatsSerialized(); 79 public abstract float[] GetFloatsSerialized();
@@ -99,7 +99,7 @@ namespace OpenSim.Framework
99 Variable2D = 22, 99 Variable2D = 22,
100 // Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions 100 // Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions
101 // and third int is the 'compression factor'. The heights are compressed as 101 // and third int is the 'compression factor'. The heights are compressed as
102 // "short compressedHeight = (short)(height * compressionFactor);" 102 // "int compressedHeight = (int)(height * compressionFactor);"
103 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256. 103 // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256.
104 Compressed2D = 27, 104 Compressed2D = 27,
105 // A revision that is not listed above or any revision greater than this value is 'Legacy256'. 105 // A revision that is not listed above or any revision greater than this value is 'Legacy256'.
@@ -109,8 +109,8 @@ namespace OpenSim.Framework
109 // Version of terrain that is a heightmap. 109 // Version of terrain that is a heightmap.
110 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge 110 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge
111 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer. 111 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer.
112 // The heighmap is kept as an array of short integers. The integer values are converted to 112 // The heighmap is kept as an array of integers. The integer values are converted to
113 // and from floats by TerrainCompressionFactor. Shorts are used to limit storage used. 113 // and from floats by TerrainCompressionFactor.
114 public class HeightmapTerrainData : TerrainData 114 public class HeightmapTerrainData : TerrainData
115 { 115 {
116 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 116 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -121,7 +121,7 @@ namespace OpenSim.Framework
121 { 121 {
122 get { return FromCompressedHeight(m_heightmap[x, y]); } 122 get { return FromCompressedHeight(m_heightmap[x, y]); }
123 set { 123 set {
124 short newVal = ToCompressedHeight(value); 124 int newVal = ToCompressedHeight(value);
125 if (m_heightmap[x, y] != newVal) 125 if (m_heightmap[x, y] != newVal)
126 { 126 {
127 m_heightmap[x, y] = newVal; 127 m_heightmap[x, y] = newVal;
@@ -164,7 +164,7 @@ namespace OpenSim.Framework
164 // TerrainData.ClearLand(float) 164 // TerrainData.ClearLand(float)
165 public override void ClearLand(float pHeight) 165 public override void ClearLand(float pHeight)
166 { 166 {
167 short flatHeight = ToCompressedHeight(pHeight); 167 int flatHeight = ToCompressedHeight(pHeight);
168 for (int xx = 0; xx < SizeX; xx++) 168 for (int xx = 0; xx < SizeX; xx++)
169 for (int yy = 0; yy < SizeY; yy++) 169 for (int yy = 0; yy < SizeY; yy++)
170 m_heightmap[xx, yy] = flatHeight; 170 m_heightmap[xx, yy] = flatHeight;
@@ -214,9 +214,9 @@ namespace OpenSim.Framework
214 public override float CompressionFactor { get { return m_compressionFactor; } } 214 public override float CompressionFactor { get { return m_compressionFactor; } }
215 215
216 // TerrainData.GetCompressedMap 216 // TerrainData.GetCompressedMap
217 public override short[] GetCompressedMap() 217 public override int[] GetCompressedMap()
218 { 218 {
219 short[] newMap = new short[SizeX * SizeY]; 219 int[] newMap = new int[SizeX * SizeY];
220 220
221 int ind = 0; 221 int ind = 0;
222 for (int xx = 0; xx < SizeX; xx++) 222 for (int xx = 0; xx < SizeX; xx++)
@@ -230,7 +230,7 @@ namespace OpenSim.Framework
230 public override TerrainData Clone() 230 public override TerrainData Clone()
231 { 231 {
232 HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ); 232 HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ);
233 ret.m_heightmap = (short[,])this.m_heightmap.Clone(); 233 ret.m_heightmap = (int[,])this.m_heightmap.Clone();
234 return ret; 234 return ret;
235 } 235 }
236 236
@@ -267,19 +267,19 @@ namespace OpenSim.Framework
267 267
268 // ============================================================= 268 // =============================================================
269 269
270 private short[,] m_heightmap; 270 private int[,] m_heightmap;
271 // Remember subregions of the heightmap that has changed. 271 // Remember subregions of the heightmap that has changed.
272 private bool[,] m_taint; 272 private bool[,] m_taint;
273 273
274 // To save space (especially for large regions), keep the height as a short integer 274 // To save space (especially for large regions), keep the height as a short integer
275 // that is coded as the float height times the compression factor (usually '100' 275 // that is coded as the float height times the compression factor (usually '100'
276 // to make for two decimal points). 276 // to make for two decimal points).
277 public short ToCompressedHeight(double pHeight) 277 public int ToCompressedHeight(double pHeight)
278 { 278 {
279 return (short)(pHeight * CompressionFactor); 279 return (int)(pHeight * CompressionFactor);
280 } 280 }
281 281
282 public float FromCompressedHeight(short pHeight) 282 public float FromCompressedHeight(int pHeight)
283 { 283 {
284 return ((float)pHeight) / CompressionFactor; 284 return ((float)pHeight) / CompressionFactor;
285 } 285 }
@@ -293,7 +293,7 @@ namespace OpenSim.Framework
293 SizeZ = (int)Constants.RegionHeight; 293 SizeZ = (int)Constants.RegionHeight;
294 m_compressionFactor = 100.0f; 294 m_compressionFactor = 100.0f;
295 295
296 m_heightmap = new short[SizeX, SizeY]; 296 m_heightmap = new int[SizeX, SizeY];
297 for (int ii = 0; ii < SizeX; ii++) 297 for (int ii = 0; ii < SizeX; ii++)
298 { 298 {
299 for (int jj = 0; jj < SizeY; jj++) 299 for (int jj = 0; jj < SizeY; jj++)
@@ -315,14 +315,14 @@ namespace OpenSim.Framework
315 SizeY = pY; 315 SizeY = pY;
316 SizeZ = pZ; 316 SizeZ = pZ;
317 m_compressionFactor = 100.0f; 317 m_compressionFactor = 100.0f;
318 m_heightmap = new short[SizeX, SizeY]; 318 m_heightmap = new int[SizeX, SizeY];
319 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; 319 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
320 // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); 320 // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
321 ClearTaint(); 321 ClearTaint();
322 ClearLand(0f); 322 ClearLand(0f);
323 } 323 }
324 324
325 public HeightmapTerrainData(short[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ) 325 public HeightmapTerrainData(int[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ)
326 { 326 {
327 m_compressionFactor = pCompressionFactor; 327 m_compressionFactor = pCompressionFactor;
328 int ind = 0; 328 int ind = 0;
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
index cc040a6..3d563a6 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
@@ -363,8 +363,8 @@ namespace OpenSim.Region.Framework.Scenes
363 public int SizeY; 363 public int SizeY;
364 public int SizeZ; 364 public int SizeZ;
365 public float CompressionFactor; 365 public float CompressionFactor;
366 public short[] Map; 366 public int[] Map;
367 public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, short[] pMap) 367 public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, int[] pMap)
368 { 368 {
369 Version = 1; 369 Version = 1;
370 SizeX = pX; 370 SizeX = pX;