remove terraindata abstraction layer, since we only have heightmap type

This commit is contained in:
UbitUmarov
2019-01-21 06:05:21 +00:00
parent a287a8e121
commit 33a062612f
13 changed files with 125 additions and 196 deletions

View File

@@ -37,56 +37,6 @@ using log4net;
namespace OpenSim.Framework
{
public abstract class TerrainData
{
// Terrain always is a square
public int SizeX { get; protected set; }
public int SizeY { get; protected set; }
public int SizeZ { get; protected set; }
// A height used when the user doesn't specify anything
public const float DefaultTerrainHeight = 21f;
public abstract float this[int x, int y] { get; set; }
// Someday terrain will have caves
// at most holes :p
public abstract float this[int x, int y, int z] { get; set; }
public abstract bool IsTaintedAt(int xx, int yy);
public abstract bool IsTaintedAt(int xx, int yy, bool clearOnTest);
public abstract void TaintAllTerrain();
public abstract void ClearTaint();
public abstract void ClearLand();
public abstract void ClearLand(float height);
// Return a representation of this terrain for storing as a blob in the database.
// Returns 'true' to say blob was stored in the 'out' locations.
public abstract bool GetDatabaseBlob(out int DBFormatRevisionCode, out Array blob);
// Given a revision code and a blob from the database, create and return the right type of TerrainData.
// The sizes passed are the expected size of the region. The database info will be used to
// initialize the heightmap of that sized region with as much data is in the blob.
// Return created TerrainData or 'null' if unsuccessful.
public static TerrainData CreateFromDatabaseBlobFactory(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob)
{
// For the moment, there is only one implementation class
return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob);
}
// return a special compressed representation of the heightmap in ushort
public abstract float[] GetCompressedMap();
public abstract float CompressionFactor { get; }
public abstract float[] GetFloatsSerialized();
public abstract double[,] GetDoubles();
public abstract void GetPatchMinMax(int px, int py, out float zmin, out float zmax);
public abstract void GetPatchBlock(float[] block, int px, int py, float sub, float premult);
public abstract TerrainData Clone();
}
// The terrain is stored in the database as a blob with a 'revision' field.
// Some implementations of terrain storage would fill the revision field with
// the time the terrain was stored. When real revisions were added and this
@@ -116,18 +66,37 @@ namespace OpenSim.Framework
RevisionHigh = 1234
}
// 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 ushorts. The ushort values are converted to
// and from floats by TerrainCompressionFactor.
public class HeightmapTerrainData : TerrainData
public class TerrainData
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static string LogHeader = "[HEIGHTMAP TERRAIN DATA]";
private static string LogHeader = "[TERRAIN DATA]";
// TerrainData.this[x, y]
public override float this[int x, int y]
private float[,] m_heightmap;
// Remember subregions of the heightmap that has changed.
private bool[,] m_taint;
// legacy CompressionFactor
public float CompressionFactor { get; private set; }
// Terrain always is a square
public int SizeX { get; protected set; }
public int SizeY { get; protected set; }
public int SizeZ { get; protected set; }
// A height used when the user doesn't specify anything
public const float DefaultTerrainHeight = 21f;
// Given a revision code and a blob from the database, create and return the right type of TerrainData.
// The sizes passed are the expected size of the region. The database info will be used to
// initialize the heightmap of that sized region with as much data is in the blob.
// Return created TerrainData or 'null' if unsuccessful.
public static TerrainData CreateFromDatabaseBlobFactory(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob)
{
// For the moment, there is only one implementation class
return new TerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob);
}
public float this[int x, int y]
{
get { return m_heightmap[x, y]; }
set
@@ -140,21 +109,18 @@ namespace OpenSim.Framework
}
}
// TerrainData.this[x, y, z]
public override float this[int x, int y, int z]
public float this[int x, int y, int z]
{
get { return this[x, y]; }
set { this[x, y] = value; }
}
// TerrainData.ClearTaint
public override void ClearTaint()
public void ClearTaint()
{
SetAllTaint(false);
}
// TerrainData.TaintAllTerrain
public override void TaintAllTerrain()
public void TaintAllTerrain()
{
SetAllTaint(true);
}
@@ -166,13 +132,12 @@ namespace OpenSim.Framework
m_taint[ii, jj] = setting;
}
// TerrainData.ClearLand
public override void ClearLand()
public void ClearLand()
{
ClearLand(DefaultTerrainHeight);
}
// TerrainData.ClearLand(float)
public override void ClearLand(float pHeight)
public void ClearLand(float pHeight)
{
for (int xx = 0; xx < SizeX; xx++)
for (int yy = 0; yy < SizeY; yy++)
@@ -182,7 +147,7 @@ namespace OpenSim.Framework
// Return 'true' of the patch that contains these region coordinates has been modified.
// Note that checking the taint clears it.
// There is existing code that relies on this feature.
public override bool IsTaintedAt(int xx, int yy, bool clearOnTest)
public bool IsTaintedAt(int xx, int yy, bool clearOnTest)
{
int tx = xx / Constants.TerrainPatchSize;
int ty = yy / Constants.TerrainPatchSize;
@@ -195,41 +160,22 @@ namespace OpenSim.Framework
// Old form that clears the taint flag when we check it.
// ubit: this dangerus naming should be only check without clear
// keeping for old modules outthere
public override bool IsTaintedAt(int xx, int yy)
public bool IsTaintedAt(int xx, int yy)
{
return IsTaintedAt(xx, yy, true /* clearOnTest */);
}
// TerrainData.GetDatabaseBlob
// The user wants something to store in the database.
public override bool GetDatabaseBlob(out int DBRevisionCode, out Array blob)
public bool GetDatabaseBlob(out int DBRevisionCode, out Array blob)
{
bool ret = false;
/* save all as Variable2DGzip
if (SizeX == Constants.RegionSize && SizeY == Constants.RegionSize)
{
DBRevisionCode = (int)DBTerrainRevision.Legacy256;
blob = ToLegacyTerrainSerialization();
ret = true;
}
else
{
*/
DBRevisionCode = (int)DBTerrainRevision.Variable2DGzip;
// DBRevisionCode = (int)DBTerrainRevision.Variable2D;
blob = ToCompressedTerrainSerializationV2DGzip();
// blob = ToCompressedTerrainSerializationV2D();
ret = true;
// }
return ret;
DBRevisionCode = (int)DBTerrainRevision.Variable2DGzip;
blob = ToCompressedTerrainSerializationV2DGzip();
return true;
}
// TerrainData.CompressionFactor
private float m_compressionFactor = 100.0f;
public override float CompressionFactor { get { return m_compressionFactor; } }
// TerrainData.GetCompressedMap
public override float[] GetCompressedMap()
public float[] GetCompressedMap()
{
float[] newMap = new float[SizeX * SizeY];
@@ -241,19 +187,18 @@ namespace OpenSim.Framework
return newMap;
}
// TerrainData.Clone
public override TerrainData Clone()
public TerrainData Clone()
{
HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ);
TerrainData ret = new TerrainData(SizeX, SizeY, SizeZ);
ret.m_heightmap = (float[,])this.m_heightmap.Clone();
return ret;
}
// TerrainData.GetFloatsSerialized
// This one dimensional version is ordered so height = map[y*sizeX+x];
// DEPRECATED: don't use this function as it does not retain the dimensions of the terrain
// and the caller will probably do the wrong thing if the terrain is not the legacy 256x256.
public override float[] GetFloatsSerialized()
public float[] GetFloatsSerialized()
{
int points = SizeX * SizeY;
float[] heights = new float[points];
@@ -269,7 +214,7 @@ namespace OpenSim.Framework
}
// TerrainData.GetDoubles
public override double[,] GetDoubles()
public double[,] GetDoubles()
{
double[,] ret = new double[SizeX, SizeY];
for (int xx = 0; xx < SizeX; xx++)
@@ -279,7 +224,7 @@ namespace OpenSim.Framework
return ret;
}
public override unsafe void GetPatchMinMax(int px, int py, out float zmin, out float zmax)
public unsafe void GetPatchMinMax(int px, int py, out float zmin, out float zmax)
{
zmax = float.MinValue;
zmin = float.MaxValue;
@@ -304,7 +249,7 @@ namespace OpenSim.Framework
}
}
public override unsafe void GetPatchBlock(float[] _block, int px, int py, float sub, float premult)
public unsafe void GetPatchBlock(float[] _block, int px, int py, float sub, float premult)
{
int k = 0;
int stride = m_heightmap.GetLength(1);
@@ -324,13 +269,8 @@ namespace OpenSim.Framework
}
}
// =============================================================
private float[,] m_heightmap;
// Remember subregions of the heightmap that has changed.
private bool[,] m_taint;
// 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).
public short ToCompressedHeightshort(float pHeight)
{
@@ -353,6 +293,7 @@ namespace OpenSim.Framework
return ushort.MaxValue;
return (ushort)pHeight;
}
*/
public float FromCompressedHeight(short pHeight)
{
@@ -366,12 +307,12 @@ namespace OpenSim.Framework
// To keep with the legacy theme, create an instance of this class based on the
// way terrain used to be passed around.
public HeightmapTerrainData(double[,] pTerrain)
public TerrainData(double[,] pTerrain)
{
SizeX = pTerrain.GetLength(0);
SizeY = pTerrain.GetLength(1);
SizeZ = (int)Constants.RegionHeight;
m_compressionFactor = 100.0f;
CompressionFactor = 100.0f;
m_heightmap = new float[SizeX, SizeY];
for (int ii = 0; ii < SizeX; ii++)
@@ -389,12 +330,12 @@ namespace OpenSim.Framework
}
// Create underlying structures but don't initialize the heightmap assuming the caller will immediately do that
public HeightmapTerrainData(int pX, int pY, int pZ)
public TerrainData(int pX, int pY, int pZ)
{
SizeX = pX;
SizeY = pY;
SizeZ = pZ;
m_compressionFactor = 100.0f;
CompressionFactor = 100.0f;
m_heightmap = new float[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);
@@ -402,10 +343,10 @@ namespace OpenSim.Framework
ClearLand(0f);
}
public HeightmapTerrainData(float[] cmap, float pCompressionFactor, int pX, int pY, int pZ)
public TerrainData(float[] cmap, float pCompressionFactor, int pX, int pY, int pZ)
: this(pX, pY, pZ)
{
m_compressionFactor = pCompressionFactor;
CompressionFactor = pCompressionFactor;
int ind = 0;
for (int xx = 0; xx < SizeX; xx++)
for (int yy = 0; yy < SizeY; yy++)
@@ -414,7 +355,7 @@ namespace OpenSim.Framework
}
// Create a heighmap from a database blob
public HeightmapTerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob)
public TerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob)
: this(pSizeX, pSizeY, pSizeZ)
{
switch ((DBTerrainRevision)pFormatCode)
@@ -589,7 +530,7 @@ namespace OpenSim.Framework
hmSizeY = br.ReadInt32();
hmCompressionFactor = br.ReadInt32();
m_compressionFactor = hmCompressionFactor;
CompressionFactor = hmCompressionFactor;
// In case database info doesn't match real terrain size, initialize the whole terrain.
ClearLand();