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)
avinationmerge
UbitUmarov 2015-08-24 18:40:28 +01:00
parent 3829df1059
commit 1c752296bf
2 changed files with 21 additions and 21 deletions

View File

@ -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;
}

View File

@ -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;