diff options
author | Robert Adams | 2013-10-16 07:52:30 -0700 |
---|---|---|
committer | Robert Adams | 2013-10-16 07:52:30 -0700 |
commit | 97bc5263de990ce80fc0adfbdb632ba8c5cbb77b (patch) | |
tree | 6d6d27ea6f8b8d93a8622f6fd9b257387ac7ca94 /OpenSim | |
parent | Merge branch 'master' into varregion (diff) | |
download | opensim-SC-97bc5263de990ce80fc0adfbdb632ba8c5cbb77b.zip opensim-SC-97bc5263de990ce80fc0adfbdb632ba8c5cbb77b.tar.gz opensim-SC-97bc5263de990ce80fc0adfbdb632ba8c5cbb77b.tar.bz2 opensim-SC-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')
-rw-r--r-- | OpenSim/Framework/Constants.cs | 2 | ||||
-rw-r--r-- | OpenSim/Framework/TerrainData.cs | 43 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | 8 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/TerrainChannel.cs | 24 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/TerrainCompressor.cs | 2 |
5 files changed, 42 insertions, 37 deletions
diff --git a/OpenSim/Framework/Constants.cs b/OpenSim/Framework/Constants.cs index 9ddb34b..d18b32e 100644 --- a/OpenSim/Framework/Constants.cs +++ b/OpenSim/Framework/Constants.cs | |||
@@ -36,8 +36,6 @@ namespace OpenSim.Framework | |||
36 | public const uint RegionSize = 256; | 36 | public const uint RegionSize = 256; |
37 | public const uint RegionHeight = 4096; | 37 | public const uint RegionHeight = 4096; |
38 | 38 | ||
39 | // Terrain heightmap is kept as shorts that are the float value times this compression factor | ||
40 | public const float TerrainCompression = 100.0f; | ||
41 | // Since terrain is stored in 16x16 heights, regions must be a multiple of this number and that is the minimum | 39 | // Since terrain is stored in 16x16 heights, regions must be a multiple of this number and that is the minimum |
42 | public const int MinRegionSize = 16; | 40 | public const int MinRegionSize = 16; |
43 | public const int TerrainPatchSize = 16; | 41 | public const int TerrainPatchSize = 16; |
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 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | ||
31 | 32 | ||
32 | using OpenMetaverse; | 33 | using OpenMetaverse; |
33 | 34 | ||
35 | using log4net; | ||
36 | |||
34 | namespace OpenSim.Framework | 37 | namespace 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 | ||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index eb6187b..459af73 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -74,6 +74,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
74 | #endregion | 74 | #endregion |
75 | 75 | ||
76 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 76 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
77 | private static readonly string LogHeader = "[TERRAIN MODULE]"; | ||
77 | 78 | ||
78 | private readonly Commander m_commander = new Commander("terrain"); | 79 | private readonly Commander m_commander = new Commander("terrain"); |
79 | 80 | ||
@@ -712,7 +713,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
712 | private void CheckForTerrainUpdates(bool respectEstateSettings) | 713 | private void CheckForTerrainUpdates(bool respectEstateSettings) |
713 | { | 714 | { |
714 | bool shouldTaint = false; | 715 | bool shouldTaint = false; |
715 | float[] terrData = m_channel.GetFloatsSerialised(); | 716 | float[] terrHeights = m_channel.GetFloatsSerialised(); |
716 | int x; | 717 | int x; |
717 | for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize) | 718 | for (x = 0; x < m_channel.Width; x += Constants.TerrainPatchSize) |
718 | { | 719 | { |
@@ -727,10 +728,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
727 | if (respectEstateSettings && LimitChannelChanges(x, y)) | 728 | if (respectEstateSettings && LimitChannelChanges(x, y)) |
728 | { | 729 | { |
729 | // Terrain heights were modified. Refetch the terrain info. | 730 | // Terrain heights were modified. Refetch the terrain info. |
730 | terrData = m_channel.GetFloatsSerialised(); | 731 | terrHeights = m_channel.GetFloatsSerialised(); |
731 | } | 732 | } |
732 | 733 | ||
733 | SendToClients(terrData, x, y); | 734 | // m_log.DebugFormat("{0} Patch modified. Sending (x,y) = ({1},{2})", LogHeader, x, y); |
735 | SendToClients(terrHeights, x, y); | ||
734 | shouldTaint = true; | 736 | shouldTaint = true; |
735 | } | 737 | } |
736 | } | 738 | } |
diff --git a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs index 65e890f..6d245cb 100644 --- a/OpenSim/Region/Framework/Scenes/TerrainChannel.cs +++ b/OpenSim/Region/Framework/Scenes/TerrainChannel.cs | |||
@@ -183,21 +183,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
183 | 183 | ||
184 | #endregion | 184 | #endregion |
185 | 185 | ||
186 | /* | ||
187 | // To save space (especially for large regions), keep the height as a short integer | ||
188 | // that is coded as the float height times the compression factor (usually '100' | ||
189 | // to make for two decimal points). | ||
190 | public static short ToCompressedHeight(double pHeight) | ||
191 | { | ||
192 | return (short)(pHeight * Constants.TerrainCompression); | ||
193 | } | ||
194 | |||
195 | public static float FromCompressedHeight(short pHeight) | ||
196 | { | ||
197 | return ((float)pHeight) / Constants.TerrainCompression; | ||
198 | } | ||
199 | */ | ||
200 | |||
201 | public TerrainChannel Copy() | 186 | public TerrainChannel Copy() |
202 | { | 187 | { |
203 | TerrainChannel copy = new TerrainChannel(); | 188 | TerrainChannel copy = new TerrainChannel(); |
@@ -280,13 +265,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
280 | public int SizeX; | 265 | public int SizeX; |
281 | public int SizeY; | 266 | public int SizeY; |
282 | public int SizeZ; | 267 | public int SizeZ; |
268 | public float CompressionFactor; | ||
283 | public short[] Map; | 269 | public short[] Map; |
284 | public TerrainChannelXMLPackage(int pX, int pY, int pZ, short[] pMap) | 270 | public TerrainChannelXMLPackage(int pX, int pY, int pZ, float pCompressionFactor, short[] pMap) |
285 | { | 271 | { |
286 | Version = 1; | 272 | Version = 1; |
287 | SizeX = pX; | 273 | SizeX = pX; |
288 | SizeY = pY; | 274 | SizeY = pY; |
289 | SizeZ = pZ; | 275 | SizeZ = pZ; |
276 | CompressionFactor = pCompressionFactor; | ||
290 | Map = pMap; | 277 | Map = pMap; |
291 | } | 278 | } |
292 | } | 279 | } |
@@ -294,7 +281,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
294 | // New terrain serialization format that includes the width and length. | 281 | // New terrain serialization format that includes the width and length. |
295 | private void ToXml2(XmlWriter xmlWriter) | 282 | private void ToXml2(XmlWriter xmlWriter) |
296 | { | 283 | { |
297 | TerrainChannelXMLPackage package = new TerrainChannelXMLPackage(Width, Height, Altitude, m_terrainData.GetCompressedMap()); | 284 | TerrainChannelXMLPackage package = new TerrainChannelXMLPackage(Width, Height, Altitude, m_terrainData.CompressionFactor, |
285 | m_terrainData.GetCompressedMap()); | ||
298 | XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage)); | 286 | XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage)); |
299 | serializer.Serialize(xmlWriter, package); | 287 | serializer.Serialize(xmlWriter, package); |
300 | } | 288 | } |
@@ -304,7 +292,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
304 | { | 292 | { |
305 | XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage)); | 293 | XmlSerializer serializer = new XmlSerializer(typeof(TerrainChannelXMLPackage)); |
306 | TerrainChannelXMLPackage package = (TerrainChannelXMLPackage)serializer.Deserialize(xmlReader); | 294 | TerrainChannelXMLPackage package = (TerrainChannelXMLPackage)serializer.Deserialize(xmlReader); |
307 | m_terrainData = new HeightmapTerrainData(package.Map, package.SizeX, package.SizeY, package.SizeZ); | 295 | m_terrainData = new HeightmapTerrainData(package.Map, package.CompressionFactor, package.SizeX, package.SizeY, package.SizeZ); |
308 | } | 296 | } |
309 | 297 | ||
310 | // Fill the heightmap with the center bump terrain | 298 | // Fill the heightmap with the center bump terrain |
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs index 511745d..e91c959 100644 --- a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs +++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs | |||
@@ -112,7 +112,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
112 | // This is an intermediate step in converting terrain into a variable sized heightmap. Some of the | 112 | // This is an intermediate step in converting terrain into a variable sized heightmap. Some of the |
113 | // routines (like IClientAPI) only pass the float array of heights around. This entry | 113 | // routines (like IClientAPI) only pass the float array of heights around. This entry |
114 | // converts that legacy representation into the more compact represenation used in | 114 | // converts that legacy representation into the more compact represenation used in |
115 | // TerrainChannel. Someday fix the plumbing between here and the scene. | 115 | // TerrainData. Someday fix the plumbing between here and the scene. |
116 | public static LayerDataPacket CreateLandPacket(TerrainData terrData, int patchX, int patchY) | 116 | public static LayerDataPacket CreateLandPacket(TerrainData terrData, int patchX, int patchY) |
117 | { | 117 | { |
118 | int[] xPieces = new int[1]; | 118 | int[] xPieces = new int[1]; |