aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/TerrainCompressor.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainCompressor.cs72
1 files changed, 32 insertions, 40 deletions
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
index e0095e8..0db1033 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
@@ -82,8 +82,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
82 } 82 }
83 83
84 // Used to send cloud and wind patches 84 // Used to send cloud and wind patches
85 public static LayerDataPacket CreateLayerDataPacket(TerrainPatch[] patches, byte type, int pRegionSizeX, 85 public static LayerDataPacket CreateLayerDataPacketStandardSize(TerrainPatch[] patches, byte type)
86 int pRegionSizeY)
87 { 86 {
88 LayerDataPacket layer = new LayerDataPacket {LayerID = {Type = type}}; 87 LayerDataPacket layer = new LayerDataPacket {LayerID = {Type = type}};
89 88
@@ -98,7 +97,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
98 bitpack.PackBits(type, 8); 97 bitpack.PackBits(type, 8);
99 98
100 foreach (TerrainPatch t in patches) 99 foreach (TerrainPatch t in patches)
101 CreatePatch(bitpack, t.Data, t.X, t.Y, pRegionSizeX, pRegionSizeY); 100 CreatePatchtStandardSize(bitpack, t.Data, t.X, t.Y);
102 101
103 bitpack.PackBits(END_OF_PATCHES, 8); 102 bitpack.PackBits(END_OF_PATCHES, 8);
104 103
@@ -108,27 +107,38 @@ namespace OpenSim.Region.ClientStack.LindenUDP
108 return layer; 107 return layer;
109 } 108 }
110 109
111 public static void CreatePatch(BitPack output, float[] patchData, int x, int y, int pRegionSizeX, int pRegionSizeY) 110 public static void CreatePatchtStandardSize(BitPack output, float[] patchData, int x, int y)
112 { 111 {
113 TerrainPatch.Header header = PrescanPatch(patchData); 112 TerrainPatch.Header header = PrescanPatch(patchData);
114 header.QuantWBits = 136; 113 header.QuantWBits = 136;
115 if (pRegionSizeX > Constants.RegionSize || pRegionSizeY > Constants.RegionSize) 114
116 { 115 header.PatchIDs = (y & 0x1F);
117 header.PatchIDs = (y & 0xFFFF); 116 header.PatchIDs += (x << 5);
118 header.PatchIDs += (x << 16);
119 }
120 else
121 {
122 header.PatchIDs = (y & 0x1F);
123 header.PatchIDs += (x << 5);
124 }
125 117
126 int wbits; 118 int wbits;
127 int[] patch = CompressPatch(patchData, header, 10, out wbits); 119 int[] patch = CompressPatch(patchData, header, 10, out wbits);
128 wbits = EncodePatchHeader(output, header, patch, Constants.RegionSize, Constants.RegionSize, wbits); 120 EncodePatchHeader(output, header, patch, false, ref wbits);
129 EncodePatch(output, patch, 0, wbits); 121 EncodePatch(output, patch, 0, wbits);
130 } 122 }
131 123
124 private static TerrainPatch.Header PrescanPatch(float[] patch)
125 {
126 TerrainPatch.Header header = new TerrainPatch.Header();
127 float zmax = -99999999.0f;
128 float zmin = 99999999.0f;
129
130 for (int i = 0; i < Constants.TerrainPatchSize * Constants.TerrainPatchSize; i++)
131 {
132 float val = patch[i];
133 if (val > zmax) zmax = val;
134 if (val < zmin) zmin = val;
135 }
136
137 header.DCOffset = zmin;
138 header.Range = (int)((zmax - zmin) + 1.0f);
139
140 return header;
141 }
132 private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits) 142 private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits)
133 { 143 {
134 float[] block = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize]; 144 float[] block = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
@@ -232,11 +242,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
232 TerrainPatch.Header header = PrescanPatch(terrData, patchX, patchY, out frange); 242 TerrainPatch.Header header = PrescanPatch(terrData, patchX, patchY, out frange);
233 header.QuantWBits = 130; 243 header.QuantWBits = 130;
234 244
245 bool largeRegion = false;
235 // If larger than legacy region size, pack patch X and Y info differently. 246 // If larger than legacy region size, pack patch X and Y info differently.
236 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize) 247 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize)
237 { 248 {
238 header.PatchIDs = (patchY & 0xFFFF); 249 header.PatchIDs = (patchY & 0xFFFF);
239 header.PatchIDs += (patchX << 16); 250 header.PatchIDs += (patchX << 16);
251 largeRegion = true;
240 } 252 }
241 else 253 else
242 { 254 {
@@ -246,7 +258,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
246 258
247 if(Math.Round((double)frange,2) == 1.0) 259 if(Math.Round((double)frange,2) == 1.0)
248 { 260 {
249 // flat terrain spead up things 261 // flat terrain speed up things
250 262
251 header.DCOffset -= 0.5f; 263 header.DCOffset -= 0.5f;
252 264
@@ -254,7 +266,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
254 output.PackBits(header.QuantWBits, 8); 266 output.PackBits(header.QuantWBits, 8);
255 output.PackFloat(header.DCOffset); 267 output.PackFloat(header.DCOffset);
256 output.PackBits(1, 16); 268 output.PackBits(1, 16);
257 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize) 269 if (largeRegion)
258 output.PackBits(header.PatchIDs, 32); 270 output.PackBits(header.PatchIDs, 32);
259 else 271 else
260 output.PackBits(header.PatchIDs, 10); 272 output.PackBits(header.PatchIDs, 10);
@@ -266,28 +278,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
266 278
267 int wbits; 279 int wbits;
268 int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits); 280 int[] patch = CompressPatch(terrData, patchX, patchY, header, 10, out wbits);
269 wbits = EncodePatchHeader(output, header, patch, (uint)terrData.SizeX, (uint)terrData.SizeY, wbits); 281 EncodePatchHeader(output, header, patch, largeRegion, ref wbits);
270 EncodePatch(output, patch, 0, wbits); 282 EncodePatch(output, patch, 0, wbits);
271 } 283 }
272 284
273 private static TerrainPatch.Header PrescanPatch(float[] patch)
274 {
275 TerrainPatch.Header header = new TerrainPatch.Header();
276 float zmax = -99999999.0f;
277 float zmin = 99999999.0f;
278 285
279 for (int i = 0; i < Constants.TerrainPatchSize*Constants.TerrainPatchSize; i++)
280 {
281 float val = patch[i];
282 if (val > zmax) zmax = val;
283 if (val < zmin) zmin = val;
284 }
285
286 header.DCOffset = zmin;
287 header.Range = (int) ((zmax - zmin) + 1.0f);
288
289 return header;
290 }
291 286
292 // Scan the height info we're returning and return a patch packet header for this patch. 287 // Scan the height info we're returning and return a patch packet header for this patch.
293 private static TerrainPatch.Header PrescanPatch(TerrainData terrData, int patchX, int patchY, out float frange) 288 private static TerrainPatch.Header PrescanPatch(TerrainData terrData, int patchX, int patchY, out float frange)
@@ -338,8 +333,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
338 return header; 333 return header;
339 } 334 }
340 335
341 private static int EncodePatchHeader(BitPack output, TerrainPatch.Header header, int[] patch, uint pRegionSizeX, 336 private static void EncodePatchHeader(BitPack output, TerrainPatch.Header header, int[] patch, bool largeRegion, ref int wbits)
342 uint pRegionSizeY, int wbits)
343 { 337 {
344 if (wbits > 17) 338 if (wbits > 17)
345 wbits = 17; 339 wbits = 17;
@@ -352,12 +346,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
352 output.PackBits(header.QuantWBits, 8); 346 output.PackBits(header.QuantWBits, 8);
353 output.PackFloat(header.DCOffset); 347 output.PackFloat(header.DCOffset);
354 output.PackBits(header.Range, 16); 348 output.PackBits(header.Range, 16);
355 if (pRegionSizeX > Constants.RegionSize || pRegionSizeY > Constants.RegionSize) 349 if (largeRegion)
356 output.PackBits(header.PatchIDs, 32); 350 output.PackBits(header.PatchIDs, 32);
357 else 351 else
358 output.PackBits(header.PatchIDs, 10); 352 output.PackBits(header.PatchIDs, 10);
359
360 return wbits;
361 } 353 }
362 354
363 private static void IDCTColumn16(float[] linein, float[] lineout, int column) 355 private static void IDCTColumn16(float[] linein, float[] lineout, int column)