aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs138
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs16
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs21
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainCompressor.cs948
-rw-r--r--OpenSim/Region/Framework/Scenes/TerrainUtil.cs16
-rw-r--r--OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs7
-rw-r--r--OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs7
8 files changed, 554 insertions, 601 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index b61bdeb..d197f5c 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -1185,13 +1185,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1185 /// region's patches to the client. 1185 /// region's patches to the client.
1186 /// </summary> 1186 /// </summary>
1187 /// <param name="map">heightmap</param> 1187 /// <param name="map">heightmap</param>
1188 public virtual void SendLayerData(float[] map) 1188 public virtual void SendLayerData()
1189 { 1189 {
1190 Util.FireAndForget(DoSendLayerData, m_scene.Heightmap.GetTerrainData(), "LLClientView.DoSendLayerData"); 1190 Util.FireAndForget(DoSendLayerData, null, "LLClientView.DoSendLayerData");
1191
1192 // Send it sync, and async. It's not that much data
1193 // and it improves user experience just so much!
1194// DoSendLayerData(map);
1195 } 1191 }
1196 1192
1197 /// <summary> 1193 /// <summary>
@@ -1200,21 +1196,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1200 /// <param name="o"></param> 1196 /// <param name="o"></param>
1201 private void DoSendLayerData(object o) 1197 private void DoSendLayerData(object o)
1202 { 1198 {
1203 TerrainData map = (TerrainData)o; 1199 TerrainData map = m_scene.Heightmap.GetTerrainData();
1204
1205 try 1200 try
1206 { 1201 {
1207 // Send LayerData in typerwriter pattern
1208 //for (int y = 0; y < 16; y++)
1209 //{
1210 // for (int x = 0; x < 16; x++)
1211 // {
1212 // SendLayerData(x, y, map);
1213 // }
1214 //}
1215
1216 // Send LayerData in a spiral pattern. Fun! 1202 // Send LayerData in a spiral pattern. Fun!
1217 SendLayerTopRight(map, 0, 0, map.SizeX / Constants.TerrainPatchSize - 1, map.SizeY / Constants.TerrainPatchSize - 1); 1203 SendLayerTopRight(0, 0, map.SizeX / Constants.TerrainPatchSize - 1, map.SizeY / Constants.TerrainPatchSize - 1);
1218 } 1204 }
1219 catch (Exception e) 1205 catch (Exception e)
1220 { 1206 {
@@ -1222,63 +1208,68 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1222 } 1208 }
1223 } 1209 }
1224 1210
1225 private void SendLayerTopRight(TerrainData map, int x1, int y1, int x2, int y2) 1211 private void SendLayerTopRight(int x1, int y1, int x2, int y2)
1226 { 1212 {
1213 int[] p = new int[2];
1214
1227 // Row 1215 // Row
1228 for (int i = x1; i <= x2; i++) 1216 p[1] = y1;
1229 SendLayerData(i, y1, map); 1217 for (int i = x1; i <= x2; ++i)
1218 {
1219 p[0] = i;
1220 SendLayerData(p);
1221 }
1230 1222
1231 // Column 1223 // Column
1232 for (int j = y1 + 1; j <= y2; j++) 1224 p[0] = x2;
1233 SendLayerData(x2, j, map); 1225 for (int j = y1 + 1; j <= y2; ++j)
1226 {
1227 p[1] = j;
1228 SendLayerData(p);
1229 }
1234 1230
1235 if (x2 - x1 > 0 && y2 - y1 > 0) 1231 if (x2 - x1 > 0 && y2 - y1 > 0)
1236 SendLayerBottomLeft(map, x1, y1 + 1, x2 - 1, y2); 1232 SendLayerBottomLeft(x1, y1 + 1, x2 - 1, y2);
1237 } 1233 }
1238 1234
1239 void SendLayerBottomLeft(TerrainData map, int x1, int y1, int x2, int y2) 1235 void SendLayerBottomLeft(int x1, int y1, int x2, int y2)
1240 { 1236 {
1237 int[] p = new int[2];
1238
1241 // Row in reverse 1239 // Row in reverse
1242 for (int i = x2; i >= x1; i--) 1240 p[1] = y2;
1243 SendLayerData(i, y2, map); 1241 for (int i = x2; i >= x1; --i)
1242 {
1243 p[0] = i;
1244 SendLayerData(p);
1245 }
1244 1246
1245 // Column in reverse 1247 // Column in reverse
1246 for (int j = y2 - 1; j >= y1; j--) 1248 p[0] = x1;
1247 SendLayerData(x1, j, map); 1249 for (int j = y2 - 1; j >= y1; --j)
1250 {
1251 p[1] = j;
1252 SendLayerData(p);
1253 }
1248 1254
1249 if (x2 - x1 > 0 && y2 - y1 > 0) 1255 if (x2 - x1 > 0 && y2 - y1 > 0)
1250 SendLayerTopRight(map, x1 + 1, y1, x2, y2 - 1); 1256 SendLayerTopRight(x1 + 1, y1, x2, y2 - 1);
1251 } 1257 }
1252 1258
1253 1259 public void SendLayerData(int[] map)
1254 // Legacy form of invocation that passes around a bare data array.
1255 // Just ignore what was passed and use the real terrain info that is part of the scene.
1256 // As a HORRIBLE kludge in an attempt to not change the definition of IClientAPI,
1257 // there is a special form for specifying multiple terrain patches to send.
1258 // The form is to pass 'px' as negative the number of patches to send and to
1259 // pass the float array as pairs of patch X and Y coordinates. So, passing 'px'
1260 // as -2 and map= [3, 5, 8, 4] would mean to send two terrain heightmap patches
1261 // and the patches to send are <3,5> and <8,4>.
1262 public void SendLayerData(int px, int py, float[] map)
1263 { 1260 {
1264 if (px >= 0) 1261 if(map == null)
1262 return;
1263
1264 try
1265 { 1265 {
1266 SendLayerData(px, py, m_scene.Heightmap.GetTerrainData()); 1266 List<LayerDataPacket> packets = OpenSimTerrainCompressor.CreateLayerDataPackets(m_scene.Heightmap.GetTerrainData(), map);
1267 foreach (LayerDataPacket pkt in packets)
1268 OutPacket(pkt, ThrottleOutPacketType.Land);
1267 } 1269 }
1268 else 1270 catch (Exception e)
1269 { 1271 {
1270 int numPatches = -px; 1272 m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
1271 int[] xPatches = new int[numPatches];
1272 int[] yPatches = new int[numPatches];
1273 for (int pp = 0; pp < numPatches; pp++)
1274 {
1275 xPatches[pp] = (int)map[pp * 2];
1276 yPatches[pp] = (int)map[pp * 2 + 1];
1277 }
1278
1279 // DebugSendingPatches("SendLayerData", xPatches, yPatches);
1280
1281 SendLayerData(xPatches, yPatches, m_scene.Heightmap.GetTerrainData());
1282 } 1273 }
1283 } 1274 }
1284 1275
@@ -1298,43 +1289,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1298 } 1289 }
1299 } 1290 }
1300 1291
1301 /// <summary>
1302
1303 /// Sends a terrain packet for the point specified.
1304 /// This is a legacy call that has refarbed the terrain into a flat map of floats.
1305 /// We just use the terrain from the region we know about.
1306 /// </summary>
1307 /// <param name="px">Patch coordinate (x) 0..15</param>
1308 /// <param name="py">Patch coordinate (y) 0..15</param>
1309 /// <param name="map">heightmap</param>
1310 public void SendLayerData(int px, int py, TerrainData terrData)
1311 {
1312 int[] xPatches = new[] { px };
1313 int[] yPatches = new[] { py };
1314 SendLayerData(xPatches, yPatches, terrData);
1315 }
1316
1317 private void SendLayerData(int[] px, int[] py, TerrainData terrData)
1318 {
1319 try
1320 {
1321 byte landPacketType;
1322 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize)
1323 landPacketType = (byte)TerrainPatch.LayerType.LandExtended;
1324 else
1325 landPacketType = (byte)TerrainPatch.LayerType.Land;
1326
1327 List<LayerDataPacket> packets = OpenSimTerrainCompressor.CreateLayerDataPackets(terrData, px, py, landPacketType);
1328 foreach(LayerDataPacket pkt in packets)
1329 OutPacket(pkt, ThrottleOutPacketType.Land);
1330 }
1331 catch (Exception e)
1332 {
1333 m_log.Error("[CLIENT]: SendLayerData() Failed with exception: " + e.Message, e);
1334 }
1335 }
1336
1337
1338 // wind caching 1292 // wind caching
1339 private static Dictionary<ulong,int> lastWindVersion = new Dictionary<ulong,int>(); 1293 private static Dictionary<ulong,int> lastWindVersion = new Dictionary<ulong,int>();
1340 private static Dictionary<ulong,List<LayerDataPacket>> lastWindPackets = 1294 private static Dictionary<ulong,List<LayerDataPacket>> lastWindPackets =
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
index 5f35782..35d29a5 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs
@@ -866,21 +866,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
866 m_log.Error("[LLUDPSERVER]: Failed to split " + packet.Type + " with estimated length " + packet.Length); 866 m_log.Error("[LLUDPSERVER]: Failed to split " + packet.Type + " with estimated length " + packet.Length);
867 867
868 for (int i = 0; i < packetCount; i++) 868 for (int i = 0; i < packetCount; i++)
869 { 869 SendPacketData(udpClient, datas[i], packet.Type, category, method);
870 byte[] data = datas[i];
871// if (!SendPacketData(udpClient, data, packet.Type, category, method))
872// packetQueued = true;
873 SendPacketData(udpClient, data, packet.Type, category, method);
874 }
875 } 870 }
876 else 871 else
877 { 872 {
878 byte[] data = packet.ToBytes(); 873 byte[] data = packet.ToBytes();
879// if (!SendPacketData(udpClient, data, packet.Type, category, method))
880// packetQueued = true;
881 SendPacketData(udpClient, data, packet.Type, category, method); 874 SendPacketData(udpClient, data, packet.Type, category, method);
882 } 875 }
883
884 PacketPool.Instance.ReturnPacket(packet); 876 PacketPool.Instance.ReturnPacket(packet);
885 } 877 }
886 878
@@ -908,7 +900,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
908 if (zerocount != 0) 900 if (zerocount != 0)
909 { 901 {
910 dest[zerolen++] = 0x00; 902 dest[zerolen++] = 0x00;
911 dest[zerolen++] = (byte)zerocount; 903 dest[zerolen++] = zerocount;
912 zerocount = 0; 904 zerocount = 0;
913 } 905 }
914 906
@@ -919,10 +911,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
919 if (zerocount != 0) 911 if (zerocount != 0)
920 { 912 {
921 dest[zerolen++] = 0x00; 913 dest[zerolen++] = 0x00;
922 dest[zerolen++] = (byte)zerocount; 914 dest[zerolen++] = zerocount;
923 } 915 }
924 916
925 return (int)zerolen; 917 return zerolen;
926 } 918 }
927 /// <summary> 919 /// <summary>
928 /// Start the process of sending a packet to the client. 920 /// Start the process of sending a packet to the client.
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
index 65d4c4a..a786568 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs
@@ -592,7 +592,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
592 else 592 else
593 { 593 {
594 // The traditional way is to call into the protocol stack to send them all. 594 // The traditional way is to call into the protocol stack to send them all.
595 pClient.SendLayerData(new float[10]); 595 pClient.SendLayerData();
596 } 596 }
597 } 597 }
598 598
@@ -1066,13 +1066,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1066 // Legacy update sending where the update is sent out as soon as noticed 1066 // Legacy update sending where the update is sent out as soon as noticed
1067 // We know the actual terrain data that is passed is ignored so this passes a dummy heightmap. 1067 // We know the actual terrain data that is passed is ignored so this passes a dummy heightmap.
1068 //float[] heightMap = terrData.GetFloatsSerialized(); 1068 //float[] heightMap = terrData.GetFloatsSerialized();
1069 float[] heightMap = new float[10]; 1069 int[] map = new int[]{ x / Constants.TerrainPatchSize, y / Constants.TerrainPatchSize };
1070 m_scene.ForEachClient( 1070 m_scene.ForEachClient(
1071 delegate (IClientAPI controller) 1071 delegate (IClientAPI controller)
1072 { 1072 {
1073 controller.SendLayerData(x / Constants.TerrainPatchSize, 1073 controller.SendLayerData(map);
1074 y / Constants.TerrainPatchSize,
1075 heightMap);
1076 } 1074 }
1077 ); 1075 );
1078 } 1076 }
@@ -1131,14 +1129,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1131 } 1129 }
1132 */ 1130 */
1133 1131
1134 float[] patchPieces = new float[toSend.Count * 2]; 1132 int[] patchPieces = new int[toSend.Count * 2];
1135 int pieceIndex = 0; 1133 int pieceIndex = 0;
1136 foreach (PatchesToSend pts in toSend) 1134 foreach (PatchesToSend pts in toSend)
1137 { 1135 {
1138 patchPieces[pieceIndex++] = pts.PatchX; 1136 patchPieces[pieceIndex++] = pts.PatchX;
1139 patchPieces[pieceIndex++] = pts.PatchY; 1137 patchPieces[pieceIndex++] = pts.PatchY;
1140 } 1138 }
1141 pups.Presence.ControllingClient.SendLayerData(-toSend.Count, 0, patchPieces); 1139 pups.Presence.ControllingClient.SendLayerData(patchPieces);
1142 } 1140 }
1143 if (pups.sendAll && toSend.Count < 1024) 1141 if (pups.sendAll && toSend.Count < 1024)
1144 SendAllModifiedPatchs(pups); 1142 SendAllModifiedPatchs(pups);
@@ -1206,16 +1204,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1206 npatchs = patchs.Count; 1204 npatchs = patchs.Count;
1207 if (npatchs > 0) 1205 if (npatchs > 0)
1208 { 1206 {
1209 int[] xPieces = new int[npatchs]; 1207 int[] patchPieces = new int[npatchs * 2];
1210 int[] yPieces = new int[npatchs];
1211 float[] patchPieces = new float[npatchs * 2];
1212 int pieceIndex = 0; 1208 int pieceIndex = 0;
1213 foreach (PatchesToSend pts in patchs) 1209 foreach (PatchesToSend pts in patchs)
1214 { 1210 {
1215 patchPieces[pieceIndex++] = pts.PatchX; 1211 patchPieces[pieceIndex++] = pts.PatchX;
1216 patchPieces[pieceIndex++] = pts.PatchY; 1212 patchPieces[pieceIndex++] = pts.PatchY;
1217 } 1213 }
1218 pups.Presence.ControllingClient.SendLayerData(-npatchs, 0, patchPieces); 1214 pups.Presence.ControllingClient.SendLayerData(patchPieces);
1219 } 1215 }
1220 } 1216 }
1221 1217
@@ -1457,8 +1453,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
1457 { 1453 {
1458 //m_log.Debug("Terrain packet unacked, resending patch: " + patchX + " , " + patchY); 1454 //m_log.Debug("Terrain packet unacked, resending patch: " + patchX + " , " + patchY);
1459 // SendLayerData does not use the heightmap parameter. This kludge is so as to not change IClientAPI. 1455 // SendLayerData does not use the heightmap parameter. This kludge is so as to not change IClientAPI.
1460 float[] heightMap = new float[10]; 1456 client.SendLayerData(new int[]{patchX, patchY});
1461 client.SendLayerData(patchX, patchY, heightMap);
1462 } 1457 }
1463 1458
1464 private void StoreUndoState() 1459 private void StoreUndoState()
diff --git a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
index d3f2737..2070463 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainCompressor.cs
@@ -155,16 +155,24 @@ namespace OpenSim.Region.ClientStack.LindenUDP
155 return iout; 155 return iout;
156 } 156 }
157 157
158 static double tt;
158 // new using terrain data and patchs indexes 159 // new using terrain data and patchs indexes
159 public static List<LayerDataPacket> CreateLayerDataPackets(TerrainData terrData, int[] x, int[] y, byte landPacketType) 160 public static List<LayerDataPacket> CreateLayerDataPackets(TerrainData terrData, int[] map)
160 { 161 {
161 List<LayerDataPacket> ret = new List<LayerDataPacket>(); 162 List<LayerDataPacket> ret = new List<LayerDataPacket>();
162 163
163 byte[] data = new byte[x.Length * 256 * 2]; 164 int numberPatchs = map.Length / 2;
165 byte[] data = new byte[numberPatchs * 256 * 2];
164 166
165 //create packet and global header 167 //create packet and global header
166 LayerDataPacket layer = new LayerDataPacket(); 168 LayerDataPacket layer = new LayerDataPacket();
167 169
170 byte landPacketType;
171 if (terrData.SizeX > Constants.RegionSize || terrData.SizeY > Constants.RegionSize)
172 landPacketType = (byte)TerrainPatch.LayerType.LandExtended;
173 else
174 landPacketType = (byte)TerrainPatch.LayerType.Land;
175
168 layer.LayerID.Type = landPacketType; 176 layer.LayerID.Type = landPacketType;
169 177
170 BitPack bitpack = new BitPack(data, 0); 178 BitPack bitpack = new BitPack(data, 0);
@@ -172,11 +180,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP
172 bitpack.PackBitsFromByte(16); 180 bitpack.PackBitsFromByte(16);
173 bitpack.PackBitsFromByte(landPacketType); 181 bitpack.PackBitsFromByte(landPacketType);
174 182
175 for (int i = 0; i < x.Length; i++) 183 tt = 0;
184
185 int s;
186 for (int i = 0; i < numberPatchs; i++)
176 { 187 {
177 CreatePatchFromTerrainData(bitpack, terrData, x[i], y[i]); 188 s = 2 * i;
189 tt -= Util.GetTimeStampMS();
190 CreatePatchFromTerrainData(bitpack, terrData, map[s], map[s + 1]);
191 tt += Util.GetTimeStampMS();
178 192
179 if (bitpack.BytePos > 980 && i != x.Length - 1) 193 if (bitpack.BytePos > 980 && i != numberPatchs - 1)
180 { 194 {
181 //finish this packet 195 //finish this packet
182 bitpack.PackBitsFromByte(END_OF_PATCHES); 196 bitpack.PackBitsFromByte(END_OF_PATCHES);
@@ -284,7 +298,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
284 output.PackBits(header.PatchIDs, 10); 298 output.PackBits(header.PatchIDs, 10);
285 } 299 }
286 300
287 private static void EncodePatch(BitPack output, int[] patch, int postquant, int wbits) 301 private unsafe static void EncodePatch(BitPack output, int[] _patch, int postquant, int wbits)
288 { 302 {
289 int maxwbitssize = (1 << wbits) - 1; 303 int maxwbitssize = (1 << wbits) - 1;
290 304
@@ -296,60 +310,63 @@ namespace OpenSim.Region.ClientStack.LindenUDP
296 310
297 int lastZeroindx = 256 - postquant; 311 int lastZeroindx = 256 - postquant;
298 312
299 if (lastZeroindx != 256) 313 fixed(int * patch = _patch)
300 patch[lastZeroindx] = 0;
301
302 int i = 0;
303 while(i < 256)
304 { 314 {
305 int temp = patch[i]; 315 if (lastZeroindx != 256)
316 patch[lastZeroindx] = 0;
306 317
307 if (temp == 0) 318 int i = 0;
319 while(i < 256)
308 { 320 {
309 int j = i + 1; 321 int temp = patch[i];
310 while(j < lastZeroindx)
311 {
312 if (patch[j] != 0)
313 break;
314 ++j;
315 }
316 322
317 if (j == lastZeroindx) 323 if (temp == 0)
318 { 324 {
319 output.PackBits(ZERO_EOB, 2); 325 int j = i + 1;
320 return; 326 while(j < lastZeroindx)
321 } 327 {
328 if (patch[j] != 0)
329 break;
330 ++j;
331 }
322 332
323 i = j - i; 333 if (j == lastZeroindx)
324 while(i > 8) 334 {
325 { 335 output.PackBits(ZERO_EOB, 2);
326 output.PackBitsFromByte(ZERO_CODE); 336 return;
327 i -= 8; 337 }
338
339 i = j - i;
340 while(i > 8)
341 {
342 output.PackBitsFromByte(ZERO_CODE);
343 i -= 8;
344 }
345 if( i > 0)
346 output.PackBitsFromByte(ZERO_CODE, i);
347 i = j;
348 continue;
328 } 349 }
329 if( i > 0)
330 output.PackBitsFromByte(ZERO_CODE, i);
331 i = j;
332 continue;
333 }
334 350
335 if (temp < 0) 351 if (temp < 0)
336 { 352 {
337 temp *= -1; 353 temp *= -1;
338 if (temp > maxwbitssize) 354 if (temp > maxwbitssize)
339 temp = maxwbitssize; 355 temp = maxwbitssize;
340 356
341 output.PackBits(NEGATIVE_VALUE, 3); 357 output.PackBits(NEGATIVE_VALUE, 3);
342 output.PackBits(temp, wbits); 358 output.PackBits(temp, wbits);
343 } 359 }
344 else 360 else
345 { 361 {
346 if (temp > maxwbitssize) 362 if (temp > maxwbitssize)
347 temp = maxwbitssize; 363 temp = maxwbitssize;
348 364
349 output.PackBits(POSITIVE_VALUE, 3); 365 output.PackBits(POSITIVE_VALUE, 3);
350 output.PackBits(temp, wbits); 366 output.PackBits(temp, wbits);
367 }
368 ++i;
351 } 369 }
352 ++i;
353 } 370 }
354 } 371 }
355 372
@@ -369,7 +386,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
369 header.QuantWBits = wordsize; 386 header.QuantWBits = wordsize;
370 header.QuantWBits |= wordsize << 4; 387 header.QuantWBits |= wordsize << 4;
371 388
372 terrData.GetPatchBlock(ref block, patchX, patchY, sub, premult); 389 terrData.GetPatchBlock(block, patchX, patchY, sub, premult);
373 390
374 wbits = (prequant >> 1); 391 wbits = (prequant >> 1);
375 392
@@ -391,20 +408,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
391 } 408 }
392 } 409 }
393 410
394 private static void BuildQuantizeTable16() 411 private unsafe static void BuildQuantizeTable16()
395 { 412 {
396 const float oosob = 2.0f / 16; 413 const float oosob = 2.0f / 16;
397 for (int j = 0; j < 16; j++) 414 fixed(float* fQuantizeTable16 = QuantizeTable16)
398 { 415 {
399 int c = j * 16; 416 for (int j = 0; j < 16; j++)
400 for (int i = 0; i < 16; i++)
401 { 417 {
402 QuantizeTable16[c + i] = oosob / (1.0f + 2.0f * (i + j)); 418 int c = j * 16;
419 for (int i = 0; i < 16; i++)
420 {
421 fQuantizeTable16[c + i] = oosob / (1.0f + 2.0f * (i + j));
422 }
403 } 423 }
404 } 424 }
405 } 425 }
406 426
407 private static void BuildCopyMatrix16() 427 private unsafe static void BuildCopyMatrix16()
408 { 428 {
409 bool diag = false; 429 bool diag = false;
410 bool right = true; 430 bool right = true;
@@ -412,42 +432,45 @@ namespace OpenSim.Region.ClientStack.LindenUDP
412 int j = 0; 432 int j = 0;
413 int count = 0; 433 int count = 0;
414 434
415 while (i < 16 && j < 16) 435 fixed (int* fCopyMatrix16 = CopyMatrix16)
416 { 436 {
417 CopyMatrix16[j * 16 + i] = count++; 437 while (i < 16 && j < 16)
418
419 if (!diag)
420 { 438 {
421 if (right) 439 fCopyMatrix16[j * 16 + i] = count++;
422 {
423 if (i < 15) i++;
424 else j++;
425 440
426 right = false; 441 if (!diag)
427 diag = true;
428 }
429 else
430 { 442 {
431 if (j < 15 ) j++; 443 if (right)
432 else i++; 444 {
445 if (i < 15) i++;
446 else j++;
433 447
434 right = true; 448 right = false;
435 diag = true; 449 diag = true;
436 } 450 }
437 } 451 else
438 else 452 {
439 { 453 if (j < 15 ) j++;
440 if (right) 454 else i++;
441 { 455
442 i++; 456 right = true;
443 j--; 457 diag = true;
444 if (i == 15 || j == 0) diag = false; 458 }
445 } 459 }
446 else 460 else
447 { 461 {
448 i--; 462 if (right)
449 j++; 463 {
450 if (j == 15 || i == 0) diag = false; 464 i++;
465 j--;
466 if (i == 15 || j == 0) diag = false;
467 }
468 else
469 {
470 i--;
471 j++;
472 if (j == 15 || i == 0) diag = false;
473 }
451 } 474 }
452 } 475 }
453 } 476 }
@@ -455,9 +478,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
455 478
456 #endregion Initialization 479 #endregion Initialization
457 480
458
459
460
461 #region DCT 481 #region DCT
462 482
463 /* DCT (Discrete Cosine Transform) 483 /* DCT (Discrete Cosine Transform)
@@ -506,9 +526,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
506 const float W16_8R = 0.70710678118654752440f; 526 const float W16_8R = 0.70710678118654752440f;
507 527
508 528
509 static void dct16x16(float[] a, int[] iout, ref int wbits) 529 unsafe static void dct16x16(float[] _a, int[] _iout, ref int wbits)
510 { 530 {
511 float[] tmp = new float[256]; 531 float[] _tmp = new float[256];
512 532
513 float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; 533 float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
514 float x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i; 534 float x4r, x4i, x5r, x5i, x6r, x6i, x7r, x7i;
@@ -523,479 +543,483 @@ namespace OpenSim.Region.ClientStack.LindenUDP
523 int wbitsMaxValue = 1 << wbits; 543 int wbitsMaxValue = 1 << wbits;
524 bool dowbits = wbits < 17; 544 bool dowbits = wbits < 17;
525 545
526 for (j = 0, k = 0; j < 256; j += 16, k++) 546 fixed (float* a = _a, tmp = _tmp, fQuantizeTable16 = QuantizeTable16)
547 fixed (int* iout = _iout, fCopyMatrix16 = CopyMatrix16)
527 { 548 {
528 x4r = a[0 + j] - a[15 + j]; 549 for (j = 0, k = 0; j < 256; j += 16, k++)
529 xr = a[0 + j] + a[15 + j]; 550 {
530 x4i = a[8 + j] - a[7 + j]; 551 x4r = a[0 + j] - a[15 + j];
531 xi = a[8 + j] + a[7 + j]; 552 xr = a[0 + j] + a[15 + j];
532 x0r = xr + xi; 553 x4i = a[8 + j] - a[7 + j];
533 x0i = xr - xi; 554 xi = a[8 + j] + a[7 + j];
534 x5r = a[2 + j] - a[13 + j]; 555 x0r = xr + xi;
535 xr = a[2 + j] + a[13 + j]; 556 x0i = xr - xi;
536 x5i = a[10 + j] - a[5 + j]; 557 x5r = a[2 + j] - a[13 + j];
537 xi = a[10 + j] + a[5 + j]; 558 xr = a[2 + j] + a[13 + j];
538 x1r = xr + xi; 559 x5i = a[10 + j] - a[5 + j];
539 x1i = xr - xi; 560 xi = a[10 + j] + a[5 + j];
540 x6r = a[4 + j] - a[11 + j]; 561 x1r = xr + xi;
541 xr = a[4 + j] + a[11 + j]; 562 x1i = xr - xi;
542 x6i = a[12 + j] - a[3 + j]; 563 x6r = a[4 + j] - a[11 + j];
543 xi = a[12 + j] + a[3 + j]; 564 xr = a[4 + j] + a[11 + j];
544 x2r = xr + xi; 565 x6i = a[12 + j] - a[3 + j];
545 x2i = xr - xi; 566 xi = a[12 + j] + a[3 + j];
546 x7r = a[6 + j] - a[9 + j]; 567 x2r = xr + xi;
547 xr = a[6 + j] + a[9 + j]; 568 x2i = xr - xi;
548 x7i = a[14 + j] - a[1 + j]; 569 x7r = a[6 + j] - a[9 + j];
549 xi = a[14 + j] + a[1 + j]; 570 xr = a[6 + j] + a[9 + j];
550 x3r = xr + xi; 571 x7i = a[14 + j] - a[1 + j];
551 x3i = xr - xi; 572 xi = a[14 + j] + a[1 + j];
552 xr = x0r + x2r; 573 x3r = xr + xi;
553 xi = x1r + x3r; 574 x3i = xr - xi;
554 tmp[k] = C16_8R * (xr + xi); // 575 xr = x0r + x2r;
555 tmp[8 * 16 + k] = C16_8R * (xr - xi); // 576 xi = x1r + x3r;
556 xr = x0r - x2r; 577 tmp[k] = C16_8R * (xr + xi); //
557 xi = x1r - x3r; 578 tmp[8 * 16 + k] = C16_8R * (xr - xi); //
558 tmp[4 * 16 + k] = C16_4R * xr - C16_4I * xi; // 579 xr = x0r - x2r;
559 tmp[12 * 16 + k] = C16_4R * xi + C16_4I * xr; // 580 xi = x1r - x3r;
560 x0r = W16_8R * (x1i - x3i); 581 tmp[4 * 16 + k] = C16_4R * xr - C16_4I * xi; //
561 x2r = W16_8R * (x1i + x3i); 582 tmp[12 * 16 + k] = C16_4R * xi + C16_4I * xr; //
562 xr = x0i + x0r; 583 x0r = W16_8R * (x1i - x3i);
563 xi = x2r + x2i; 584 x2r = W16_8R * (x1i + x3i);
564 tmp[2 * 16 + k] = C16_2R * xr - C16_2I * xi; // 585 xr = x0i + x0r;
565 tmp[14 * 16 + k] = C16_2R * xi + C16_2I * xr; // 586 xi = x2r + x2i;
566 xr = x0i - x0r; 587 tmp[2 * 16 + k] = C16_2R * xr - C16_2I * xi; //
567 xi = x2r - x2i; 588 tmp[14 * 16 + k] = C16_2R * xi + C16_2I * xr; //
568 tmp[6 * 16 + k] = C16_6R * xr - C16_6I * xi; // 589 xr = x0i - x0r;
569 tmp[10 * 16 + k] = C16_6R * xi + C16_6I * xr; // 590 xi = x2r - x2i;
570 xr = W16_8R * (x6r - x6i); 591 tmp[6 * 16 + k] = C16_6R * xr - C16_6I * xi; //
571 xi = W16_8R * (x6i + x6r); 592 tmp[10 * 16 + k] = C16_6R * xi + C16_6I * xr; //
572 x6r = x4r - xr; 593 xr = W16_8R * (x6r - x6i);
573 x6i = x4i - xi; 594 xi = W16_8R * (x6i + x6r);
574 x4r += xr; 595 x6r = x4r - xr;
575 x4i += xi; 596 x6i = x4i - xi;
576 xr = W16_4I * x7r - W16_4R * x7i; 597 x4r += xr;
577 xi = W16_4I * x7i + W16_4R * x7r; 598 x4i += xi;
578 x7r = W16_4R * x5r - W16_4I * x5i; 599 xr = W16_4I * x7r - W16_4R * x7i;
579 x7i = W16_4R * x5i + W16_4I * x5r; 600 xi = W16_4I * x7i + W16_4R * x7r;
580 x5r = x7r + xr; 601 x7r = W16_4R * x5r - W16_4I * x5i;
581 x5i = x7i + xi; 602 x7i = W16_4R * x5i + W16_4I * x5r;
582 x7r -= xr; 603 x5r = x7r + xr;
583 x7i -= xi; 604 x5i = x7i + xi;
584 xr = x4r + x5r; 605 x7r -= xr;
585 xi = x5i + x4i; 606 x7i -= xi;
586 tmp[16 + k] = C16_1R * xr - C16_1I * xi; // 607 xr = x4r + x5r;
587 tmp[15 * 16 + k] = C16_1R * xi + C16_1I * xr; // 608 xi = x5i + x4i;
588 xr = x4r - x5r; 609 tmp[16 + k] = C16_1R * xr - C16_1I * xi; //
589 xi = x5i - x4i; 610 tmp[15 * 16 + k] = C16_1R * xi + C16_1I * xr; //
590 tmp[7 * 16 + k] = C16_7R * xr - C16_7I * xi; // 611 xr = x4r - x5r;
591 tmp[9 * 16 + k] = C16_7R * xi + C16_7I * xr; // 612 xi = x5i - x4i;
592 xr = x6r - x7i; 613 tmp[7 * 16 + k] = C16_7R * xr - C16_7I * xi; //
593 xi = x7r + x6i; 614 tmp[9 * 16 + k] = C16_7R * xi + C16_7I * xr; //
594 tmp[5 * 16 + k] = C16_5R * xr - C16_5I * xi; // 615 xr = x6r - x7i;
595 tmp[11 * 16 + k] = C16_5R * xi + C16_5I * xr; // 616 xi = x7r + x6i;
596 xr = x6r + x7i; 617 tmp[5 * 16 + k] = C16_5R * xr - C16_5I * xi; //
597 xi = x7r - x6i; 618 tmp[11 * 16 + k] = C16_5R * xi + C16_5I * xr; //
598 tmp[3 * 16 + k] = C16_3R * xr - C16_3I * xi; // 619 xr = x6r + x7i;
599 tmp[13 * 16 + k] = C16_3R * xi + C16_3I * xr; // 620 xi = x7r - x6i;
600 } 621 tmp[3 * 16 + k] = C16_3R * xr - C16_3I * xi; //
622 tmp[13 * 16 + k] = C16_3R * xi + C16_3I * xr; //
623 }
601 624
602 for (j = 0, k = 0; j < 256; j += 16, k++) 625 for (j = 0, k = 0; j < 256; j += 16, k++)
603 {
604 x4r = tmp[0 + j] - tmp[15 + j];
605 xr = tmp[0 + j] + tmp[15 + j];
606 x4i = tmp[8 + j] - tmp[7 + j];
607 xi = tmp[8 + j] + tmp[7 + j];
608 x0r = xr + xi;
609 x0i = xr - xi;
610 x5r = tmp[2 + j] - tmp[13 + j];
611 xr = tmp[2 + j] + tmp[13 + j];
612 x5i = tmp[10 + j] - tmp[5 + j];
613 xi = tmp[10 + j] + tmp[5 + j];
614 x1r = xr + xi;
615 x1i = xr - xi;
616 x6r = tmp[4 + j] - tmp[11 + j];
617 xr = tmp[4 + j] + tmp[11 + j];
618 x6i = tmp[12 + j] - tmp[3 + j];
619 xi = tmp[12 + j] + tmp[3 + j];
620 x2r = xr + xi;
621 x2i = xr - xi;
622 x7r = tmp[6 + j] - tmp[9 + j];
623 xr = tmp[6 + j] + tmp[9 + j];
624 x7i = tmp[14 + j] - tmp[1 + j];
625 xi = tmp[14 + j] + tmp[1 + j];
626 x3r = xr + xi;
627 x3i = xr - xi;
628 xr = x0r + x2r;
629 xi = x1r + x3r;
630
631 //tmp[0 + k] = C16_8R * (xr + xi); //
632 ftmp = C16_8R * (xr + xi);
633 itmp = (int)(ftmp * QuantizeTable16[k]);
634 iout[CopyMatrix16[k]] = itmp;
635
636 if (dowbits)
637 { 626 {
638 if (itmp < 0) itmp *= -1; 627 x4r = tmp[0 + j] - tmp[15 + j];
639 while (itmp > wbitsMaxValue) 628 xr = tmp[0 + j] + tmp[15 + j];
629 x4i = tmp[8 + j] - tmp[7 + j];
630 xi = tmp[8 + j] + tmp[7 + j];
631 x0r = xr + xi;
632 x0i = xr - xi;
633 x5r = tmp[2 + j] - tmp[13 + j];
634 xr = tmp[2 + j] + tmp[13 + j];
635 x5i = tmp[10 + j] - tmp[5 + j];
636 xi = tmp[10 + j] + tmp[5 + j];
637 x1r = xr + xi;
638 x1i = xr - xi;
639 x6r = tmp[4 + j] - tmp[11 + j];
640 xr = tmp[4 + j] + tmp[11 + j];
641 x6i = tmp[12 + j] - tmp[3 + j];
642 xi = tmp[12 + j] + tmp[3 + j];
643 x2r = xr + xi;
644 x2i = xr - xi;
645 x7r = tmp[6 + j] - tmp[9 + j];
646 xr = tmp[6 + j] + tmp[9 + j];
647 x7i = tmp[14 + j] - tmp[1 + j];
648 xi = tmp[14 + j] + tmp[1 + j];
649 x3r = xr + xi;
650 x3i = xr - xi;
651 xr = x0r + x2r;
652 xi = x1r + x3r;
653
654 //tmp[0 + k] = C16_8R * (xr + xi); //
655 ftmp = C16_8R * (xr + xi);
656 itmp = (int)(ftmp * fQuantizeTable16[k]);
657 iout[fCopyMatrix16[k]] = itmp;
658
659 if (dowbits)
640 { 660 {
641 wbits++; 661 if (itmp < 0) itmp *= -1;
642 wbitsMaxValue = 1 << wbits; 662 while (itmp > wbitsMaxValue)
643 if (wbits == maxwbits)
644 { 663 {
645 dowbits = false; 664 wbits++;
646 break; 665 wbitsMaxValue = 1 << wbits;
666 if (wbits == maxwbits)
667 {
668 dowbits = false;
669 break;
670 }
647 } 671 }
648 } 672 }
649 }
650 673
651 //tmp[8 * Constants.TerrainPatchSize + k] = C16_8R * (xr - xi); // 674 //tmp[8 * Constants.TerrainPatchSize + k] = C16_8R * (xr - xi); //
652 ftmp = C16_8R * (xr - xi); 675 ftmp = C16_8R * (xr - xi);
653 indx = 8 * 16 + k; 676 indx = 8 * 16 + k;
654 itmp = (int)(ftmp * QuantizeTable16[indx]); 677 itmp = (int)(ftmp * fQuantizeTable16[indx]);
655 iout[CopyMatrix16[indx]] = itmp; 678 iout[fCopyMatrix16[indx]] = itmp;
656 679
657 if (dowbits) 680 if (dowbits)
658 {
659 if (itmp < 0) itmp *= -1;
660 while (itmp > wbitsMaxValue)
661 { 681 {
662 wbits++; 682 if (itmp < 0) itmp *= -1;
663 wbitsMaxValue = 1 << wbits; 683 while (itmp > wbitsMaxValue)
664 if (wbits == maxwbits)
665 { 684 {
666 dowbits = false; 685 wbits++;
667 break; 686 wbitsMaxValue = 1 << wbits;
687 if (wbits == maxwbits)
688 {
689 dowbits = false;
690 break;
691 }
668 } 692 }
669 } 693 }
670 }
671 694
672 xr = x0r - x2r; 695 xr = x0r - x2r;
673 xi = x1r - x3r; 696 xi = x1r - x3r;
674 697
675 //tmp[4 * Constants.TerrainPatchSize + k] = C16_4R * xr - C16_4I * xi; // 698 //tmp[4 * Constants.TerrainPatchSize + k] = C16_4R * xr - C16_4I * xi; //
676 ftmp = C16_4R * xr - C16_4I * xi; 699 ftmp = C16_4R * xr - C16_4I * xi;
677 indx = 4 * 16 + k; 700 indx = 4 * 16 + k;
678 itmp = (int)(ftmp * QuantizeTable16[indx]); 701 itmp = (int)(ftmp * fQuantizeTable16[indx]);
679 iout[CopyMatrix16[indx]] = itmp; 702 iout[fCopyMatrix16[indx]] = itmp;
680 703
681 if (dowbits) 704 if (dowbits)
682 {
683 if (itmp < 0) itmp *= -1;
684 while (itmp > wbitsMaxValue)
685 { 705 {
686 wbits++; 706 if (itmp < 0) itmp *= -1;
687 wbitsMaxValue = 1 << wbits; 707 while (itmp > wbitsMaxValue)
688 if (wbits == maxwbits)
689 { 708 {
690 dowbits = false; 709 wbits++;
691 break; 710 wbitsMaxValue = 1 << wbits;
711 if (wbits == maxwbits)
712 {
713 dowbits = false;
714 break;
715 }
692 } 716 }
693 } 717 }
694 }
695 718
696 //tmp[12 * Constants.TerrainPatchSize + k] = C16_4R * xi + C16_4I * xr; // 719 //tmp[12 * Constants.TerrainPatchSize + k] = C16_4R * xi + C16_4I * xr; //
697 ftmp = C16_4R * xi + C16_4I * xr; 720 ftmp = C16_4R * xi + C16_4I * xr;
698 indx = 12 * 16 + k; 721 indx = 12 * 16 + k;
699 itmp = (int)(ftmp * QuantizeTable16[indx]); 722 itmp = (int)(ftmp * fQuantizeTable16[indx]);
700 iout[CopyMatrix16[indx]] = itmp; 723 iout[fCopyMatrix16[indx]] = itmp;
701 724
702 if (dowbits) 725 if (dowbits)
703 {
704 if (itmp < 0) itmp *= -1;
705 while (itmp > wbitsMaxValue)
706 { 726 {
707 wbits++; 727 if (itmp < 0) itmp *= -1;
708 wbitsMaxValue = 1 << wbits; 728 while (itmp > wbitsMaxValue)
709 if (wbits == maxwbits)
710 { 729 {
711 dowbits = false; 730 wbits++;
712 break; 731 wbitsMaxValue = 1 << wbits;
732 if (wbits == maxwbits)
733 {
734 dowbits = false;
735 break;
736 }
713 } 737 }
714 } 738 }
715 }
716 739
717 x0r = W16_8R * (x1i - x3i); 740 x0r = W16_8R * (x1i - x3i);
718 x2r = W16_8R * (x1i + x3i); 741 x2r = W16_8R * (x1i + x3i);
719 xr = x0i + x0r; 742 xr = x0i + x0r;
720 xi = x2r + x2i; 743 xi = x2r + x2i;
721 744
722 //tmp[2 * Constants.TerrainPatchSize + k] = C16_2R * xr - C16_2I * xi; // 745 //tmp[2 * Constants.TerrainPatchSize + k] = C16_2R * xr - C16_2I * xi; //
723 ftmp = C16_2R * xr - C16_2I * xi; 746 ftmp = C16_2R * xr - C16_2I * xi;
724 indx = 2 * 16 + k; 747 indx = 2 * 16 + k;
725 itmp = (int)(ftmp * QuantizeTable16[indx]); 748 itmp = (int)(ftmp * fQuantizeTable16[indx]);
726 iout[CopyMatrix16[indx]] = itmp; 749 iout[fCopyMatrix16[indx]] = itmp;
727 750
728 if (dowbits) 751 if (dowbits)
729 {
730 if (itmp < 0) itmp *= -1;
731 while (itmp > wbitsMaxValue)
732 { 752 {
733 wbits++; 753 if (itmp < 0) itmp *= -1;
734 wbitsMaxValue = 1 << wbits; 754 while (itmp > wbitsMaxValue)
735 if (wbits == maxwbits)
736 { 755 {
737 dowbits = false; 756 wbits++;
738 break; 757 wbitsMaxValue = 1 << wbits;
758 if (wbits == maxwbits)
759 {
760 dowbits = false;
761 break;
762 }
739 } 763 }
740 } 764 }
741 }
742 765
743 //tmp[14 * Constants.TerrainPatchSize + k] = C16_2R * xi + C16_2I * xr; // 766 //tmp[14 * Constants.TerrainPatchSize + k] = C16_2R * xi + C16_2I * xr; //
744 ftmp = C16_2R * xi + C16_2I * xr; 767 ftmp = C16_2R * xi + C16_2I * xr;
745 indx = 14 * 16 + k; 768 indx = 14 * 16 + k;
746 itmp = (int)(ftmp * QuantizeTable16[indx]); 769 itmp = (int)(ftmp * fQuantizeTable16[indx]);
747 iout[CopyMatrix16[indx]] = itmp; 770 iout[fCopyMatrix16[indx]] = itmp;
748 771
749 if (dowbits) 772 if (dowbits)
750 {
751 if (itmp < 0) itmp *= -1;
752 while (itmp > wbitsMaxValue)
753 { 773 {
754 wbits++; 774 if (itmp < 0) itmp *= -1;
755 wbitsMaxValue = 1 << wbits; 775 while (itmp > wbitsMaxValue)
756 if (wbits == maxwbits)
757 { 776 {
758 dowbits = false; 777 wbits++;
759 break; 778 wbitsMaxValue = 1 << wbits;
779 if (wbits == maxwbits)
780 {
781 dowbits = false;
782 break;
783 }
760 } 784 }
761 } 785 }
762 }
763 786
764 xr = x0i - x0r; 787 xr = x0i - x0r;
765 xi = x2r - x2i; 788 xi = x2r - x2i;
766 789
767 //tmp[6 * Constants.TerrainPatchSize + k] = C16_6R * xr - C16_6I * xi; // 790 //tmp[6 * Constants.TerrainPatchSize + k] = C16_6R * xr - C16_6I * xi; //
768 ftmp = C16_6R * xr - C16_6I * xi; 791 ftmp = C16_6R * xr - C16_6I * xi;
769 indx = 6 * 16 + k; 792 indx = 6 * 16 + k;
770 itmp = (int)(ftmp * QuantizeTable16[indx]); 793 itmp = (int)(ftmp * fQuantizeTable16[indx]);
771 iout[CopyMatrix16[indx]] = itmp; 794 iout[fCopyMatrix16[indx]] = itmp;
772 795
773 if (dowbits) 796 if (dowbits)
774 {
775 if (itmp < 0) itmp *= -1;
776 while (itmp > wbitsMaxValue)
777 { 797 {
778 wbits++; 798 if (itmp < 0) itmp *= -1;
779 wbitsMaxValue = 1 << wbits; 799 while (itmp > wbitsMaxValue)
780 if (wbits == maxwbits)
781 { 800 {
782 dowbits = false; 801 wbits++;
783 break; 802 wbitsMaxValue = 1 << wbits;
803 if (wbits == maxwbits)
804 {
805 dowbits = false;
806 break;
807 }
784 } 808 }
785 } 809 }
786 }
787 810
788 //tmp[10 * Constants.TerrainPatchSize + k] = C16_6R * xi + C16_6I * xr; // 811 //tmp[10 * Constants.TerrainPatchSize + k] = C16_6R * xi + C16_6I * xr; //
789 ftmp = C16_6R * xi + C16_6I * xr; 812 ftmp = C16_6R * xi + C16_6I * xr;
790 indx = 10 * 16 + k; 813 indx = 10 * 16 + k;
791 itmp = (int)(ftmp * QuantizeTable16[indx]); 814 itmp = (int)(ftmp * fQuantizeTable16[indx]);
792 iout[CopyMatrix16[indx]] = itmp; 815 iout[fCopyMatrix16[indx]] = itmp;
793 816
794 if (dowbits) 817 if (dowbits)
795 {
796 if (itmp < 0) itmp *= -1;
797 while (itmp > wbitsMaxValue)
798 { 818 {
799 wbits++; 819 if (itmp < 0) itmp *= -1;
800 wbitsMaxValue = 1 << wbits; 820 while (itmp > wbitsMaxValue)
801 if (wbits == maxwbits)
802 { 821 {
803 dowbits = false; 822 wbits++;
804 break; 823 wbitsMaxValue = 1 << wbits;
824 if (wbits == maxwbits)
825 {
826 dowbits = false;
827 break;
828 }
805 } 829 }
806 } 830 }
807 }
808 831
809 xr = W16_8R * (x6r - x6i); 832 xr = W16_8R * (x6r - x6i);
810 xi = W16_8R * (x6i + x6r); 833 xi = W16_8R * (x6i + x6r);
811 x6r = x4r - xr; 834 x6r = x4r - xr;
812 x6i = x4i - xi; 835 x6i = x4i - xi;
813 x4r += xr; 836 x4r += xr;
814 x4i += xi; 837 x4i += xi;
815 xr = W16_4I * x7r - W16_4R * x7i; 838 xr = W16_4I * x7r - W16_4R * x7i;
816 xi = W16_4I * x7i + W16_4R * x7r; 839 xi = W16_4I * x7i + W16_4R * x7r;
817 x7r = W16_4R * x5r - W16_4I * x5i; 840 x7r = W16_4R * x5r - W16_4I * x5i;
818 x7i = W16_4R * x5i + W16_4I * x5r; 841 x7i = W16_4R * x5i + W16_4I * x5r;
819 x5r = x7r + xr; 842 x5r = x7r + xr;
820 x5i = x7i + xi; 843 x5i = x7i + xi;
821 x7r -= xr; 844 x7r -= xr;
822 x7i -= xi; 845 x7i -= xi;
823 xr = x4r + x5r; 846 xr = x4r + x5r;
824 xi = x5i + x4i; 847 xi = x5i + x4i;
825 848
826 //tmp[1 * Constants.TerrainPatchSize + k] = C16_1R * xr - C16_1I * xi; // 849 //tmp[1 * Constants.TerrainPatchSize + k] = C16_1R * xr - C16_1I * xi; //
827 ftmp = C16_1R * xr - C16_1I * xi; 850 ftmp = C16_1R * xr - C16_1I * xi;
828 indx = 16 + k; 851 indx = 16 + k;
829 itmp = (int)(ftmp * QuantizeTable16[indx]); 852 itmp = (int)(ftmp * fQuantizeTable16[indx]);
830 iout[CopyMatrix16[indx]] = itmp; 853 iout[fCopyMatrix16[indx]] = itmp;
831 854
832 if (dowbits) 855 if (dowbits)
833 {
834 if (itmp < 0) itmp *= -1;
835 while (itmp > wbitsMaxValue)
836 { 856 {
837 wbits++; 857 if (itmp < 0) itmp *= -1;
838 wbitsMaxValue = 1 << wbits; 858 while (itmp > wbitsMaxValue)
839 if (wbits == maxwbits)
840 { 859 {
841 dowbits = false; 860 wbits++;
842 break; 861 wbitsMaxValue = 1 << wbits;
862 if (wbits == maxwbits)
863 {
864 dowbits = false;
865 break;
866 }
843 } 867 }
844 } 868 }
845 }
846 869
847 //tmp[15 * Constants.TerrainPatchSize + k] = C16_1R * xi + C16_1I * xr; // 870 //tmp[15 * Constants.TerrainPatchSize + k] = C16_1R * xi + C16_1I * xr; //
848 ftmp = C16_1R * xi + C16_1I * xr; 871 ftmp = C16_1R * xi + C16_1I * xr;
849 indx = 15 * 16 + k; 872 indx = 15 * 16 + k;
850 itmp = (int)(ftmp * QuantizeTable16[indx]); 873 itmp = (int)(ftmp * fQuantizeTable16[indx]);
851 iout[CopyMatrix16[indx]] = itmp; 874 iout[fCopyMatrix16[indx]] = itmp;
852 875
853 if (dowbits) 876 if (dowbits)
854 {
855 if (itmp < 0) itmp *= -1;
856 while (itmp > wbitsMaxValue)
857 { 877 {
858 wbits++; 878 if (itmp < 0) itmp *= -1;
859 wbitsMaxValue = 1 << wbits; 879 while (itmp > wbitsMaxValue)
860 if (wbits == maxwbits)
861 { 880 {
862 dowbits = false; 881 wbits++;
863 break; 882 wbitsMaxValue = 1 << wbits;
883 if (wbits == maxwbits)
884 {
885 dowbits = false;
886 break;
887 }
864 } 888 }
865 } 889 }
866 }
867 890
868 xr = x4r - x5r; 891 xr = x4r - x5r;
869 xi = x5i - x4i; 892 xi = x5i - x4i;
870 893
871 //tmp[7 * Constants.TerrainPatchSize + k] = C16_7R * xr - C16_7I * xi; // 894 //tmp[7 * Constants.TerrainPatchSize + k] = C16_7R * xr - C16_7I * xi; //
872 ftmp = C16_7R * xr - C16_7I * xi; 895 ftmp = C16_7R * xr - C16_7I * xi;
873 indx = 7 * 16 + k; 896 indx = 7 * 16 + k;
874 itmp = (int)(ftmp * QuantizeTable16[indx]); 897 itmp = (int)(ftmp * fQuantizeTable16[indx]);
875 iout[CopyMatrix16[indx]] = itmp; 898 iout[fCopyMatrix16[indx]] = itmp;
876 899
877 if (dowbits) 900 if (dowbits)
878 {
879 if (itmp < 0) itmp *= -1;
880 while (itmp > wbitsMaxValue)
881 { 901 {
882 wbits++; 902 if (itmp < 0) itmp *= -1;
883 wbitsMaxValue = 1 << wbits; 903 while (itmp > wbitsMaxValue)
884 if (wbits == maxwbits)
885 { 904 {
886 dowbits = false; 905 wbits++;
887 break; 906 wbitsMaxValue = 1 << wbits;
907 if (wbits == maxwbits)
908 {
909 dowbits = false;
910 break;
911 }
888 } 912 }
889 } 913 }
890 }
891 914
892 //tmp[9 * Constants.TerrainPatchSize + k] = C16_7R * xi + C16_7I * xr; // 915 //tmp[9 * Constants.TerrainPatchSize + k] = C16_7R * xi + C16_7I * xr; //
893 ftmp = C16_7R * xi + C16_7I * xr; 916 ftmp = C16_7R * xi + C16_7I * xr;
894 indx = 9 * 16 + k; 917 indx = 9 * 16 + k;
895 itmp = (int)(ftmp * QuantizeTable16[indx]); 918 itmp = (int)(ftmp * fQuantizeTable16[indx]);
896 iout[CopyMatrix16[indx]] = itmp; 919 iout[fCopyMatrix16[indx]] = itmp;
897 920
898 if (dowbits) 921 if (dowbits)
899 {
900 if (itmp < 0) itmp *= -1;
901 while (itmp > wbitsMaxValue)
902 { 922 {
903 wbits++; 923 if (itmp < 0) itmp *= -1;
904 wbitsMaxValue = 1 << wbits; 924 while (itmp > wbitsMaxValue)
905 if (wbits == maxwbits)
906 { 925 {
907 dowbits = false; 926 wbits++;
908 break; 927 wbitsMaxValue = 1 << wbits;
928 if (wbits == maxwbits)
929 {
930 dowbits = false;
931 break;
932 }
909 } 933 }
910 } 934 }
911 }
912 935
913 xr = x6r - x7i; 936 xr = x6r - x7i;
914 xi = x7r + x6i; 937 xi = x7r + x6i;
915 938
916 //tmp[5 * Constants.TerrainPatchSize + k] = C16_5R * xr - C16_5I * xi; // 939 //tmp[5 * Constants.TerrainPatchSize + k] = C16_5R * xr - C16_5I * xi; //
917 ftmp = C16_5R * xr - C16_5I * xi; 940 ftmp = C16_5R * xr - C16_5I * xi;
918 indx = 5 * 16 + k; 941 indx = 5 * 16 + k;
919 itmp = (int)(ftmp * QuantizeTable16[indx]); 942 itmp = (int)(ftmp * fQuantizeTable16[indx]);
920 iout[CopyMatrix16[indx]] = itmp; 943 iout[fCopyMatrix16[indx]] = itmp;
921 944
922 if (dowbits) 945 if (dowbits)
923 {
924 if (itmp < 0) itmp *= -1;
925 while (itmp > wbitsMaxValue)
926 { 946 {
927 wbits++; 947 if (itmp < 0) itmp *= -1;
928 wbitsMaxValue = 1 << wbits; 948 while (itmp > wbitsMaxValue)
929 if (wbits == maxwbits)
930 { 949 {
931 dowbits = false; 950 wbits++;
932 break; 951 wbitsMaxValue = 1 << wbits;
952 if (wbits == maxwbits)
953 {
954 dowbits = false;
955 break;
956 }
933 } 957 }
934 } 958 }
935 }
936 959
937 //tmp[11 * Constants.TerrainPatchSize + k] = C16_5R * xi + C16_5I * xr; // 960 //tmp[11 * Constants.TerrainPatchSize + k] = C16_5R * xi + C16_5I * xr; //
938 ftmp = C16_5R * xi + C16_5I * xr; 961 ftmp = C16_5R * xi + C16_5I * xr;
939 indx = 11 * 16 + k; 962 indx = 11 * 16 + k;
940 itmp = (int)(ftmp * QuantizeTable16[indx]); 963 itmp = (int)(ftmp * fQuantizeTable16[indx]);
941 iout[CopyMatrix16[indx]] = itmp; 964 iout[fCopyMatrix16[indx]] = itmp;
942 965
943 if (dowbits) 966 if (dowbits)
944 {
945 if (itmp < 0) itmp *= -1;
946 while (itmp > wbitsMaxValue)
947 { 967 {
948 wbits++; 968 if (itmp < 0) itmp *= -1;
949 wbitsMaxValue = 1 << wbits; 969 while (itmp > wbitsMaxValue)
950 if (wbits == maxwbits)
951 { 970 {
952 dowbits = false; 971 wbits++;
953 break; 972 wbitsMaxValue = 1 << wbits;
973 if (wbits == maxwbits)
974 {
975 dowbits = false;
976 break;
977 }
954 } 978 }
955 } 979 }
956 }
957 980
958 xr = x6r + x7i; 981 xr = x6r + x7i;
959 xi = x7r - x6i; 982 xi = x7r - x6i;
960 983
961 //tmp[3 * Constants.TerrainPatchSize + k] = C16_3R * xr - C16_3I * xi; // 984 //tmp[3 * Constants.TerrainPatchSize + k] = C16_3R * xr - C16_3I * xi; //
962 ftmp = C16_3R * xr - C16_3I * xi; 985 ftmp = C16_3R * xr - C16_3I * xi;
963 indx = 3 * 16 + k; 986 indx = 3 * 16 + k;
964 itmp = (int)(ftmp * QuantizeTable16[indx]); 987 itmp = (int)(ftmp * fQuantizeTable16[indx]);
965 iout[CopyMatrix16[indx]] = itmp; 988 iout[fCopyMatrix16[indx]] = itmp;
966 989
967 if (dowbits) 990 if (dowbits)
968 {
969 if (itmp < 0) itmp *= -1;
970 while (itmp > wbitsMaxValue)
971 { 991 {
972 wbits++; 992 if (itmp < 0) itmp *= -1;
973 wbitsMaxValue = 1 << wbits; 993 while (itmp > wbitsMaxValue)
974 if (wbits == maxwbits)
975 { 994 {
976 dowbits = false; 995 wbits++;
977 break; 996 wbitsMaxValue = 1 << wbits;
997 if (wbits == maxwbits)
998 {
999 dowbits = false;
1000 break;
1001 }
978 } 1002 }
979 } 1003 }
980 }
981 1004
982 //tmp[13 * Constants.TerrainPatchSize + k] = C16_3R * xi + C16_3I * xr; // 1005 //tmp[13 * Constants.TerrainPatchSize + k] = C16_3R * xi + C16_3I * xr; //
983 ftmp = C16_3R * xi + C16_3I * xr; 1006 ftmp = C16_3R * xi + C16_3I * xr;
984 indx = 13 * 16 + k; 1007 indx = 13 * 16 + k;
985 itmp = (int)(ftmp * QuantizeTable16[indx]); 1008 itmp = (int)(ftmp * fQuantizeTable16[indx]);
986 iout[CopyMatrix16[indx]] = itmp; 1009 iout[fCopyMatrix16[indx]] = itmp;
987 1010
988 if (dowbits) 1011 if (dowbits)
989 {
990 if (itmp < 0) itmp *= -1;
991 while (itmp > wbitsMaxValue)
992 { 1012 {
993 wbits++; 1013 if (itmp < 0) itmp *= -1;
994 wbitsMaxValue = 1 << wbits; 1014 while (itmp > wbitsMaxValue)
995 if (wbits == maxwbits)
996 { 1015 {
997 dowbits = false; 1016 wbits++;
998 break; 1017 wbitsMaxValue = 1 << wbits;
1018 if (wbits == maxwbits)
1019 {
1020 dowbits = false;
1021 break;
1022 }
999 } 1023 }
1000 } 1024 }
1001 } 1025 }
diff --git a/OpenSim/Region/Framework/Scenes/TerrainUtil.cs b/OpenSim/Region/Framework/Scenes/TerrainUtil.cs
index 79ce908..7f76e01 100644
--- a/OpenSim/Region/Framework/Scenes/TerrainUtil.cs
+++ b/OpenSim/Region/Framework/Scenes/TerrainUtil.cs
@@ -62,17 +62,13 @@ namespace OpenSim.Region.Framework.Scenes
62 double h10 = map[(int) x + stepSize, (int) y]; 62 double h10 = map[(int) x + stepSize, (int) y];
63 double h01 = map[(int) x, (int) y + stepSize]; 63 double h01 = map[(int) x, (int) y + stepSize];
64 double h11 = map[(int) x + stepSize, (int) y + stepSize]; 64 double h11 = map[(int) x + stepSize, (int) y + stepSize];
65 double h1 = h00; 65 double a00 = h00;
66 double h2 = h10; 66 double a10 = h10 - h00;
67 double h3 = h01; 67 double a01 = h01 - h00;
68 double h4 = h11; 68 double a11 = h11 - h10 - h01 + h00;
69 double a00 = h1;
70 double a10 = h2 - h1;
71 double a01 = h3 - h1;
72 double a11 = h1 - h2 - h3 + h4;
73 double partialx = x - (int) x; 69 double partialx = x - (int) x;
74 double partialz = y - (int) y; 70 double partialy = y - (int) y;
75 double hi = a00 + (a10 * partialx) + (a01 * partialz) + (a11 * partialx * partialz); 71 double hi = a00 + (a10 * partialx) + (a01 * partialy) + (a11 * partialx * partialy);
76 return hi; 72 return hi;
77 } 73 }
78 74
diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
index c7b7818..0fc724b 100644
--- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
+++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
@@ -1014,19 +1014,16 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
1014 return false; 1014 return false;
1015 } 1015 }
1016 1016
1017 public void SendLayerData(float[] map) 1017 public void SendLayerData()
1018 { 1018 {
1019
1020 } 1019 }
1021 1020
1022 public void SendLayerData(int px, int py, float[] map) 1021 public void SendLayerData(int[] map)
1023 { 1022 {
1024
1025 } 1023 }
1026 1024
1027 public void SendWindData(int version, Vector2[] windSpeeds) 1025 public void SendWindData(int version, Vector2[] windSpeeds)
1028 { 1026 {
1029
1030 } 1027 }
1031 1028
1032 public void SendCloudData(int version, float[] cloudCover) 1029 public void SendCloudData(int version, float[] cloudCover)
diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs
index c661268..516f9eb 100644
--- a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs
+++ b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs
@@ -630,9 +630,7 @@ namespace OpenSim.Region.OptionalModules.Materials
630 if (faceEntry != null) 630 if (faceEntry != null)
631 { 631 {
632 faceEntry.MaterialID = id; 632 faceEntry.MaterialID = id;
633
634 //m_log.DebugFormat("[Materials]: in \"{0}\" {1}, setting material ID for face {2} to {3}", sop.Name, sop.UUID, face, id); 633 //m_log.DebugFormat("[Materials]: in \"{0}\" {1}, setting material ID for face {2} to {3}", sop.Name, sop.UUID, face, id);
635
636 // We can't use sop.UpdateTextureEntry(te) because it filters, so do it manually 634 // We can't use sop.UpdateTextureEntry(te) because it filters, so do it manually
637 sop.Shape.TextureEntry = te.GetBytes(); 635 sop.Shape.TextureEntry = te.GetBytes();
638 } 636 }
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
index 0758fc9..9c13061 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
@@ -742,14 +742,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
742 return false; 742 return false;
743 } 743 }
744 744
745 public virtual void SendLayerData(float[] map) 745 public virtual void SendLayerData()
746 { 746 {
747 } 747 }
748 748
749 public virtual void SendLayerData(int px, int py, float[] map) 749 public void SendLayerData(int[] map)
750 {
751 }
752 public virtual void SendLayerData(int px, int py, float[] map, bool track)
753 { 750 {
754 } 751 }
755 752