aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs515
1 files changed, 437 insertions, 78 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 7e49a5e..5a6fb6c 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -63,6 +63,7 @@ namespace OpenSim.Region.Framework.Scenes
63 63
64 struct ScriptControllers 64 struct ScriptControllers
65 { 65 {
66 public UUID objectID;
66 public UUID itemID; 67 public UUID itemID;
67 public ScriptControlled ignoreControls; 68 public ScriptControlled ignoreControls;
68 public ScriptControlled eventControls; 69 public ScriptControlled eventControls;
@@ -93,7 +94,7 @@ namespace OpenSim.Region.Framework.Scenes
93 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 94 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
94 /// issue #1716 95 /// issue #1716
95 /// </summary> 96 /// </summary>
96 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); 97 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.4f);
97 98
98 /// <summary> 99 /// <summary>
99 /// Movement updates for agents in neighboring regions are sent directly to clients. 100 /// Movement updates for agents in neighboring regions are sent directly to clients.
@@ -170,6 +171,7 @@ namespace OpenSim.Region.Framework.Scenes
170// private int m_lastColCount = -1; //KF: Look for Collision chnages 171// private int m_lastColCount = -1; //KF: Look for Collision chnages
171// private int m_updateCount = 0; //KF: Update Anims for a while 172// private int m_updateCount = 0; //KF: Update Anims for a while
172// private static readonly int UPDATE_COUNT = 10; // how many frames to update for 173// private static readonly int UPDATE_COUNT = 10; // how many frames to update for
174 private List<uint> m_lastColliders = new List<uint>();
173 175
174 private TeleportFlags m_teleportFlags; 176 private TeleportFlags m_teleportFlags;
175 public TeleportFlags TeleportFlags 177 public TeleportFlags TeleportFlags
@@ -231,6 +233,13 @@ namespace OpenSim.Region.Framework.Scenes
231 //private int m_moveToPositionStateStatus; 233 //private int m_moveToPositionStateStatus;
232 //***************************************************** 234 //*****************************************************
233 235
236 private bool m_collisionEventFlag = false;
237 private object m_collisionEventLock = new Object();
238
239 private int m_movementAnimationUpdateCounter = 0;
240
241 private Vector3 m_prevSitOffset;
242
234 protected AvatarAppearance m_appearance; 243 protected AvatarAppearance m_appearance;
235 244
236 public AvatarAppearance Appearance 245 public AvatarAppearance Appearance
@@ -570,6 +579,13 @@ namespace OpenSim.Region.Framework.Scenes
570 /// </summary> 579 /// </summary>
571 public uint ParentID { get; set; } 580 public uint ParentID { get; set; }
572 581
582 public UUID ParentUUID
583 {
584 get { return m_parentUUID; }
585 set { m_parentUUID = value; }
586 }
587 private UUID m_parentUUID = UUID.Zero;
588
573 /// <summary> 589 /// <summary>
574 /// If the avatar is sitting, the prim that it's sitting on. If not sitting then null. 590 /// If the avatar is sitting, the prim that it's sitting on. If not sitting then null.
575 /// </summary> 591 /// </summary>
@@ -730,6 +746,33 @@ namespace OpenSim.Region.Framework.Scenes
730 Appearance = appearance; 746 Appearance = appearance;
731 } 747 }
732 748
749 private void RegionHeartbeatEnd(Scene scene)
750 {
751 if (IsChildAgent)
752 return;
753
754 m_movementAnimationUpdateCounter ++;
755 if (m_movementAnimationUpdateCounter >= 2)
756 {
757 m_movementAnimationUpdateCounter = 0;
758 if (Animator != null)
759 {
760 // If the parentID == 0 we are not sitting
761 // if !SitGournd then we are not sitting on the ground
762 // Fairly straightforward, now here comes the twist
763 // if ParentUUID is NOT UUID.Zero, we are looking to
764 // be sat on an object that isn't there yet. Should
765 // be treated as if sat.
766 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
767 Animator.UpdateMovementAnimations();
768 }
769 else
770 {
771 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
772 }
773 }
774 }
775
733 public void RegisterToEvents() 776 public void RegisterToEvents()
734 { 777 {
735 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 778 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -799,10 +842,38 @@ namespace OpenSim.Region.Framework.Scenes
799 "[SCENE]: Upgrading child to root agent for {0} in {1}", 842 "[SCENE]: Upgrading child to root agent for {0} in {1}",
800 Name, m_scene.RegionInfo.RegionName); 843 Name, m_scene.RegionInfo.RegionName);
801 844
802 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
803
804 bool wasChild = IsChildAgent; 845 bool wasChild = IsChildAgent;
805 IsChildAgent = false; 846
847 if (ParentUUID != UUID.Zero)
848 {
849 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
850 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
851 if (part == null)
852 {
853 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
854 }
855 else
856 {
857 part.ParentGroup.AddAvatar(UUID);
858 if (part.SitTargetPosition != Vector3.Zero)
859 part.SitTargetAvatar = UUID;
860 ParentPosition = part.GetWorldPosition();
861 ParentID = part.LocalId;
862 ParentPart = part;
863 m_pos = m_prevSitOffset;
864 pos = ParentPosition;
865 }
866 ParentUUID = UUID.Zero;
867
868 IsChildAgent = false;
869
870 Animator.TrySetMovementAnimation("SIT");
871 }
872 else
873 {
874 IsChildAgent = false;
875 }
876
806 877
807 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 878 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
808 if (gm != null) 879 if (gm != null)
@@ -812,62 +883,72 @@ namespace OpenSim.Region.Framework.Scenes
812 883
813 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 884 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
814 885
815 // Moved this from SendInitialData to ensure that Appearance is initialized 886 if (ParentID == 0)
816 // before the inventory is processed in MakeRootAgent. This fixes a race condition
817 // related to the handling of attachments
818 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
819 if (m_scene.TestBorderCross(pos, Cardinals.E))
820 { 887 {
821 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 888 // Moved this from SendInitialData to ensure that Appearance is initialized
822 pos.X = crossedBorder.BorderLine.Z - 1; 889 // before the inventory is processed in MakeRootAgent. This fixes a race condition
823 } 890 // related to the handling of attachments
891 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
892 if (m_scene.TestBorderCross(pos, Cardinals.E))
893 {
894 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
895 pos.X = crossedBorder.BorderLine.Z - 1;
896 }
824 897
825 if (m_scene.TestBorderCross(pos, Cardinals.N)) 898 if (m_scene.TestBorderCross(pos, Cardinals.N))
826 { 899 {
827 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 900 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
828 pos.Y = crossedBorder.BorderLine.Z - 1; 901 pos.Y = crossedBorder.BorderLine.Z - 1;
829 } 902 }
830 903
831 CheckAndAdjustLandingPoint(ref pos); 904 CheckAndAdjustLandingPoint(ref pos);
832 905
833 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 906 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
834 { 907 {
835 m_log.WarnFormat( 908 m_log.WarnFormat(
836 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 909 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
837 pos, Name, UUID); 910 pos, Name, UUID);
838 911
839 if (pos.X < 0f) pos.X = 0f; 912 if (pos.X < 0f) pos.X = 0f;
840 if (pos.Y < 0f) pos.Y = 0f; 913 if (pos.Y < 0f) pos.Y = 0f;
841 if (pos.Z < 0f) pos.Z = 0f; 914 if (pos.Z < 0f) pos.Z = 0f;
842 } 915 }
843 916
844 float localAVHeight = 1.56f; 917 float localAVHeight = 1.56f;
845 if (Appearance.AvatarHeight > 0) 918 if (Appearance.AvatarHeight > 0)
846 localAVHeight = Appearance.AvatarHeight; 919 localAVHeight = Appearance.AvatarHeight;
847 920
848 float posZLimit = 0; 921 float posZLimit = 0;
849 922
850 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 923 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
851 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 924 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
852 925
853 float newPosZ = posZLimit + localAVHeight / 2; 926 float newPosZ = posZLimit + localAVHeight / 2;
854 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 927 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
855 { 928 {
856 pos.Z = newPosZ; 929 pos.Z = newPosZ;
857 } 930 }
858 AbsolutePosition = pos; 931 AbsolutePosition = pos;
859 932
860 AddToPhysicalScene(isFlying); 933 if (m_teleportFlags == TeleportFlags.Default)
934 {
935 Vector3 vel = Velocity;
936 AddToPhysicalScene(isFlying);
937 if (PhysicsActor != null)
938 PhysicsActor.SetMomentum(vel);
939 }
940 else
941 AddToPhysicalScene(isFlying);
861 942
862 if (ForceFly) 943 if (ForceFly)
863 { 944 {
864 Flying = true; 945 Flying = true;
865 } 946 }
866 else if (FlyDisabled) 947 else if (FlyDisabled)
867 { 948 {
868 Flying = false; 949 Flying = false;
950 }
869 } 951 }
870
871 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 952 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
872 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 953 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
873 // elsewhere anyway 954 // elsewhere anyway
@@ -885,14 +966,19 @@ namespace OpenSim.Region.Framework.Scenes
885 { 966 {
886 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); 967 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments...");
887 // Resume scripts 968 // Resume scripts
888 foreach (SceneObjectGroup sog in m_attachments) 969 Util.FireAndForget(delegate(object x) {
889 { 970 foreach (SceneObjectGroup sog in m_attachments)
890 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 971 {
891 sog.ResumeScripts(); 972 sog.ScheduleGroupForFullUpdate();
892 } 973 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
974 sog.ResumeScripts();
975 }
976 });
893 } 977 }
894 } 978 }
895 979
980 SendAvatarDataToAllAgents();
981
896 // send the animations of the other presences to me 982 // send the animations of the other presences to me
897 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 983 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
898 { 984 {
@@ -903,9 +989,12 @@ namespace OpenSim.Region.Framework.Scenes
903 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 989 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
904 // stall on the border crossing since the existing child agent will still have the last movement 990 // stall on the border crossing since the existing child agent will still have the last movement
905 // recorded, which stops the input from being processed. 991 // recorded, which stops the input from being processed.
992
906 MovementFlag = 0; 993 MovementFlag = 0;
907 994
908 m_scene.EventManager.TriggerOnMakeRootAgent(this); 995 m_scene.EventManager.TriggerOnMakeRootAgent(this);
996
997 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
909 } 998 }
910 999
911 public int GetStateSource() 1000 public int GetStateSource()
@@ -933,12 +1022,16 @@ namespace OpenSim.Region.Framework.Scenes
933 /// </remarks> 1022 /// </remarks>
934 public void MakeChildAgent() 1023 public void MakeChildAgent()
935 { 1024 {
1025 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1026
936 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1027 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
937 1028
938 // Reset these so that teleporting in and walking out isn't seen 1029 // Reset these so that teleporting in and walking out isn't seen
939 // as teleporting back 1030 // as teleporting back
940 TeleportFlags = TeleportFlags.Default; 1031 TeleportFlags = TeleportFlags.Default;
941 1032
1033 MovementFlag = 0;
1034
942 // It looks like Animator is set to null somewhere, and MakeChild 1035 // It looks like Animator is set to null somewhere, and MakeChild
943 // is called after that. Probably in aborted teleports. 1036 // is called after that. Probably in aborted teleports.
944 if (Animator == null) 1037 if (Animator == null)
@@ -946,6 +1039,7 @@ namespace OpenSim.Region.Framework.Scenes
946 else 1039 else
947 Animator.ResetAnimations(); 1040 Animator.ResetAnimations();
948 1041
1042
949// m_log.DebugFormat( 1043// m_log.DebugFormat(
950// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1044// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
951// Name, UUID, m_scene.RegionInfo.RegionName); 1045// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -972,9 +1066,9 @@ namespace OpenSim.Region.Framework.Scenes
972 { 1066 {
973// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1067// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
974 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1068 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
975 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
976 PhysicsActor.UnSubscribeEvents();
977 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1069 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1070 PhysicsActor.UnSubscribeEvents();
1071 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
978 PhysicsActor = null; 1072 PhysicsActor = null;
979 } 1073 }
980// else 1074// else
@@ -991,7 +1085,7 @@ namespace OpenSim.Region.Framework.Scenes
991 /// <param name="pos"></param> 1085 /// <param name="pos"></param>
992 public void Teleport(Vector3 pos) 1086 public void Teleport(Vector3 pos)
993 { 1087 {
994 TeleportWithMomentum(pos, null); 1088 TeleportWithMomentum(pos, Vector3.Zero);
995 } 1089 }
996 1090
997 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1091 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1013,6 +1107,41 @@ namespace OpenSim.Region.Framework.Scenes
1013 SendTerseUpdateToAllClients(); 1107 SendTerseUpdateToAllClients();
1014 } 1108 }
1015 1109
1110 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1111 {
1112 CheckLandingPoint(ref newpos);
1113 AbsolutePosition = newpos;
1114
1115 if (newvel.HasValue)
1116 {
1117 if ((Vector3)newvel == Vector3.Zero)
1118 {
1119 if (PhysicsActor != null)
1120 PhysicsActor.SetMomentum(Vector3.Zero);
1121 m_velocity = Vector3.Zero;
1122 }
1123 else
1124 {
1125 if (PhysicsActor != null)
1126 PhysicsActor.SetMomentum((Vector3)newvel);
1127 m_velocity = (Vector3)newvel;
1128
1129 if (rotateToVelXY)
1130 {
1131 Vector3 lookAt = (Vector3)newvel;
1132 lookAt.Z = 0;
1133 lookAt.Normalize();
1134 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1135 return;
1136 }
1137 }
1138 }
1139
1140 SendTerseUpdateToAllClients();
1141 }
1142
1143
1144
1016 public void StopFlying() 1145 public void StopFlying()
1017 { 1146 {
1018 ControllingClient.StopFlying(this); 1147 ControllingClient.StopFlying(this);
@@ -1322,8 +1451,18 @@ namespace OpenSim.Region.Framework.Scenes
1322 { 1451 {
1323 if (m_followCamAuto) 1452 if (m_followCamAuto)
1324 { 1453 {
1325 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1454 // Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
1326 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1455 // m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback);
1456
1457 Vector3 posAdjusted = AbsolutePosition + HEAD_ADJUSTMENT;
1458 Vector3 distTocam = CameraPosition - posAdjusted;
1459 float distTocamlen = distTocam.Length();
1460 if (distTocamlen > 0)
1461 {
1462 distTocam *= 1.0f / distTocamlen;
1463 m_scene.PhysicsScene.RaycastWorld(posAdjusted, distTocam, distTocamlen + 0.3f, RayCastCameraCallback);
1464 }
1465
1327 } 1466 }
1328 } 1467 }
1329 1468
@@ -1756,12 +1895,17 @@ namespace OpenSim.Region.Framework.Scenes
1756// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 1895// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1757 1896
1758 SitGround = false; 1897 SitGround = false;
1898
1899/* move this down so avatar gets physical in the new position and not where it is siting
1759 if (PhysicsActor == null) 1900 if (PhysicsActor == null)
1760 AddToPhysicalScene(false); 1901 AddToPhysicalScene(false);
1902 */
1761 1903
1762 if (ParentID != 0) 1904 if (ParentID != 0)
1763 { 1905 {
1764 SceneObjectPart part = ParentPart; 1906 SceneObjectPart part = ParentPart;
1907 UnRegisterSeatControls(part.ParentGroup.UUID);
1908
1765 TaskInventoryDictionary taskIDict = part.TaskInventory; 1909 TaskInventoryDictionary taskIDict = part.TaskInventory;
1766 if (taskIDict != null) 1910 if (taskIDict != null)
1767 { 1911 {
@@ -1781,6 +1925,7 @@ namespace OpenSim.Region.Framework.Scenes
1781 if (part.SitTargetAvatar == UUID) 1925 if (part.SitTargetAvatar == UUID)
1782 part.SitTargetAvatar = UUID.Zero; 1926 part.SitTargetAvatar = UUID.Zero;
1783 1927
1928 part.ParentGroup.DeleteAvatar(UUID);
1784 ParentPosition = part.GetWorldPosition(); 1929 ParentPosition = part.GetWorldPosition();
1785 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1930 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1786 1931
@@ -1789,6 +1934,10 @@ namespace OpenSim.Region.Framework.Scenes
1789 1934
1790 ParentID = 0; 1935 ParentID = 0;
1791 ParentPart = null; 1936 ParentPart = null;
1937
1938 if (PhysicsActor == null)
1939 AddToPhysicalScene(false);
1940
1792 SendAvatarDataToAllAgents(); 1941 SendAvatarDataToAllAgents();
1793 m_requestedSitTargetID = 0; 1942 m_requestedSitTargetID = 0;
1794 1943
@@ -1796,6 +1945,9 @@ namespace OpenSim.Region.Framework.Scenes
1796 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 1945 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1797 } 1946 }
1798 1947
1948 else if (PhysicsActor == null)
1949 AddToPhysicalScene(false);
1950
1799 Animator.TrySetMovementAnimation("STAND"); 1951 Animator.TrySetMovementAnimation("STAND");
1800 } 1952 }
1801 1953
@@ -1919,7 +2071,7 @@ namespace OpenSim.Region.Framework.Scenes
1919 forceMouselook = part.GetForceMouselook(); 2071 forceMouselook = part.GetForceMouselook();
1920 2072
1921 ControllingClient.SendSitResponse( 2073 ControllingClient.SendSitResponse(
1922 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2074 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
1923 2075
1924 m_requestedSitTargetUUID = targetID; 2076 m_requestedSitTargetUUID = targetID;
1925 2077
@@ -2201,14 +2353,36 @@ namespace OpenSim.Region.Framework.Scenes
2201 2353
2202 //Quaternion result = (sitTargetOrient * vq) * nq; 2354 //Quaternion result = (sitTargetOrient * vq) * nq;
2203 2355
2204 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2356 double x, y, z, m;
2357
2358 Quaternion r = sitTargetOrient;
2359 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2360
2361 if (Math.Abs(1.0 - m) > 0.000001)
2362 {
2363 m = 1.0 / Math.Sqrt(m);
2364 r.X *= (float)m;
2365 r.Y *= (float)m;
2366 r.Z *= (float)m;
2367 r.W *= (float)m;
2368 }
2369
2370 x = 2 * (r.X * r.Z + r.Y * r.W);
2371 y = 2 * (-r.X * r.W + r.Y * r.Z);
2372 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2373
2374 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2375 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2376 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2205 Rotation = sitTargetOrient; 2377 Rotation = sitTargetOrient;
2206 ParentPosition = part.AbsolutePosition; 2378 ParentPosition = part.AbsolutePosition;
2379 part.ParentGroup.AddAvatar(UUID);
2207 } 2380 }
2208 else 2381 else
2209 { 2382 {
2210 m_pos -= part.AbsolutePosition; 2383 m_pos -= part.AbsolutePosition;
2211 ParentPosition = part.AbsolutePosition; 2384 ParentPosition = part.AbsolutePosition;
2385 part.ParentGroup.AddAvatar(UUID);
2212 2386
2213// m_log.DebugFormat( 2387// m_log.DebugFormat(
2214// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2388// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2306,14 +2480,15 @@ namespace OpenSim.Region.Framework.Scenes
2306 direc.Z *= 2.6f; 2480 direc.Z *= 2.6f;
2307 2481
2308 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2482 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2309 Animator.TrySetMovementAnimation("PREJUMP"); 2483// Animator.TrySetMovementAnimation("PREJUMP");
2310 Animator.TrySetMovementAnimation("JUMP"); 2484// Animator.TrySetMovementAnimation("JUMP");
2311 } 2485 }
2312 } 2486 }
2313 } 2487 }
2314 2488
2315 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2489 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2316 m_forceToApply = direc; 2490 m_forceToApply = direc;
2491 Animator.UpdateMovementAnimations();
2317 } 2492 }
2318 2493
2319 #endregion 2494 #endregion
@@ -3047,6 +3222,9 @@ namespace OpenSim.Region.Framework.Scenes
3047 cAgent.AlwaysRun = SetAlwaysRun; 3222 cAgent.AlwaysRun = SetAlwaysRun;
3048 3223
3049 cAgent.Appearance = new AvatarAppearance(Appearance); 3224 cAgent.Appearance = new AvatarAppearance(Appearance);
3225
3226 cAgent.ParentPart = ParentUUID;
3227 cAgent.SitOffset = m_pos;
3050 3228
3051 lock (scriptedcontrols) 3229 lock (scriptedcontrols)
3052 { 3230 {
@@ -3055,7 +3233,7 @@ namespace OpenSim.Region.Framework.Scenes
3055 3233
3056 foreach (ScriptControllers c in scriptedcontrols.Values) 3234 foreach (ScriptControllers c in scriptedcontrols.Values)
3057 { 3235 {
3058 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3236 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3059 } 3237 }
3060 cAgent.Controllers = controls; 3238 cAgent.Controllers = controls;
3061 } 3239 }
@@ -3066,6 +3244,7 @@ namespace OpenSim.Region.Framework.Scenes
3066 cAgent.Anims = Animator.Animations.ToArray(); 3244 cAgent.Anims = Animator.Animations.ToArray();
3067 } 3245 }
3068 catch { } 3246 catch { }
3247 cAgent.DefaultAnim = Animator.Animations.DefaultAnimation;
3069 3248
3070 // Attachment objects 3249 // Attachment objects
3071 List<SceneObjectGroup> attachments = GetAttachments(); 3250 List<SceneObjectGroup> attachments = GetAttachments();
@@ -3106,6 +3285,8 @@ namespace OpenSim.Region.Framework.Scenes
3106 CameraAtAxis = cAgent.AtAxis; 3285 CameraAtAxis = cAgent.AtAxis;
3107 CameraLeftAxis = cAgent.LeftAxis; 3286 CameraLeftAxis = cAgent.LeftAxis;
3108 CameraUpAxis = cAgent.UpAxis; 3287 CameraUpAxis = cAgent.UpAxis;
3288 ParentUUID = cAgent.ParentPart;
3289 m_prevSitOffset = cAgent.SitOffset;
3109 3290
3110 // When we get to the point of re-computing neighbors everytime this 3291 // When we get to the point of re-computing neighbors everytime this
3111 // changes, then start using the agent's drawdistance rather than the 3292 // changes, then start using the agent's drawdistance rather than the
@@ -3143,6 +3324,7 @@ namespace OpenSim.Region.Framework.Scenes
3143 foreach (ControllerData c in cAgent.Controllers) 3324 foreach (ControllerData c in cAgent.Controllers)
3144 { 3325 {
3145 ScriptControllers sc = new ScriptControllers(); 3326 ScriptControllers sc = new ScriptControllers();
3327 sc.objectID = c.ObjectID;
3146 sc.itemID = c.ItemID; 3328 sc.itemID = c.ItemID;
3147 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3329 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3148 sc.eventControls = (ScriptControlled)c.EventControls; 3330 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3157,6 +3339,8 @@ namespace OpenSim.Region.Framework.Scenes
3157 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object? 3339 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object?
3158 if (cAgent.Anims != null) 3340 if (cAgent.Anims != null)
3159 Animator.Animations.FromArray(cAgent.Anims); 3341 Animator.Animations.FromArray(cAgent.Anims);
3342 if (cAgent.DefaultAnim != null)
3343 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero);
3160 3344
3161 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0) 3345 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0)
3162 { 3346 {
@@ -3258,18 +3442,6 @@ namespace OpenSim.Region.Framework.Scenes
3258 if (IsChildAgent) 3442 if (IsChildAgent)
3259 return; 3443 return;
3260 3444
3261 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
3262 // The Physics Scene will send updates every 500 ms grep: PhysicsActor.SubscribeEvents(
3263 // as of this comment the interval is set in AddToPhysicalScene
3264 if (Animator != null)
3265 {
3266// if (m_updateCount > 0)
3267// {
3268 Animator.UpdateMovementAnimations();
3269// m_updateCount--;
3270// }
3271 }
3272
3273 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3445 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3274 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3446 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3275 3447
@@ -3644,10 +3816,15 @@ namespace OpenSim.Region.Framework.Scenes
3644 3816
3645 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 3817 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3646 { 3818 {
3819 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
3820 if (p == null)
3821 return;
3822
3647 ScriptControllers obj = new ScriptControllers(); 3823 ScriptControllers obj = new ScriptControllers();
3648 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 3824 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3649 obj.eventControls = ScriptControlled.CONTROL_ZERO; 3825 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3650 3826
3827 obj.objectID = p.ParentGroup.UUID;
3651 obj.itemID = Script_item_UUID; 3828 obj.itemID = Script_item_UUID;
3652 if (pass_on == 0 && accept == 0) 3829 if (pass_on == 0 && accept == 0)
3653 { 3830 {
@@ -3696,6 +3873,21 @@ namespace OpenSim.Region.Framework.Scenes
3696 ControllingClient.SendTakeControls(int.MaxValue, false, false); 3873 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3697 } 3874 }
3698 3875
3876 private void UnRegisterSeatControls(UUID obj)
3877 {
3878 List<UUID> takers = new List<UUID>();
3879
3880 foreach (ScriptControllers c in scriptedcontrols.Values)
3881 {
3882 if (c.objectID == obj)
3883 takers.Add(c.itemID);
3884 }
3885 foreach (UUID t in takers)
3886 {
3887 UnRegisterControlEventsToScript(0, t);
3888 }
3889 }
3890
3699 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 3891 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3700 { 3892 {
3701 ScriptControllers takecontrols; 3893 ScriptControllers takecontrols;
@@ -3950,6 +4142,12 @@ namespace OpenSim.Region.Framework.Scenes
3950 4142
3951 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4143 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
3952 { 4144 {
4145 string reason;
4146
4147 // Honor bans
4148 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4149 return;
4150
3953 SceneObjectGroup telehub = null; 4151 SceneObjectGroup telehub = null;
3954 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4152 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
3955 { 4153 {
@@ -3989,11 +4187,173 @@ namespace OpenSim.Region.Framework.Scenes
3989 pos = land.LandData.UserLocation; 4187 pos = land.LandData.UserLocation;
3990 } 4188 }
3991 } 4189 }
3992 4190
3993 land.SendLandUpdateToClient(ControllingClient); 4191 land.SendLandUpdateToClient(ControllingClient);
3994 } 4192 }
3995 } 4193 }
3996 4194
4195 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4196 {
4197 lock(m_collisionEventLock)
4198 {
4199 if (m_collisionEventFlag)
4200 return;
4201 m_collisionEventFlag = true;
4202 }
4203
4204 Util.FireAndForget(delegate(object x)
4205 {
4206 try
4207 {
4208 List<uint> thisHitColliders = new List<uint>();
4209 List<uint> endedColliders = new List<uint>();
4210 List<uint> startedColliders = new List<uint>();
4211
4212 foreach (uint localid in coldata.Keys)
4213 {
4214 thisHitColliders.Add(localid);
4215 if (!m_lastColliders.Contains(localid))
4216 {
4217 startedColliders.Add(localid);
4218 }
4219 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4220 }
4221
4222 // calculate things that ended colliding
4223 foreach (uint localID in m_lastColliders)
4224 {
4225 if (!thisHitColliders.Contains(localID))
4226 {
4227 endedColliders.Add(localID);
4228 }
4229 }
4230 //add the items that started colliding this time to the last colliders list.
4231 foreach (uint localID in startedColliders)
4232 {
4233 m_lastColliders.Add(localID);
4234 }
4235 // remove things that ended colliding from the last colliders list
4236 foreach (uint localID in endedColliders)
4237 {
4238 m_lastColliders.Remove(localID);
4239 }
4240
4241 // do event notification
4242 if (startedColliders.Count > 0)
4243 {
4244 ColliderArgs StartCollidingMessage = new ColliderArgs();
4245 List<DetectedObject> colliding = new List<DetectedObject>();
4246 foreach (uint localId in startedColliders)
4247 {
4248 if (localId == 0)
4249 continue;
4250
4251 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4252 string data = "";
4253 if (obj != null)
4254 {
4255 DetectedObject detobj = new DetectedObject();
4256 detobj.keyUUID = obj.UUID;
4257 detobj.nameStr = obj.Name;
4258 detobj.ownerUUID = obj.OwnerID;
4259 detobj.posVector = obj.AbsolutePosition;
4260 detobj.rotQuat = obj.GetWorldRotation();
4261 detobj.velVector = obj.Velocity;
4262 detobj.colliderType = 0;
4263 detobj.groupUUID = obj.GroupID;
4264 colliding.Add(detobj);
4265 }
4266 }
4267
4268 if (colliding.Count > 0)
4269 {
4270 StartCollidingMessage.Colliders = colliding;
4271
4272 foreach (SceneObjectGroup att in GetAttachments())
4273 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
4274 }
4275 }
4276
4277 if (endedColliders.Count > 0)
4278 {
4279 ColliderArgs EndCollidingMessage = new ColliderArgs();
4280 List<DetectedObject> colliding = new List<DetectedObject>();
4281 foreach (uint localId in endedColliders)
4282 {
4283 if (localId == 0)
4284 continue;
4285
4286 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4287 string data = "";
4288 if (obj != null)
4289 {
4290 DetectedObject detobj = new DetectedObject();
4291 detobj.keyUUID = obj.UUID;
4292 detobj.nameStr = obj.Name;
4293 detobj.ownerUUID = obj.OwnerID;
4294 detobj.posVector = obj.AbsolutePosition;
4295 detobj.rotQuat = obj.GetWorldRotation();
4296 detobj.velVector = obj.Velocity;
4297 detobj.colliderType = 0;
4298 detobj.groupUUID = obj.GroupID;
4299 colliding.Add(detobj);
4300 }
4301 }
4302
4303 if (colliding.Count > 0)
4304 {
4305 EndCollidingMessage.Colliders = colliding;
4306
4307 foreach (SceneObjectGroup att in GetAttachments())
4308 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
4309 }
4310 }
4311
4312 if (thisHitColliders.Count > 0)
4313 {
4314 ColliderArgs CollidingMessage = new ColliderArgs();
4315 List<DetectedObject> colliding = new List<DetectedObject>();
4316 foreach (uint localId in thisHitColliders)
4317 {
4318 if (localId == 0)
4319 continue;
4320
4321 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4322 string data = "";
4323 if (obj != null)
4324 {
4325 DetectedObject detobj = new DetectedObject();
4326 detobj.keyUUID = obj.UUID;
4327 detobj.nameStr = obj.Name;
4328 detobj.ownerUUID = obj.OwnerID;
4329 detobj.posVector = obj.AbsolutePosition;
4330 detobj.rotQuat = obj.GetWorldRotation();
4331 detobj.velVector = obj.Velocity;
4332 detobj.colliderType = 0;
4333 detobj.groupUUID = obj.GroupID;
4334 colliding.Add(detobj);
4335 }
4336 }
4337
4338 if (colliding.Count > 0)
4339 {
4340 CollidingMessage.Colliders = colliding;
4341
4342 lock (m_attachments)
4343 {
4344 foreach (SceneObjectGroup att in m_attachments)
4345 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
4346 }
4347 }
4348 }
4349 }
4350 finally
4351 {
4352 m_collisionEventFlag = false;
4353 }
4354 });
4355 }
4356
3997 private void TeleportFlagsDebug() { 4357 private void TeleportFlagsDebug() {
3998 4358
3999 // Some temporary debugging help to show all the TeleportFlags we have... 4359 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4018,6 +4378,5 @@ namespace OpenSim.Region.Framework.Scenes
4018 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4378 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4019 4379
4020 } 4380 }
4021
4022 } 4381 }
4023} 4382}