From 39777db8ef0604ad228854ce226bb530c2d27239 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Thu, 31 Oct 2013 09:24:06 -0700
Subject: varregion: fix problem of X/Y dimensions swapped and incorrect
terrain compression base computation. Complete replacement of float[] for
terrain heightmap with TerrainData instance.
---
OpenSim/Region/Framework/Scenes/TerrainChannel.cs | 20 +++++++------
.../Region/Framework/Scenes/TerrainCompressor.cs | 35 ++++++++++------------
2 files changed, 27 insertions(+), 28 deletions(-)
(limited to 'OpenSim/Region/Framework')
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
index 6d245cb..d641c87 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs
@@ -100,16 +100,20 @@ namespace OpenSim.Region.Framework.Scenes
}
// ITerrainChannel.GetFloatsSerialized()
- // NOTICE that the one dimensional form is ordered by Y!!
+ // 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 float[] GetFloatsSerialised()
{
int points = Width * Height;
float[] heights = new float[points];
int idx = 0;
- for (int ii = 0; ii < Height; ii++)
- for (int jj = 0; jj < Width; jj++)
- heights[idx++] = m_terrainData[jj, ii];
+ for (int jj = 0; jj < Height; jj++)
+ for (int ii = 0; ii < Width; ii++)
+ {
+ heights[idx++] = m_terrainData[ii, jj];
+ }
return heights;
}
@@ -117,14 +121,12 @@ namespace OpenSim.Region.Framework.Scenes
// ITerrainChannel.GetDoubles()
public double[,] GetDoubles()
{
- int w = Width;
- int l = Height;
- double[,] heights = new double[w, l];
+ double[,] heights = new double[Width, Height];
int idx = 0; // index into serialized array
- for (int ii = 0; ii < w; ii++)
+ for (int ii = 0; ii < Width; ii++)
{
- for (int jj = 0; jj < l; jj++)
+ for (int jj = 0; jj < Height; jj++)
{
heights[ii, jj] = (double)m_terrainData[ii, jj];
idx++;
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
index e91c959..e4513ad 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
@@ -108,11 +108,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return layer;
}
- // Legacy land packet generation gluing old land representation (heights) to compressed representation.
- // This is an intermediate step in converting terrain into a variable sized heightmap. Some of the
- // routines (like IClientAPI) only pass the float array of heights around. This entry
- // converts that legacy representation into the more compact represenation used in
- // TerrainData. Someday fix the plumbing between here and the scene.
+ // Create a land packet for a single patch.
public static LayerDataPacket CreateLandPacket(TerrainData terrData, int patchX, int patchY)
{
int[] xPieces = new int[1];
@@ -120,9 +116,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
xPieces[0] = patchX; // patch X dimension
yPieces[0] = patchY;
- m_log.DebugFormat("{0} CreateLandPacket. patchX={1}, patchY={2}, sizeX={3}, sizeY={4}",
- LogHeader, patchX, patchY, terrData.SizeX, terrData.SizeY);
-
return CreateLandPacket(terrData, xPieces, yPieces, (int)TerrainPatch.LayerType.Land);
}
@@ -130,19 +123,20 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// Creates a LayerData packet for compressed land data given a full
/// simulator heightmap and an array of indices of patches to compress
///
- ///
- /// A 256 * 256 array of floating point values
- /// specifying the height at each meter in the simulator
+ ///
+ /// Terrain data that can result in a meter square heightmap.
///
///
- /// Array of indexes in the 16x16 grid of patches
- /// for this simulator. For example if 1 and 17 are specified, patches
- /// x=1,y=0 and x=1,y=1 are sent
+ /// Array of indexes in the grid of patches
+ /// for this simulator.
+ /// If creating a packet for multiple patches, there will be entries in
+ /// both the X and Y arrays for each of the patches.
+ /// For example if patches 1 and 17 are to be sent,
+ /// x[] = {1,1} and y[] = {0,1} which specifies the patches at
+ /// indexes <1,0> and <1,1> (presuming the terrain size is 16x16 patches).
///
///
- /// Array of indexes in the 16x16 grid of patches
- /// for this simulator. For example if 1 and 17 are specified, patches
- /// x=1,y=0 and x=1,y=1 are sent
+ /// Array of indexes in the grid of patches.
///
///
///
@@ -228,6 +222,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
header.PatchIDs += (patchX << 5);
}
+ // m_log.DebugFormat("{0} CreatePatchFromHeightmap. patchX={1}, patchY={2}, DCOffset={3}, range={4}",
+ // LogHeader, patchX, patchY, header.DCOffset, header.Range);
+
// NOTE: No idea what prequant and postquant should be or what they do
int wbits;
int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits);
@@ -266,7 +263,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
for (int i = patchX*16; i < (patchX + 1)*16; i++)
{
// short val = heightmap[j*pRegionSizeX + i];
- float val = terrData[j, i];
+ float val = terrData[i, j];
if (val > zmax) zmax = val;
if (val < zmin) zmin = val;
}
@@ -838,7 +835,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
for (int i = patchX * Constants.TerrainPatchSize; i < iPatchLimit; i++)
{
// block[k++] = (heightmap[j*pRegionSizeX + i])*premult - sub;
- block[k++] = terrData[j, i] - sub;
+ block[k++] = terrData[i, j] * premult - sub;
}
}
--
cgit v1.1