From 9138fee6b03bdb9eb25cbc602ba18c8cfa44ee9b Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Wed, 21 Apr 2010 00:00:54 +0000 Subject: [PATCH] * Handle "-0" values in wearable assets * Login fix for Linux clients now that the null ID0 is blacklisted * Change Parcel from a struct to a class (this object is huge!) and remove the redundant initializers in the constructor * Moved Terrain and WindSpeed data from TerrainManager to the Simulator class * Don't track wind data either if STORE_LAND_PATCHES is disabled git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3298 52acb1d6-8a22-11de-b505-999d5b087335 --- .../Assets/AssetTypes/AssetWearable.cs | 7 +- OpenMetaverse/Login.cs | 6 +- OpenMetaverse/ParcelManager.cs | 47 ++------------ OpenMetaverse/Simulator.cs | 39 +++++++++++ OpenMetaverse/TerrainManager.cs | 64 ++----------------- Programs/examples/Heightmap/frmHeightmap.cs | 7 +- .../TestClient/Commands/Land/WindCommand.cs | 2 +- 7 files changed, 60 insertions(+), 112 deletions(-) diff --git a/OpenMetaverse/Assets/AssetTypes/AssetWearable.cs b/OpenMetaverse/Assets/AssetTypes/AssetWearable.cs index 24208f43..de7d2ac6 100644 --- a/OpenMetaverse/Assets/AssetTypes/AssetWearable.cs +++ b/OpenMetaverse/Assets/AssetTypes/AssetWearable.cs @@ -127,7 +127,12 @@ namespace OpenMetaverse.Assets line = lines[stri].Trim(); fields = line.Split(' '); - int id = Int32.Parse(fields[0]); + int id = 0; + + // Special handling for -0 edge case + if (fields[0] != "-0") + id = Int32.Parse(fields[0]); + if (fields[1] == ",") fields[1] = "0"; else diff --git a/OpenMetaverse/Login.cs b/OpenMetaverse/Login.cs index 3cab6868..5ae4cf4a 100644 --- a/OpenMetaverse/Login.cs +++ b/OpenMetaverse/Login.cs @@ -1413,13 +1413,15 @@ namespace OpenMetaverse private static string GetMAC() { string mac = String.Empty; - System.Net.NetworkInformation.NetworkInterface[] nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); +#if USE_NIC + System.Net.NetworkInformation.NetworkInterface[] nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(); if (nics.Length > 0) mac = nics[0].GetPhysicalAddress().ToString().ToUpper(); +#endif if (mac.Length < 12) - mac = "000000000000"; + mac = UUID.Random().ToString().Substring(24, 12); return String.Format("{0}:{1}:{2}:{3}:{4}:{5}", mac.Substring(0, 2), diff --git a/OpenMetaverse/ParcelManager.cs b/OpenMetaverse/ParcelManager.cs index f7ebc689..634eaa8b 100644 --- a/OpenMetaverse/ParcelManager.cs +++ b/OpenMetaverse/ParcelManager.cs @@ -458,7 +458,7 @@ namespace OpenMetaverse /// /// Parcel of land, a portion of virtual real estate in a simulator /// - public struct Parcel + public class Parcel { /// The total number of contiguous 4x4 meter blocks your agent owns within this parcel public int SelfCount; @@ -590,52 +590,14 @@ namespace OpenMetaverse public Parcel(int localID) { LocalID = localID; - SelfCount = 0; - OtherCount = 0; - PublicCount = 0; - OwnerID = UUID.Zero; - IsGroupOwned = false; - AuctionID = 0; ClaimDate = Utils.Epoch; - ClaimPrice = 0; - RentPrice = 0; - AABBMin = Vector3.Zero; - AABBMax = Vector3.Zero; Bitmap = Utils.EmptyBytes; - Area = 0; - Status = ParcelStatus.None; - SimWideMaxPrims = 0; - SimWideTotalPrims = 0; - MaxPrims = 0; - TotalPrims = 0; - OwnerPrims = 0; - GroupPrims = 0; - OtherPrims = 0; - ParcelPrimBonus = 0; - OtherCleanTime = 0; - Flags = ParcelFlags.None; - SalePrice = 0; Name = String.Empty; Desc = String.Empty; MusicURL = String.Empty; - GroupID = UUID.Zero; - PassPrice = 0; - PassHours = 0; - Category = ParcelCategory.None; - AuthBuyerID = UUID.Zero; - SnapshotID = UUID.Zero; - UserLocation = Vector3.Zero; - UserLookAt = Vector3.Zero; - Landing = LandingType.None; - Dwell = 0; - RegionDenyAnonymous = false; - RegionPushOverride = false; - AccessWhiteList = new List(); + AccessWhiteList = new List(0); AccessBlackList = new List(0); - RegionDenyAgeUnverified = false; Media = new ParcelMedia(); - ObscureMedia = false; - ObscureMusic = false; } /// @@ -990,10 +952,9 @@ namespace OpenMetaverse } #endregion Delegates - private GridClient Client; - private AutoResetEvent WaitForSimParcel; + #region Public Methods /// @@ -1451,7 +1412,7 @@ namespace OpenMetaverse y = (int)p.AABBMax.Y - (int)p.AABBMin.Y / 2; } - if (!Client.Terrain.TerrainHeightAtPoint(simulator.Handle, x, y, out height)) + if (!simulator.TerrainHeightAtPoint(x, y, out height)) { Logger.Log("Land Patch not stored for location", Helpers.LogLevel.Warning, Client); return false; diff --git a/OpenMetaverse/Simulator.cs b/OpenMetaverse/Simulator.cs index 87103148..726e1416 100644 --- a/OpenMetaverse/Simulator.cs +++ b/OpenMetaverse/Simulator.cs @@ -353,6 +353,10 @@ namespace OpenMetaverse /// public InternalDictionary ObjectsPrimitives = new InternalDictionary(); + public readonly TerrainPatch[] Terrain; + + public readonly Vector2[] WindSpeeds; + /// The current sequence number for packets sent to this /// simulator. Must be Interlocked before modifying. Only /// useful for applications manipulating sequence numbers @@ -466,6 +470,12 @@ namespace OpenMetaverse PacketArchive = new IncomingPacketIDCollection(Settings.PACKET_ARCHIVE_SIZE); InBytes = new Queue(Client.Settings.STATS_QUEUE_SIZE); OutBytes = new Queue(Client.Settings.STATS_QUEUE_SIZE); + + if (client.Settings.STORE_LAND_PATCHES) + { + Terrain = new TerrainPatch[16 * 16]; + WindSpeeds = new Vector2[16 * 16]; + } } /// @@ -659,6 +669,35 @@ namespace OpenMetaverse Client.Network.SendPacket(resume, this); } + /// + /// Retrieve the terrain height at a given coordinate + /// + /// Sim X coordinate, valid range is from 0 to 255 + /// Sim Y coordinate, valid range is from 0 to 255 + /// The terrain height at the given point if the + /// lookup was successful, otherwise 0.0f + /// True if the lookup was successful, otherwise false + public bool TerrainHeightAtPoint(int x, int y, out float height) + { + if (Terrain != null && x >= 0 && x < 256 && y >= 0 && y < 256) + { + int patchX = x / 16; + int patchY = y / 16; + x = x % 16; + y = y % 16; + + TerrainPatch patch = Terrain[patchY * 16 + patchX]; + if (patch != null) + { + height = patch.Data[y * 16 + x]; + return true; + } + } + + height = 0.0f; + return false; + } + #region Packet Sending /// diff --git a/OpenMetaverse/TerrainManager.cs b/OpenMetaverse/TerrainManager.cs index adfb33b0..773066d3 100644 --- a/OpenMetaverse/TerrainManager.cs +++ b/OpenMetaverse/TerrainManager.cs @@ -57,9 +57,6 @@ namespace OpenMetaverse } #endregion - public InternalDictionary SimPatches = new InternalDictionary(); - public InternalDictionary WindSpeeds = new InternalDictionary(); - private GridClient Client; /// @@ -72,44 +69,6 @@ namespace OpenMetaverse Client.Network.RegisterCallback(PacketType.LayerData, LayerDataHandler); } - /// - /// Retrieve the terrain height at a given coordinate - /// - /// The region that the point of interest is in - /// Sim X coordinate, valid range is from 0 to 255 - /// Sim Y coordinate, valid range is from 0 to 255 - /// The terrain height at the given point if the - /// lookup was successful, otherwise 0.0f - /// True if the lookup was successful, otherwise false - public bool TerrainHeightAtPoint(ulong regionHandle, int x, int y, out float height) - { - if (x >= 0 && x < 256 && y >= 0 && y < 256) - { - TerrainPatch[] found; - lock (SimPatches.Dictionary) - { - if (!SimPatches.TryGetValue(regionHandle, out found)) - { - height = 0.0f; - return false; - } - } - int patchX = x / 16; - int patchY = y / 16; - x = x % 16; - y = y % 16; - TerrainPatch patch = found[patchY * 16 + patchX]; - if (patch != null) - { - height = patch.Data[y * 16 + x]; - return true; - } - } - - height = 0.0f; - return false; - } - private void DecompressLand(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) { int x; @@ -149,19 +108,11 @@ namespace OpenMetaverse if (Client.Settings.STORE_LAND_PATCHES) { - TerrainPatch[] found; - lock (SimPatches.Dictionary) - if (!SimPatches.TryGetValue(simulator.Handle, out found)) - { - found = new TerrainPatch[16 * 16]; - SimPatches.Add(simulator.Handle, found); - } TerrainPatch patch = new TerrainPatch(); patch.Data = heightmap; patch.X = x; patch.Y = y; - found[y * 16 + x] = patch; - + simulator.Terrain[y * 16 + x] = patch; } } } @@ -188,17 +139,12 @@ namespace OpenMetaverse header = TerrainCompressor.DecodePatchHeader(bitpack); TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize); float[] yvalues = TerrainCompressor.DecompressPatch(patches, header, group); - ulong handle = simulator.Handle; - Vector2[] windSpeeds; - lock (WindSpeeds.Dictionary) + + if (simulator.Client.Settings.STORE_LAND_PATCHES) { - if (!WindSpeeds.TryGetValue(handle, out windSpeeds)) - { - windSpeeds = WindSpeeds[handle] = new Vector2[256]; - } + for (int i = 0; i < 256; i++) + simulator.WindSpeeds[i] = new Vector2(xvalues[i], yvalues[i]); } - for (int i = 0; i < 256; i++) - windSpeeds[i] = new Vector2(xvalues[i], yvalues[i]); } private void DecompressCloud(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group) diff --git a/Programs/examples/Heightmap/frmHeightmap.cs b/Programs/examples/Heightmap/frmHeightmap.cs index 2bd731e4..0937d0bb 100644 --- a/Programs/examples/Heightmap/frmHeightmap.cs +++ b/Programs/examples/Heightmap/frmHeightmap.cs @@ -101,15 +101,10 @@ namespace Heightmap if (Boxes[x, y] == sender) { float height; - if (Client.Terrain.TerrainHeightAtPoint(Client.Network.CurrentSim.Handle, - x * 16 + e.X, y * 16 + e.Y, out height)) - { + if (Client.Network.CurrentSim.TerrainHeightAtPoint(x * 16 + e.X, y * 16 + e.Y, out height)) MessageBox.Show( string.Format("{0},{1}:{2}",x*16+e.X,255-(y*16+e.Y),height) ); - } else - { MessageBox.Show("Unknown height"); - } return; } } diff --git a/Programs/examples/TestClient/Commands/Land/WindCommand.cs b/Programs/examples/TestClient/Commands/Land/WindCommand.cs index 50290e5e..d16c9016 100644 --- a/Programs/examples/TestClient/Commands/Land/WindCommand.cs +++ b/Programs/examples/TestClient/Commands/Land/WindCommand.cs @@ -20,7 +20,7 @@ namespace OpenMetaverse.TestClient int xPos = (int)Utils.Clamp(agentPos.X, 0.0f, 255.0f) / 16; int yPos = (int)Utils.Clamp(agentPos.Y, 0.0f, 255.0f) / 16; - Vector2 windSpeed = Client.Terrain.WindSpeeds[Client.Network.CurrentSim.Handle][yPos * 16 + xPos]; + Vector2 windSpeed = Client.Network.CurrentSim.WindSpeeds[yPos * 16 + xPos]; return "Local wind speed is " + windSpeed.ToString(); }