diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 521 |
1 files changed, 80 insertions, 441 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 08c144a..1dedcf1 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -35,6 +35,7 @@ using OpenSim.Framework; | |||
35 | using OpenSim.Framework.Client; | 35 | using OpenSim.Framework.Client; |
36 | using OpenSim.Framework.Communications.Cache; | 36 | using OpenSim.Framework.Communications.Cache; |
37 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes.Animation; | ||
38 | using OpenSim.Region.Framework.Scenes.Types; | 39 | using OpenSim.Region.Framework.Scenes.Types; |
39 | using OpenSim.Region.Physics.Manager; | 40 | using OpenSim.Region.Physics.Manager; |
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 41 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
@@ -79,6 +80,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
79 | // private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); | 80 | // private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); |
80 | private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); | 81 | private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); |
81 | private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); | 82 | private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); |
83 | |||
82 | /// <summary> | 84 | /// <summary> |
83 | /// Experimentally determined "fudge factor" to make sit-target positions | 85 | /// Experimentally determined "fudge factor" to make sit-target positions |
84 | /// the same as in SecondLife. Fudge factor was tested for 36 different | 86 | /// the same as in SecondLife. Fudge factor was tested for 36 different |
@@ -93,7 +95,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
93 | 95 | ||
94 | private ISceneViewer m_sceneViewer; | 96 | private ISceneViewer m_sceneViewer; |
95 | 97 | ||
96 | private AnimationSet m_animations = new AnimationSet(); | 98 | /// <value> |
99 | /// The animator for this avatar | ||
100 | /// </value> | ||
101 | public ScenePresenceAnimator Animator | ||
102 | { | ||
103 | get { return m_animator; } | ||
104 | } | ||
105 | protected ScenePresenceAnimator m_animator; | ||
106 | |||
97 | private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>(); | 107 | private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>(); |
98 | private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; | 108 | private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO; |
99 | private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; | 109 | private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO; |
@@ -134,12 +144,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
134 | private int m_perfMonMS; | 144 | private int m_perfMonMS; |
135 | 145 | ||
136 | private bool m_setAlwaysRun; | 146 | private bool m_setAlwaysRun; |
137 | 147 | ||
138 | private string m_movementAnimation = "DEFAULT"; | ||
139 | private int m_animTickFall; | ||
140 | private int m_animTickJump; | ||
141 | private bool m_useFlySlow; | ||
142 | private bool m_usePreJump; | ||
143 | private bool m_forceFly; | 148 | private bool m_forceFly; |
144 | private bool m_flyDisabled; | 149 | private bool m_flyDisabled; |
145 | 150 | ||
@@ -227,7 +232,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
227 | DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, | 232 | DIR_CONTROL_FLAG_DOWN = AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG, |
228 | DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG | 233 | DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG |
229 | } | 234 | } |
230 | |||
231 | 235 | ||
232 | /// <summary> | 236 | /// <summary> |
233 | /// Position at which a significant movement was made | 237 | /// Position at which a significant movement was made |
@@ -238,7 +242,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
238 | string m_callbackURI; | 242 | string m_callbackURI; |
239 | ulong m_rootRegionHandle; | 243 | ulong m_rootRegionHandle; |
240 | 244 | ||
241 | private IScriptModule[] m_scriptEngines; | 245 | /// <value> |
246 | /// Script engines present in the scene | ||
247 | /// </value> | ||
248 | private IScriptModule[] m_scriptEngines; | ||
242 | 249 | ||
243 | #region Properties | 250 | #region Properties |
244 | 251 | ||
@@ -586,11 +593,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
586 | } | 593 | } |
587 | } | 594 | } |
588 | 595 | ||
589 | public AnimationSet Animations | ||
590 | { | ||
591 | get { return m_animations; } | ||
592 | } | ||
593 | |||
594 | private bool m_inTransit; | 596 | private bool m_inTransit; |
595 | private bool m_mouseLook; | 597 | private bool m_mouseLook; |
596 | private bool m_leftButtonDown; | 598 | private bool m_leftButtonDown; |
@@ -625,6 +627,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
625 | 627 | ||
626 | private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) | 628 | private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) |
627 | { | 629 | { |
630 | m_animator = new ScenePresenceAnimator(this); | ||
628 | m_sendCourseLocationsMethod = SendCoarseLocationsDefault; | 631 | m_sendCourseLocationsMethod = SendCoarseLocationsDefault; |
629 | CreateSceneViewer(); | 632 | CreateSceneViewer(); |
630 | m_rootRegionHandle = reginfo.RegionHandle; | 633 | m_rootRegionHandle = reginfo.RegionHandle; |
@@ -637,15 +640,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
637 | m_regionInfo = reginfo; | 640 | m_regionInfo = reginfo; |
638 | m_localId = m_scene.AllocateLocalId(); | 641 | m_localId = m_scene.AllocateLocalId(); |
639 | 642 | ||
640 | m_useFlySlow = m_scene.m_useFlySlow; | ||
641 | m_usePreJump = m_scene.m_usePreJump; | ||
642 | |||
643 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); | 643 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); |
644 | if (gm != null) | 644 | if (gm != null) |
645 | m_grouptitle = gm.GetGroupTitle(m_uuid); | 645 | m_grouptitle = gm.GetGroupTitle(m_uuid); |
646 | 646 | ||
647 | m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); | 647 | m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); |
648 | 648 | ||
649 | AbsolutePosition = posLastSignificantMove = m_CameraCenter = | 649 | AbsolutePosition = posLastSignificantMove = m_CameraCenter = |
650 | m_lastCameraCenter = m_controllingClient.StartPos; | 650 | m_lastCameraCenter = m_controllingClient.StartPos; |
651 | 651 | ||
@@ -656,7 +656,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
656 | 656 | ||
657 | AdjustKnownSeeds(); | 657 | AdjustKnownSeeds(); |
658 | 658 | ||
659 | TrySetMovementAnimation("STAND"); // TODO: I think, this won't send anything, as we are still a child here... | 659 | // TODO: I think, this won't send anything, as we are still a child here... |
660 | Animator.TrySetMovementAnimation("STAND"); | ||
660 | 661 | ||
661 | // we created a new ScenePresence (a new child agent) in a fresh region. | 662 | // we created a new ScenePresence (a new child agent) in a fresh region. |
662 | // Request info about all the (root) agents in this region | 663 | // Request info about all the (root) agents in this region |
@@ -665,21 +666,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
665 | 666 | ||
666 | RegisterToEvents(); | 667 | RegisterToEvents(); |
667 | SetDirectionVectors(); | 668 | SetDirectionVectors(); |
668 | |||
669 | } | 669 | } |
670 | 670 | ||
671 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, | 671 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, |
672 | AvatarWearable[] wearables) | 672 | AvatarWearable[] wearables) |
673 | : this(client, world, reginfo) | 673 | : this(client, world, reginfo) |
674 | { | 674 | { |
675 | CreateSceneViewer(); | 675 | m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams); |
676 | m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams); | ||
677 | } | 676 | } |
678 | 677 | ||
679 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) | 678 | public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) |
680 | : this(client, world, reginfo) | 679 | : this(client, world, reginfo) |
681 | { | 680 | { |
682 | CreateSceneViewer(); | ||
683 | m_appearance = appearance; | 681 | m_appearance = appearance; |
684 | } | 682 | } |
685 | 683 | ||
@@ -857,7 +855,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
857 | // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying | 855 | // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying |
858 | // avatar to return to the standing position in mid-air. On login it looks like this is being sent | 856 | // avatar to return to the standing position in mid-air. On login it looks like this is being sent |
859 | // elsewhere anyway | 857 | // elsewhere anyway |
860 | //SendAnimPack(); | 858 | // Animator.SendAnimPack(); |
861 | 859 | ||
862 | m_scene.SwapRootAgentCount(false); | 860 | m_scene.SwapRootAgentCount(false); |
863 | 861 | ||
@@ -879,7 +877,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
879 | ScenePresence presence = animAgents[i]; | 877 | ScenePresence presence = animAgents[i]; |
880 | 878 | ||
881 | if (presence != this) | 879 | if (presence != this) |
882 | presence.SendAnimPackToClient(ControllingClient); | 880 | presence.Animator.SendAnimPackToClient(ControllingClient); |
883 | } | 881 | } |
884 | 882 | ||
885 | m_scene.EventManager.TriggerOnMakeRootAgent(this); | 883 | m_scene.EventManager.TriggerOnMakeRootAgent(this); |
@@ -894,7 +892,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
894 | /// </summary> | 892 | /// </summary> |
895 | public void MakeChildAgent() | 893 | public void MakeChildAgent() |
896 | { | 894 | { |
897 | m_animations.Clear(); | 895 | Animator.ResetAnimations(); |
898 | 896 | ||
899 | // m_log.DebugFormat( | 897 | // m_log.DebugFormat( |
900 | // "[SCENEPRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", | 898 | // "[SCENEPRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", |
@@ -995,7 +993,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
995 | AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); | 993 | AbsolutePosition = AbsolutePosition + new Vector3(0f, 0f, (1.56f / 6f)); |
996 | } | 994 | } |
997 | 995 | ||
998 | TrySetMovementAnimation("LAND"); | 996 | Animator.TrySetMovementAnimation("LAND"); |
999 | SendFullUpdateToAllClients(); | 997 | SendFullUpdateToAllClients(); |
1000 | } | 998 | } |
1001 | 999 | ||
@@ -1247,7 +1245,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1247 | // TODO: This doesn't prevent the user from walking yet. | 1245 | // TODO: This doesn't prevent the user from walking yet. |
1248 | // Setting parent ID would fix this, if we knew what value | 1246 | // Setting parent ID would fix this, if we knew what value |
1249 | // to use. Or we could add a m_isSitting variable. | 1247 | // to use. Or we could add a m_isSitting variable. |
1250 | TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); | 1248 | Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); |
1251 | } | 1249 | } |
1252 | 1250 | ||
1253 | // In the future, these values might need to go global. | 1251 | // In the future, these values might need to go global. |
@@ -1453,7 +1451,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1453 | AddNewMovement(agent_control_v3, q); | 1451 | AddNewMovement(agent_control_v3, q); |
1454 | 1452 | ||
1455 | if (update_movementflag) | 1453 | if (update_movementflag) |
1456 | UpdateMovementAnimations(); | 1454 | Animator.UpdateMovementAnimations(); |
1457 | } | 1455 | } |
1458 | } | 1456 | } |
1459 | 1457 | ||
@@ -1561,7 +1559,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1561 | } | 1559 | } |
1562 | } | 1560 | } |
1563 | /// <summary> | 1561 | /// <summary> |
1564 | /// Perform the logic necessary to stand the client up. This method also executes | 1562 | /// Perform the logic necessary to stand the avatar up. This method also executes |
1565 | /// the stand animation. | 1563 | /// the stand animation. |
1566 | /// </summary> | 1564 | /// </summary> |
1567 | public void StandUp() | 1565 | public void StandUp() |
@@ -1611,7 +1609,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1611 | } | 1609 | } |
1612 | } | 1610 | } |
1613 | 1611 | ||
1614 | TrySetMovementAnimation("STAND"); | 1612 | Animator.TrySetMovementAnimation("STAND"); |
1615 | } | 1613 | } |
1616 | 1614 | ||
1617 | private SceneObjectPart FindNextAvailableSitTarget(UUID targetID) | 1615 | private SceneObjectPart FindNextAvailableSitTarget(UUID targetID) |
@@ -1850,7 +1848,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1850 | Velocity = Vector3.Zero; | 1848 | Velocity = Vector3.Zero; |
1851 | RemoveFromPhysicalScene(); | 1849 | RemoveFromPhysicalScene(); |
1852 | 1850 | ||
1853 | TrySetMovementAnimation(sitAnimation); | 1851 | Animator.TrySetMovementAnimation(sitAnimation); |
1854 | SendFullUpdateToAllClients(); | 1852 | SendFullUpdateToAllClients(); |
1855 | // This may seem stupid, but Our Full updates don't send avatar rotation :P | 1853 | // This may seem stupid, but Our Full updates don't send avatar rotation :P |
1856 | // So we're also sending a terse update (which has avatar rotation) | 1854 | // So we're also sending a terse update (which has avatar rotation) |
@@ -1870,352 +1868,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
1870 | PhysicsActor.SetAlwaysRun = pSetAlwaysRun; | 1868 | PhysicsActor.SetAlwaysRun = pSetAlwaysRun; |
1871 | } | 1869 | } |
1872 | } | 1870 | } |
1873 | public BinBVHAnimation GenerateRandomAnimation() | ||
1874 | { | ||
1875 | int rnditerations = 3; | ||
1876 | BinBVHAnimation anim = new BinBVHAnimation(); | ||
1877 | List<string> parts = new List<string>(); | ||
1878 | parts.Add("mPelvis");parts.Add("mHead");parts.Add("mTorso"); | ||
1879 | parts.Add("mHipLeft");parts.Add("mHipRight");parts.Add("mHipLeft");parts.Add("mKneeLeft"); | ||
1880 | parts.Add("mKneeRight");parts.Add("mCollarLeft");parts.Add("mCollarRight");parts.Add("mNeck"); | ||
1881 | parts.Add("mElbowLeft");parts.Add("mElbowRight");parts.Add("mWristLeft");parts.Add("mWristRight"); | ||
1882 | parts.Add("mShoulderLeft");parts.Add("mShoulderRight");parts.Add("mAnkleLeft");parts.Add("mAnkleRight"); | ||
1883 | parts.Add("mEyeRight");parts.Add("mChest");parts.Add("mToeLeft");parts.Add("mToeRight"); | ||
1884 | parts.Add("mFootLeft");parts.Add("mFootRight");parts.Add("mEyeLeft"); | ||
1885 | anim.HandPose = 1; | ||
1886 | anim.InPoint = 0; | ||
1887 | anim.OutPoint = (rnditerations * .10f); | ||
1888 | anim.Priority = 7; | ||
1889 | anim.Loop = false; | ||
1890 | anim.Length = (rnditerations * .10f); | ||
1891 | anim.ExpressionName = "afraid"; | ||
1892 | anim.EaseInTime = 0; | ||
1893 | anim.EaseOutTime = 0; | ||
1894 | |||
1895 | string[] strjoints = parts.ToArray(); | ||
1896 | anim.Joints = new binBVHJoint[strjoints.Length]; | ||
1897 | for (int j = 0; j < strjoints.Length; j++) | ||
1898 | { | ||
1899 | anim.Joints[j] = new binBVHJoint(); | ||
1900 | anim.Joints[j].Name = strjoints[j]; | ||
1901 | anim.Joints[j].Priority = 7; | ||
1902 | anim.Joints[j].positionkeys = new binBVHJointKey[rnditerations]; | ||
1903 | anim.Joints[j].rotationkeys = new binBVHJointKey[rnditerations]; | ||
1904 | Random rnd = new Random(); | ||
1905 | for (int i = 0; i < rnditerations; i++) | ||
1906 | { | ||
1907 | anim.Joints[j].rotationkeys[i] = new binBVHJointKey(); | ||
1908 | anim.Joints[j].rotationkeys[i].time = (i*.10f); | ||
1909 | anim.Joints[j].rotationkeys[i].key_element.X = ((float) rnd.NextDouble()*2 - 1); | ||
1910 | anim.Joints[j].rotationkeys[i].key_element.Y = ((float) rnd.NextDouble()*2 - 1); | ||
1911 | anim.Joints[j].rotationkeys[i].key_element.Z = ((float) rnd.NextDouble()*2 - 1); | ||
1912 | anim.Joints[j].positionkeys[i] = new binBVHJointKey(); | ||
1913 | anim.Joints[j].positionkeys[i].time = (i*.10f); | ||
1914 | anim.Joints[j].positionkeys[i].key_element.X = 0; | ||
1915 | anim.Joints[j].positionkeys[i].key_element.Y = 0; | ||
1916 | anim.Joints[j].positionkeys[i].key_element.Z = 0; | ||
1917 | } | ||
1918 | } | ||
1919 | |||
1920 | |||
1921 | AssetBase Animasset = new AssetBase(UUID.Random(), "Random Animation", (sbyte)AssetType.Animation); | ||
1922 | Animasset.Data = anim.ToBytes(); | ||
1923 | Animasset.Temporary = true; | ||
1924 | Animasset.Local = true; | ||
1925 | Animasset.Description = "dance"; | ||
1926 | //BinBVHAnimation bbvhanim = new BinBVHAnimation(Animasset.Data); | ||
1927 | |||
1928 | |||
1929 | m_scene.AssetService.Store(Animasset); | ||
1930 | AddAnimation(Animasset.FullID, UUID); | ||
1931 | return anim; | ||
1932 | } | ||
1933 | public void AddAnimation(UUID animID, UUID objectID) | ||
1934 | { | ||
1935 | if (m_isChildAgent) | ||
1936 | return; | ||
1937 | |||
1938 | if (m_animations.Add(animID, m_controllingClient.NextAnimationSequenceNumber, objectID)) | ||
1939 | SendAnimPack(); | ||
1940 | } | ||
1941 | |||
1942 | // Called from scripts | ||
1943 | public void AddAnimation(string name, UUID objectID) | ||
1944 | { | ||
1945 | if (m_isChildAgent) | ||
1946 | return; | ||
1947 | |||
1948 | UUID animID = m_controllingClient.GetDefaultAnimation(name); | ||
1949 | if (animID == UUID.Zero) | ||
1950 | return; | ||
1951 | |||
1952 | AddAnimation(animID, objectID); | ||
1953 | } | ||
1954 | |||
1955 | public void RemoveAnimation(UUID animID) | ||
1956 | { | ||
1957 | if (m_isChildAgent) | ||
1958 | return; | ||
1959 | |||
1960 | if (m_animations.Remove(animID)) | ||
1961 | SendAnimPack(); | ||
1962 | } | ||
1963 | |||
1964 | // Called from scripts | ||
1965 | public void RemoveAnimation(string name) | ||
1966 | { | ||
1967 | if (m_isChildAgent) | ||
1968 | return; | ||
1969 | |||
1970 | UUID animID = m_controllingClient.GetDefaultAnimation(name); | ||
1971 | if (animID == UUID.Zero) | ||
1972 | return; | ||
1973 | |||
1974 | RemoveAnimation(animID); | ||
1975 | } | ||
1976 | |||
1977 | public UUID[] GetAnimationArray() | ||
1978 | { | ||
1979 | UUID[] animIDs; | ||
1980 | int[] sequenceNums; | ||
1981 | UUID[] objectIDs; | ||
1982 | m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs); | ||
1983 | return animIDs; | ||
1984 | } | ||
1985 | 1871 | ||
1986 | public void HandleStartAnim(IClientAPI remoteClient, UUID animID) | 1872 | public void HandleStartAnim(IClientAPI remoteClient, UUID animID) |
1987 | { | 1873 | { |
1988 | AddAnimation(animID, UUID.Zero); | 1874 | Animator.AddAnimation(animID, UUID.Zero); |
1989 | } | 1875 | } |
1990 | 1876 | ||
1991 | public void HandleStopAnim(IClientAPI remoteClient, UUID animID) | 1877 | public void HandleStopAnim(IClientAPI remoteClient, UUID animID) |
1992 | { | 1878 | { |
1993 | RemoveAnimation(animID); | 1879 | Animator.RemoveAnimation(animID); |
1994 | } | ||
1995 | |||
1996 | /// <summary> | ||
1997 | /// The movement animation is reserved for "main" animations | ||
1998 | /// that are mutually exclusive, e.g. flying and sitting. | ||
1999 | /// </summary> | ||
2000 | protected void TrySetMovementAnimation(string anim) | ||
2001 | { | ||
2002 | //m_log.DebugFormat("Updating movement animation to {0}", anim); | ||
2003 | |||
2004 | if (!m_isChildAgent) | ||
2005 | { | ||
2006 | if (m_animations.TrySetDefaultAnimation(anim, m_controllingClient.NextAnimationSequenceNumber, UUID.Zero)) | ||
2007 | { | ||
2008 | if (m_scriptEngines != null) | ||
2009 | { | ||
2010 | lock (m_attachments) | ||
2011 | { | ||
2012 | foreach (SceneObjectGroup grp in m_attachments) | ||
2013 | { | ||
2014 | // 16384 is CHANGED_ANIMATION | ||
2015 | // | ||
2016 | // Send this to all attachment root prims | ||
2017 | // | ||
2018 | foreach (IScriptModule m in m_scriptEngines) | ||
2019 | { | ||
2020 | if (m == null) // No script engine loaded | ||
2021 | continue; | ||
2022 | |||
2023 | m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { 16384 }); | ||
2024 | } | ||
2025 | } | ||
2026 | } | ||
2027 | } | ||
2028 | SendAnimPack(); | ||
2029 | } | ||
2030 | } | ||
2031 | } | ||
2032 | |||
2033 | /// <summary> | ||
2034 | /// This method determines the proper movement related animation | ||
2035 | /// </summary> | ||
2036 | public string GetMovementAnimation() | ||
2037 | { | ||
2038 | const float FALL_DELAY = 0.33f; | ||
2039 | const float PREJUMP_DELAY = 0.25f; | ||
2040 | |||
2041 | #region Inputs | ||
2042 | |||
2043 | AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_AgentControlFlags; | ||
2044 | PhysicsActor actor = m_physicsActor; | ||
2045 | |||
2046 | // Create forward and left vectors from the current avatar rotation | ||
2047 | Matrix4 rotMatrix = Matrix4.CreateFromQuaternion(m_bodyRot); | ||
2048 | Vector3 fwd = Vector3.Transform(Vector3.UnitX, rotMatrix); | ||
2049 | Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); | ||
2050 | |||
2051 | // Check control flags | ||
2052 | bool heldForward = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS; | ||
2053 | bool heldBack = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG; | ||
2054 | bool heldLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS; | ||
2055 | bool heldRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG; | ||
2056 | //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; | ||
2057 | //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; | ||
2058 | bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; | ||
2059 | bool heldDown = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG; | ||
2060 | //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY; | ||
2061 | //bool mouselook = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK; | ||
2062 | |||
2063 | // Direction in which the avatar is trying to move | ||
2064 | Vector3 move = Vector3.Zero; | ||
2065 | if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; } | ||
2066 | if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; } | ||
2067 | if (heldLeft) { move.X += left.X; move.Y += left.Y; } | ||
2068 | if (heldRight) { move.X -= left.X; move.Y -= left.Y; } | ||
2069 | if (heldUp) { move.Z += 1; } | ||
2070 | if (heldDown) { move.Z -= 1; } | ||
2071 | |||
2072 | // Is the avatar trying to move? | ||
2073 | // bool moving = (move != Vector3.Zero); | ||
2074 | bool jumping = m_animTickJump != 0; | ||
2075 | |||
2076 | #endregion Inputs | ||
2077 | |||
2078 | #region Flying | ||
2079 | |||
2080 | if (actor != null && actor.Flying) | ||
2081 | { | ||
2082 | m_animTickFall = 0; | ||
2083 | m_animTickJump = 0; | ||
2084 | |||
2085 | if (move.X != 0f || move.Y != 0f) | ||
2086 | { | ||
2087 | return (m_useFlySlow ? "FLYSLOW" : "FLY"); | ||
2088 | } | ||
2089 | else if (move.Z > 0f) | ||
2090 | { | ||
2091 | return "HOVER_UP"; | ||
2092 | } | ||
2093 | else if (move.Z < 0f) | ||
2094 | { | ||
2095 | if (actor != null && actor.IsColliding) | ||
2096 | return "LAND"; | ||
2097 | else | ||
2098 | return "HOVER_DOWN"; | ||
2099 | } | ||
2100 | else | ||
2101 | { | ||
2102 | return "HOVER"; | ||
2103 | } | ||
2104 | } | ||
2105 | |||
2106 | #endregion Flying | ||
2107 | |||
2108 | #region Falling/Floating/Landing | ||
2109 | |||
2110 | if (actor == null || !actor.IsColliding) | ||
2111 | { | ||
2112 | float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; | ||
2113 | float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f; | ||
2114 | |||
2115 | if (m_animTickFall == 0 || (fallElapsed > FALL_DELAY && fallVelocity >= 0.0f)) | ||
2116 | { | ||
2117 | // Just started falling | ||
2118 | m_animTickFall = Environment.TickCount; | ||
2119 | } | ||
2120 | else if (!jumping && fallElapsed > FALL_DELAY) | ||
2121 | { | ||
2122 | // Falling long enough to trigger the animation | ||
2123 | return "FALLDOWN"; | ||
2124 | } | ||
2125 | |||
2126 | return m_movementAnimation; | ||
2127 | } | ||
2128 | |||
2129 | #endregion Falling/Floating/Landing | ||
2130 | |||
2131 | #region Ground Movement | ||
2132 | |||
2133 | if (m_movementAnimation == "FALLDOWN") | ||
2134 | { | ||
2135 | m_animTickFall = Environment.TickCount; | ||
2136 | |||
2137 | // TODO: SOFT_LAND support | ||
2138 | return "LAND"; | ||
2139 | } | ||
2140 | else if (m_movementAnimation == "LAND") | ||
2141 | { | ||
2142 | float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; | ||
2143 | |||
2144 | if (landElapsed <= FALL_DELAY) | ||
2145 | return "LAND"; | ||
2146 | } | ||
2147 | |||
2148 | m_animTickFall = 0; | ||
2149 | |||
2150 | if (move.Z > 0f) | ||
2151 | { | ||
2152 | // Jumping | ||
2153 | if (!jumping) | ||
2154 | { | ||
2155 | // Begin prejump | ||
2156 | m_animTickJump = Environment.TickCount; | ||
2157 | return "PREJUMP"; | ||
2158 | } | ||
2159 | else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 1000.0f) | ||
2160 | { | ||
2161 | // Start actual jump | ||
2162 | if (m_animTickJump == -1) | ||
2163 | { | ||
2164 | // Already jumping! End the current jump | ||
2165 | m_animTickJump = 0; | ||
2166 | return "JUMP"; | ||
2167 | } | ||
2168 | |||
2169 | m_animTickJump = -1; | ||
2170 | return "JUMP"; | ||
2171 | } | ||
2172 | } | ||
2173 | else | ||
2174 | { | ||
2175 | // Not jumping | ||
2176 | m_animTickJump = 0; | ||
2177 | |||
2178 | if (move.X != 0f || move.Y != 0f) | ||
2179 | { | ||
2180 | // Walking / crouchwalking / running | ||
2181 | if (move.Z < 0f) | ||
2182 | return "CROUCHWALK"; | ||
2183 | else if (m_setAlwaysRun) | ||
2184 | return "RUN"; | ||
2185 | else | ||
2186 | return "WALK"; | ||
2187 | } | ||
2188 | else | ||
2189 | { | ||
2190 | // Not walking | ||
2191 | if (move.Z < 0f) | ||
2192 | return "CROUCH"; | ||
2193 | else | ||
2194 | return "STAND"; | ||
2195 | } | ||
2196 | } | ||
2197 | |||
2198 | #endregion Ground Movement | ||
2199 | |||
2200 | return m_movementAnimation; | ||
2201 | } | ||
2202 | |||
2203 | /// <summary> | ||
2204 | /// Update the movement animation of this avatar according to its current state | ||
2205 | /// </summary> | ||
2206 | protected void UpdateMovementAnimations() | ||
2207 | { | ||
2208 | m_movementAnimation = GetMovementAnimation(); | ||
2209 | |||
2210 | if (m_movementAnimation == "PREJUMP" && !m_usePreJump) | ||
2211 | { | ||
2212 | // This was the previous behavior before PREJUMP | ||
2213 | TrySetMovementAnimation("JUMP"); | ||
2214 | } | ||
2215 | else | ||
2216 | { | ||
2217 | TrySetMovementAnimation(m_movementAnimation); | ||
2218 | } | ||
2219 | } | 1880 | } |
2220 | 1881 | ||
2221 | /// <summary> | 1882 | /// <summary> |
@@ -2289,8 +1950,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2289 | direc.Z *= 3.0f; | 1950 | direc.Z *= 3.0f; |
2290 | 1951 | ||
2291 | // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. | 1952 | // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. |
2292 | TrySetMovementAnimation("PREJUMP"); | 1953 | Animator.TrySetMovementAnimation("PREJUMP"); |
2293 | TrySetMovementAnimation("JUMP"); | 1954 | Animator.TrySetMovementAnimation("JUMP"); |
2294 | } | 1955 | } |
2295 | } | 1956 | } |
2296 | } | 1957 | } |
@@ -2504,7 +2165,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2504 | { | 2165 | { |
2505 | avatar.SendFullUpdateToOtherClient(this); | 2166 | avatar.SendFullUpdateToOtherClient(this); |
2506 | avatar.SendAppearanceToOtherAgent(this); | 2167 | avatar.SendAppearanceToOtherAgent(this); |
2507 | avatar.SendAnimPackToClient(ControllingClient); | 2168 | avatar.Animator.SendAnimPackToClient(ControllingClient); |
2508 | } | 2169 | } |
2509 | } | 2170 | } |
2510 | } | 2171 | } |
@@ -2512,7 +2173,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2512 | m_scene.StatsReporter.AddAgentUpdates(avatars.Length); | 2173 | m_scene.StatsReporter.AddAgentUpdates(avatars.Length); |
2513 | m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); | 2174 | m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); |
2514 | 2175 | ||
2515 | //SendAnimPack(); | 2176 | //Animator.SendAnimPack(); |
2516 | } | 2177 | } |
2517 | 2178 | ||
2518 | public void SendFullUpdateToAllClients() | 2179 | public void SendFullUpdateToAllClients() |
@@ -2529,7 +2190,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2529 | m_scene.StatsReporter.AddAgentUpdates(avatars.Count); | 2190 | m_scene.StatsReporter.AddAgentUpdates(avatars.Count); |
2530 | m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); | 2191 | m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); |
2531 | 2192 | ||
2532 | SendAnimPack(); | 2193 | Animator.SendAnimPack(); |
2533 | } | 2194 | } |
2534 | 2195 | ||
2535 | /// <summary> | 2196 | /// <summary> |
@@ -2646,7 +2307,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2646 | SendAppearanceToAllOtherAgents(); | 2307 | SendAppearanceToAllOtherAgents(); |
2647 | if (!m_startAnimationSet) | 2308 | if (!m_startAnimationSet) |
2648 | { | 2309 | { |
2649 | UpdateMovementAnimations(); | 2310 | Animator.UpdateMovementAnimations(); |
2650 | m_startAnimationSet = true; | 2311 | m_startAnimationSet = true; |
2651 | } | 2312 | } |
2652 | 2313 | ||
@@ -2674,54 +2335,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2674 | set { m_appearance = value; } | 2335 | set { m_appearance = value; } |
2675 | } | 2336 | } |
2676 | 2337 | ||
2677 | /// <summary> | ||
2678 | /// | ||
2679 | /// </summary> | ||
2680 | /// <param name="animations"></param> | ||
2681 | /// <param name="seqs"></param> | ||
2682 | /// <param name="objectIDs"></param> | ||
2683 | public void SendAnimPack(UUID[] animations, int[] seqs, UUID[] objectIDs) | ||
2684 | { | ||
2685 | if (m_isChildAgent) | ||
2686 | return; | ||
2687 | |||
2688 | m_scene.ForEachClient( | ||
2689 | delegate(IClientAPI client) { client.SendAnimations(animations, seqs, m_controllingClient.AgentId, objectIDs); }); | ||
2690 | } | ||
2691 | |||
2692 | public void SendAnimPackToClient(IClientAPI client) | ||
2693 | { | ||
2694 | if (m_isChildAgent) | ||
2695 | return; | ||
2696 | UUID[] animIDs; | ||
2697 | int[] sequenceNums; | ||
2698 | UUID[] objectIDs; | ||
2699 | |||
2700 | m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs); | ||
2701 | |||
2702 | client.SendAnimations(animIDs, sequenceNums, m_controllingClient.AgentId, objectIDs); | ||
2703 | } | ||
2704 | |||
2705 | /// <summary> | ||
2706 | /// Send animation information about this avatar to all clients. | ||
2707 | /// </summary> | ||
2708 | public void SendAnimPack() | ||
2709 | { | ||
2710 | //m_log.Debug("Sending animation pack to all"); | ||
2711 | |||
2712 | if (m_isChildAgent) | ||
2713 | return; | ||
2714 | |||
2715 | UUID[] animIDs; | ||
2716 | int[] sequenceNums; | ||
2717 | UUID[] objectIDs; | ||
2718 | |||
2719 | m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs); | ||
2720 | |||
2721 | SendAnimPack(animIDs, sequenceNums, objectIDs); | ||
2722 | } | ||
2723 | |||
2724 | |||
2725 | #endregion | 2338 | #endregion |
2726 | 2339 | ||
2727 | #region Significant Movement Method | 2340 | #region Significant Movement Method |
@@ -2919,13 +2532,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
2919 | public void Reset() | 2532 | public void Reset() |
2920 | { | 2533 | { |
2921 | // Put the child agent back at the center | 2534 | // Put the child agent back at the center |
2922 | AbsolutePosition = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); | 2535 | AbsolutePosition |
2923 | ResetAnimations(); | 2536 | = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 70); |
2924 | } | 2537 | Animator.ResetAnimations(); |
2925 | |||
2926 | public void ResetAnimations() | ||
2927 | { | ||
2928 | m_animations.Clear(); | ||
2929 | } | 2538 | } |
2930 | 2539 | ||
2931 | /// <summary> | 2540 | /// <summary> |
@@ -3149,7 +2758,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3149 | // Animations | 2758 | // Animations |
3150 | try | 2759 | try |
3151 | { | 2760 | { |
3152 | cAgent.Anims = m_animations.ToArray(); | 2761 | cAgent.Anims = Animator.Animations.ToArray(); |
3153 | } | 2762 | } |
3154 | catch { } | 2763 | catch { } |
3155 | 2764 | ||
@@ -3228,15 +2837,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
3228 | // Animations | 2837 | // Animations |
3229 | try | 2838 | try |
3230 | { | 2839 | { |
3231 | m_animations.Clear(); | 2840 | Animator.ResetAnimations(); |
3232 | m_animations.FromArray(cAgent.Anims); | 2841 | Animator.Animations.FromArray(cAgent.Anims); |
3233 | } | 2842 | } |
3234 | catch { } | 2843 | catch { } |
3235 | 2844 | ||
3236 | //cAgent.GroupID = ?? | 2845 | //cAgent.GroupID = ?? |
3237 | //Groups??? | 2846 | //Groups??? |
3238 | |||
3239 | |||
3240 | } | 2847 | } |
3241 | 2848 | ||
3242 | public bool CopyAgent(out IAgentData agent) | 2849 | public bool CopyAgent(out IAgentData agent) |
@@ -3318,7 +2925,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3318 | //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) | 2925 | //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) |
3319 | // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents( | 2926 | // The Physics Scene will send updates every 500 ms grep: m_physicsActor.SubscribeEvents( |
3320 | // as of this comment the interval is set in AddToPhysicalScene | 2927 | // as of this comment the interval is set in AddToPhysicalScene |
3321 | UpdateMovementAnimations(); | 2928 | Animator.UpdateMovementAnimations(); |
3322 | 2929 | ||
3323 | CollisionEventUpdate collisionData = (CollisionEventUpdate)e; | 2930 | CollisionEventUpdate collisionData = (CollisionEventUpdate)e; |
3324 | Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; | 2931 | Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; |
@@ -3327,7 +2934,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3327 | 2934 | ||
3328 | if (coldata.Count != 0) | 2935 | if (coldata.Count != 0) |
3329 | { | 2936 | { |
3330 | switch (m_movementAnimation) | 2937 | switch (Animator.CurrentMovementAnimation) |
3331 | { | 2938 | { |
3332 | case "STAND": | 2939 | case "STAND": |
3333 | case "WALK": | 2940 | case "WALK": |
@@ -3415,6 +3022,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3415 | } | 3022 | } |
3416 | m_attachments.Clear(); | 3023 | m_attachments.Clear(); |
3417 | } | 3024 | } |
3025 | |||
3418 | lock (m_knownChildRegions) | 3026 | lock (m_knownChildRegions) |
3419 | { | 3027 | { |
3420 | m_knownChildRegions.Clear(); | 3028 | m_knownChildRegions.Clear(); |
@@ -3425,6 +3033,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3425 | m_reprioritization_timer.Enabled = false; | 3033 | m_reprioritization_timer.Enabled = false; |
3426 | m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize); | 3034 | m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize); |
3427 | } | 3035 | } |
3036 | |||
3428 | // I don't get it but mono crashes when you try to dispose of this timer, | 3037 | // I don't get it but mono crashes when you try to dispose of this timer, |
3429 | // unsetting the elapsed callback should be enough to allow for cleanup however. | 3038 | // unsetting the elapsed callback should be enough to allow for cleanup however. |
3430 | //m_reprioritizationTimer.Dispose(); | 3039 | //m_reprioritizationTimer.Dispose(); |
@@ -3436,8 +3045,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
3436 | 3045 | ||
3437 | public ScenePresence() | 3046 | public ScenePresence() |
3438 | { | 3047 | { |
3439 | m_sendCourseLocationsMethod = SendCoarseLocationsDefault; | 3048 | m_sendCourseLocationsMethod = SendCoarseLocationsDefault; |
3440 | CreateSceneViewer(); | 3049 | CreateSceneViewer(); |
3050 | m_animator = new ScenePresenceAnimator(this); | ||
3441 | } | 3051 | } |
3442 | 3052 | ||
3443 | public void AddAttachment(SceneObjectGroup gobj) | 3053 | public void AddAttachment(SceneObjectGroup gobj) |
@@ -3497,6 +3107,35 @@ namespace OpenSim.Region.Framework.Scenes | |||
3497 | return true; | 3107 | return true; |
3498 | } | 3108 | } |
3499 | 3109 | ||
3110 | /// <summary> | ||
3111 | /// Send a script event to this scene presence's attachments | ||
3112 | /// </summary> | ||
3113 | /// <param name="eventName">The name of the event</param> | ||
3114 | /// <param name="args">The arguments for the event</param> | ||
3115 | public void SendScriptEventToAttachments(string eventName, Object[] args) | ||
3116 | { | ||
3117 | if (m_scriptEngines != null) | ||
3118 | { | ||
3119 | lock (m_attachments) | ||
3120 | { | ||
3121 | foreach (SceneObjectGroup grp in m_attachments) | ||
3122 | { | ||
3123 | // 16384 is CHANGED_ANIMATION | ||
3124 | // | ||
3125 | // Send this to all attachment root prims | ||
3126 | // | ||
3127 | foreach (IScriptModule m in m_scriptEngines) | ||
3128 | { | ||
3129 | if (m == null) // No script engine loaded | ||
3130 | continue; | ||
3131 | |||
3132 | m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { 16384 }); | ||
3133 | } | ||
3134 | } | ||
3135 | } | ||
3136 | } | ||
3137 | } | ||
3138 | |||
3500 | public bool CrossAttachmentsIntoNewRegion(ulong regionHandle, bool silent) | 3139 | public bool CrossAttachmentsIntoNewRegion(ulong regionHandle, bool silent) |
3501 | { | 3140 | { |
3502 | lock (m_attachments) | 3141 | lock (m_attachments) |
@@ -3939,4 +3578,4 @@ namespace OpenSim.Region.Framework.Scenes | |||
3939 | } | 3578 | } |
3940 | } | 3579 | } |
3941 | } | 3580 | } |
3942 | } | 3581 | } \ No newline at end of file |