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
parent
3829df1059
commit
1c752296bf
|
@ -72,8 +72,8 @@ namespace OpenSim.Framework
|
||||||
return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob);
|
return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a special compressed representation of the heightmap in ints
|
// return a special compressed representation of the heightmap in ushort
|
||||||
public abstract int[] GetCompressedMap();
|
public abstract ushort[] GetCompressedMap();
|
||||||
public abstract float CompressionFactor { get; }
|
public abstract float CompressionFactor { get; }
|
||||||
|
|
||||||
public abstract float[] GetFloatsSerialized();
|
public abstract float[] GetFloatsSerialized();
|
||||||
|
@ -99,7 +99,7 @@ namespace OpenSim.Framework
|
||||||
Variable2D = 22,
|
Variable2D = 22,
|
||||||
// Terrain is 'int32, int32, int32, int16[]' where the ints are X and Y dimensions
|
// 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
|
// 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.
|
// The dimensions are presumed to be multiples of 16 and, more likely, multiples of 256.
|
||||||
Compressed2D = 27,
|
Compressed2D = 27,
|
||||||
// A revision that is not listed above or any revision greater than this value is 'Legacy256'.
|
// 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.
|
// Version of terrain that is a heightmap.
|
||||||
// This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge
|
// This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge
|
||||||
// of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer.
|
// 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.
|
// and from floats by TerrainCompressionFactor.
|
||||||
public class HeightmapTerrainData : TerrainData
|
public class HeightmapTerrainData : TerrainData
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,7 @@ namespace OpenSim.Framework
|
||||||
{
|
{
|
||||||
get { return FromCompressedHeight(m_heightmap[x, y]); }
|
get { return FromCompressedHeight(m_heightmap[x, y]); }
|
||||||
set {
|
set {
|
||||||
int newVal = ToCompressedHeight(value);
|
ushort newVal = ToCompressedHeight(value);
|
||||||
if (m_heightmap[x, y] != newVal)
|
if (m_heightmap[x, y] != newVal)
|
||||||
{
|
{
|
||||||
m_heightmap[x, y] = newVal;
|
m_heightmap[x, y] = newVal;
|
||||||
|
@ -164,7 +164,7 @@ namespace OpenSim.Framework
|
||||||
// TerrainData.ClearLand(float)
|
// TerrainData.ClearLand(float)
|
||||||
public override void ClearLand(float pHeight)
|
public override void ClearLand(float pHeight)
|
||||||
{
|
{
|
||||||
int flatHeight = ToCompressedHeight(pHeight);
|
ushort flatHeight = ToCompressedHeight(pHeight);
|
||||||
for (int xx = 0; xx < SizeX; xx++)
|
for (int xx = 0; xx < SizeX; xx++)
|
||||||
for (int yy = 0; yy < SizeY; yy++)
|
for (int yy = 0; yy < SizeY; yy++)
|
||||||
m_heightmap[xx, yy] = flatHeight;
|
m_heightmap[xx, yy] = flatHeight;
|
||||||
|
@ -214,9 +214,9 @@ namespace OpenSim.Framework
|
||||||
public override float CompressionFactor { get { return m_compressionFactor; } }
|
public override float CompressionFactor { get { return m_compressionFactor; } }
|
||||||
|
|
||||||
// TerrainData.GetCompressedMap
|
// 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;
|
int ind = 0;
|
||||||
for (int xx = 0; xx < SizeX; xx++)
|
for (int xx = 0; xx < SizeX; xx++)
|
||||||
|
@ -230,7 +230,7 @@ namespace OpenSim.Framework
|
||||||
public override TerrainData Clone()
|
public override TerrainData Clone()
|
||||||
{
|
{
|
||||||
HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ);
|
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;
|
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.
|
// Remember subregions of the heightmap that has changed.
|
||||||
private bool[,] m_taint;
|
private bool[,] m_taint;
|
||||||
|
|
||||||
// To save space (especially for large regions), keep the height as a short integer
|
// 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'
|
// that is coded as the float height times the compression factor (usually '100'
|
||||||
// to make for two decimal points).
|
// 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;
|
return ((float)pHeight) / CompressionFactor;
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ namespace OpenSim.Framework
|
||||||
SizeZ = (int)Constants.RegionHeight;
|
SizeZ = (int)Constants.RegionHeight;
|
||||||
m_compressionFactor = 100.0f;
|
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 ii = 0; ii < SizeX; ii++)
|
||||||
{
|
{
|
||||||
for (int jj = 0; jj < SizeY; jj++)
|
for (int jj = 0; jj < SizeY; jj++)
|
||||||
|
@ -315,14 +315,14 @@ namespace OpenSim.Framework
|
||||||
SizeY = pY;
|
SizeY = pY;
|
||||||
SizeZ = pZ;
|
SizeZ = pZ;
|
||||||
m_compressionFactor = 100.0f;
|
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_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);
|
// m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ);
|
||||||
ClearTaint();
|
ClearTaint();
|
||||||
ClearLand(0f);
|
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;
|
m_compressionFactor = pCompressionFactor;
|
||||||
int ind = 0;
|
int ind = 0;
|
||||||
|
@ -401,7 +401,7 @@ namespace OpenSim.Framework
|
||||||
public Array ToCompressedTerrainSerialization()
|
public Array ToCompressedTerrainSerialization()
|
||||||
{
|
{
|
||||||
Array ret = null;
|
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))
|
using (BinaryWriter bw = new BinaryWriter(str))
|
||||||
{
|
{
|
||||||
|
@ -412,7 +412,7 @@ namespace OpenSim.Framework
|
||||||
for (int yy = 0; yy < SizeY; yy++)
|
for (int yy = 0; yy < SizeY; yy++)
|
||||||
for (int xx = 0; xx < SizeX; xx++)
|
for (int xx = 0; xx < SizeX; xx++)
|
||||||
{
|
{
|
||||||
bw.Write((Int16)m_heightmap[xx, yy]);
|
bw.Write((ushort)m_heightmap[xx, yy]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = str.ToArray();
|
ret = str.ToArray();
|
||||||
|
@ -448,7 +448,7 @@ namespace OpenSim.Framework
|
||||||
{
|
{
|
||||||
for (int xx = 0; xx < hmSizeX; xx++)
|
for (int xx = 0; xx < hmSizeX; xx++)
|
||||||
{
|
{
|
||||||
Int16 val = br.ReadInt16();
|
ushort val = br.ReadUInt16();
|
||||||
if (xx < SizeX && yy < SizeY)
|
if (xx < SizeX && yy < SizeY)
|
||||||
m_heightmap[xx, yy] = val;
|
m_heightmap[xx, yy] = val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,8 +363,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
public int SizeY;
|
public int SizeY;
|
||||||
public int SizeZ;
|
public int SizeZ;
|
||||||
public float CompressionFactor;
|
public float CompressionFactor;
|
||||||
public int[] Map;
|
public ushort[] Map;
|
||||||
public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, int[] pMap)
|
public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, ushort[] pMap)
|
||||||
{
|
{
|
||||||
Version = 1;
|
Version = 1;
|
||||||
SizeX = pX;
|
SizeX = pX;
|
||||||
|
|
Loading…
Reference in New Issue