diff --git a/OpenSim/Framework/LandData.cs b/OpenSim/Framework/LandData.cs index 6e989d7194..cbfa5f771a 100644 --- a/OpenSim/Framework/LandData.cs +++ b/OpenSim/Framework/LandData.cs @@ -46,8 +46,8 @@ namespace OpenSim.Framework /// public class LandData { - private Vector3 _AABBMax = new Vector3(); - private Vector3 _AABBMin = new Vector3(); + private Vector3 _AABBMax = new(); + private Vector3 _AABBMin = new(); private int _area = 0; private uint _auctionID = 0; //Unemplemented. If set to 0, not being auctioned private UUID _authBuyerID = UUID.Zero; //Unemplemented. Authorized Buyer's UUID @@ -75,15 +75,15 @@ namespace OpenSim.Framework private string _mediaURL = String.Empty; private string _musicURL = String.Empty; private UUID _ownerID = UUID.Zero; - private List _parcelAccessList = new List(); + private List _parcelAccessList = new(); private float _passHours = 0; private int _passPrice = 0; private int _salePrice = 0; //Unemeplemented. Parcels price. private int _simwideArea = 0; private int _simwidePrims = 0; private UUID _snapshotID = UUID.Zero; - private Vector3 _userLocation = new Vector3(); - private Vector3 _userLookAt = new Vector3(); + private Vector3 _userLocation = new(); + private Vector3 _userLookAt = new(); private int _otherCleanTime = 0; private string _mediaType = "none/none"; private string _mediaDescription = ""; @@ -763,60 +763,63 @@ namespace OpenSim.Framework /// public LandData Copy() { - LandData landData = new LandData(); - - landData._AABBMax = _AABBMax; - landData._AABBMin = _AABBMin; - landData._area = _area; - landData._auctionID = _auctionID; - landData._authBuyerID = _authBuyerID; - landData._category = _category; - landData._claimDate = _claimDate; - landData._claimPrice = _claimPrice; - landData._globalID = _globalID; - landData.m_fakeID = m_fakeID; - landData._groupID = _groupID; - landData._isGroupOwned = _isGroupOwned; - landData._localID = _localID; - landData._landingType = _landingType; - landData._mediaAutoScale = _mediaAutoScale; - landData._mediaID = _mediaID; - landData._mediaURL = _mediaURL; - landData._musicURL = _musicURL; - landData._ownerID = _ownerID; - landData._bitmap = (byte[])_bitmap.Clone(); - landData._description = _description; - landData._flags = _flags; - landData._name = _name; - landData._status = _status; - landData._passHours = _passHours; - landData._passPrice = _passPrice; - landData._salePrice = _salePrice; - landData._snapshotID = _snapshotID; - landData._userLocation = _userLocation; - landData._userLookAt = _userLookAt; - landData._otherCleanTime = _otherCleanTime; - landData._mediaType = _mediaType; - landData._mediaDescription = _mediaDescription; - landData._mediaWidth = _mediaWidth; - landData._mediaHeight = _mediaHeight; - landData._mediaLoop = _mediaLoop; - landData._obscureMusic = _obscureMusic; - landData._obscureMedia = _obscureMedia; - landData._simwideArea = _simwideArea; - landData._simwidePrims = _simwidePrims; - landData.m_dwell = m_dwell; - landData.SeeAVs = SeeAVs; - landData.AnyAVSounds = AnyAVSounds; - landData.GroupAVSounds = GroupAVSounds; + LandData landData = new() + { + _AABBMax = _AABBMax, + _AABBMin = _AABBMin, + _area = _area, + _auctionID = _auctionID, + _authBuyerID = _authBuyerID, + _category = _category, + _claimDate = _claimDate, + _claimPrice = _claimPrice, + _globalID = _globalID, + m_fakeID = m_fakeID, + _groupID = _groupID, + _isGroupOwned = _isGroupOwned, + _localID = _localID, + _landingType = _landingType, + _mediaAutoScale = _mediaAutoScale, + _mediaID = _mediaID, + _mediaURL = _mediaURL, + _musicURL = _musicURL, + _ownerID = _ownerID, + _bitmap = (byte[])_bitmap.Clone(), + _description = _description, + _flags = _flags, + _name = _name, + _status = _status, + _passHours = _passHours, + _passPrice = _passPrice, + _salePrice = _salePrice, + _snapshotID = _snapshotID, + _userLocation = _userLocation, + _userLookAt = _userLookAt, + _otherCleanTime = _otherCleanTime, + _mediaType = _mediaType, + _mediaDescription = _mediaDescription, + _mediaWidth = _mediaWidth, + _mediaHeight = _mediaHeight, + _mediaLoop = _mediaLoop, + _obscureMusic = _obscureMusic, + _obscureMedia = _obscureMedia, + _simwideArea = _simwideArea, + _simwidePrims = _simwidePrims, + m_dwell = m_dwell, + SeeAVs = SeeAVs, + AnyAVSounds = AnyAVSounds, + GroupAVSounds = GroupAVSounds + }; landData._parcelAccessList.Clear(); foreach (LandAccessEntry entry in _parcelAccessList) { - LandAccessEntry newEntry = new LandAccessEntry(); - newEntry.AgentID = entry.AgentID; - newEntry.Flags = entry.Flags; - newEntry.Expires = entry.Expires; + LandAccessEntry newEntry = new() + { + AgentID = entry.AgentID, + Flags = entry.Flags, + Expires = entry.Expires + }; landData._parcelAccessList.Add(newEntry); } diff --git a/OpenSim/Region/CoreModules/World/Land/LandChannel.cs b/OpenSim/Region/CoreModules/World/Land/LandChannel.cs index 44049e7b17..2323696e25 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandChannel.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandChannel.cs @@ -74,7 +74,6 @@ namespace OpenSim.Region.CoreModules.World.Land #endregion - private readonly Scene m_scene; private readonly LandManagementModule m_landManagementModule; private float m_BanLineSafeHeight = 100.0f; @@ -95,9 +94,8 @@ namespace OpenSim.Region.CoreModules.World.Land public LandChannel(Scene scene, LandManagementModule landManagementMod) { - m_scene = scene; m_landManagementModule = landManagementMod; - if(landManagementMod != null) + if(landManagementMod is not null) m_BanLineSafeHeight = landManagementMod.BanLineSafeHeight; } @@ -105,19 +103,19 @@ namespace OpenSim.Region.CoreModules.World.Land [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(float x_float, float y_float) { - return m_landManagementModule != null ? m_landManagementModule.GetLandObject(x_float, y_float) : null; + return m_landManagementModule?.GetLandObject(x_float, y_float); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(int localID) { - return m_landManagementModule != null ? m_landManagementModule.GetLandObject(localID) : null; + return m_landManagementModule?.GetLandObject(localID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(UUID GlobalID) { - return m_landManagementModule != null ? m_landManagementModule.GetLandObject(GlobalID) : null; + return m_landManagementModule?.GetLandObject(GlobalID); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -129,19 +127,19 @@ namespace OpenSim.Region.CoreModules.World.Land [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(int x, int y) { - return m_landManagementModule != null ? m_landManagementModule.GetLandObject(x, y) : null; + return m_landManagementModule?.GetLandObject(x, y); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObjectClippedXY(float x, float y) { - return m_landManagementModule != null ? m_landManagementModule.GetLandObjectClippedXY(x, y) : null; + return m_landManagementModule?.GetLandObjectClippedXY(x, y); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public List AllParcels() { - return m_landManagementModule != null ? m_landManagementModule.AllParcels() : new List(); + return m_landManagementModule is not null ? m_landManagementModule.AllParcels() : new List(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -153,13 +151,13 @@ namespace OpenSim.Region.CoreModules.World.Land [MethodImpl(MethodImplOptions.AggressiveInlining)] public List ParcelsNearPoint(Vector3 position) { - return m_landManagementModule != null ? m_landManagementModule.ParcelsNearPoint(position) : new List(); + return m_landManagementModule is not null ? m_landManagementModule.ParcelsNearPoint(position) : new List(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsForcefulBansAllowed() { - return m_landManagementModule != null ? m_landManagementModule.AllowedForcefulBans : false; + return m_landManagementModule is not null && m_landManagementModule.AllowedForcefulBans; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index 219b82eff5..28e6506a27 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs @@ -51,7 +51,7 @@ namespace OpenSim.Region.CoreModules.World.Land protected const int GROUPMEMBERCACHETIMEOUT = 30000; // cache invalidation after 30s - private int m_lastSeqId = 0; + private int m_lastSeqId = 0; private int m_expiryCounter = 0; protected readonly Scene m_scene; @@ -62,12 +62,12 @@ namespace OpenSim.Region.CoreModules.World.Land protected readonly ScenePermissions m_scenePermissions; protected readonly EstateSettings m_estateSettings; - protected readonly List primsOverMe = new List(); - private readonly ExpiringCacheOS m_listTransactions = new ExpiringCacheOS(30000); - private readonly object m_listTransactionsLock = new object(); + protected readonly List primsOverMe = new(); + private readonly ExpiringCacheOS m_listTransactions = new(30000); + private readonly object m_listTransactionsLock = new(); - protected readonly ExpiringCacheOS m_groupMemberCache = new ExpiringCacheOS(30000); - IDwellModule m_dwellModule; + protected readonly ExpiringCacheOS m_groupMemberCache = new(30000); + protected readonly IDwellModule m_dwellModule; private bool[,] m_landBitmap; public bool[,] LandBitmap @@ -97,7 +97,7 @@ namespace OpenSim.Region.CoreModules.World.Land { get { - return m_landData == null ? UUID.Zero : m_landData.GlobalID; + return m_landData is null ? UUID.Zero : m_landData.GlobalID; } } @@ -105,7 +105,7 @@ namespace OpenSim.Region.CoreModules.World.Land { get { - return m_landData == null ? UUID.Zero : m_landData.FakeID; + return m_landData is null ? UUID.Zero : m_landData.FakeID; } } @@ -113,7 +113,7 @@ namespace OpenSim.Region.CoreModules.World.Land { get { - return m_landData == null ? UUID.Zero : m_landData.OwnerID; + return m_landData is null ? UUID.Zero : m_landData.OwnerID; } } @@ -121,7 +121,7 @@ namespace OpenSim.Region.CoreModules.World.Land { get { - return m_landData == null ? UUID.Zero : m_landData.GroupID; + return m_landData is null ? UUID.Zero : m_landData.GroupID; } } @@ -129,7 +129,7 @@ namespace OpenSim.Region.CoreModules.World.Land { get { - return m_landData == null ? -1 : m_landData.LocalID; + return m_landData is null ? -1 : m_landData.LocalID; } } @@ -180,24 +180,25 @@ namespace OpenSim.Region.CoreModules.World.Land [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2? GetNearestPoint(Vector3 pos) { - Vector3 direction = new Vector3(m_centerPoint.X - pos.X, m_centerPoint.Y - pos.Y, 0f ); - return GetNearestPointAlongDirection(pos, direction); + return GetNearestPointAlongDirection(pos, new Vector2(m_centerPoint.X - pos.X, m_centerPoint.Y - pos.Y)); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2? GetNearestPointAlongDirection(Vector3 pos, Vector3 pdirection) { - Vector2 testpos; - Vector2 direction; + return GetNearestPointAlongDirection(pos, new Vector2(pdirection.X, pdirection.Y)); + } + public Vector2? GetNearestPointAlongDirection(Vector3 pos, Vector2 direction) + { + Vector2 testpos; + testpos.X = pos.X / Constants.LandUnit; testpos.Y = pos.Y / Constants.LandUnit; if(LandBitmap[(int)testpos.X, (int)testpos.Y]) return new Vector2(pos.X, pos.Y); // we are already here - direction.X = pdirection.X; - direction.Y = pdirection.Y; - if(direction.X == 0f && direction.Y == 0f) return null; // we can't look anywhere @@ -412,8 +413,10 @@ namespace OpenSim.Region.CoreModules.World.Land [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject Copy() { - ILandObject newLand = new LandObject(LandData, m_scene); - newLand.LandBitmap = (bool[,]) (LandBitmap.Clone()); + ILandObject newLand = new LandObject(LandData, m_scene) + { + LandBitmap = (bool[,])(LandBitmap.Clone()) + }; return newLand; } @@ -461,7 +464,7 @@ namespace OpenSim.Region.CoreModules.World.Land [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetSimulatorMaxPrimCount() { - if (overrideSimulatorMaxPrimCount != null) + if (overrideSimulatorMaxPrimCount is not null) { return overrideSimulatorMaxPrimCount(this); } @@ -870,15 +873,14 @@ namespace OpenSim.Region.CoreModules.World.Land return false; // check for a NPC - ScenePresence sp; - if (!m_scene.TryGetScenePresence(avatar, out sp)) + if (!m_scene.TryGetScenePresence(avatar, out ScenePresence sp)) return true; - if(sp==null || !sp.IsNPC) + if(sp is null || !sp.IsNPC) return true; INPC npccli = (INPC)sp.ControllingClient; - if(npccli== null) + if(npccli is null) return true; UUID owner = npccli.Owner; @@ -984,7 +986,7 @@ namespace OpenSim.Region.CoreModules.World.Land { ExpireAccessList(); - List list = new List(); + List list = new(); foreach (LandAccessEntry entry in LandData.ParcelAccessList) { if (entry.Flags == flag) @@ -992,10 +994,12 @@ namespace OpenSim.Region.CoreModules.World.Land } if (list.Count == 0) { - LandAccessEntry e = new LandAccessEntry(); - e.AgentID = UUID.Zero; - e.Flags = 0; - e.Expires = 0; + LandAccessEntry e = new() + { + AgentID = UUID.Zero, + Flags = 0, + Expires = 0 + }; list.Add(e); } @@ -1027,7 +1031,7 @@ namespace OpenSim.Region.CoreModules.World.Land return; // we only have access and ban // get a work copy of lists - List parcelAccessList = new List(LandData.ParcelAccessList); + List parcelAccessList = new(LandData.ParcelAccessList); // first packet on a transaction clears before adding // we need to this way because viewer protocol does not seem reliable @@ -1037,7 +1041,7 @@ namespace OpenSim.Region.CoreModules.World.Land { m_listTransactions.Add(flags, transactionID); - List toRemove = new List(); + List toRemove = new(); foreach (LandAccessEntry entry in parcelAccessList) { if (((uint)entry.Flags & flags) != 0) @@ -1062,10 +1066,12 @@ namespace OpenSim.Region.CoreModules.World.Land foreach (LandAccessEntry entry in entries) { - LandAccessEntry temp = new LandAccessEntry(); - temp.AgentID = entry.AgentID; - temp.Expires = entry.Expires; - temp.Flags = (AccessList)flags; + LandAccessEntry temp = new() + { + AgentID = entry.AgentID, + Expires = entry.Expires, + Flags = (AccessList)flags + }; parcelAccessList.Add(temp); } @@ -1538,7 +1544,7 @@ namespace OpenSim.Region.CoreModules.World.Land { if (LandBitmap[x, y]) tempByte |= mask; - mask = mask << 1; + mask <<= 1; if (mask == 0x100) { mask = 1; @@ -1593,7 +1599,7 @@ namespace OpenSim.Region.CoreModules.World.Land for (int i = 0; i < bitmapLen; i++) { tempByte = LandData.Bitmap[i]; - for (int bitmask = 0x01; bitmask < 0x100; bitmask = bitmask << 1) + for (int bitmask = 0x01; bitmask < 0x100; bitmask <<= 1) { bool bit = (tempByte & bitmask) == bitmask; try @@ -1650,7 +1656,7 @@ namespace OpenSim.Region.CoreModules.World.Land { if (m_scenePermissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true)) { - List resultLocalIDs = new List(); + List resultLocalIDs = new(); try { lock (primsOverMe) @@ -1699,8 +1705,8 @@ namespace OpenSim.Region.CoreModules.World.Land { if (m_scenePermissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true)) { - Dictionary primCount = new Dictionary(); - List groups = new List(); + Dictionary primCount = new(); + List groups = new(); lock (primsOverMe) { @@ -1747,7 +1753,7 @@ namespace OpenSim.Region.CoreModules.World.Land public Dictionary GetLandObjectOwners() { - Dictionary ownersAndCount = new Dictionary(); + Dictionary ownersAndCount = new(); lock (primsOverMe) { @@ -1791,8 +1797,7 @@ namespace OpenSim.Region.CoreModules.World.Land return; } - ScenePresence sp; - if (!m_scene.TryGetScenePresence(LandData.OwnerID, out sp)) + if (!m_scene.TryGetScenePresence(LandData.OwnerID, out ScenePresence sp)) { m_log.Error("[LAND OBJECT]: New owner is not present in scene"); return; @@ -1825,7 +1830,7 @@ namespace OpenSim.Region.CoreModules.World.Land // m_log.DebugFormat( // "[LAND OBJECT]: Request to return objects in {0} from {1}", LandData.Name, remote_client.Name); - Dictionary> returns = new Dictionary>(); + Dictionary> returns = new(); lock (primsOverMe) { @@ -1871,8 +1876,7 @@ namespace OpenSim.Region.CoreModules.World.Land } else if (type == (uint)ObjectReturnType.List) { - List ownerlist = new List(owners); - + List ownerlist = new(owners); foreach (SceneObjectGroup obj in primsOverMe) { if (ownerlist.Contains(obj.OwnerID)) @@ -1934,7 +1938,7 @@ namespace OpenSim.Region.CoreModules.World.Land { try { - Uri dummmy = new Uri(url, UriKind.Absolute); + Uri dummmy = new(url, UriKind.Absolute); LandData.MediaURL = url; } catch (Exception e) @@ -1959,7 +1963,7 @@ namespace OpenSim.Region.CoreModules.World.Land { try { - Uri dummmy = new Uri(url, UriKind.Absolute); + Uri dummmy = new(url, UriKind.Absolute); LandData.MusicURL = url; } catch (Exception e) @@ -1995,7 +1999,7 @@ namespace OpenSim.Region.CoreModules.World.Land } // need to update dwell here bc landdata has no parent info - if(LandData != null && m_dwellModule != null) + if(LandData is not null && m_dwellModule is not null) { double now = Util.GetTimeStampMS(); double elapsed = now - LandData.LastDwellTimeMS; @@ -2005,18 +2009,18 @@ namespace OpenSim.Region.CoreModules.World.Land double cur = dwell * 60000.0; double decay = 1.5e-8 * cur * elapsed; cur -= decay; - if(cur < 0) + if (cur < 0) cur = 0; UUID lgid = LandData.GlobalID; m_scene.ForEachRootScenePresence(delegate(ScenePresence sp) { - if(sp.IsNPC || sp.IsDeleted || sp.currentParcelUUID != lgid) + if(sp.IsNPC || sp.IsDeleted || sp.currentParcelUUID.NotEqual(lgid)) return; cur += (now - sp.ParcelDwellTickMS); sp.ParcelDwellTickMS = now; }); - + float newdwell = (float)(cur * 1.666666666667e-5); LandData.Dwell = newdwell; @@ -2028,8 +2032,7 @@ namespace OpenSim.Region.CoreModules.World.Land private void ExpireAccessList() { - List delete = new List(); - + List delete = new(); foreach (LandAccessEntry entry in LandData.ParcelAccessList) { if (entry.Expires != 0 && entry.Expires < Util.UnixTimeSinceEpoch()) @@ -2038,9 +2041,8 @@ namespace OpenSim.Region.CoreModules.World.Land foreach (LandAccessEntry entry in delete) { LandData.ParcelAccessList.Remove(entry); - ScenePresence presence; - if (m_scene.TryGetScenePresence(entry.AgentID, out presence) && (!presence.IsChildAgent)) + if (m_scene.TryGetScenePresence(entry.AgentID, out ScenePresence presence) && (!presence.IsChildAgent)) { ILandObject land = m_scene.LandChannel.GetLandObject(presence.AbsolutePosition.X, presence.AbsolutePosition.Y); if (land.LandData.LocalID == LandData.LocalID)