From c34ab0ee669f674b29d863267e64104b1a3437ef Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Mon, 12 Dec 2011 02:43:38 -0800 Subject: Cleaned up ScenePresence parameters for Flying, WasFlying, FlyingOld and IsColliding --- OpenSim/Region/Framework/Scenes/Scene.cs | 8 +- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 89 ++++++++++++---------- .../Scenes/Tests/ScenePresenceAnimationTests.cs | 2 +- .../Scenes/Tests/ScenePresenceAutopilotTests.cs | 2 +- .../World/NPC/Tests/NPCModuleTests.cs | 2 +- .../Shared/Api/Implementation/LSL_Api.cs | 4 +- 6 files changed, 57 insertions(+), 50 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 85debc4..4ab6fe4 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -5083,7 +5083,7 @@ namespace OpenSim.Region.Framework.Scenes presence.AbsolutePosition = presence.MoveToPositionTarget; presence.ResetMoveToTarget(); - if (presence.PhysicsActor.Flying) + if (presence.Flying) { // A horrible hack to stop the avatar dead in its tracks rather than having them overshoot // the target if flying. @@ -5091,16 +5091,16 @@ namespace OpenSim.Region.Framework.Scenes // least be able to set collision status once, rather than 5 times to give it enough // weighting so that that PhysicsActor thinks it really is colliding. for (int i = 0; i < 5; i++) - presence.PhysicsActor.IsColliding = true; + presence.IsColliding = true; if (presence.LandAtTarget) - presence.PhysicsActor.Flying = false; + presence.Flying = false; // Vector3 targetPos = presence.MoveToPositionTarget; // float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y]; // if (targetPos.Z - terrainHeight < 0.2) // { -// presence.PhysicsActor.Flying = false; +// presence.Flying = false; // } } diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index fa731a7..beff239 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -142,12 +142,27 @@ namespace OpenSim.Region.Framework.Scenes { get { return m_userFlags; } } - private bool m_flyingOld; // add for fly velocity control + + // Flying + public bool Flying + { + get { return PhysicsActor != null && PhysicsActor.Flying; } + set { PhysicsActor.Flying = value; } + } + + // add for fly velocity control + private bool FlyingOld {get; set;} public bool WasFlying { - get { return m_wasFlying; } + get; private set; + } + + public bool IsColliding + { + get { return PhysicsActor != null && PhysicsActor.IsColliding; } + // We would expect setting IsColliding to be private but it's used by a hack in Scene + set { PhysicsActor.IsColliding = value; } } - private bool m_wasFlying; // add for fly velocity control // private int m_lastColCount = -1; //KF: Look for Collision chnages // private int m_updateCount = 0; //KF: Update Anims for a while @@ -682,9 +697,9 @@ namespace OpenSim.Region.Framework.Scenes set { if(value) { - if ((PhysicsActor != null) && PhysicsActor.Flying) + if (Flying) m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY; - else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0) + else m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY; } m_inTransit = value; @@ -908,11 +923,11 @@ namespace OpenSim.Region.Framework.Scenes if (ForceFly) { - PhysicsActor.Flying = true; + Flying = true; } else if (FlyDisabled) { - PhysicsActor.Flying = false; + Flying = false; } // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying @@ -1037,10 +1052,7 @@ namespace OpenSim.Region.Framework.Scenes /// public void Teleport(Vector3 pos) { - bool isFlying = false; - if (PhysicsActor != null) - isFlying = PhysicsActor.Flying; - + bool isFlying = Flying; RemoveFromPhysicalScene(); Velocity = Vector3.Zero; AbsolutePosition = pos; @@ -1051,10 +1063,7 @@ namespace OpenSim.Region.Framework.Scenes public void TeleportWithMomentum(Vector3 pos) { - bool isFlying = false; - if (PhysicsActor != null) - isFlying = PhysicsActor.Flying; - + bool isFlying = Flying; RemoveFromPhysicalScene(); AbsolutePosition = pos; AddToPhysicalScene(isFlying); @@ -1188,8 +1197,8 @@ namespace OpenSim.Region.Framework.Scenes AbsolutePosition = pos; } - bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); - MakeRootAgent(AbsolutePosition, m_flying); + bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); + MakeRootAgent(AbsolutePosition, flying); if ((m_callbackURI != null) && !m_callbackURI.Equals("")) { @@ -1414,7 +1423,7 @@ namespace OpenSim.Region.Framework.Scenes bool DCFlagKeyPressed = false; Vector3 agent_control_v3 = Vector3.Zero; - bool oldflying = PhysicsActor.Flying; + bool oldflying = Flying; if (ForceFly) actor.Flying = true; @@ -1434,7 +1443,7 @@ namespace OpenSim.Region.Framework.Scenes // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying // this prevents 'jumping' in inappropriate situations. - if ((m_mouseLook && !PhysicsActor.Flying) || (m_leftButtonDown && !PhysicsActor.Flying)) + if (!Flying && (m_mouseLook || m_leftButtonDown)) dirVectors = GetWalkDirectionVectors(); else dirVectors = Dir_Vectors; @@ -1521,7 +1530,7 @@ namespace OpenSim.Region.Framework.Scenes // with something with the down arrow pressed. // Only do this if we're flying - if (PhysicsActor != null && PhysicsActor.Flying && !ForceFly) + if (Flying && !ForceFly) { // Landing detection code @@ -1529,7 +1538,7 @@ namespace OpenSim.Region.Framework.Scenes bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); - if (PhysicsActor.Flying && PhysicsActor.IsColliding && controlland) + if (Flying && IsColliding && controlland) { // nesting this check because LengthSquared() is expensive and we don't // want to do it every step when flying. @@ -1742,9 +1751,9 @@ namespace OpenSim.Region.Framework.Scenes Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); if (noFly) - PhysicsActor.Flying = false; + Flying = false; else if (pos.Z > terrainHeight) - PhysicsActor.Flying = true; + Flying = true; LandAtTarget = landAtTarget; MovingToTarget = true; @@ -2307,42 +2316,42 @@ namespace OpenSim.Region.Framework.Scenes Vector3 direc = vec * Rotation; direc.Normalize(); - if (PhysicsActor.Flying != m_flyingOld) // add for fly velocity control + if (Flying != FlyingOld) // add for fly velocity control { - m_flyingOld = PhysicsActor.Flying; // add for fly velocity control - if (!PhysicsActor.Flying) - m_wasFlying = true; // add for fly velocity control + FlyingOld = Flying; // add for fly velocity control + if (!Flying) + WasFlying = true; // add for fly velocity control } - if (PhysicsActor.IsColliding == true) - m_wasFlying = false; // add for fly velocity control + if (IsColliding) + WasFlying = false; // add for fly velocity control - if ((vec.Z == 0f) && !PhysicsActor.Flying) + if ((vec.Z == 0f) && !Flying) direc.Z = 0f; // Prevent camera WASD up. direc *= 0.03f * 128f * SpeedModifier; if (PhysicsActor != null) { - if (PhysicsActor.Flying) + if (Flying) { direc *= 4.0f; //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); //if (controlland) // m_log.Info("[AGENT]: landCommand"); - //if (PhysicsActor.IsColliding) + //if (IsColliding) // m_log.Info("[AGENT]: colliding"); - //if (PhysicsActor.Flying && PhysicsActor.IsColliding && controlland) + //if (Flying && IsColliding && controlland) //{ // StopFlying(); // m_log.Info("[AGENT]: Stop Flying"); //} } - if (Animator.Falling && m_wasFlying) // if falling from flying, disable motion add + if (Animator.Falling && WasFlying) // if falling from flying, disable motion add { direc *= 0.0f; } - else if (!PhysicsActor.Flying && PhysicsActor.IsColliding) + else if (!Flying && IsColliding) { if (direc.Z > 2.0f) { @@ -2809,7 +2818,7 @@ namespace OpenSim.Region.Framework.Scenes { if (m_requestedSitTargetUUID == UUID.Zero) { - bool isFlying = PhysicsActor.Flying; + bool isFlying = Flying; RemoveFromPhysicalScene(); Vector3 pos = AbsolutePosition; @@ -2836,7 +2845,7 @@ namespace OpenSim.Region.Framework.Scenes { if (m_requestedSitTargetUUID == UUID.Zero) { - bool isFlying = PhysicsActor.Flying; + bool isFlying = Flying; RemoveFromPhysicalScene(); Vector3 pos = AbsolutePosition; @@ -2886,7 +2895,7 @@ namespace OpenSim.Region.Framework.Scenes { try { - return m_scene.CrossAgentToNewRegion(this, PhysicsActor.Flying); + return m_scene.CrossAgentToNewRegion(this, Flying); } catch { @@ -3162,7 +3171,7 @@ namespace OpenSim.Region.Framework.Scenes Appearance = new AvatarAppearance(cAgent.Appearance); if (PhysicsActor != null) { - bool isFlying = PhysicsActor.Flying; + bool isFlying = Flying; RemoveFromPhysicalScene(); AddToPhysicalScene(isFlying); } @@ -3265,7 +3274,7 @@ namespace OpenSim.Region.Framework.Scenes private void OutOfBoundsCall(Vector3 pos) { - //bool flying = PhysicsActor.Flying; + //bool flying = Flying; //RemoveFromPhysicalScene(); //AddToPhysicalScene(flying); diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs index 4a0533c..89f8007 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAnimationTests.cs @@ -61,7 +61,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestScene scene = SceneHelpers.SetupScene(); ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); - sp.PhysicsActor.Flying = true; + sp.Flying = true; sp.PhysicsCollisionUpdate(new CollisionEventUpdate()); Assert.That(sp.Animator.CurrentMovementAnimation, Is.EqualTo("HOVER")); diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs index 64c36ff..442cb8b 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs @@ -79,7 +79,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests // Vector3 startPos = new Vector3(128, 128, 30); // For now, we'll make the scene presence fly to simplify this test, but this needs to change. - sp.PhysicsActor.Flying = true; + sp.Flying = true; m_scene.Update(); Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index dce0ec8..9c66b25 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -175,7 +175,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); // For now, we'll make the scene presence fly to simplify this test, but this needs to change. - npc.PhysicsActor.Flying = true; + npc.Flying = true; scene.Update(); Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 6d067b0..443e7a5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5573,9 +5573,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant // and don't collide when walking downhill, which instantly registers as in-air, briefly. should // there be some minimum non-collision threshold time before claiming the avatar is in-air? - if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && - agent.PhysicsActor != null && - !agent.PhysicsActor.IsColliding) + if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding ) { flags |= ScriptBaseClass.AGENT_IN_AIR; } -- cgit v1.1