aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/TerrainData.cs
diff options
context:
space:
mode:
authorRobert Adams2013-10-16 07:52:30 -0700
committerRobert Adams2013-10-16 07:52:30 -0700
commit97bc5263de990ce80fc0adfbdb632ba8c5cbb77b (patch)
tree6d6d27ea6f8b8d93a8622f6fd9b257387ac7ca94 /OpenSim/Framework/TerrainData.cs
parentMerge branch 'master' into varregion (diff)
downloadopensim-SC_OLD-97bc5263de990ce80fc0adfbdb632ba8c5cbb77b.zip
opensim-SC_OLD-97bc5263de990ce80fc0adfbdb632ba8c5cbb77b.tar.gz
opensim-SC_OLD-97bc5263de990ce80fc0adfbdb632ba8c5cbb77b.tar.bz2
opensim-SC_OLD-97bc5263de990ce80fc0adfbdb632ba8c5cbb77b.tar.xz
varregion: move the compressed heighmap compression factor from
Constants into TerrainData. Save compression factor with the terrain blob in the database.
Diffstat (limited to 'OpenSim/Framework/TerrainData.cs')
-rw-r--r--OpenSim/Framework/TerrainData.cs43
1 files changed, 30 insertions, 13 deletions
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs
index bee6814..103359b 100644
--- a/OpenSim/Framework/TerrainData.cs
+++ b/OpenSim/Framework/TerrainData.cs
@@ -28,9 +28,12 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection;
31 32
32using OpenMetaverse; 33using OpenMetaverse;
33 34
35using log4net;
36
34namespace OpenSim.Framework 37namespace OpenSim.Framework
35{ 38{
36 public abstract class TerrainData 39 public abstract class TerrainData
@@ -54,12 +57,13 @@ namespace OpenSim.Framework
54 57
55 // return a special compressed representation of the heightmap in shorts 58 // return a special compressed representation of the heightmap in shorts
56 public abstract short[] GetCompressedMap(); 59 public abstract short[] GetCompressedMap();
57 public abstract void SetCompressedMap(short[] cmap); 60 public abstract float CompressionFactor { get; }
61 public abstract void SetCompressedMap(short[] cmap, float pCompressionFactor);
58 62
59 public abstract TerrainData Clone(); 63 public abstract TerrainData Clone();
60 } 64 }
61 65
62 // The terrain is stored as a blob in the database with a 'revision' field. 66 // The terrain is stored in the database as a blob with a 'revision' field.
63 // Some implementations of terrain storage would fill the revision field with 67 // Some implementations of terrain storage would fill the revision field with
64 // the time the terrain was stored. When real revisions were added and this 68 // the time the terrain was stored. When real revisions were added and this
65 // feature removed, that left some old entries with the time in the revision 69 // feature removed, that left some old entries with the time in the revision
@@ -83,9 +87,12 @@ namespace OpenSim.Framework
83 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge 87 // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge
84 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer. 88 // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer.
85 // The heighmap is kept as an array of short integers. The integer values are converted to 89 // The heighmap is kept as an array of short integers. The integer values are converted to
86 // and from floats by TerrainCompressionFactor. 90 // and from floats by TerrainCompressionFactor. Shorts are used to limit storage used.
87 public class HeightmapTerrainData : TerrainData 91 public class HeightmapTerrainData : TerrainData
88 { 92 {
93 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
94 private static string LogHeader = "[TERRAIN DATA]";
95
89 // TerrainData.this[x, y] 96 // TerrainData.this[x, y]
90 public override float this[int x, int y] 97 public override float this[int x, int y]
91 { 98 {
@@ -96,7 +103,7 @@ namespace OpenSim.Framework
96 { 103 {
97 m_heightmap[x, y] = newVal; 104 m_heightmap[x, y] = newVal;
98 m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true; 105 m_taint[x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize] = true;
99 106 m_log.DebugFormat("{0} set[{1},{2}] to {3} ({4})", LogHeader, x, y, value, newVal);
100 } 107 }
101 } 108 }
102 } 109 }
@@ -131,6 +138,11 @@ namespace OpenSim.Framework
131 return false; 138 return false;
132 } 139 }
133 140
141 // TerrainData.CompressionFactor
142 private float m_compressionFactor = 100.0f;
143 public override float CompressionFactor { get { return m_compressionFactor; } }
144
145 // TerrainData.GetCompressedMap
134 public override short[] GetCompressedMap() 146 public override short[] GetCompressedMap()
135 { 147 {
136 short[] newMap = new short[SizeX * SizeY]; 148 short[] newMap = new short[SizeX * SizeY];
@@ -143,8 +155,11 @@ namespace OpenSim.Framework
143 return newMap; 155 return newMap;
144 156
145 } 157 }
146 public override void SetCompressedMap(short[] cmap) 158 // TerrainData.SetCompressedMap
159 public override void SetCompressedMap(short[] cmap, float pCompressionFactor)
147 { 160 {
161 m_compressionFactor = pCompressionFactor;
162
148 int ind = 0; 163 int ind = 0;
149 for (int xx = 0; xx < SizeX; xx++) 164 for (int xx = 0; xx < SizeX; xx++)
150 for (int yy = 0; yy < SizeY; yy++) 165 for (int yy = 0; yy < SizeY; yy++)
@@ -168,23 +183,24 @@ namespace OpenSim.Framework
168 // To save space (especially for large regions), keep the height as a short integer 183 // To save space (especially for large regions), keep the height as a short integer
169 // that is coded as the float height times the compression factor (usually '100' 184 // that is coded as the float height times the compression factor (usually '100'
170 // to make for two decimal points). 185 // to make for two decimal points).
171 public static short ToCompressedHeight(double pHeight) 186 public short ToCompressedHeight(double pHeight)
172 { 187 {
173 return (short)(pHeight * Constants.TerrainCompression); 188 return (short)(pHeight * CompressionFactor);
174 } 189 }
175 190
176 public static float FromCompressedHeight(short pHeight) 191 public float FromCompressedHeight(short pHeight)
177 { 192 {
178 return ((float)pHeight) / Constants.TerrainCompression; 193 return ((float)pHeight) / CompressionFactor;
179 } 194 }
180 195
181 // To keep with the legacy theme, this can be created with the way terrain 196 // To keep with the legacy theme, create an instance of this class based on the
182 // used to passed around as. 197 // way terrain used to be passed around.
183 public HeightmapTerrainData(double[,] pTerrain) 198 public HeightmapTerrainData(double[,] pTerrain)
184 { 199 {
185 SizeX = pTerrain.GetLength(0); 200 SizeX = pTerrain.GetLength(0);
186 SizeY = pTerrain.GetLength(1); 201 SizeY = pTerrain.GetLength(1);
187 SizeZ = (int)Constants.RegionHeight; 202 SizeZ = (int)Constants.RegionHeight;
203 m_compressionFactor = 100.0f;
188 204
189 m_heightmap = new short[SizeX, SizeY]; 205 m_heightmap = new short[SizeX, SizeY];
190 for (int ii = 0; ii < SizeX; ii++) 206 for (int ii = 0; ii < SizeX; ii++)
@@ -206,14 +222,15 @@ namespace OpenSim.Framework
206 SizeX = pX; 222 SizeX = pX;
207 SizeY = pY; 223 SizeY = pY;
208 SizeZ = pZ; 224 SizeZ = pZ;
225 m_compressionFactor = 100.0f;
209 m_heightmap = new short[SizeX, SizeY]; 226 m_heightmap = new short[SizeX, SizeY];
210 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; 227 m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize];
211 ClearTaint(); 228 ClearTaint();
212 } 229 }
213 230
214 public HeightmapTerrainData(short[] cmap, int pX, int pY, int pZ) : this(pX, pY, pZ) 231 public HeightmapTerrainData(short[] cmap, float pCompressionFactor, int pX, int pY, int pZ) : this(pX, pY, pZ)
215 { 232 {
216 SetCompressedMap(cmap); 233 SetCompressedMap(cmap, pCompressionFactor);
217 } 234 }
218 235
219 236