diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 453 |
1 files changed, 375 insertions, 78 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 8cb4921..9e60c88 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -92,7 +92,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
92 | /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis | 92 | /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis |
93 | /// issue #1716 | 93 | /// issue #1716 |
94 | /// </summary> | 94 | /// </summary> |
95 | public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); | 95 | public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.4f); |
96 | 96 | ||
97 | /// <summary> | 97 | /// <summary> |
98 | /// Movement updates for agents in neighboring regions are sent directly to clients. | 98 | /// Movement updates for agents in neighboring regions are sent directly to clients. |
@@ -169,6 +169,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
169 | // private int m_lastColCount = -1; //KF: Look for Collision chnages | 169 | // private int m_lastColCount = -1; //KF: Look for Collision chnages |
170 | // private int m_updateCount = 0; //KF: Update Anims for a while | 170 | // private int m_updateCount = 0; //KF: Update Anims for a while |
171 | // private static readonly int UPDATE_COUNT = 10; // how many frames to update for | 171 | // private static readonly int UPDATE_COUNT = 10; // how many frames to update for |
172 | private List<uint> m_lastColliders = new List<uint>(); | ||
172 | 173 | ||
173 | private TeleportFlags m_teleportFlags; | 174 | private TeleportFlags m_teleportFlags; |
174 | public TeleportFlags TeleportFlags | 175 | public TeleportFlags TeleportFlags |
@@ -230,6 +231,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
230 | //private int m_moveToPositionStateStatus; | 231 | //private int m_moveToPositionStateStatus; |
231 | //***************************************************** | 232 | //***************************************************** |
232 | 233 | ||
234 | private bool m_collisionEventFlag = false; | ||
235 | private object m_collisionEventLock = new Object(); | ||
236 | |||
237 | private int m_movementAnimationUpdateCounter = 0; | ||
238 | |||
239 | private Vector3 m_prevSitOffset; | ||
240 | |||
233 | protected AvatarAppearance m_appearance; | 241 | protected AvatarAppearance m_appearance; |
234 | 242 | ||
235 | public AvatarAppearance Appearance | 243 | public AvatarAppearance Appearance |
@@ -569,6 +577,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
569 | /// </summary> | 577 | /// </summary> |
570 | public uint ParentID { get; set; } | 578 | public uint ParentID { get; set; } |
571 | 579 | ||
580 | public UUID ParentUUID | ||
581 | { | ||
582 | get { return m_parentUUID; } | ||
583 | set { m_parentUUID = value; } | ||
584 | } | ||
585 | private UUID m_parentUUID = UUID.Zero; | ||
586 | |||
572 | /// <summary> | 587 | /// <summary> |
573 | /// If the avatar is sitting, the prim that it's sitting on. If not sitting then null. | 588 | /// If the avatar is sitting, the prim that it's sitting on. If not sitting then null. |
574 | /// </summary> | 589 | /// </summary> |
@@ -729,6 +744,27 @@ namespace OpenSim.Region.Framework.Scenes | |||
729 | Appearance = appearance; | 744 | Appearance = appearance; |
730 | } | 745 | } |
731 | 746 | ||
747 | private void RegionHeartbeatEnd(Scene scene) | ||
748 | { | ||
749 | if (IsChildAgent) | ||
750 | return; | ||
751 | |||
752 | m_movementAnimationUpdateCounter ++; | ||
753 | if (m_movementAnimationUpdateCounter >= 2) | ||
754 | { | ||
755 | m_movementAnimationUpdateCounter = 0; | ||
756 | if (Animator != null) | ||
757 | { | ||
758 | if(ParentID == 0) // skip it if sitting | ||
759 | Animator.UpdateMovementAnimations(); | ||
760 | } | ||
761 | else | ||
762 | { | ||
763 | m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd; | ||
764 | } | ||
765 | } | ||
766 | } | ||
767 | |||
732 | public void RegisterToEvents() | 768 | public void RegisterToEvents() |
733 | { | 769 | { |
734 | ControllingClient.OnCompleteMovementToRegion += CompleteMovement; | 770 | ControllingClient.OnCompleteMovementToRegion += CompleteMovement; |
@@ -798,10 +834,38 @@ namespace OpenSim.Region.Framework.Scenes | |||
798 | "[SCENE]: Upgrading child to root agent for {0} in {1}", | 834 | "[SCENE]: Upgrading child to root agent for {0} in {1}", |
799 | Name, m_scene.RegionInfo.RegionName); | 835 | Name, m_scene.RegionInfo.RegionName); |
800 | 836 | ||
801 | //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); | ||
802 | |||
803 | bool wasChild = IsChildAgent; | 837 | bool wasChild = IsChildAgent; |
804 | IsChildAgent = false; | 838 | |
839 | if (ParentUUID != UUID.Zero) | ||
840 | { | ||
841 | m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID); | ||
842 | SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID); | ||
843 | if (part == null) | ||
844 | { | ||
845 | m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID); | ||
846 | } | ||
847 | else | ||
848 | { | ||
849 | part.ParentGroup.AddAvatar(UUID); | ||
850 | if (part.SitTargetPosition != Vector3.Zero) | ||
851 | part.SitTargetAvatar = UUID; | ||
852 | ParentPosition = part.GetWorldPosition(); | ||
853 | ParentID = part.LocalId; | ||
854 | ParentPart = part; | ||
855 | m_pos = m_prevSitOffset; | ||
856 | pos = ParentPosition; | ||
857 | } | ||
858 | ParentUUID = UUID.Zero; | ||
859 | |||
860 | IsChildAgent = false; | ||
861 | |||
862 | Animator.TrySetMovementAnimation("SIT"); | ||
863 | } | ||
864 | else | ||
865 | { | ||
866 | IsChildAgent = false; | ||
867 | } | ||
868 | |||
805 | 869 | ||
806 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); | 870 | IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); |
807 | if (gm != null) | 871 | if (gm != null) |
@@ -811,62 +875,64 @@ namespace OpenSim.Region.Framework.Scenes | |||
811 | 875 | ||
812 | m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); | 876 | m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); |
813 | 877 | ||
814 | // Moved this from SendInitialData to ensure that Appearance is initialized | 878 | if (ParentID == 0) |
815 | // before the inventory is processed in MakeRootAgent. This fixes a race condition | ||
816 | // related to the handling of attachments | ||
817 | //m_scene.GetAvatarAppearance(ControllingClient, out Appearance); | ||
818 | if (m_scene.TestBorderCross(pos, Cardinals.E)) | ||
819 | { | 879 | { |
820 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); | 880 | // Moved this from SendInitialData to ensure that Appearance is initialized |
821 | pos.X = crossedBorder.BorderLine.Z - 1; | 881 | // before the inventory is processed in MakeRootAgent. This fixes a race condition |
822 | } | 882 | // related to the handling of attachments |
883 | //m_scene.GetAvatarAppearance(ControllingClient, out Appearance); | ||
884 | if (m_scene.TestBorderCross(pos, Cardinals.E)) | ||
885 | { | ||
886 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); | ||
887 | pos.X = crossedBorder.BorderLine.Z - 1; | ||
888 | } | ||
823 | 889 | ||
824 | if (m_scene.TestBorderCross(pos, Cardinals.N)) | 890 | if (m_scene.TestBorderCross(pos, Cardinals.N)) |
825 | { | 891 | { |
826 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); | 892 | Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); |
827 | pos.Y = crossedBorder.BorderLine.Z - 1; | 893 | pos.Y = crossedBorder.BorderLine.Z - 1; |
828 | } | 894 | } |
829 | 895 | ||
830 | CheckAndAdjustLandingPoint(ref pos); | 896 | CheckAndAdjustLandingPoint(ref pos); |
831 | 897 | ||
832 | if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) | 898 | if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) |
833 | { | 899 | { |
834 | m_log.WarnFormat( | 900 | m_log.WarnFormat( |
835 | "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", | 901 | "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", |
836 | pos, Name, UUID); | 902 | pos, Name, UUID); |
837 | 903 | ||
838 | if (pos.X < 0f) pos.X = 0f; | 904 | if (pos.X < 0f) pos.X = 0f; |
839 | if (pos.Y < 0f) pos.Y = 0f; | 905 | if (pos.Y < 0f) pos.Y = 0f; |
840 | if (pos.Z < 0f) pos.Z = 0f; | 906 | if (pos.Z < 0f) pos.Z = 0f; |
841 | } | 907 | } |
842 | 908 | ||
843 | float localAVHeight = 1.56f; | 909 | float localAVHeight = 1.56f; |
844 | if (Appearance.AvatarHeight > 0) | 910 | if (Appearance.AvatarHeight > 0) |
845 | localAVHeight = Appearance.AvatarHeight; | 911 | localAVHeight = Appearance.AvatarHeight; |
846 | 912 | ||
847 | float posZLimit = 0; | 913 | float posZLimit = 0; |
848 | 914 | ||
849 | if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) | 915 | if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) |
850 | posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; | 916 | posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; |
851 | 917 | ||
852 | float newPosZ = posZLimit + localAVHeight / 2; | 918 | float newPosZ = posZLimit + localAVHeight / 2; |
853 | if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) | 919 | if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) |
854 | { | 920 | { |
855 | pos.Z = newPosZ; | 921 | pos.Z = newPosZ; |
856 | } | 922 | } |
857 | AbsolutePosition = pos; | 923 | AbsolutePosition = pos; |
858 | 924 | ||
859 | AddToPhysicalScene(isFlying); | 925 | AddToPhysicalScene(isFlying); |
860 | 926 | ||
861 | if (ForceFly) | 927 | if (ForceFly) |
862 | { | 928 | { |
863 | Flying = true; | 929 | Flying = true; |
864 | } | 930 | } |
865 | else if (FlyDisabled) | 931 | else if (FlyDisabled) |
866 | { | 932 | { |
867 | Flying = false; | 933 | Flying = false; |
934 | } | ||
868 | } | 935 | } |
869 | |||
870 | // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying | 936 | // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying |
871 | // avatar to return to the standing position in mid-air. On login it looks like this is being sent | 937 | // avatar to return to the standing position in mid-air. On login it looks like this is being sent |
872 | // elsewhere anyway | 938 | // elsewhere anyway |
@@ -884,14 +950,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
884 | { | 950 | { |
885 | m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); | 951 | m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); |
886 | // Resume scripts | 952 | // Resume scripts |
887 | foreach (SceneObjectGroup sog in m_attachments) | 953 | Util.FireAndForget(delegate(object x) { |
888 | { | 954 | foreach (SceneObjectGroup sog in m_attachments) |
889 | sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); | 955 | { |
890 | sog.ResumeScripts(); | 956 | sog.ScheduleGroupForFullUpdate(); |
891 | } | 957 | sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); |
958 | sog.ResumeScripts(); | ||
959 | } | ||
960 | }); | ||
892 | } | 961 | } |
893 | } | 962 | } |
894 | 963 | ||
964 | SendAvatarDataToAllAgents(); | ||
965 | |||
895 | // send the animations of the other presences to me | 966 | // send the animations of the other presences to me |
896 | m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) | 967 | m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) |
897 | { | 968 | { |
@@ -905,6 +976,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
905 | MovementFlag = 0; | 976 | MovementFlag = 0; |
906 | 977 | ||
907 | m_scene.EventManager.TriggerOnMakeRootAgent(this); | 978 | m_scene.EventManager.TriggerOnMakeRootAgent(this); |
979 | |||
980 | m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd; | ||
908 | } | 981 | } |
909 | 982 | ||
910 | public int GetStateSource() | 983 | public int GetStateSource() |
@@ -932,6 +1005,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
932 | /// </remarks> | 1005 | /// </remarks> |
933 | public void MakeChildAgent() | 1006 | public void MakeChildAgent() |
934 | { | 1007 | { |
1008 | m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd; | ||
1009 | |||
935 | m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); | 1010 | m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); |
936 | 1011 | ||
937 | // Reset these so that teleporting in and walking out isn't seen | 1012 | // Reset these so that teleporting in and walking out isn't seen |
@@ -990,13 +1065,29 @@ namespace OpenSim.Region.Framework.Scenes | |||
990 | /// <param name="pos"></param> | 1065 | /// <param name="pos"></param> |
991 | public void Teleport(Vector3 pos) | 1066 | public void Teleport(Vector3 pos) |
992 | { | 1067 | { |
993 | // m_log.DebugFormat("[SCENE PRESENCE]: Moving {0} to {1} in {2}", Name, pos, Scene.RegionInfo.RegionName); | 1068 | TeleportWithMomentum(pos, Vector3.Zero); |
1069 | } | ||
1070 | |||
1071 | public void TeleportWithMomentum(Vector3 pos) | ||
1072 | { | ||
1073 | TeleportWithMomentum(pos, null); | ||
1074 | } | ||
994 | 1075 | ||
1076 | public void TeleportWithMomentum(Vector3 pos, Vector3? v) | ||
1077 | { | ||
995 | bool isFlying = Flying; | 1078 | bool isFlying = Flying; |
1079 | Vector3 vel = Velocity; | ||
996 | RemoveFromPhysicalScene(); | 1080 | RemoveFromPhysicalScene(); |
997 | CheckLandingPoint(ref pos); | 1081 | CheckLandingPoint(ref pos); |
998 | AbsolutePosition = pos; | 1082 | AbsolutePosition = pos; |
999 | AddToPhysicalScene(isFlying); | 1083 | AddToPhysicalScene(isFlying); |
1084 | if (PhysicsActor != null) | ||
1085 | { | ||
1086 | if (v.HasValue) | ||
1087 | PhysicsActor.SetMomentum((Vector3)v); | ||
1088 | else | ||
1089 | PhysicsActor.SetMomentum(vel); | ||
1090 | } | ||
1000 | 1091 | ||
1001 | SendTerseUpdateToAllClients(); | 1092 | SendTerseUpdateToAllClients(); |
1002 | } | 1093 | } |
@@ -1301,8 +1392,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
1301 | { | 1392 | { |
1302 | if (m_followCamAuto) | 1393 | if (m_followCamAuto) |
1303 | { | 1394 | { |
1304 | Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; | 1395 | // Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; |
1305 | m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); | 1396 | // m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); |
1397 | |||
1398 | Vector3 posAdjusted = AbsolutePosition + HEAD_ADJUSTMENT; | ||
1399 | Vector3 distTocam = CameraPosition - posAdjusted; | ||
1400 | float distTocamlen = distTocam.Length(); | ||
1401 | if (distTocamlen > 0) | ||
1402 | { | ||
1403 | distTocam *= 1.0f / distTocamlen; | ||
1404 | m_scene.PhysicsScene.RaycastWorld(posAdjusted, distTocam, distTocamlen + 0.3f, RayCastCameraCallback); | ||
1405 | } | ||
1406 | |||
1306 | } | 1407 | } |
1307 | } | 1408 | } |
1308 | 1409 | ||
@@ -1679,9 +1780,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
1679 | if (pos.Z - terrainHeight < 0.2) | 1780 | if (pos.Z - terrainHeight < 0.2) |
1680 | pos.Z = terrainHeight; | 1781 | pos.Z = terrainHeight; |
1681 | 1782 | ||
1682 | m_log.DebugFormat( | 1783 | // m_log.DebugFormat( |
1683 | "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", | 1784 | // "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", |
1684 | Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); | 1785 | // Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); |
1685 | 1786 | ||
1686 | if (noFly) | 1787 | if (noFly) |
1687 | Flying = false; | 1788 | Flying = false; |
@@ -1738,8 +1839,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1738 | // m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); | 1839 | // m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); |
1739 | 1840 | ||
1740 | SitGround = false; | 1841 | SitGround = false; |
1842 | |||
1843 | /* move this down so avatar gets physical in the new position and not where it is siting | ||
1741 | if (PhysicsActor == null) | 1844 | if (PhysicsActor == null) |
1742 | AddToPhysicalScene(false); | 1845 | AddToPhysicalScene(false); |
1846 | */ | ||
1743 | 1847 | ||
1744 | if (ParentID != 0) | 1848 | if (ParentID != 0) |
1745 | { | 1849 | { |
@@ -1763,6 +1867,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1763 | if (part.SitTargetAvatar == UUID) | 1867 | if (part.SitTargetAvatar == UUID) |
1764 | part.SitTargetAvatar = UUID.Zero; | 1868 | part.SitTargetAvatar = UUID.Zero; |
1765 | 1869 | ||
1870 | part.ParentGroup.DeleteAvatar(UUID); | ||
1766 | ParentPosition = part.GetWorldPosition(); | 1871 | ParentPosition = part.GetWorldPosition(); |
1767 | ControllingClient.SendClearFollowCamProperties(part.ParentUUID); | 1872 | ControllingClient.SendClearFollowCamProperties(part.ParentUUID); |
1768 | 1873 | ||
@@ -1771,6 +1876,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
1771 | 1876 | ||
1772 | ParentID = 0; | 1877 | ParentID = 0; |
1773 | ParentPart = null; | 1878 | ParentPart = null; |
1879 | |||
1880 | if (PhysicsActor == null) | ||
1881 | AddToPhysicalScene(false); | ||
1882 | |||
1774 | SendAvatarDataToAllAgents(); | 1883 | SendAvatarDataToAllAgents(); |
1775 | m_requestedSitTargetID = 0; | 1884 | m_requestedSitTargetID = 0; |
1776 | 1885 | ||
@@ -1778,6 +1887,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
1778 | part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); | 1887 | part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); |
1779 | } | 1888 | } |
1780 | 1889 | ||
1890 | else if (PhysicsActor == null) | ||
1891 | AddToPhysicalScene(false); | ||
1892 | |||
1781 | Animator.TrySetMovementAnimation("STAND"); | 1893 | Animator.TrySetMovementAnimation("STAND"); |
1782 | } | 1894 | } |
1783 | 1895 | ||
@@ -1901,7 +2013,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1901 | forceMouselook = part.GetForceMouselook(); | 2013 | forceMouselook = part.GetForceMouselook(); |
1902 | 2014 | ||
1903 | ControllingClient.SendSitResponse( | 2015 | ControllingClient.SendSitResponse( |
1904 | targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); | 2016 | part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); |
1905 | 2017 | ||
1906 | m_requestedSitTargetUUID = targetID; | 2018 | m_requestedSitTargetUUID = targetID; |
1907 | 2019 | ||
@@ -2183,14 +2295,36 @@ namespace OpenSim.Region.Framework.Scenes | |||
2183 | 2295 | ||
2184 | //Quaternion result = (sitTargetOrient * vq) * nq; | 2296 | //Quaternion result = (sitTargetOrient * vq) * nq; |
2185 | 2297 | ||
2186 | m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; | 2298 | double x, y, z, m; |
2299 | |||
2300 | Quaternion r = sitTargetOrient; | ||
2301 | m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W; | ||
2302 | |||
2303 | if (Math.Abs(1.0 - m) > 0.000001) | ||
2304 | { | ||
2305 | m = 1.0 / Math.Sqrt(m); | ||
2306 | r.X *= (float)m; | ||
2307 | r.Y *= (float)m; | ||
2308 | r.Z *= (float)m; | ||
2309 | r.W *= (float)m; | ||
2310 | } | ||
2311 | |||
2312 | x = 2 * (r.X * r.Z + r.Y * r.W); | ||
2313 | y = 2 * (-r.X * r.W + r.Y * r.Z); | ||
2314 | z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W; | ||
2315 | |||
2316 | Vector3 up = new Vector3((float)x, (float)y, (float)z); | ||
2317 | Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f; | ||
2318 | m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT; | ||
2187 | Rotation = sitTargetOrient; | 2319 | Rotation = sitTargetOrient; |
2188 | ParentPosition = part.AbsolutePosition; | 2320 | ParentPosition = part.AbsolutePosition; |
2321 | part.ParentGroup.AddAvatar(UUID); | ||
2189 | } | 2322 | } |
2190 | else | 2323 | else |
2191 | { | 2324 | { |
2192 | m_pos -= part.AbsolutePosition; | 2325 | m_pos -= part.AbsolutePosition; |
2193 | ParentPosition = part.AbsolutePosition; | 2326 | ParentPosition = part.AbsolutePosition; |
2327 | part.ParentGroup.AddAvatar(UUID); | ||
2194 | 2328 | ||
2195 | // m_log.DebugFormat( | 2329 | // m_log.DebugFormat( |
2196 | // "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", | 2330 | // "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", |
@@ -2288,14 +2422,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
2288 | direc.Z *= 2.6f; | 2422 | direc.Z *= 2.6f; |
2289 | 2423 | ||
2290 | // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. | 2424 | // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. |
2291 | Animator.TrySetMovementAnimation("PREJUMP"); | 2425 | // Animator.TrySetMovementAnimation("PREJUMP"); |
2292 | Animator.TrySetMovementAnimation("JUMP"); | 2426 | // Animator.TrySetMovementAnimation("JUMP"); |
2293 | } | 2427 | } |
2294 | } | 2428 | } |
2295 | } | 2429 | } |
2296 | 2430 | ||
2297 | // TODO: Add the force instead of only setting it to support multiple forces per frame? | 2431 | // TODO: Add the force instead of only setting it to support multiple forces per frame? |
2298 | m_forceToApply = direc; | 2432 | m_forceToApply = direc; |
2433 | Animator.UpdateMovementAnimations(); | ||
2299 | } | 2434 | } |
2300 | 2435 | ||
2301 | #endregion | 2436 | #endregion |
@@ -3029,6 +3164,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
3029 | cAgent.AlwaysRun = SetAlwaysRun; | 3164 | cAgent.AlwaysRun = SetAlwaysRun; |
3030 | 3165 | ||
3031 | cAgent.Appearance = new AvatarAppearance(Appearance); | 3166 | cAgent.Appearance = new AvatarAppearance(Appearance); |
3167 | |||
3168 | cAgent.ParentPart = ParentUUID; | ||
3169 | cAgent.SitOffset = m_pos; | ||
3032 | 3170 | ||
3033 | lock (scriptedcontrols) | 3171 | lock (scriptedcontrols) |
3034 | { | 3172 | { |
@@ -3088,6 +3226,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3088 | CameraAtAxis = cAgent.AtAxis; | 3226 | CameraAtAxis = cAgent.AtAxis; |
3089 | CameraLeftAxis = cAgent.LeftAxis; | 3227 | CameraLeftAxis = cAgent.LeftAxis; |
3090 | CameraUpAxis = cAgent.UpAxis; | 3228 | CameraUpAxis = cAgent.UpAxis; |
3229 | ParentUUID = cAgent.ParentPart; | ||
3230 | m_prevSitOffset = cAgent.SitOffset; | ||
3091 | 3231 | ||
3092 | // When we get to the point of re-computing neighbors everytime this | 3232 | // When we get to the point of re-computing neighbors everytime this |
3093 | // changes, then start using the agent's drawdistance rather than the | 3233 | // changes, then start using the agent's drawdistance rather than the |
@@ -3240,18 +3380,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
3240 | if (IsChildAgent) | 3380 | if (IsChildAgent) |
3241 | return; | 3381 | return; |
3242 | 3382 | ||
3243 | //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) | ||
3244 | // The Physics Scene will send updates every 500 ms grep: PhysicsActor.SubscribeEvents( | ||
3245 | // as of this comment the interval is set in AddToPhysicalScene | ||
3246 | if (Animator != null) | ||
3247 | { | ||
3248 | // if (m_updateCount > 0) | ||
3249 | // { | ||
3250 | Animator.UpdateMovementAnimations(); | ||
3251 | // m_updateCount--; | ||
3252 | // } | ||
3253 | } | ||
3254 | |||
3255 | CollisionEventUpdate collisionData = (CollisionEventUpdate)e; | 3383 | CollisionEventUpdate collisionData = (CollisionEventUpdate)e; |
3256 | Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; | 3384 | Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; |
3257 | 3385 | ||
@@ -3294,6 +3422,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3294 | } | 3422 | } |
3295 | } | 3423 | } |
3296 | 3424 | ||
3425 | RaiseCollisionScriptEvents(coldata); | ||
3426 | |||
3297 | if (Invulnerable) | 3427 | if (Invulnerable) |
3298 | return; | 3428 | return; |
3299 | 3429 | ||
@@ -3878,6 +4008,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
3878 | 4008 | ||
3879 | private void CheckAndAdjustLandingPoint(ref Vector3 pos) | 4009 | private void CheckAndAdjustLandingPoint(ref Vector3 pos) |
3880 | { | 4010 | { |
4011 | string reason; | ||
4012 | |||
4013 | // Honor bans | ||
4014 | if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y)) | ||
4015 | return; | ||
4016 | |||
3881 | SceneObjectGroup telehub = null; | 4017 | SceneObjectGroup telehub = null; |
3882 | if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) | 4018 | if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) |
3883 | { | 4019 | { |
@@ -3917,11 +4053,173 @@ namespace OpenSim.Region.Framework.Scenes | |||
3917 | pos = land.LandData.UserLocation; | 4053 | pos = land.LandData.UserLocation; |
3918 | } | 4054 | } |
3919 | } | 4055 | } |
3920 | 4056 | ||
3921 | land.SendLandUpdateToClient(ControllingClient); | 4057 | land.SendLandUpdateToClient(ControllingClient); |
3922 | } | 4058 | } |
3923 | } | 4059 | } |
3924 | 4060 | ||
4061 | private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata) | ||
4062 | { | ||
4063 | lock(m_collisionEventLock) | ||
4064 | { | ||
4065 | if (m_collisionEventFlag) | ||
4066 | return; | ||
4067 | m_collisionEventFlag = true; | ||
4068 | } | ||
4069 | |||
4070 | Util.FireAndForget(delegate(object x) | ||
4071 | { | ||
4072 | try | ||
4073 | { | ||
4074 | List<uint> thisHitColliders = new List<uint>(); | ||
4075 | List<uint> endedColliders = new List<uint>(); | ||
4076 | List<uint> startedColliders = new List<uint>(); | ||
4077 | |||
4078 | foreach (uint localid in coldata.Keys) | ||
4079 | { | ||
4080 | thisHitColliders.Add(localid); | ||
4081 | if (!m_lastColliders.Contains(localid)) | ||
4082 | { | ||
4083 | startedColliders.Add(localid); | ||
4084 | } | ||
4085 | //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); | ||
4086 | } | ||
4087 | |||
4088 | // calculate things that ended colliding | ||
4089 | foreach (uint localID in m_lastColliders) | ||
4090 | { | ||
4091 | if (!thisHitColliders.Contains(localID)) | ||
4092 | { | ||
4093 | endedColliders.Add(localID); | ||
4094 | } | ||
4095 | } | ||
4096 | //add the items that started colliding this time to the last colliders list. | ||
4097 | foreach (uint localID in startedColliders) | ||
4098 | { | ||
4099 | m_lastColliders.Add(localID); | ||
4100 | } | ||
4101 | // remove things that ended colliding from the last colliders list | ||
4102 | foreach (uint localID in endedColliders) | ||
4103 | { | ||
4104 | m_lastColliders.Remove(localID); | ||
4105 | } | ||
4106 | |||
4107 | // do event notification | ||
4108 | if (startedColliders.Count > 0) | ||
4109 | { | ||
4110 | ColliderArgs StartCollidingMessage = new ColliderArgs(); | ||
4111 | List<DetectedObject> colliding = new List<DetectedObject>(); | ||
4112 | foreach (uint localId in startedColliders) | ||
4113 | { | ||
4114 | if (localId == 0) | ||
4115 | continue; | ||
4116 | |||
4117 | SceneObjectPart obj = Scene.GetSceneObjectPart(localId); | ||
4118 | string data = ""; | ||
4119 | if (obj != null) | ||
4120 | { | ||
4121 | DetectedObject detobj = new DetectedObject(); | ||
4122 | detobj.keyUUID = obj.UUID; | ||
4123 | detobj.nameStr = obj.Name; | ||
4124 | detobj.ownerUUID = obj.OwnerID; | ||
4125 | detobj.posVector = obj.AbsolutePosition; | ||
4126 | detobj.rotQuat = obj.GetWorldRotation(); | ||
4127 | detobj.velVector = obj.Velocity; | ||
4128 | detobj.colliderType = 0; | ||
4129 | detobj.groupUUID = obj.GroupID; | ||
4130 | colliding.Add(detobj); | ||
4131 | } | ||
4132 | } | ||
4133 | |||
4134 | if (colliding.Count > 0) | ||
4135 | { | ||
4136 | StartCollidingMessage.Colliders = colliding; | ||
4137 | |||
4138 | foreach (SceneObjectGroup att in GetAttachments()) | ||
4139 | Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); | ||
4140 | } | ||
4141 | } | ||
4142 | |||
4143 | if (endedColliders.Count > 0) | ||
4144 | { | ||
4145 | ColliderArgs EndCollidingMessage = new ColliderArgs(); | ||
4146 | List<DetectedObject> colliding = new List<DetectedObject>(); | ||
4147 | foreach (uint localId in endedColliders) | ||
4148 | { | ||
4149 | if (localId == 0) | ||
4150 | continue; | ||
4151 | |||
4152 | SceneObjectPart obj = Scene.GetSceneObjectPart(localId); | ||
4153 | string data = ""; | ||
4154 | if (obj != null) | ||
4155 | { | ||
4156 | DetectedObject detobj = new DetectedObject(); | ||
4157 | detobj.keyUUID = obj.UUID; | ||
4158 | detobj.nameStr = obj.Name; | ||
4159 | detobj.ownerUUID = obj.OwnerID; | ||
4160 | detobj.posVector = obj.AbsolutePosition; | ||
4161 | detobj.rotQuat = obj.GetWorldRotation(); | ||
4162 | detobj.velVector = obj.Velocity; | ||
4163 | detobj.colliderType = 0; | ||
4164 | detobj.groupUUID = obj.GroupID; | ||
4165 | colliding.Add(detobj); | ||
4166 | } | ||
4167 | } | ||
4168 | |||
4169 | if (colliding.Count > 0) | ||
4170 | { | ||
4171 | EndCollidingMessage.Colliders = colliding; | ||
4172 | |||
4173 | foreach (SceneObjectGroup att in GetAttachments()) | ||
4174 | Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage); | ||
4175 | } | ||
4176 | } | ||
4177 | |||
4178 | if (thisHitColliders.Count > 0) | ||
4179 | { | ||
4180 | ColliderArgs CollidingMessage = new ColliderArgs(); | ||
4181 | List<DetectedObject> colliding = new List<DetectedObject>(); | ||
4182 | foreach (uint localId in thisHitColliders) | ||
4183 | { | ||
4184 | if (localId == 0) | ||
4185 | continue; | ||
4186 | |||
4187 | SceneObjectPart obj = Scene.GetSceneObjectPart(localId); | ||
4188 | string data = ""; | ||
4189 | if (obj != null) | ||
4190 | { | ||
4191 | DetectedObject detobj = new DetectedObject(); | ||
4192 | detobj.keyUUID = obj.UUID; | ||
4193 | detobj.nameStr = obj.Name; | ||
4194 | detobj.ownerUUID = obj.OwnerID; | ||
4195 | detobj.posVector = obj.AbsolutePosition; | ||
4196 | detobj.rotQuat = obj.GetWorldRotation(); | ||
4197 | detobj.velVector = obj.Velocity; | ||
4198 | detobj.colliderType = 0; | ||
4199 | detobj.groupUUID = obj.GroupID; | ||
4200 | colliding.Add(detobj); | ||
4201 | } | ||
4202 | } | ||
4203 | |||
4204 | if (colliding.Count > 0) | ||
4205 | { | ||
4206 | CollidingMessage.Colliders = colliding; | ||
4207 | |||
4208 | lock (m_attachments) | ||
4209 | { | ||
4210 | foreach (SceneObjectGroup att in m_attachments) | ||
4211 | Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage); | ||
4212 | } | ||
4213 | } | ||
4214 | } | ||
4215 | } | ||
4216 | finally | ||
4217 | { | ||
4218 | m_collisionEventFlag = false; | ||
4219 | } | ||
4220 | }); | ||
4221 | } | ||
4222 | |||
3925 | private void TeleportFlagsDebug() { | 4223 | private void TeleportFlagsDebug() { |
3926 | 4224 | ||
3927 | // Some temporary debugging help to show all the TeleportFlags we have... | 4225 | // Some temporary debugging help to show all the TeleportFlags we have... |
@@ -3946,6 +4244,5 @@ namespace OpenSim.Region.Framework.Scenes | |||
3946 | m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); | 4244 | m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); |
3947 | 4245 | ||
3948 | } | 4246 | } |
3949 | |||
3950 | } | 4247 | } |
3951 | } | 4248 | } |