aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2013-11-30 01:44:30 +0000
committerJustin Clark-Casey (justincc)2013-11-30 01:44:30 +0000
commit4cde02a2a36dd7f6afce49e5e6db78af021ab14b (patch)
tree531062a5641e071376d01f99a6b91df63ccd3bce /OpenSim
parentRemove nudgehack from SP.HandleAgentUpdate by making MovementFlag a uint rath... (diff)
downloadopensim-SC_OLD-4cde02a2a36dd7f6afce49e5e6db78af021ab14b.zip
opensim-SC_OLD-4cde02a2a36dd7f6afce49e5e6db78af021ab14b.tar.gz
opensim-SC_OLD-4cde02a2a36dd7f6afce49e5e6db78af021ab14b.tar.bz2
opensim-SC_OLD-4cde02a2a36dd7f6afce49e5e6db78af021ab14b.tar.xz
Implement most effects of AGENT_CONTROL_STOP
AGENT_CONTROL_STOP is specified to SP.HandleAgentUpdate if the user holds down the space bar on a viewer. For a stopped avatar, this prevents fly or walk/run (though not rotate) until released. For a walking/running avatar, this reduces movement to half speed. For a flying avatar, this stops the avatar. These are observed behaviours on the LL grid - there was no previous OpenSimulator implementation This commit introduces an optional parameter to SP.AddNewMovement(), which means that it will no longer compile on .NET 3.5 or earlier versions of Mono than 2.8 Currently, this does not work for jumping, and if used whilst flying the avatar continues the fly animation even though it does not move
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs17
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs131
2 files changed, 104 insertions, 44 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index 3b5a5bd..5beee73 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -403,11 +403,18 @@ namespace OpenSim.Region.Framework.Scenes.Animation
403 Falling = false; 403 Falling = false;
404 // Walking / crouchwalking / running 404 // Walking / crouchwalking / running
405 if (move.Z < 0f) 405 if (move.Z < 0f)
406 {
406 return "CROUCHWALK"; 407 return "CROUCHWALK";
407 else if (m_scenePresence.SetAlwaysRun) 408 }
408 return "RUN"; 409 // We need to prevent these animations if the user tries to make their avatar walk or run whilst
409 else 410 // specifying AGENT_CONTROL_STOP (pressing down space on viewers).
410 return "WALK"; 411 else if (!m_scenePresence.AgentControlStopActive)
412 {
413 if (m_scenePresence.SetAlwaysRun)
414 return "RUN";
415 else
416 return "WALK";
417 }
411 } 418 }
412 else if (!m_jumping) 419 else if (!m_jumping)
413 { 420 {
@@ -435,6 +442,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
435 /// <returns>'true' if the animation was changed</returns> 442 /// <returns>'true' if the animation was changed</returns>
436 public bool UpdateMovementAnimations() 443 public bool UpdateMovementAnimations()
437 { 444 {
445// m_log.DebugFormat("[SCENE PRESENCE ANIMATOR]: Updating movement animations for {0}", m_scenePresence.Name);
446
438 bool ret = false; 447 bool ret = false;
439 lock (m_animations) 448 lock (m_animations)
440 { 449 {
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index a34c44c..7a6a334 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -355,6 +355,11 @@ namespace OpenSim.Region.Framework.Scenes
355 355
356 private bool m_updateflag; 356 private bool m_updateflag;
357 357
358 /// <summary>
359 /// Is the agent stop control flag currently active?
360 /// </summary>
361 public bool AgentControlStopActive { get; private set; }
362
358 public bool Updated 363 public bool Updated
359 { 364 {
360 set { m_updateflag = value; } 365 set { m_updateflag = value; }
@@ -768,6 +773,14 @@ namespace OpenSim.Region.Framework.Scenes
768 set { m_speedModifier = value; } 773 set { m_speedModifier = value; }
769 } 774 }
770 775
776 /// <summary>
777 /// Modifier for agent movement if we get an AGENT_CONTROL_STOP whilst walking or running
778 /// </summary>
779 /// <remarks>
780 /// AGENT_CONTRL_STOP comes about if user holds down space key on viewers.
781 /// </remarks>
782 private float AgentControlStopSlowWhilstMoving = 0.5f;
783
771 private bool m_forceFly; 784 private bool m_forceFly;
772 785
773 public bool ForceFly 786 public bool ForceFly
@@ -1634,7 +1647,6 @@ namespace OpenSim.Region.Framework.Scenes
1634 if ((oldState & (uint)AgentState.Editing) != 0 && State == (uint)AgentState.None) 1647 if ((oldState & (uint)AgentState.Editing) != 0 && State == (uint)AgentState.None)
1635 ControllingClient.SendAgentTerseUpdate(this); 1648 ControllingClient.SendAgentTerseUpdate(this);
1636 1649
1637
1638 PhysicsActor actor = PhysicsActor; 1650 PhysicsActor actor = PhysicsActor;
1639 if (actor == null) 1651 if (actor == null)
1640 { 1652 {
@@ -1712,7 +1724,7 @@ namespace OpenSim.Region.Framework.Scenes
1712 // Why did I get this? 1724 // Why did I get this?
1713 } 1725 }
1714 1726
1715 if ((MovementFlag & (uint)DCF) == 0) 1727 if (((MovementFlag & (uint)DCF) == 0) & !AgentControlStopActive)
1716 { 1728 {
1717 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with {1}", Name, DCF); 1729 //m_log.DebugFormat("[SCENE PRESENCE]: Updating MovementFlag for {0} with {1}", Name, DCF);
1718 MovementFlag += (uint)DCF; 1730 MovementFlag += (uint)DCF;
@@ -1744,6 +1756,13 @@ namespace OpenSim.Region.Framework.Scenes
1744 i++; 1756 i++;
1745 } 1757 }
1746 1758
1759 // Detect AGENT_CONTROL_STOP state changes
1760 if (AgentControlStopActive != ((flags & AgentManager.ControlFlags.AGENT_CONTROL_STOP) != 0))
1761 {
1762 AgentControlStopActive = !AgentControlStopActive;
1763 update_movementflag = true;
1764 }
1765
1747 if (MovingToTarget) 1766 if (MovingToTarget)
1748 { 1767 {
1749 // If the user has pressed a key then we want to cancel any move to target. 1768 // If the user has pressed a key then we want to cancel any move to target.
@@ -1769,53 +1788,79 @@ namespace OpenSim.Region.Framework.Scenes
1769 // Only do this if we're flying 1788 // Only do this if we're flying
1770 if (Flying && !ForceFly) 1789 if (Flying && !ForceFly)
1771 { 1790 {
1772 // Landing detection code 1791 // Need to stop in mid air if user holds down AGENT_CONTROL_STOP
1773 1792 if (AgentControlStopActive)
1774 // Are the landing controls requirements filled?
1775 bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
1776 ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
1777
1778 //m_log.Debug("[CONTROL]: " +flags);
1779 // Applies a satisfying roll effect to the avatar when flying.
1780 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) != 0 && (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
1781 { 1793 {
1782 ApplyFlyingRoll( 1794 agent_control_v3 = Vector3.Zero;
1783 FLY_ROLL_RADIANS_PER_UPDATE,
1784 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0,
1785 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0);
1786 }
1787 else if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) != 0 &&
1788 (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
1789 {
1790 ApplyFlyingRoll(
1791 -FLY_ROLL_RADIANS_PER_UPDATE,
1792 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0,
1793 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0);
1794 } 1795 }
1795 else 1796 else
1796 { 1797 {
1797 if (m_AngularVelocity.Z != 0) 1798 // Landing detection code
1798 m_AngularVelocity.Z += CalculateFlyingRollResetToZero(FLY_ROLL_RESET_RADIANS_PER_UPDATE);
1799 }
1800 1799
1801 if (Flying && IsColliding && controlland) 1800 // Are the landing controls requirements filled?
1802 { 1801 bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
1803 // nesting this check because LengthSquared() is expensive and we don't 1802 ((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
1804 // want to do it every step when flying. 1803
1805 if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX)) 1804 //m_log.Debug("[CONTROL]: " +flags);
1806 StopFlying(); 1805 // Applies a satisfying roll effect to the avatar when flying.
1806 if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) != 0 && (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
1807 {
1808 ApplyFlyingRoll(
1809 FLY_ROLL_RADIANS_PER_UPDATE,
1810 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0,
1811 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0);
1812 }
1813 else if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) != 0 &&
1814 (flags & AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
1815 {
1816 ApplyFlyingRoll(
1817 -FLY_ROLL_RADIANS_PER_UPDATE,
1818 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0,
1819 (flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0);
1820 }
1821 else
1822 {
1823 if (m_AngularVelocity.Z != 0)
1824 m_AngularVelocity.Z += CalculateFlyingRollResetToZero(FLY_ROLL_RESET_RADIANS_PER_UPDATE);
1825 }
1826
1827 if (Flying && IsColliding && controlland)
1828 {
1829 // nesting this check because LengthSquared() is expensive and we don't
1830 // want to do it every step when flying.
1831 if ((Velocity.LengthSquared() <= LAND_VELOCITYMAG_MAX))
1832 StopFlying();
1833 }
1807 } 1834 }
1808 } 1835 }
1809 1836
1837// m_log.DebugFormat("[SCENE PRESENCE]: MovementFlag {0} for {1}", MovementFlag, Name);
1838
1810 // If the agent update does move the avatar, then calculate the force ready for the velocity update, 1839 // If the agent update does move the avatar, then calculate the force ready for the velocity update,
1811 // which occurs later in the main scene loop 1840 // which occurs later in the main scene loop
1812 if (update_movementflag || (update_rotation && DCFlagKeyPressed)) 1841 // We also need to update if the user rotates their avatar whilst it is slow walking/running (if they
1842 // held down AGENT_CONTROL_STOP whilst normal walking/running). However, we do not want to update
1843 // if the user rotated whilst holding down AGENT_CONTROL_STOP when already still (which locks the
1844 // avatar location in place).
1845 if (update_movementflag
1846 || (update_rotation && DCFlagKeyPressed && (!AgentControlStopActive || MovementFlag != 0)))
1813 { 1847 {
1814// m_log.DebugFormat( 1848// if (update_movementflag || !AgentControlStopActive || MovementFlag != 0)
1815// "[SCENE PRESENCE]: In {0} adding velocity of {1} to {2}, umf = {3}, ur = {4}", 1849// {
1816// m_scene.RegionInfo.RegionName, agent_control_v3, Name, update_movementflag, update_rotation); 1850// m_log.DebugFormat(
1851// "[SCENE PRESENCE]: In {0} adding velocity of {1} to {2}, umf = {3}, mf = {4}, ur = {5}",
1852// m_scene.RegionInfo.RegionName, agent_control_v3, Name,
1853// update_movementflag, MovementFlag, update_rotation);
1854
1855 float speedModifier;
1856
1857 if (AgentControlStopActive)
1858 speedModifier = 0.5f;
1859 else
1860 speedModifier = 1;
1817 1861
1818 AddNewMovement(agent_control_v3); 1862 AddNewMovement(agent_control_v3, speedModifier);
1863// }
1819 } 1864 }
1820// else 1865// else
1821// { 1866// {
@@ -1828,7 +1873,10 @@ namespace OpenSim.Region.Framework.Scenes
1828// } 1873// }
1829 1874
1830 if (update_movementflag && ParentID == 0) 1875 if (update_movementflag && ParentID == 0)
1876 {
1877// m_log.DebugFormat("[SCENE PRESENCE]: Updating movement animations for {0}", Name);
1831 Animator.UpdateMovementAnimations(); 1878 Animator.UpdateMovementAnimations();
1879 }
1832 1880
1833 SendControlsToScripts(flagsForScripts); 1881 SendControlsToScripts(flagsForScripts);
1834 } 1882 }
@@ -2711,10 +2759,13 @@ namespace OpenSim.Region.Framework.Scenes
2711 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2759 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2712 /// </summary> 2760 /// </summary>
2713 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2761 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2714 public void AddNewMovement(Vector3 vec) 2762 /// <param name="thisAddSpeedModifier">
2763 /// Optional additional speed modifier for this particular add. Default is 1</param>
2764 public void AddNewMovement(Vector3 vec, float thisAddSpeedModifier = 1)
2715 { 2765 {
2716// m_log.DebugFormat( 2766// m_log.DebugFormat(
2717// "[SCENE PRESENCE]: Adding new movement {0} with rotation {1} for {2}", vec, Rotation, Name); 2767// "[SCENE PRESENCE]: Adding new movement {0} with rotation {1}, thisAddSpeedModifier {2} for {3}",
2768// vec, Rotation, thisAddSpeedModifier, Name);
2718 2769
2719 Vector3 direc = vec * Rotation; 2770 Vector3 direc = vec * Rotation;
2720 direc.Normalize(); 2771 direc.Normalize();
@@ -2732,7 +2783,7 @@ namespace OpenSim.Region.Framework.Scenes
2732 if ((vec.Z == 0f) && !Flying) 2783 if ((vec.Z == 0f) && !Flying)
2733 direc.Z = 0f; // Prevent camera WASD up. 2784 direc.Z = 0f; // Prevent camera WASD up.
2734 2785
2735 direc *= 0.03f * 128f * SpeedModifier; 2786 direc *= 0.03f * 128f * SpeedModifier * thisAddSpeedModifier;
2736 2787
2737// m_log.DebugFormat("[SCENE PRESENCE]: Force to apply before modification was {0} for {1}", direc, Name); 2788// m_log.DebugFormat("[SCENE PRESENCE]: Force to apply before modification was {0} for {1}", direc, Name);
2738 2789