From 2433ea82c955c263393671a9e941d5bec6f5e659 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 24 Feb 2023 00:07:46 +0000 Subject: [PATCH] cosmetics on scenepresence and grid map --- .../Region/Framework/Scenes/ScenePresence.cs | 330 +++++++----------- .../MapImageService/MapImageService.cs | 17 +- 2 files changed, 143 insertions(+), 204 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index bc06a47c90..1f63617dd4 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -116,8 +116,7 @@ namespace OpenSim.Region.Framework.Scenes public void TriggerScenePresenceUpdated() { - if (m_scene != null) - m_scene.EventManager.TriggerScenePresenceUpdated(this); + m_scene?.EventManager.TriggerScenePresenceUpdated(this); } public bool IsNPC { get; private set; } @@ -146,7 +145,7 @@ namespace OpenSim.Region.Framework.Scenes public bool HideTitle; public bool MuteCollisions; - private ScenePresenceStateMachine m_stateMachine; + private readonly ScenePresenceStateMachine m_stateMachine; /// /// The current state of this presence. Governs only the existence lifecycle. See ScenePresenceStateMachine @@ -173,9 +172,9 @@ namespace OpenSim.Region.Framework.Scenes /// TODO: The child -> agent transition should be folded into LifecycleState and the CompleteMovement /// regulation done there. /// - private readonly object m_completeMovementLock = new object(); + private readonly object m_completeMovementLock = new(); - private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); + private static readonly Vector3 HEAD_ADJUSTMENT = new(0f, 0f, 0.3f); /// /// Experimentally determined "fudge factor" to make sit-target positions @@ -185,7 +184,7 @@ namespace OpenSim.Region.Framework.Scenes /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis /// issue #1716 /// - public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.4f); + public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new(0.0f, 0.0f, 0.4f); public readonly bool LegacySitOffsets = true; /// @@ -204,7 +203,7 @@ namespace OpenSim.Region.Framework.Scenes private UUID m_currentParcelUUID = UUID.Zero; private bool m_previusParcelHide = false; private bool m_currentParcelHide = false; - private readonly object parcelLock = new Object(); + private readonly object parcelLock = new(); public double ParcelDwellTickMS; public UUID currentParcelUUID @@ -304,11 +303,11 @@ namespace OpenSim.Region.Framework.Scenes /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is /// necessary. /// - private List m_attachments = new List(); + private readonly List m_attachments = new(); public Object AttachmentsSyncLock { get; private set; } - private Dictionary scriptedcontrols = new Dictionary(); + private readonly Dictionary scriptedcontrols = new(); private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; private bool MouseDown = false; @@ -322,7 +321,7 @@ namespace OpenSim.Region.Framework.Scenes private Vector3 m_lastPosition; private Quaternion m_lastRotation; private Vector3 m_lastVelocity; - private Vector3 m_lastSize = new Vector3(0.45f,0.6f,1.9f); + private Vector3 m_lastSize = new(0.45f, 0.6f, 1.9f); private int NeedInitialData = 1; private int m_userFlags; @@ -349,7 +348,7 @@ namespace OpenSim.Region.Framework.Scenes set { PhysicsActor.IsColliding = value; } } - private List m_lastColliders = new List(); + private List m_lastColliders = new(); private bool m_lastLandCollide; private TeleportFlags m_teleportFlags; @@ -388,8 +387,6 @@ namespace OpenSim.Region.Framework.Scenes private float m_FOV = 1.04f; - private const int LAND_VELOCITYMAG_MAX = 12; - private const float FLY_ROLL_MAX_RADIANS = 1.1f; private const float FLY_ROLL_RADIANS_PER_UPDATE = 0.06f; @@ -477,7 +474,7 @@ namespace OpenSim.Region.Framework.Scenes private bool CameraConstraintActive; - private readonly object m_collisionEventLock = new Object(); + private readonly object m_collisionEventLock = new(); private int m_movementAnimationUpdateCounter = 0; @@ -505,7 +502,7 @@ namespace OpenSim.Region.Framework.Scenes get { return m_InTransitScriptStates; } private set { m_InTransitScriptStates = value; } } - private List m_InTransitScriptStates = new List(); + private List m_InTransitScriptStates = new(); /// /// Position at which a significant movement was made @@ -535,10 +532,10 @@ namespace OpenSim.Region.Framework.Scenes /// the very latest value and not using some cached version. Cannot make m_originRegionID itself volatite as /// it is a value type. /// - private readonly object m_originRegionIDAccessLock = new object(); + private readonly object m_originRegionIDAccessLock = new(); - private AutoResetEvent m_updateAgentReceivedAfterTransferEvent = new AutoResetEvent(false); + private AutoResetEvent m_updateAgentReceivedAfterTransferEvent = new(false); /// /// Used by the entity transfer module to signal when the presence should not be closed because a subsequent @@ -607,7 +604,7 @@ namespace OpenSim.Region.Framework.Scenes public GodController GodController { get; private set; } private ulong m_rootRegionHandle; - private Vector3 m_rootRegionPosition = new Vector3(); + private Vector3 m_rootRegionPosition = new(); public ulong RegionHandle { @@ -628,7 +625,7 @@ namespace OpenSim.Region.Framework.Scenes /// // protected Vector3 m_lastCameraPosition; - private Vector4 m_lastCameraCollisionPlane = new Vector4(0f, 0f, 0f, 1); + private Vector4 m_lastCameraCollisionPlane = new(0f, 0f, 0f, 1); private bool m_doingCamRayCast = false; public Vector3 CameraPosition { get; set; } @@ -645,7 +642,7 @@ namespace OpenSim.Region.Framework.Scenes { get { - Vector3 a = new Vector3(CameraAtAxis.X, CameraAtAxis.Y, 0); + Vector3 a = new(CameraAtAxis.X, CameraAtAxis.Y, 0); a.Normalize(); return a; } @@ -1273,7 +1270,6 @@ namespace OpenSim.Region.Framework.Scenes if(m_healRatePerFrame != 0f && Health != 100.0f) { - float last = Health; Health += m_healRatePerFrame; if(Health > 100.0f) { @@ -1481,7 +1477,7 @@ namespace OpenSim.Region.Framework.Scenes float dist = physTestHeight - groundHeight + localAVHalfHeight; - Vector3 direction = new Vector3(0f, 0f, -1f); + Vector3 direction = new(0f, 0f, -1f); Vector3 RayStart = pos; RayStart.Z = physTestHeight; @@ -1536,8 +1532,7 @@ namespace OpenSim.Region.Framework.Scenes { Vector3 vel = Velocity; AddToPhysicalScene(isFlying); - if (PhysicsActor != null) - PhysicsActor.SetMomentum(vel); + PhysicsActor?.SetMomentum(vel); } else { @@ -1755,14 +1750,7 @@ namespace OpenSim.Region.Framework.Scenes AbsolutePosition = pos; AddToPhysicalScene(isFlying); - if (PhysicsActor != null) - { - if (v.HasValue) - PhysicsActor.SetMomentum((Vector3)v); - else - PhysicsActor.SetMomentum(vel); - } - + PhysicsActor?.SetMomentum(v ?? vel); SendTerseUpdateToAllClients(); } @@ -1808,7 +1796,7 @@ namespace OpenSim.Region.Framework.Scenes newvel.Y = 0; } - if (!m_scene.TestLandRestrictions(UUID, out string reason, ref newpos.X, ref newpos.Y)) + if (!m_scene.TestLandRestrictions(UUID, out string _, ref newpos.X, ref newpos.Y)) return ; if (IsSitting) @@ -1817,11 +1805,8 @@ namespace OpenSim.Region.Framework.Scenes if(m_movingToTarget) ResetMoveToTarget(); - float localHalfAVHeight = 0.8f; - if (Appearance != null) - localHalfAVHeight = Appearance.AvatarHeight * 0.5f; - - float posZLimit = (float)Scene.Heightmap[(int)newpos.X, (int)newpos.Y]; + float localHalfAVHeight = Appearance is null ? 0.8f : Appearance.AvatarHeight * 0.5f; + float posZLimit = Scene.GetGroundHeight(newpos.X, newpos.Y); posZLimit += localHalfAVHeight + 0.1f; if (newpos.Z < posZLimit) newpos.Z = posZLimit; @@ -1843,7 +1828,7 @@ namespace OpenSim.Region.Framework.Scenes { newlookat.Z = 0; newlookat.Normalize(); - if (Math.Abs(newlookat.X) > 0.001 || Math.Abs(newlookat.Y) > 0.001) + if (MathF.Abs(newlookat.X) > 0.001f || MathF.Abs(newlookat.Y) > 0.001f) lookat = newlookat; } else if((flags & 4) != 0) @@ -1854,7 +1839,7 @@ namespace OpenSim.Region.Framework.Scenes newlookat = m_velocity; newlookat.Z = 0; newlookat.Normalize(); - if (Math.Abs(newlookat.X) > 0.001 || Math.Abs(newlookat.Y) > 0.001) + if (MathF.Abs(newlookat.X) > 0.001f || MathF.Abs(newlookat.Y) > 0.001f) lookat = newlookat; } @@ -1866,8 +1851,7 @@ namespace OpenSim.Region.Framework.Scenes if ((flags & 1) != 0) { - if (PhysicsActor != null) - PhysicsActor.SetMomentum(newvel); + PhysicsActor?.SetMomentum(newvel); m_velocity = newvel; } @@ -1977,7 +1961,7 @@ namespace OpenSim.Region.Framework.Scenes // neighbouring regions we have enabled a child agent in // holds the seed cap for the child agent in that region - private Dictionary m_knownChildRegions = new Dictionary(); + private Dictionary m_knownChildRegions = new(); struct spRegionSizeInfo { @@ -1991,7 +1975,7 @@ namespace OpenSim.Region.Framework.Scenes } } - private Dictionary m_knownChildRegionsSizeInfo = new Dictionary(); + private Dictionary m_knownChildRegionsSizeInfo = new(); public void AddNeighbourRegion(GridRegion region, string capsPath) { @@ -2160,18 +2144,11 @@ namespace OpenSim.Region.Framework.Scenes Rotation = Quaternion.Identity; return; } - n = lookAt.X/(float)Math.Sqrt(n); - float angle = (float)Math.Acos(n); + n = lookAt.X/MathF.Sqrt(n); + float angle = MathF.Acos(n); angle *= 0.5f; - float s = (float)Math.Sin(angle); - if(lookAt.Y < 0) - s = -s; - Rotation = new Quaternion( - 0f, - 0f, - s, - (float)Math.Cos(angle) - ); + float s = lookAt.Y >= 0 ? MathF.Sin(angle) : -MathF.Sin(angle); + Rotation = new Quaternion(0f, 0f, s, MathF.Cos(angle)); } } @@ -2326,8 +2303,7 @@ namespace OpenSim.Region.Framework.Scenes Scene.SendLayerData(ControllingClient); // send initial land overlay and parcel - if (landch != null) - landch.sendClientInitialLandInfo(client, !m_gotCrossUpdate); + landch?.sendClientInitialLandInfo(client, !m_gotCrossUpdate); } List allpresences = m_scene.GetScenePresences(); @@ -2346,8 +2322,7 @@ namespace OpenSim.Region.Framework.Scenes int[] animseqs = null; UUID[] animsobjs = null; - if (Animator != null) - Animator.GetArrays(out animIDs, out animseqs, out animsobjs); + Animator?.GetArrays(out animIDs, out animseqs, out animsobjs); bool haveAnims = (animIDs != null && animseqs != null && animsobjs != null); @@ -2424,10 +2399,7 @@ namespace OpenSim.Region.Framework.Scenes // Create child agents in neighbouring regions IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface(); - if (m_agentTransfer != null) - { - m_agentTransfer.EnableChildAgents(this); - } + m_agentTransfer?.EnableChildAgents(this); m_lastChildUpdatesTime = Util.EnvironmentTickCount() + 10000; m_lastChildAgentUpdatePosition = AbsolutePosition; @@ -2499,7 +2471,7 @@ namespace OpenSim.Region.Framework.Scenes { if (CameraConstraintActive) { - Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right... + Vector4 plane = new(0.9f, 0.0f, 0.361f, -10000f); // not right... UpdateCameraCollisionPlane(plane); CameraConstraintActive = false; } @@ -2531,7 +2503,7 @@ namespace OpenSim.Region.Framework.Scenes if (CameraConstraintActive) { - Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right... + Vector4 plane = new(0.9f, 0.0f, 0.361f, -10000f); // not right... UpdateCameraCollisionPlane(plane); CameraConstraintActive = false; } @@ -2564,7 +2536,7 @@ namespace OpenSim.Region.Framework.Scenes collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1); collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1); - Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z, collisionPoint.Dot(pNormal)); + Vector4 plane = new(pNormal.X, pNormal.Y, pNormal.Z, collisionPoint.Dot(pNormal)); UpdateCameraCollisionPlane(plane); } } @@ -2579,13 +2551,13 @@ namespace OpenSim.Region.Framework.Scenes collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1); collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1); - Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z,collisionPoint.Dot(pNormal)); + Vector4 plane = new(pNormal.X, pNormal.Y, pNormal.Z,collisionPoint.Dot(pNormal)); UpdateCameraCollisionPlane(plane); } } else if(CameraConstraintActive) { - Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right... + Vector4 plane = new(0.9f, 0.0f, 0.361f, -9000f); // not right... UpdateCameraCollisionPlane(plane); CameraConstraintActive = false; } @@ -2958,7 +2930,7 @@ namespace OpenSim.Region.Framework.Scenes if (m_moveToSpeed > 0 && distanceToTarget <= m_moveToSpeed * m_moveToSpeed * Scene.FrameTime * Scene.FrameTime) - m_moveToSpeed = (float)Math.Sqrt(distanceToTarget) / Scene.FrameTime; + m_moveToSpeed = MathF.Sqrt(distanceToTarget) / Scene.FrameTime; try { @@ -2968,10 +2940,10 @@ namespace OpenSim.Region.Framework.Scenes // unknown forces are acting on the avatar and we need to adaptively respond // to such forces, but the following simple approach seems to works fine. - float angle = 0.5f * (float)Math.Atan2(LocalVectorToTarget3D.Y, LocalVectorToTarget3D.X); - Quaternion rot = new Quaternion(0,0, (float)Math.Sin(angle),(float)Math.Cos(angle)); + float angle = 0.5f * MathF.Atan2(LocalVectorToTarget3D.Y, LocalVectorToTarget3D.X); + Quaternion rot = new(0,0, MathF.Sin(angle),MathF.Cos(angle)); Rotation = rot; - LocalVectorToTarget3D = LocalVectorToTarget3D * Quaternion.Inverse(rot); // change to avatar coords + LocalVectorToTarget3D *= Quaternion.Inverse(rot); // change to avatar coords if(!Flying) LocalVectorToTarget3D.Z = 0; LocalVectorToTarget3D.Normalize(); @@ -3079,7 +3051,6 @@ namespace OpenSim.Region.Framework.Scenes pos.Y = regionSize.Y - 0.5f; float terrainHeight; - Scene targetScene = m_scene; terrainHeight = m_scene.GetGroundHeight(pos.X, pos.Y); // dont try to land underground @@ -3088,15 +3059,15 @@ namespace OpenSim.Region.Framework.Scenes if(terrainHeight > pos.Z) pos.Z = terrainHeight; - // m_log.DebugFormat( - // "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", - // Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); + //m_log.DebugFormat( + // "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", + // Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); bool shouldfly = true; if(IsNPC) { if (!Flying) - shouldfly = noFly ? false : (pos.Z > terrainHeight + Appearance.AvatarHeight); + shouldfly = !noFly && (pos.Z > terrainHeight + Appearance.AvatarHeight); LandAtTarget = landAtTarget && shouldfly; } else @@ -3196,7 +3167,7 @@ namespace OpenSim.Region.Framework.Scenes Quaternion standRotation = part.ParentGroup.RootPart.RotationOffset; Vector3 sitWorldPosition = part.ParentGroup.AbsolutePosition + m_pos * standRotation; - standRotation = standRotation * m_bodyRot; + standRotation *= m_bodyRot; m_bodyRot = standRotation; Quaternion standRotationZ; @@ -3360,7 +3331,7 @@ namespace OpenSim.Region.Framework.Scenes if (!part.IsRoot) { sitOrientation = part.RotationOffset * sitOrientation; - offset = offset * part.RotationOffset; + offset *= part.RotationOffset; offset += part.OffsetPosition; if (cameraAtOffset.IsZero() && cameraEyeOffset.IsZero()) @@ -3370,9 +3341,9 @@ namespace OpenSim.Region.Framework.Scenes } else { - cameraAtOffset = cameraAtOffset * part.RotationOffset; + cameraAtOffset *= part.RotationOffset; cameraAtOffset += part.OffsetPosition; - cameraEyeOffset = cameraEyeOffset * part.RotationOffset; + cameraEyeOffset *= part.RotationOffset; cameraEyeOffset += part.OffsetPosition; } } @@ -3494,7 +3465,7 @@ namespace OpenSim.Region.Framework.Scenes if (!part.IsRoot) { Orientation = part.RotationOffset * Orientation; - offset = offset * part.RotationOffset; + offset *= part.RotationOffset; offset += part.OffsetPosition; if (cameraAtOffset.IsZero() && cameraEyeOffset.IsZero()) @@ -3504,9 +3475,9 @@ namespace OpenSim.Region.Framework.Scenes } else { - cameraAtOffset = cameraAtOffset * part.RotationOffset; + cameraAtOffset *= part.RotationOffset; cameraAtOffset += part.OffsetPosition; - cameraEyeOffset = cameraEyeOffset * part.RotationOffset; + cameraEyeOffset *= part.RotationOffset; cameraEyeOffset += part.OffsetPosition; } } @@ -3560,11 +3531,11 @@ namespace OpenSim.Region.Framework.Scenes Vector3 sitTargetPos = part.SitTargetPosition; Quaternion sitTargetOrient = part.SitTargetOrientation; -// m_log.DebugFormat( -// "[SCENE PRESENCE]: Sitting {0} at sit target {1}, {2} on {3} {4}", -// Name, sitTargetPos, sitTargetOrient, part.Name, part.LocalId); + //m_log.DebugFormat( + // "[SCENE PRESENCE]: Sitting {0} at sit target {1}, {2} on {3} {4}", + // Name, sitTargetPos, sitTargetOrient, part.Name, part.LocalId); - double x, y, z, m; + float x, y, z, m; Vector3 sitOffset; Quaternion r = sitTargetOrient; @@ -3573,7 +3544,7 @@ namespace OpenSim.Region.Framework.Scenes if (LegacySitOffsets) { - double m1,m2; + float m1, m2; m1 = r.X * r.X + r.Y * r.Y; m2 = r.Z * r.Z + r.W * r.W; @@ -3588,35 +3559,35 @@ namespace OpenSim.Region.Framework.Scenes // This constant is emperically determined to be what is used in SL. // See also http://opensimulator.org/mantis/view.php?id=7096 - double offset = 0.05; + float offset = 0.05f; // Normally m will be ~ 1, but if someone passed a handcrafted quaternion // to llSitTarget with values so small that squaring them is rounded off // to zero, then m could be zero. The result of this floating point // round off error (causing us to skip this impossible normalization) // is only 5 cm. - if (m > 0.000001) + if (m > 0.000001f) { offset /= m; } - Vector3 up = new Vector3((float)x, (float)y, (float)z); - sitOffset = up * (float)offset; + Vector3 up = new (x, y, z); + sitOffset = up * offset; newPos = sitTargetPos - sitOffset + SIT_TARGET_ADJUSTMENT; } else { m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W; - if (Math.Abs(1.0 - m) > 0.000001) + if (MathF.Abs(1.0f - m) > 0.000001f) { - if(m != 0) + if(m != 0f) { - m = 1.0 / Math.Sqrt(m); - r.X *= (float)m; - r.Y *= (float)m; - r.Z *= (float)m; - r.W *= (float)m; + m = 1.0f / MathF.Sqrt(m); + r.X *= m; + r.Y *= m; + r.Z *= m; + r.W *= m; } else { @@ -3624,14 +3595,13 @@ namespace OpenSim.Region.Framework.Scenes r.Y = 0.0f; r.Z = 0.0f; r.W = 1.0f; - m = 1.0f; } } x = 2 * (r.X * r.Z + r.Y * r.W); y = 2 * (-r.X * r.W + r.Y * r.Z); z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W; - Vector3 up = new Vector3((float)x, (float)y, (float)z); + Vector3 up = new(x, y, z); sitOffset = up * Appearance.AvatarHeight * 0.02638f; newPos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT; } @@ -3642,7 +3612,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - newPos = newPos * part.RotationOffset; + newPos *= part.RotationOffset; newRot = part.RotationOffset * sitTargetOrient; } @@ -3650,7 +3620,7 @@ namespace OpenSim.Region.Framework.Scenes m_pos = newPos; Rotation = newRot; - // ParentPosition = part.AbsolutePosition; + //ParentPosition = part.AbsolutePosition; } else { @@ -4078,10 +4048,7 @@ namespace OpenSim.Region.Framework.Scenes m_newCallbackURI = null; } IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface(); - if (m_agentTransfer != null) - { - m_agentTransfer.CloseOldChildAgents(this); - } + m_agentTransfer?.CloseOldChildAgents(this); } m_log.DebugFormat("[SCENE PRESENCE({0})]: SendInitialData for {1}", m_scene.RegionInfo.RegionName, UUID); @@ -4090,8 +4057,7 @@ namespace OpenSim.Region.Framework.Scenes m_scene.SendLayerData(ControllingClient); ILandChannel landch = m_scene.LandChannel; - if (landch != null) - landch.sendClientInitialLandInfo(ControllingClient, true); + landch?.sendClientInitialLandInfo(ControllingClient, true); } m_log.DebugFormat("[SCENE PRESENCE({0})]: SendInitialData at parcel {1}", m_scene.RegionInfo.RegionName, currentParcelUUID); @@ -4117,17 +4083,16 @@ namespace OpenSim.Region.Framework.Scenes { foreach (EntityBase e in entities) { - if (e != null && e is SceneObjectGroup && !((SceneObjectGroup)e).IsAttachment) - ((SceneObjectGroup)e).SendFullAnimUpdateToClient(ControllingClient); + if (e is SceneObjectGroup sog && !sog.IsAttachment) + sog.SendFullAnimUpdateToClient(ControllingClient); } } else { foreach (EntityBase e in entities) { - if (e != null && e is SceneObjectGroup && !((SceneObjectGroup)e).IsAttachment) + if (e is SceneObjectGroup grp && !grp.IsAttachment) { - SceneObjectGroup grp = e as SceneObjectGroup; if(grp.IsViewerCachable) grp.SendUpdateProbes(ControllingClient); else @@ -4147,10 +4112,7 @@ namespace OpenSim.Region.Framework.Scenes { // Create child agents in neighbouring regions IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface(); - if (m_agentTransfer != null) - { - m_agentTransfer.EnableChildAgents(this); - } + m_agentTransfer?.EnableChildAgents(this); m_lastChildUpdatesTime = Util.EnvironmentTickCount() + 10000; m_lastChildAgentUpdatePosition = AbsolutePosition; @@ -4518,7 +4480,7 @@ namespace OpenSim.Region.Framework.Scenes m_lastChildAgentUpdateDrawDistance = DrawDistance; // m_lastChildAgentUpdateCamPosition = CameraPosition; - AgentPosition agentpos = new AgentPosition() + AgentPosition agentpos = new() { AgentID = UUID, SessionID = ControllingClient.SessionId, @@ -4668,7 +4630,7 @@ namespace OpenSim.Region.Framework.Scenes public List GetChildAgentsToClose(ulong newRegionHandle, int newRegionSizeX, int newRegionSizeY) { ulong curRegionHandle = m_scene.RegionInfo.RegionHandle; - List byebyeRegions = new List(); + List byebyeRegions = new(); if(newRegionHandle == curRegionHandle) //?? return byebyeRegions; @@ -4746,7 +4708,7 @@ namespace OpenSim.Region.Framework.Scenes public void closeAllChildAgents() { - List byebyeRegions = new List(); + List byebyeRegions = new(); List knownRegions = KnownRegionHandles; foreach (ulong handle in knownRegions) { @@ -4798,7 +4760,7 @@ namespace OpenSim.Region.Framework.Scenes m_updateAgentReceivedAfterTransferEvent.Set(); } - private static Vector3 marker = new Vector3(-1f, -1f, -1f); + private static Vector3 marker = new(-1f, -1f, -1f); /// /// This updates important decision making data about a child agent @@ -4821,7 +4783,7 @@ namespace OpenSim.Region.Framework.Scenes int shiftx = ((int)rRegionX - (int)tRegionX) * (int)Constants.RegionSize; int shifty = ((int)rRegionY - (int)tRegionY) * (int)Constants.RegionSize; - Vector3 offset = new Vector3(shiftx, shifty, 0f); + Vector3 offset = new(shiftx, shifty, 0f); DrawDistance = cAgentData.Far; @@ -4921,8 +4883,7 @@ namespace OpenSim.Region.Framework.Scenes cAgent.MotionState = (byte)Animator.currentControlState; - if (Scene.AttachmentsModule != null) - Scene.AttachmentsModule.CopyAttachments(this, cAgent); + Scene.AttachmentsModule?.CopyAttachments(this, cAgent); if(isCrossUpdate) { @@ -4986,10 +4947,7 @@ namespace OpenSim.Region.Framework.Scenes if (cAgent.ChildrenCapSeeds != null && cAgent.ChildrenCapSeeds.Count > 0) { - if (Scene.CapsModule != null) - { - Scene.CapsModule.SetChildrenSeed(UUID, cAgent.ChildrenCapSeeds); - } + Scene.CapsModule?.SetChildrenSeed(UUID, cAgent.ChildrenCapSeeds); KnownRegions = cAgent.ChildrenCapSeeds; } @@ -5014,8 +4972,7 @@ namespace OpenSim.Region.Framework.Scenes } */ - if (Scene.AttachmentsModule != null) - Scene.AttachmentsModule.CopyAttachments(cAgent, this); + Scene.AttachmentsModule?.CopyAttachments(cAgent, this); try { @@ -5028,7 +4985,7 @@ namespace OpenSim.Region.Framework.Scenes foreach (ControllerData c in cAgent.Controllers) { - ScriptControllers sc = new ScriptControllers() + ScriptControllers sc = new() { objectID = c.ObjectID, itemID = c.ItemID, @@ -5106,8 +5063,7 @@ namespace OpenSim.Region.Framework.Scenes { // we got a unknown active group so get what groups thinks about us IGroupsModule gm = m_scene.RequestModuleInterface(); - if (gm != null) - gm.SendAgentGroupDataUpdate(ControllingClient); + gm?.SendAgentGroupDataUpdate(ControllingClient); } } @@ -5194,12 +5150,7 @@ namespace OpenSim.Region.Framework.Scenes private void OutOfBoundsCall(Vector3 pos) { - //bool flying = Flying; - //RemoveFromPhysicalScene(); - - //AddToPhysicalScene(flying); - if (ControllingClient != null) - ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); + ControllingClient?.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); } /// @@ -5263,7 +5214,7 @@ namespace OpenSim.Region.Framework.Scenes if(coldata.Count > 0) { uint killerObj = 0; - SceneObjectPart part = null; + SceneObjectPart part; float rvel; // relative velocity, negative on approch foreach (uint localid in coldata.Keys) { @@ -5340,8 +5291,7 @@ namespace OpenSim.Region.Framework.Scenes } IBakedTextureModule bakedModule = m_scene.RequestModuleInterface(); - if (bakedModule != null) - bakedModule.UpdateMeshAvatar(m_uuid); + bakedModule?.UpdateMeshAvatar(m_uuid); } public int GetAttachmentsCount() @@ -5366,7 +5316,7 @@ namespace OpenSim.Region.Framework.Scenes /// Returns an empty list if there were no attachments at the point. public List GetAttachments(uint attachmentPoint) { - List attachments = new List(); + List attachments = new(); if (attachmentPoint >= 0) { @@ -5758,25 +5708,18 @@ namespace OpenSim.Region.Framework.Scenes internal void Jump(float impulseZ) { - if (PhysicsActor != null) - { - PhysicsActor.AvatarJump(impulseZ); - } + PhysicsActor?.AvatarJump(impulseZ); } internal void PushForce(Vector3 impulse) { - if (PhysicsActor != null) - { - PhysicsActor.AddForce(impulse, true); - } + PhysicsActor?.AddForce(impulse, true); } private CameraData CameraDataCache; CameraData physActor_OnPhysicsRequestingCameraData() { - if(CameraDataCache == null) - CameraDataCache = new CameraData(); + CameraDataCache ??= new CameraData(); CameraDataCache.MouseLook = m_mouseLook; CameraDataCache.CameraRotation = CameraRotation; CameraDataCache.CameraAtAxis = CameraAtAxis; @@ -5792,7 +5735,7 @@ namespace OpenSim.Region.Framework.Scenes ControllingClient.SendTakeControls(controls, false, false); ControllingClient.SendTakeControls(controls, true, false); - ScriptControllers obj = new ScriptControllers() + ScriptControllers obj = new() { ignoreControls = ScriptControlled.CONTROL_ZERO, eventControls = ScriptControlled.CONTROL_ZERO, @@ -5834,7 +5777,7 @@ namespace OpenSim.Region.Framework.Scenes } } - ControllingClient.SendTakeControls(controls, pass_on == 1 ? true : false, true); + ControllingClient.SendTakeControls(controls, pass_on == 1, true); } private void AddScriptToControlNotifications(OpenMetaverse.UUID Script_item_UUID, SceneObjectPart part, ref ScriptControllers obj) @@ -5895,10 +5838,7 @@ namespace OpenSim.Region.Framework.Scenes else { SceneObjectPart part = m_scene.GetSceneObjectPart(objectID); - if(part != null) - { - part.Inventory.RemoveScriptsPermissions(this, (int)permissions); - } + part?.Inventory.RemoveScriptsPermissions(this, (int)permissions); } } @@ -5913,7 +5853,7 @@ namespace OpenSim.Region.Framework.Scenes public void UnRegisterSeatControls(UUID obj) { - List takers = new List(); + List takers = new(); foreach (ScriptControllers c in scriptedcontrols.Values) { @@ -6138,7 +6078,7 @@ namespace OpenSim.Region.Framework.Scenes { // forcing telehubs on any tp that reachs this if ((m_teleportFlags & TeleHubTPFlags) != 0 || - (m_scene.TelehubAllowLandmarks ? false : ((m_teleportFlags & TeleportFlags.ViaLandmark) != 0 ))) + (!m_scene.TelehubAllowLandmarks && ((m_teleportFlags & TeleportFlags.ViaLandmark) != 0 ))) { ILandObject land; Vector3 teleHubPosition = telehub.AbsolutePosition; @@ -6162,7 +6102,7 @@ namespace OpenSim.Region.Framework.Scenes int index; int tries; bool selected = false; - bool validhub = false; + bool validhub; Vector3 spawnPosition; Quaternion teleHubRotation = telehub.GroupRotation; @@ -6271,11 +6211,11 @@ namespace OpenSim.Region.Framework.Scenes private bool CheckAndAdjustLandingPoint_OS(ref Vector3 pos, ref Vector3 lookat, ref bool positionChanged) { // Honor bans - if (!m_scene.TestLandRestrictions(UUID, out string reason, ref pos.X, ref pos.Y)) + if (!m_scene.TestLandRestrictions(UUID, out string _, ref pos.X, ref pos.Y)) return false; - SceneObjectGroup telehub = null; - if (!m_scene.RegionInfo.RegionSettings.TelehubObject.IsZero() && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) + SceneObjectGroup telehub; + if (!m_scene.RegionInfo.RegionSettings.TelehubObject.IsZero() && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) is not null) { if (!m_scene.RegionInfo.EstateSettings.AllowDirectTeleport) { @@ -6331,8 +6271,8 @@ namespace OpenSim.Region.Framework.Scenes if (!m_scene.RegionInfo.EstateSettings.AllowDirectTeleport) { - SceneObjectGroup telehub = null; - if (!m_scene.RegionInfo.RegionSettings.TelehubObject.IsZero() && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) + SceneObjectGroup telehub; + if (!m_scene.RegionInfo.RegionSettings.TelehubObject.IsZero() && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) is not null) { if(CheckAndAdjustTelehub(telehub, ref pos, ref positionChanged)) return true; @@ -6340,11 +6280,11 @@ namespace OpenSim.Region.Framework.Scenes } // Honor bans, actually we don't honour them - if (!m_scene.TestLandRestrictions(UUID, out string reason, ref pos.X, ref pos.Y)) + if (!m_scene.TestLandRestrictions(UUID, out string _, ref pos.X, ref pos.Y)) return false; ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y); - if (land != null) + if (land is not null) { if (Scene.DebugTeleporting) TeleportFlagsDebug(); @@ -6391,7 +6331,7 @@ namespace OpenSim.Region.Framework.Scenes [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] private DetectedObject CreateDetObject(ScenePresence av) { - DetectedObject detobj = new DetectedObject() + DetectedObject detobj = new() { keyUUID = av.UUID, nameStr = av.ControllingClient.Name, @@ -6414,7 +6354,7 @@ namespace OpenSim.Region.Framework.Scenes [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] private DetectedObject CreateDetObjectForGround() { - DetectedObject detobj = new DetectedObject() + DetectedObject detobj = new() { keyUUID = UUID.Zero, nameStr = "", @@ -6431,8 +6371,8 @@ namespace OpenSim.Region.Framework.Scenes private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List colliders) { - ColliderArgs colliderArgs = new ColliderArgs(); - List colliding = new List(); + ColliderArgs colliderArgs = new(); + List colliding = new(); foreach (uint localId in colliders) { if (localId == 0) @@ -6482,8 +6422,8 @@ namespace OpenSim.Region.Framework.Scenes { if ((dest.RootPart.ScriptEvents & ev) != 0) { - ColliderArgs LandCollidingMessage = new ColliderArgs(); - List colliding = new List(){CreateDetObjectForGround()}; + ColliderArgs LandCollidingMessage = new(); + List colliding = new(){CreateDetObjectForGround()}; LandCollidingMessage.Colliders = colliding; notify(dest.RootPart.LocalId, LandCollidingMessage); @@ -6527,13 +6467,13 @@ namespace OpenSim.Region.Framework.Scenes bool thisHitLand = false; bool startLand = false; - List thisHitColliders = new List(numberCollisions); - List endedColliders = new List(m_lastColliders.Count); - List startedColliders = new List(numberCollisions); + List thisHitColliders = new(numberCollisions); + List endedColliders = new(m_lastColliders.Count); + List startedColliders = new(numberCollisions); if(ParcelAllowThisAvatarSounds) { - List soundinfolist = new List(); + List soundinfolist = new(); CollisionForSoundInfo soundinfo; ContactPoint curcontact; @@ -6649,16 +6589,17 @@ namespace OpenSim.Region.Framework.Scenes m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); - uint i = 0u; - for (int x = 0; x <= 30 ; x++, i = 1u << x) + uint i; + for (int x = 0; x <= 30 ; x++) { i = 1u << x; - - if((m_teleportFlags & (TeleportFlags)i) == (TeleportFlags)i) + if((m_teleportFlags & (TeleportFlags)i) != 0) + { if (HG == false) m_log.InfoFormat("[SCENE PRESENCE]: Teleport Flags include {0}", ((TeleportFlags) i).ToString()); else m_log.InfoFormat("[SCENE PRESENCE]: HG Teleport Flags include {0}", ((TeleportFlags)i).ToString()); + } } m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); @@ -6687,11 +6628,11 @@ namespace OpenSim.Region.Framework.Scenes private void ParcelCrossCheck(UUID currentParcelID,UUID previusParcelID, bool currentParcelHide, bool previusParcelHide, bool oldhide, bool check) { - List killsToSendto = new List(); - List killsToSendme = new List(); - List viewsToSendto = new List(); - List viewsToSendme = new List(); - List allpresences = null; + List killsToSendto = new(); + List killsToSendme = new(); + List viewsToSendto = new(); + List viewsToSendme = new(); + List allpresences; if (IsInTransit || IsChildAgent) return; @@ -6859,8 +6800,7 @@ namespace OpenSim.Region.Framework.Scenes { if (nearRegion) { - if (Scene.AttachmentsModule != null) - Scene.AttachmentsModule.DeleteAttachmentsFromScene(this, true); + Scene.AttachmentsModule?.DeleteAttachmentsFromScene(this, true); if (!ParcelHideThisAvatar || IsViewerUIGod) return; @@ -6896,8 +6836,7 @@ namespace OpenSim.Region.Framework.Scenes p.SendKillTo(this); } - if (Scene.AttachmentsModule != null) - Scene.AttachmentsModule.DeleteAttachmentsFromScene(this, true); + Scene.AttachmentsModule?.DeleteAttachmentsFromScene(this, true); } } @@ -6905,7 +6844,7 @@ namespace OpenSim.Region.Framework.Scenes // kill with attachs root kills public void SendKillTo(ScenePresence p) { - List ids = new List(m_attachments.Count + 1); + List ids = new(m_attachments.Count + 1); foreach (SceneObjectGroup sog in m_attachments) { ids.Add(sog.RootPart.LocalId); @@ -6929,8 +6868,7 @@ namespace OpenSim.Region.Framework.Scenes { SendAvatarDataToAgentNF(p); SendAppearanceToAgent(p); - if (Animator != null) - Animator.SendAnimPackToClient(p.ControllingClient); + Animator?.SendAnimPackToClient(p.ControllingClient); SendAttachmentsToAgentNF(p); } diff --git a/OpenSim/Services/MapImageService/MapImageService.cs b/OpenSim/Services/MapImageService/MapImageService.cs index bb9fb4b918..28ece6d0c3 100644 --- a/OpenSim/Services/MapImageService/MapImageService.cs +++ b/OpenSim/Services/MapImageService/MapImageService.cs @@ -310,9 +310,10 @@ namespace OpenSim.Services.MapImageService private bool CreateTile(uint zoomLevel, int x, int y, UUID scopeID) { -// m_log.DebugFormat("[MAP IMAGE SERVICE]: Create tile for {0} {1}, zoom {2}", x, y, zoomLevel); - int prevWidth = (int)Math.Pow(2, (double)zoomLevel - 2); - int thisWidth = (int)Math.Pow(2, (double)zoomLevel - 1); + // m_log.DebugFormat("[MAP IMAGE SERVICE]: Create tile for {0} {1}, zoom {2}", x, y, zoomLevel); + zoomLevel--; + int thisWidth = 1 << ((int)zoomLevel); + int prevWidth = thisWidth >> 1; // Convert x and y to the bottom left tile for this zoom level int xIn = x - (x % prevWidth); @@ -323,13 +324,13 @@ namespace OpenSim.Services.MapImageService int yOut = y - (y % thisWidth); // Try to open the four input tiles from the previous zoom level - Bitmap inputBL = GetInputTileImage(GetFileName(zoomLevel - 1, xIn, yIn, scopeID)); - Bitmap inputBR = GetInputTileImage(GetFileName(zoomLevel - 1, xIn + prevWidth, yIn, scopeID)); - Bitmap inputTL = GetInputTileImage(GetFileName(zoomLevel - 1, xIn, yIn + prevWidth, scopeID)); - Bitmap inputTR = GetInputTileImage(GetFileName(zoomLevel - 1, xIn + prevWidth, yIn + prevWidth, scopeID)); + Bitmap inputBL = GetInputTileImage(GetFileName(zoomLevel, xIn, yIn, scopeID)); + Bitmap inputBR = GetInputTileImage(GetFileName(zoomLevel, xIn + prevWidth, yIn, scopeID)); + Bitmap inputTL = GetInputTileImage(GetFileName(zoomLevel, xIn, yIn + prevWidth, scopeID)); + Bitmap inputTR = GetInputTileImage(GetFileName(zoomLevel, xIn + prevWidth, yIn + prevWidth, scopeID)); // Open the output tile (current zoom level) - string outputFile = GetFileName(zoomLevel, xOut, yOut, scopeID); + string outputFile = GetFileName(++zoomLevel, xOut, yOut, scopeID); int ntiles = 0; Bitmap output = (Bitmap)m_WaterBitmap.Clone();