diff options
author | UbitUmarov | 2019-01-21 06:05:21 +0000 |
---|---|---|
committer | UbitUmarov | 2019-01-21 06:05:21 +0000 |
commit | 33a062612f9fafcb7b4c0e8ac60937c448ce3c10 (patch) | |
tree | e6d716b001e94e1d9274e0adc4e8513d2aa48148 /OpenSim/Framework/TerrainData.cs | |
parent | this looks more like ubode (diff) | |
download | opensim-SC-33a062612f9fafcb7b4c0e8ac60937c448ce3c10.zip opensim-SC-33a062612f9fafcb7b4c0e8ac60937c448ce3c10.tar.gz opensim-SC-33a062612f9fafcb7b4c0e8ac60937c448ce3c10.tar.bz2 opensim-SC-33a062612f9fafcb7b4c0e8ac60937c448ce3c10.tar.xz |
remove terraindata abstraction layer, since we only have heightmap type
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/TerrainData.cs | 177 |
1 files changed, 59 insertions, 118 deletions
diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs index 7b99427..233c39b 100644 --- a/OpenSim/Framework/TerrainData.cs +++ b/OpenSim/Framework/TerrainData.cs | |||
@@ -37,56 +37,6 @@ using log4net; | |||
37 | 37 | ||
38 | namespace OpenSim.Framework | 38 | namespace OpenSim.Framework |
39 | { | 39 | { |
40 | public abstract class TerrainData | ||
41 | { | ||
42 | // Terrain always is a square | ||
43 | public int SizeX { get; protected set; } | ||
44 | public int SizeY { get; protected set; } | ||
45 | public int SizeZ { get; protected set; } | ||
46 | |||
47 | // A height used when the user doesn't specify anything | ||
48 | public const float DefaultTerrainHeight = 21f; | ||
49 | |||
50 | public abstract float this[int x, int y] { get; set; } | ||
51 | // Someday terrain will have caves | ||
52 | // at most holes :p | ||
53 | public abstract float this[int x, int y, int z] { get; set; } | ||
54 | |||
55 | public abstract bool IsTaintedAt(int xx, int yy); | ||
56 | public abstract bool IsTaintedAt(int xx, int yy, bool clearOnTest); | ||
57 | public abstract void TaintAllTerrain(); | ||
58 | public abstract void ClearTaint(); | ||
59 | |||
60 | public abstract void ClearLand(); | ||
61 | public abstract void ClearLand(float height); | ||
62 | |||
63 | // Return a representation of this terrain for storing as a blob in the database. | ||
64 | // Returns 'true' to say blob was stored in the 'out' locations. | ||
65 | public abstract bool GetDatabaseBlob(out int DBFormatRevisionCode, out Array blob); | ||
66 | |||
67 | // Given a revision code and a blob from the database, create and return the right type of TerrainData. | ||
68 | // The sizes passed are the expected size of the region. The database info will be used to | ||
69 | // initialize the heightmap of that sized region with as much data is in the blob. | ||
70 | // Return created TerrainData or 'null' if unsuccessful. | ||
71 | public static TerrainData CreateFromDatabaseBlobFactory(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) | ||
72 | { | ||
73 | // For the moment, there is only one implementation class | ||
74 | return new HeightmapTerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob); | ||
75 | } | ||
76 | |||
77 | // return a special compressed representation of the heightmap in ushort | ||
78 | public abstract float[] GetCompressedMap(); | ||
79 | public abstract float CompressionFactor { get; } | ||
80 | |||
81 | public abstract float[] GetFloatsSerialized(); | ||
82 | public abstract double[,] GetDoubles(); | ||
83 | |||
84 | public abstract void GetPatchMinMax(int px, int py, out float zmin, out float zmax); | ||
85 | public abstract void GetPatchBlock(float[] block, int px, int py, float sub, float premult); | ||
86 | |||
87 | public abstract TerrainData Clone(); | ||
88 | } | ||
89 | |||
90 | // The terrain is stored in the database as a blob with a 'revision' field. | 40 | // The terrain is stored in the database as a blob with a 'revision' field. |
91 | // Some implementations of terrain storage would fill the revision field with | 41 | // Some implementations of terrain storage would fill the revision field with |
92 | // the time the terrain was stored. When real revisions were added and this | 42 | // the time the terrain was stored. When real revisions were added and this |
@@ -116,18 +66,37 @@ namespace OpenSim.Framework | |||
116 | RevisionHigh = 1234 | 66 | RevisionHigh = 1234 |
117 | } | 67 | } |
118 | 68 | ||
119 | // Version of terrain that is a heightmap. | 69 | public class TerrainData |
120 | // This should really be 'LLOptimizedHeightmapTerrainData' as it includes knowledge | ||
121 | // of 'patches' which are 16x16 terrain areas which can be sent separately to the viewer. | ||
122 | // The heighmap is kept as an array of ushorts. The ushort values are converted to | ||
123 | // and from floats by TerrainCompressionFactor. | ||
124 | public class HeightmapTerrainData : TerrainData | ||
125 | { | 70 | { |
126 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 71 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
127 | private static string LogHeader = "[HEIGHTMAP TERRAIN DATA]"; | 72 | private static string LogHeader = "[TERRAIN DATA]"; |
73 | |||
74 | private float[,] m_heightmap; | ||
75 | // Remember subregions of the heightmap that has changed. | ||
76 | private bool[,] m_taint; | ||
77 | |||
78 | // legacy CompressionFactor | ||
79 | public float CompressionFactor { get; private set; } | ||
128 | 80 | ||
129 | // TerrainData.this[x, y] | 81 | // Terrain always is a square |
130 | public override float this[int x, int y] | 82 | public int SizeX { get; protected set; } |
83 | public int SizeY { get; protected set; } | ||
84 | public int SizeZ { get; protected set; } | ||
85 | |||
86 | // A height used when the user doesn't specify anything | ||
87 | public const float DefaultTerrainHeight = 21f; | ||
88 | |||
89 | // Given a revision code and a blob from the database, create and return the right type of TerrainData. | ||
90 | // The sizes passed are the expected size of the region. The database info will be used to | ||
91 | // initialize the heightmap of that sized region with as much data is in the blob. | ||
92 | // Return created TerrainData or 'null' if unsuccessful. | ||
93 | public static TerrainData CreateFromDatabaseBlobFactory(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) | ||
94 | { | ||
95 | // For the moment, there is only one implementation class | ||
96 | return new TerrainData(pSizeX, pSizeY, pSizeZ, pFormatCode, pBlob); | ||
97 | } | ||
98 | |||
99 | public float this[int x, int y] | ||
131 | { | 100 | { |
132 | get { return m_heightmap[x, y]; } | 101 | get { return m_heightmap[x, y]; } |
133 | set | 102 | set |
@@ -140,21 +109,18 @@ namespace OpenSim.Framework | |||
140 | } | 109 | } |
141 | } | 110 | } |
142 | 111 | ||
143 | // TerrainData.this[x, y, z] | 112 | public float this[int x, int y, int z] |
144 | public override float this[int x, int y, int z] | ||
145 | { | 113 | { |
146 | get { return this[x, y]; } | 114 | get { return this[x, y]; } |
147 | set { this[x, y] = value; } | 115 | set { this[x, y] = value; } |
148 | } | 116 | } |
149 | 117 | ||
150 | // TerrainData.ClearTaint | 118 | public void ClearTaint() |
151 | public override void ClearTaint() | ||
152 | { | 119 | { |
153 | SetAllTaint(false); | 120 | SetAllTaint(false); |
154 | } | 121 | } |
155 | 122 | ||
156 | // TerrainData.TaintAllTerrain | 123 | public void TaintAllTerrain() |
157 | public override void TaintAllTerrain() | ||
158 | { | 124 | { |
159 | SetAllTaint(true); | 125 | SetAllTaint(true); |
160 | } | 126 | } |
@@ -166,13 +132,12 @@ namespace OpenSim.Framework | |||
166 | m_taint[ii, jj] = setting; | 132 | m_taint[ii, jj] = setting; |
167 | } | 133 | } |
168 | 134 | ||
169 | // TerrainData.ClearLand | 135 | public void ClearLand() |
170 | public override void ClearLand() | ||
171 | { | 136 | { |
172 | ClearLand(DefaultTerrainHeight); | 137 | ClearLand(DefaultTerrainHeight); |
173 | } | 138 | } |
174 | // TerrainData.ClearLand(float) | 139 | |
175 | public override void ClearLand(float pHeight) | 140 | public void ClearLand(float pHeight) |
176 | { | 141 | { |
177 | for (int xx = 0; xx < SizeX; xx++) | 142 | for (int xx = 0; xx < SizeX; xx++) |
178 | for (int yy = 0; yy < SizeY; yy++) | 143 | for (int yy = 0; yy < SizeY; yy++) |
@@ -182,7 +147,7 @@ namespace OpenSim.Framework | |||
182 | // Return 'true' of the patch that contains these region coordinates has been modified. | 147 | // Return 'true' of the patch that contains these region coordinates has been modified. |
183 | // Note that checking the taint clears it. | 148 | // Note that checking the taint clears it. |
184 | // There is existing code that relies on this feature. | 149 | // There is existing code that relies on this feature. |
185 | public override bool IsTaintedAt(int xx, int yy, bool clearOnTest) | 150 | public bool IsTaintedAt(int xx, int yy, bool clearOnTest) |
186 | { | 151 | { |
187 | int tx = xx / Constants.TerrainPatchSize; | 152 | int tx = xx / Constants.TerrainPatchSize; |
188 | int ty = yy / Constants.TerrainPatchSize; | 153 | int ty = yy / Constants.TerrainPatchSize; |
@@ -195,41 +160,22 @@ namespace OpenSim.Framework | |||
195 | // Old form that clears the taint flag when we check it. | 160 | // Old form that clears the taint flag when we check it. |
196 | // ubit: this dangerus naming should be only check without clear | 161 | // ubit: this dangerus naming should be only check without clear |
197 | // keeping for old modules outthere | 162 | // keeping for old modules outthere |
198 | public override bool IsTaintedAt(int xx, int yy) | 163 | public bool IsTaintedAt(int xx, int yy) |
199 | { | 164 | { |
200 | return IsTaintedAt(xx, yy, true /* clearOnTest */); | 165 | return IsTaintedAt(xx, yy, true /* clearOnTest */); |
201 | } | 166 | } |
202 | 167 | ||
203 | // TerrainData.GetDatabaseBlob | 168 | // TerrainData.GetDatabaseBlob |
204 | // The user wants something to store in the database. | 169 | // The user wants something to store in the database. |
205 | public override bool GetDatabaseBlob(out int DBRevisionCode, out Array blob) | 170 | public bool GetDatabaseBlob(out int DBRevisionCode, out Array blob) |
206 | { | 171 | { |
207 | bool ret = false; | 172 | DBRevisionCode = (int)DBTerrainRevision.Variable2DGzip; |
208 | /* save all as Variable2DGzip | 173 | blob = ToCompressedTerrainSerializationV2DGzip(); |
209 | if (SizeX == Constants.RegionSize && SizeY == Constants.RegionSize) | 174 | return true; |
210 | { | ||
211 | DBRevisionCode = (int)DBTerrainRevision.Legacy256; | ||
212 | blob = ToLegacyTerrainSerialization(); | ||
213 | ret = true; | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | */ | ||
218 | DBRevisionCode = (int)DBTerrainRevision.Variable2DGzip; | ||
219 | // DBRevisionCode = (int)DBTerrainRevision.Variable2D; | ||
220 | blob = ToCompressedTerrainSerializationV2DGzip(); | ||
221 | // blob = ToCompressedTerrainSerializationV2D(); | ||
222 | ret = true; | ||
223 | // } | ||
224 | return ret; | ||
225 | } | 175 | } |
226 | 176 | ||
227 | // TerrainData.CompressionFactor | ||
228 | private float m_compressionFactor = 100.0f; | ||
229 | public override float CompressionFactor { get { return m_compressionFactor; } } | ||
230 | |||
231 | // TerrainData.GetCompressedMap | 177 | // TerrainData.GetCompressedMap |
232 | public override float[] GetCompressedMap() | 178 | public float[] GetCompressedMap() |
233 | { | 179 | { |
234 | float[] newMap = new float[SizeX * SizeY]; | 180 | float[] newMap = new float[SizeX * SizeY]; |
235 | 181 | ||
@@ -241,19 +187,18 @@ namespace OpenSim.Framework | |||
241 | return newMap; | 187 | return newMap; |
242 | 188 | ||
243 | } | 189 | } |
244 | // TerrainData.Clone | 190 | |
245 | public override TerrainData Clone() | 191 | public TerrainData Clone() |
246 | { | 192 | { |
247 | HeightmapTerrainData ret = new HeightmapTerrainData(SizeX, SizeY, SizeZ); | 193 | TerrainData ret = new TerrainData(SizeX, SizeY, SizeZ); |
248 | ret.m_heightmap = (float[,])this.m_heightmap.Clone(); | 194 | ret.m_heightmap = (float[,])this.m_heightmap.Clone(); |
249 | return ret; | 195 | return ret; |
250 | } | 196 | } |
251 | 197 | ||
252 | // TerrainData.GetFloatsSerialized | ||
253 | // This one dimensional version is ordered so height = map[y*sizeX+x]; | 198 | // This one dimensional version is ordered so height = map[y*sizeX+x]; |
254 | // DEPRECATED: don't use this function as it does not retain the dimensions of the terrain | 199 | // DEPRECATED: don't use this function as it does not retain the dimensions of the terrain |
255 | // and the caller will probably do the wrong thing if the terrain is not the legacy 256x256. | 200 | // and the caller will probably do the wrong thing if the terrain is not the legacy 256x256. |
256 | public override float[] GetFloatsSerialized() | 201 | public float[] GetFloatsSerialized() |
257 | { | 202 | { |
258 | int points = SizeX * SizeY; | 203 | int points = SizeX * SizeY; |
259 | float[] heights = new float[points]; | 204 | float[] heights = new float[points]; |
@@ -269,7 +214,7 @@ namespace OpenSim.Framework | |||
269 | } | 214 | } |
270 | 215 | ||
271 | // TerrainData.GetDoubles | 216 | // TerrainData.GetDoubles |
272 | public override double[,] GetDoubles() | 217 | public double[,] GetDoubles() |
273 | { | 218 | { |
274 | double[,] ret = new double[SizeX, SizeY]; | 219 | double[,] ret = new double[SizeX, SizeY]; |
275 | for (int xx = 0; xx < SizeX; xx++) | 220 | for (int xx = 0; xx < SizeX; xx++) |
@@ -279,7 +224,7 @@ namespace OpenSim.Framework | |||
279 | return ret; | 224 | return ret; |
280 | } | 225 | } |
281 | 226 | ||
282 | public override unsafe void GetPatchMinMax(int px, int py, out float zmin, out float zmax) | 227 | public unsafe void GetPatchMinMax(int px, int py, out float zmin, out float zmax) |
283 | { | 228 | { |
284 | zmax = float.MinValue; | 229 | zmax = float.MinValue; |
285 | zmin = float.MaxValue; | 230 | zmin = float.MaxValue; |
@@ -304,7 +249,7 @@ namespace OpenSim.Framework | |||
304 | } | 249 | } |
305 | } | 250 | } |
306 | 251 | ||
307 | public override unsafe void GetPatchBlock(float[] _block, int px, int py, float sub, float premult) | 252 | public unsafe void GetPatchBlock(float[] _block, int px, int py, float sub, float premult) |
308 | { | 253 | { |
309 | int k = 0; | 254 | int k = 0; |
310 | int stride = m_heightmap.GetLength(1); | 255 | int stride = m_heightmap.GetLength(1); |
@@ -324,13 +269,8 @@ namespace OpenSim.Framework | |||
324 | } | 269 | } |
325 | } | 270 | } |
326 | 271 | ||
327 | // ============================================================= | 272 | /* |
328 | 273 | // that is coded as the float height times the compression factor (usually '100' | |
329 | private float[,] m_heightmap; | ||
330 | // Remember subregions of the heightmap that has changed. | ||
331 | private bool[,] m_taint; | ||
332 | |||
333 | // that is coded as the float height times the compression factor (usually '100' | ||
334 | // to make for two decimal points). | 274 | // to make for two decimal points). |
335 | public short ToCompressedHeightshort(float pHeight) | 275 | public short ToCompressedHeightshort(float pHeight) |
336 | { | 276 | { |
@@ -353,6 +293,7 @@ namespace OpenSim.Framework | |||
353 | return ushort.MaxValue; | 293 | return ushort.MaxValue; |
354 | return (ushort)pHeight; | 294 | return (ushort)pHeight; |
355 | } | 295 | } |
296 | */ | ||
356 | 297 | ||
357 | public float FromCompressedHeight(short pHeight) | 298 | public float FromCompressedHeight(short pHeight) |
358 | { | 299 | { |
@@ -366,12 +307,12 @@ namespace OpenSim.Framework | |||
366 | 307 | ||
367 | // To keep with the legacy theme, create an instance of this class based on the | 308 | // To keep with the legacy theme, create an instance of this class based on the |
368 | // way terrain used to be passed around. | 309 | // way terrain used to be passed around. |
369 | public HeightmapTerrainData(double[,] pTerrain) | 310 | public TerrainData(double[,] pTerrain) |
370 | { | 311 | { |
371 | SizeX = pTerrain.GetLength(0); | 312 | SizeX = pTerrain.GetLength(0); |
372 | SizeY = pTerrain.GetLength(1); | 313 | SizeY = pTerrain.GetLength(1); |
373 | SizeZ = (int)Constants.RegionHeight; | 314 | SizeZ = (int)Constants.RegionHeight; |
374 | m_compressionFactor = 100.0f; | 315 | CompressionFactor = 100.0f; |
375 | 316 | ||
376 | m_heightmap = new float[SizeX, SizeY]; | 317 | m_heightmap = new float[SizeX, SizeY]; |
377 | for (int ii = 0; ii < SizeX; ii++) | 318 | for (int ii = 0; ii < SizeX; ii++) |
@@ -389,12 +330,12 @@ namespace OpenSim.Framework | |||
389 | } | 330 | } |
390 | 331 | ||
391 | // Create underlying structures but don't initialize the heightmap assuming the caller will immediately do that | 332 | // Create underlying structures but don't initialize the heightmap assuming the caller will immediately do that |
392 | public HeightmapTerrainData(int pX, int pY, int pZ) | 333 | public TerrainData(int pX, int pY, int pZ) |
393 | { | 334 | { |
394 | SizeX = pX; | 335 | SizeX = pX; |
395 | SizeY = pY; | 336 | SizeY = pY; |
396 | SizeZ = pZ; | 337 | SizeZ = pZ; |
397 | m_compressionFactor = 100.0f; | 338 | CompressionFactor = 100.0f; |
398 | m_heightmap = new float[SizeX, SizeY]; | 339 | m_heightmap = new float[SizeX, SizeY]; |
399 | m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; | 340 | m_taint = new bool[SizeX / Constants.TerrainPatchSize, SizeY / Constants.TerrainPatchSize]; |
400 | // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); | 341 | // m_log.DebugFormat("{0} new by dimensions. sizeX={1}, sizeY={2}, sizeZ={3}", LogHeader, SizeX, SizeY, SizeZ); |
@@ -402,10 +343,10 @@ namespace OpenSim.Framework | |||
402 | ClearLand(0f); | 343 | ClearLand(0f); |
403 | } | 344 | } |
404 | 345 | ||
405 | public HeightmapTerrainData(float[] cmap, float pCompressionFactor, int pX, int pY, int pZ) | 346 | public TerrainData(float[] cmap, float pCompressionFactor, int pX, int pY, int pZ) |
406 | : this(pX, pY, pZ) | 347 | : this(pX, pY, pZ) |
407 | { | 348 | { |
408 | m_compressionFactor = pCompressionFactor; | 349 | CompressionFactor = pCompressionFactor; |
409 | int ind = 0; | 350 | int ind = 0; |
410 | for (int xx = 0; xx < SizeX; xx++) | 351 | for (int xx = 0; xx < SizeX; xx++) |
411 | for (int yy = 0; yy < SizeY; yy++) | 352 | for (int yy = 0; yy < SizeY; yy++) |
@@ -414,7 +355,7 @@ namespace OpenSim.Framework | |||
414 | } | 355 | } |
415 | 356 | ||
416 | // Create a heighmap from a database blob | 357 | // Create a heighmap from a database blob |
417 | public HeightmapTerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) | 358 | public TerrainData(int pSizeX, int pSizeY, int pSizeZ, int pFormatCode, byte[] pBlob) |
418 | : this(pSizeX, pSizeY, pSizeZ) | 359 | : this(pSizeX, pSizeY, pSizeZ) |
419 | { | 360 | { |
420 | switch ((DBTerrainRevision)pFormatCode) | 361 | switch ((DBTerrainRevision)pFormatCode) |
@@ -589,7 +530,7 @@ namespace OpenSim.Framework | |||
589 | hmSizeY = br.ReadInt32(); | 530 | hmSizeY = br.ReadInt32(); |
590 | hmCompressionFactor = br.ReadInt32(); | 531 | hmCompressionFactor = br.ReadInt32(); |
591 | 532 | ||
592 | m_compressionFactor = hmCompressionFactor; | 533 | CompressionFactor = hmCompressionFactor; |
593 | 534 | ||
594 | // In case database info doesn't match real terrain size, initialize the whole terrain. | 535 | // In case database info doesn't match real terrain size, initialize the whole terrain. |
595 | ClearLand(); | 536 | ClearLand(); |