diff options
author | UbitUmarov | 2015-08-24 18:40:28 +0100 |
---|---|---|
committer | UbitUmarov | 2015-08-24 18:40:28 +0100 |
commit | 1c752296bfc25ca709117ad1c557aff2b6097ffb (patch) | |
tree | 495650a06cc09b59dc31b2b20d8d2e79ddb1c72f /OpenSim/Framework | |
parent | try to implement core load oar options (diff) | |
download | opensim-SC_OLD-1c752296bfc25ca709117ad1c557aff2b6097ffb.zip opensim-SC_OLD-1c752296bfc25ca709117ad1c557aff2b6097ffb.tar.gz opensim-SC_OLD-1c752296bfc25ca709117ad1c557aff2b6097ffb.tar.bz2 opensim-SC_OLD-1c752296bfc25ca709117ad1c557aff2b6097ffb.tar.xz |
change internal representation of terrain from int to ushort. This will
suporte height from 0 to 655.53m that includes SL limits ( still need to
add code to trap eventual negative values from dbs or user input)
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/TerrainData.cs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs index 6b1be4e..d0eddc6 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 ints | 75 | // return a special compressed representation of the heightmap in ushort |
76 | public abstract int[] GetCompressedMap(); | 76 | public abstract ushort[] 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 | // "int compressedHeight = (int)(height * compressionFactor);" | 102 | // "ushort compressedHeight = (ushort)(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,7 +109,7 @@ 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 integers. The integer values are converted to | 112 | // The heighmap is kept as an array of ushorts. The ushort values are converted to |
113 | // and from floats by TerrainCompressionFactor. | 113 | // and from floats by TerrainCompressionFactor. |
114 | public class HeightmapTerrainData : TerrainData | 114 | public class HeightmapTerrainData : TerrainData |
115 | { | 115 | { |
@@ -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 | int newVal = ToCompressedHeight(value); | 124 | ushort 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 | int flatHeight = ToCompressedHeight(pHeight); | 167 | ushort 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 int[] GetCompressedMap() | 217 | public override ushort[] GetCompressedMap() |
218 | { | 218 | { |
219 | int[] newMap = new int[SizeX * SizeY]; | 219 | ushort[] newMap = new ushort[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 = (int[,])this.m_heightmap.Clone(); | 233 | ret.m_heightmap = (ushort[,])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 int[,] m_heightmap; | 270 | private ushort[,] 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 int ToCompressedHeight(double pHeight) | 277 | public ushort ToCompressedHeight(double pHeight) |
278 | { | 278 | { |
279 | return (int)(pHeight * CompressionFactor); | 279 | return (ushort)(pHeight * CompressionFactor); |
280 | } | 280 | } |
281 | 281 | ||
282 | public float FromCompressedHeight(int pHeight) | 282 | public float FromCompressedHeight(ushort 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 int[SizeX, SizeY]; | 296 | m_heightmap = new ushort[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 int[SizeX, SizeY]; | 318 | m_heightmap = new ushort[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(int[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ) | 325 | public HeightmapTerrainData(ushort[] 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; |
@@ -401,7 +401,7 @@ namespace OpenSim.Framework | |||
401 | public Array ToCompressedTerrainSerialization() | 401 | public Array ToCompressedTerrainSerialization() |
402 | { | 402 | { |
403 | Array ret = null; | 403 | Array ret = null; |
404 | using (MemoryStream str = new MemoryStream((3 * sizeof(Int32)) + (SizeX * SizeY * sizeof(Int16)))) | 404 | using (MemoryStream str = new MemoryStream((3 * sizeof(Int32)) + (SizeX * SizeY * sizeof(ushort)))) |
405 | { | 405 | { |
406 | using (BinaryWriter bw = new BinaryWriter(str)) | 406 | using (BinaryWriter bw = new BinaryWriter(str)) |
407 | { | 407 | { |
@@ -412,7 +412,7 @@ namespace OpenSim.Framework | |||
412 | for (int yy = 0; yy < SizeY; yy++) | 412 | for (int yy = 0; yy < SizeY; yy++) |
413 | for (int xx = 0; xx < SizeX; xx++) | 413 | for (int xx = 0; xx < SizeX; xx++) |
414 | { | 414 | { |
415 | bw.Write((Int16)m_heightmap[xx, yy]); | 415 | bw.Write((ushort)m_heightmap[xx, yy]); |
416 | } | 416 | } |
417 | } | 417 | } |
418 | ret = str.ToArray(); | 418 | ret = str.ToArray(); |
@@ -448,7 +448,7 @@ namespace OpenSim.Framework | |||
448 | { | 448 | { |
449 | for (int xx = 0; xx < hmSizeX; xx++) | 449 | for (int xx = 0; xx < hmSizeX; xx++) |
450 | { | 450 | { |
451 | Int16 val = br.ReadInt16(); | 451 | ushort val = br.ReadUInt16(); |
452 | if (xx < SizeX && yy < SizeY) | 452 | if (xx < SizeX && yy < SizeY) |
453 | m_heightmap[xx, yy] = val; | 453 | m_heightmap[xx, yy] = val; |
454 | } | 454 | } |