From 1c752296bfc25ca709117ad1c557aff2b6097ffb Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 24 Aug 2015 18:40:28 +0100 Subject: [PATCH] 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) --- OpenSim/Framework/TerrainData.cs | 38 +++++++++---------- .../Region/Framework/Scenes/TerrainChannel.cs | 4 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs index 6b1be4e9fa..d0eddc654f 100644 --- a/OpenSim/Framework/TerrainData.cs +++ b/OpenSim/Framework/TerrainData.cs @@ -72,8 +72,8 @@ namespace OpenSim.Framework return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob); } - // return a special compressed representation of the heightmap in ints - public abstract int[] GetCompressedMap(); + // return a special compressed representation of the heightmap in ushort + public abstract ushort[] GetCompressedMap(); public abstract float CompressionFactor { get; } public abstract float[] GetFloatsSerialized(); @@ -99,7 +99,7 @@ namespace OpenSim.Framework Variable2D = 22, // Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions // and third int is the 'compression factor'. The heights are compressed as - // "int compressedHeight = (int)(height * compressionFactor);" + // "ushort compressedHeight = (ushort)(height * compressionFactor);" // The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256. Compressed2D = 27, // A revision that is not listed above or any revision greater than this value is 'Legacy256'. @@ -109,7 +109,7 @@ namespace OpenSim.Framework // Version of terrain that is a heightmap. // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer. - // The heighmap is kept as an array of integers. The integer values are converted to + // The heighmap is kept as an array of ushorts. The ushort values are converted to // and from floats by TerrainCompressionFactor. public class HeightmapTerrainData : TerrainData { @@ -121,7 +121,7 @@ namespace OpenSim.Framework { get { return FromCompressedHeight(m_heightmap[x, y]); } set { - int newVal = ToCompressedHeight(value); + ushort newVal = ToCompressedHeight(value); if (m_heightmap[x, y] != newVal) { m_heightmap[x, y] = newVal; @@ -164,7 +164,7 @@ namespace OpenSim.Framework // TerrainData.ClearLand(float) public override void ClearLand(float pHeight) { - int flatHeight = ToCompressedHeight(pHeight); + ushort flatHeight = ToCompressedHeight(pHeight); for (int xx = 0; xx < SizeX; xx++) for (int yy = 0; yy < SizeY; yy++) m_heightmap[xx, yy] = flatHeight; @@ -214,9 +214,9 @@ namespace OpenSim.Framework public override float CompressionFactor { get { return m_compressionFactor; } } // TerrainData.GetCompressedMap - public override int[] GetCompressedMap() + public override ushort[] GetCompressedMap() { - int[] newMap = new int[SizeX * SizeY]; + ushort[] newMap = new ushort[SizeX * SizeY]; int ind = 0; for (int xx = 0; xx < SizeX; xx++) @@ -230,7 +230,7 @@ namespace OpenSim.Framework public override TerrainData Clone() { HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ); - ret.m_heightmap = (int[,])this.m_heightmap.Clone(); + ret.m_heightmap = (ushort[,])this.m_heightmap.Clone(); return ret; } @@ -267,19 +267,19 @@ namespace OpenSim.Framework // ============================================================= - private int[,] m_heightmap; + private ushort[,] m_heightmap; // Remember subregions of the heightmap that has changed. private bool[,] m_taint; // To save space (especially for large regions), keep the height as a short integer // that is coded as the float height times the compression factor (usually '100' // to make for two decimal points). - public int ToCompressedHeight(double pHeight) + public ushort ToCompressedHeight(double pHeight) { - return (int)(pHeight * CompressionFactor); + return (ushort)(pHeight * CompressionFactor); } - public float FromCompressedHeight(int pHeight) + public float FromCompressedHeight(ushort pHeight) { return ((float)pHeight) / CompressionFactor; } @@ -293,7 +293,7 @@ namespace OpenSim.Framework SizeZ = (int)Constants.RegionHeight; m_compressionFactor = 100.0f; - m_heightmap = new int[SizeX, SizeY]; + m_heightmap = new ushort[SizeX, SizeY]; for (int ii = 0; ii < SizeX; ii++) { for (int jj = 0; jj < SizeY; jj++) @@ -315,14 +315,14 @@ namespace OpenSim.Framework SizeY = pY; SizeZ = pZ; m_compressionFactor = 100.0f; - m_heightmap = new int[SizeX, SizeY]; + m_heightmap = new ushort[SizeX, SizeY]; m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); ClearTaint(); ClearLand(0f); } - public HeightmapTerrainData(int[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ) + public HeightmapTerrainData(ushort[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ) { m_compressionFactor = pCompressionFactor; int ind = 0; @@ -401,7 +401,7 @@ namespace OpenSim.Framework public Array ToCompressedTerrainSerialization() { Array ret = null; - using (MemoryStream str = new MemoryStream((3 * sizeof(Int32)) + (SizeX * SizeY * sizeof(Int16)))) + using (MemoryStream str = new MemoryStream((3 * sizeof(Int32)) + (SizeX * SizeY * sizeof(ushort)))) { using (BinaryWriter bw = new BinaryWriter(str)) { @@ -412,7 +412,7 @@ namespace OpenSim.Framework for (int yy = 0; yy < SizeY; yy++) for (int xx = 0; xx < SizeX; xx++) { - bw.Write((Int16)m_heightmap[xx, yy]); + bw.Write((ushort)m_heightmap[xx, yy]); } } ret = str.ToArray(); @@ -448,7 +448,7 @@ namespace OpenSim.Framework { for (int xx = 0; xx < hmSizeX; xx++) { - Int16 val = br.ReadInt16(); + ushort val = br.ReadUInt16(); if (xx < SizeX && yy < SizeY) m_heightmap[xx, yy] = val; } diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs index 684029d618..2dab246cdf 100644 --- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs +++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs @@ -363,8 +363,8 @@ namespace OpenSim.Region.Framework.Scenes public int SizeY; public int SizeZ; public float CompressionFactor; - public int[] Map; - public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, int[] pMap) + public ushort[] Map; + public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, ushort[] pMap) { Version = 1; SizeX = pX;