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.cs527
1 files changed, 448 insertions, 79 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 3adafc1..e0872d0 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;
@@ -98,7 +99,7 @@ namespace OpenSim.Region.Framework.Scenes
98 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 99 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
99 /// issue #1716 100 /// issue #1716
100 /// </summary> 101 /// </summary>
101 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); 102 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.4f);
102 103
103 /// <summary> 104 /// <summary>
104 /// Movement updates for agents in neighboring regions are sent directly to clients. 105 /// Movement updates for agents in neighboring regions are sent directly to clients.
@@ -175,6 +176,7 @@ namespace OpenSim.Region.Framework.Scenes
175// private int m_lastColCount = -1; //KF: Look for Collision chnages 176// private int m_lastColCount = -1; //KF: Look for Collision chnages
176// private int m_updateCount = 0; //KF: Update Anims for a while 177// private int m_updateCount = 0; //KF: Update Anims for a while
177// private static readonly int UPDATE_COUNT = 10; // how many frames to update for 178// private static readonly int UPDATE_COUNT = 10; // how many frames to update for
179 private List<uint> m_lastColliders = new List<uint>();
178 180
179 private TeleportFlags m_teleportFlags; 181 private TeleportFlags m_teleportFlags;
180 public TeleportFlags TeleportFlags 182 public TeleportFlags TeleportFlags
@@ -236,6 +238,13 @@ namespace OpenSim.Region.Framework.Scenes
236 //private int m_moveToPositionStateStatus; 238 //private int m_moveToPositionStateStatus;
237 //***************************************************** 239 //*****************************************************
238 240
241 private bool m_collisionEventFlag = false;
242 private object m_collisionEventLock = new Object();
243
244 private int m_movementAnimationUpdateCounter = 0;
245
246 private Vector3 m_prevSitOffset;
247
239 protected AvatarAppearance m_appearance; 248 protected AvatarAppearance m_appearance;
240 249
241 public AvatarAppearance Appearance 250 public AvatarAppearance Appearance
@@ -577,6 +586,13 @@ namespace OpenSim.Region.Framework.Scenes
577 /// </summary> 586 /// </summary>
578 public uint ParentID { get; set; } 587 public uint ParentID { get; set; }
579 588
589 public UUID ParentUUID
590 {
591 get { return m_parentUUID; }
592 set { m_parentUUID = value; }
593 }
594 private UUID m_parentUUID = UUID.Zero;
595
580 /// <summary> 596 /// <summary>
581 /// If the avatar is sitting, the prim that it's sitting on. If not sitting then null. 597 /// If the avatar is sitting, the prim that it's sitting on. If not sitting then null.
582 /// </summary> 598 /// </summary>
@@ -737,6 +753,33 @@ namespace OpenSim.Region.Framework.Scenes
737 Appearance = appearance; 753 Appearance = appearance;
738 } 754 }
739 755
756 private void RegionHeartbeatEnd(Scene scene)
757 {
758 if (IsChildAgent)
759 return;
760
761 m_movementAnimationUpdateCounter ++;
762 if (m_movementAnimationUpdateCounter >= 2)
763 {
764 m_movementAnimationUpdateCounter = 0;
765 if (Animator != null)
766 {
767 // If the parentID == 0 we are not sitting
768 // if !SitGournd then we are not sitting on the ground
769 // Fairly straightforward, now here comes the twist
770 // if ParentUUID is NOT UUID.Zero, we are looking to
771 // be sat on an object that isn't there yet. Should
772 // be treated as if sat.
773 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
774 Animator.UpdateMovementAnimations();
775 }
776 else
777 {
778 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
779 }
780 }
781 }
782
740 public void RegisterToEvents() 783 public void RegisterToEvents()
741 { 784 {
742 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 785 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -746,6 +789,7 @@ namespace OpenSim.Region.Framework.Scenes
746 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 789 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
747 ControllingClient.OnStartAnim += HandleStartAnim; 790 ControllingClient.OnStartAnim += HandleStartAnim;
748 ControllingClient.OnStopAnim += HandleStopAnim; 791 ControllingClient.OnStopAnim += HandleStopAnim;
792 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
749 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 793 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
750 ControllingClient.OnAutoPilotGo += MoveToTarget; 794 ControllingClient.OnAutoPilotGo += MoveToTarget;
751 795
@@ -806,10 +850,38 @@ namespace OpenSim.Region.Framework.Scenes
806 "[SCENE]: Upgrading child to root agent for {0} in {1}", 850 "[SCENE]: Upgrading child to root agent for {0} in {1}",
807 Name, m_scene.RegionInfo.RegionName); 851 Name, m_scene.RegionInfo.RegionName);
808 852
809 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
810
811 bool wasChild = IsChildAgent; 853 bool wasChild = IsChildAgent;
812 IsChildAgent = false; 854
855 if (ParentUUID != UUID.Zero)
856 {
857 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
858 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
859 if (part == null)
860 {
861 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
862 }
863 else
864 {
865 part.ParentGroup.AddAvatar(UUID);
866 if (part.SitTargetPosition != Vector3.Zero)
867 part.SitTargetAvatar = UUID;
868 ParentPosition = part.GetWorldPosition();
869 ParentID = part.LocalId;
870 ParentPart = part;
871 m_pos = m_prevSitOffset;
872 pos = ParentPosition;
873 }
874 ParentUUID = UUID.Zero;
875
876 IsChildAgent = false;
877
878 Animator.TrySetMovementAnimation("SIT");
879 }
880 else
881 {
882 IsChildAgent = false;
883 }
884
813 885
814 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 886 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
815 if (gm != null) 887 if (gm != null)
@@ -819,62 +891,72 @@ namespace OpenSim.Region.Framework.Scenes
819 891
820 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 892 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
821 893
822 // Moved this from SendInitialData to ensure that Appearance is initialized 894 if (ParentID == 0)
823 // before the inventory is processed in MakeRootAgent. This fixes a race condition
824 // related to the handling of attachments
825 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
826 if (m_scene.TestBorderCross(pos, Cardinals.E))
827 { 895 {
828 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 896 // Moved this from SendInitialData to ensure that Appearance is initialized
829 pos.X = crossedBorder.BorderLine.Z - 1; 897 // before the inventory is processed in MakeRootAgent. This fixes a race condition
830 } 898 // related to the handling of attachments
899 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
900 if (m_scene.TestBorderCross(pos, Cardinals.E))
901 {
902 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
903 pos.X = crossedBorder.BorderLine.Z - 1;
904 }
831 905
832 if (m_scene.TestBorderCross(pos, Cardinals.N)) 906 if (m_scene.TestBorderCross(pos, Cardinals.N))
833 { 907 {
834 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 908 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
835 pos.Y = crossedBorder.BorderLine.Z - 1; 909 pos.Y = crossedBorder.BorderLine.Z - 1;
836 } 910 }
837 911
838 CheckAndAdjustLandingPoint(ref pos); 912 CheckAndAdjustLandingPoint(ref pos);
839 913
840 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 914 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
841 { 915 {
842 m_log.WarnFormat( 916 m_log.WarnFormat(
843 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 917 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
844 pos, Name, UUID); 918 pos, Name, UUID);
845 919
846 if (pos.X < 0f) pos.X = 0f; 920 if (pos.X < 0f) pos.X = 0f;
847 if (pos.Y < 0f) pos.Y = 0f; 921 if (pos.Y < 0f) pos.Y = 0f;
848 if (pos.Z < 0f) pos.Z = 0f; 922 if (pos.Z < 0f) pos.Z = 0f;
849 } 923 }
850 924
851 float localAVHeight = 1.56f; 925 float localAVHeight = 1.56f;
852 if (Appearance.AvatarHeight > 0) 926 if (Appearance.AvatarHeight > 0)
853 localAVHeight = Appearance.AvatarHeight; 927 localAVHeight = Appearance.AvatarHeight;
854 928
855 float posZLimit = 0; 929 float posZLimit = 0;
856 930
857 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 931 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
858 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 932 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
859 933
860 float newPosZ = posZLimit + localAVHeight / 2; 934 float newPosZ = posZLimit + localAVHeight / 2;
861 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 935 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
862 { 936 {
863 pos.Z = newPosZ; 937 pos.Z = newPosZ;
864 } 938 }
865 AbsolutePosition = pos; 939 AbsolutePosition = pos;
866 940
867 AddToPhysicalScene(isFlying); 941 if (m_teleportFlags == TeleportFlags.Default)
942 {
943 Vector3 vel = Velocity;
944 AddToPhysicalScene(isFlying);
945 if (PhysicsActor != null)
946 PhysicsActor.SetMomentum(vel);
947 }
948 else
949 AddToPhysicalScene(isFlying);
868 950
869 if (ForceFly) 951 if (ForceFly)
870 { 952 {
871 Flying = true; 953 Flying = true;
872 } 954 }
873 else if (FlyDisabled) 955 else if (FlyDisabled)
874 { 956 {
875 Flying = false; 957 Flying = false;
958 }
876 } 959 }
877
878 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 960 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
879 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 961 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
880 // elsewhere anyway 962 // elsewhere anyway
@@ -892,14 +974,19 @@ namespace OpenSim.Region.Framework.Scenes
892 { 974 {
893 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); 975 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments...");
894 // Resume scripts 976 // Resume scripts
895 foreach (SceneObjectGroup sog in m_attachments) 977 Util.FireAndForget(delegate(object x) {
896 { 978 foreach (SceneObjectGroup sog in m_attachments)
897 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 979 {
898 sog.ResumeScripts(); 980 sog.ScheduleGroupForFullUpdate();
899 } 981 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
982 sog.ResumeScripts();
983 }
984 });
900 } 985 }
901 } 986 }
902 987
988 SendAvatarDataToAllAgents();
989
903 // send the animations of the other presences to me 990 // send the animations of the other presences to me
904 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 991 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
905 { 992 {
@@ -910,9 +997,12 @@ namespace OpenSim.Region.Framework.Scenes
910 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 997 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
911 // stall on the border crossing since the existing child agent will still have the last movement 998 // stall on the border crossing since the existing child agent will still have the last movement
912 // recorded, which stops the input from being processed. 999 // recorded, which stops the input from being processed.
1000
913 MovementFlag = 0; 1001 MovementFlag = 0;
914 1002
915 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1003 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1004
1005 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
916 } 1006 }
917 1007
918 public int GetStateSource() 1008 public int GetStateSource()
@@ -940,12 +1030,16 @@ namespace OpenSim.Region.Framework.Scenes
940 /// </remarks> 1030 /// </remarks>
941 public void MakeChildAgent() 1031 public void MakeChildAgent()
942 { 1032 {
1033 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1034
943 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1035 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
944 1036
945 // Reset these so that teleporting in and walking out isn't seen 1037 // Reset these so that teleporting in and walking out isn't seen
946 // as teleporting back 1038 // as teleporting back
947 TeleportFlags = TeleportFlags.Default; 1039 TeleportFlags = TeleportFlags.Default;
948 1040
1041 MovementFlag = 0;
1042
949 // It looks like Animator is set to null somewhere, and MakeChild 1043 // It looks like Animator is set to null somewhere, and MakeChild
950 // is called after that. Probably in aborted teleports. 1044 // is called after that. Probably in aborted teleports.
951 if (Animator == null) 1045 if (Animator == null)
@@ -953,6 +1047,7 @@ namespace OpenSim.Region.Framework.Scenes
953 else 1047 else
954 Animator.ResetAnimations(); 1048 Animator.ResetAnimations();
955 1049
1050
956// m_log.DebugFormat( 1051// m_log.DebugFormat(
957// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1052// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
958// Name, UUID, m_scene.RegionInfo.RegionName); 1053// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -979,9 +1074,9 @@ namespace OpenSim.Region.Framework.Scenes
979 { 1074 {
980// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1075// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
981 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1076 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
982 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
983 PhysicsActor.UnSubscribeEvents();
984 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1077 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1078 PhysicsActor.UnSubscribeEvents();
1079 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
985 PhysicsActor = null; 1080 PhysicsActor = null;
986 } 1081 }
987// else 1082// else
@@ -998,7 +1093,7 @@ namespace OpenSim.Region.Framework.Scenes
998 /// <param name="pos"></param> 1093 /// <param name="pos"></param>
999 public void Teleport(Vector3 pos) 1094 public void Teleport(Vector3 pos)
1000 { 1095 {
1001 TeleportWithMomentum(pos, null); 1096 TeleportWithMomentum(pos, Vector3.Zero);
1002 } 1097 }
1003 1098
1004 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1099 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1022,6 +1117,41 @@ namespace OpenSim.Region.Framework.Scenes
1022 SendTerseUpdateToAllClients(); 1117 SendTerseUpdateToAllClients();
1023 } 1118 }
1024 1119
1120 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1121 {
1122 CheckLandingPoint(ref newpos);
1123 AbsolutePosition = newpos;
1124
1125 if (newvel.HasValue)
1126 {
1127 if ((Vector3)newvel == Vector3.Zero)
1128 {
1129 if (PhysicsActor != null)
1130 PhysicsActor.SetMomentum(Vector3.Zero);
1131 m_velocity = Vector3.Zero;
1132 }
1133 else
1134 {
1135 if (PhysicsActor != null)
1136 PhysicsActor.SetMomentum((Vector3)newvel);
1137 m_velocity = (Vector3)newvel;
1138
1139 if (rotateToVelXY)
1140 {
1141 Vector3 lookAt = (Vector3)newvel;
1142 lookAt.Z = 0;
1143 lookAt.Normalize();
1144 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1145 return;
1146 }
1147 }
1148 }
1149
1150 SendTerseUpdateToAllClients();
1151 }
1152
1153
1154
1025 public void StopFlying() 1155 public void StopFlying()
1026 { 1156 {
1027 ControllingClient.StopFlying(this); 1157 ControllingClient.StopFlying(this);
@@ -1337,8 +1467,18 @@ namespace OpenSim.Region.Framework.Scenes
1337 { 1467 {
1338 if (m_followCamAuto) 1468 if (m_followCamAuto)
1339 { 1469 {
1340 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1470 // Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
1341 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1471 // m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback);
1472
1473 Vector3 posAdjusted = AbsolutePosition + HEAD_ADJUSTMENT;
1474 Vector3 distTocam = CameraPosition - posAdjusted;
1475 float distTocamlen = distTocam.Length();
1476 if (distTocamlen > 0)
1477 {
1478 distTocam *= 1.0f / distTocamlen;
1479 m_scene.PhysicsScene.RaycastWorld(posAdjusted, distTocam, distTocamlen + 0.3f, RayCastCameraCallback);
1480 }
1481
1342 } 1482 }
1343 } 1483 }
1344 1484
@@ -1772,12 +1912,17 @@ namespace OpenSim.Region.Framework.Scenes
1772// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 1912// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1773 1913
1774 SitGround = false; 1914 SitGround = false;
1915
1916/* move this down so avatar gets physical in the new position and not where it is siting
1775 if (PhysicsActor == null) 1917 if (PhysicsActor == null)
1776 AddToPhysicalScene(false); 1918 AddToPhysicalScene(false);
1919 */
1777 1920
1778 if (ParentID != 0) 1921 if (ParentID != 0)
1779 { 1922 {
1780 SceneObjectPart part = ParentPart; 1923 SceneObjectPart part = ParentPart;
1924 UnRegisterSeatControls(part.ParentGroup.UUID);
1925
1781 TaskInventoryDictionary taskIDict = part.TaskInventory; 1926 TaskInventoryDictionary taskIDict = part.TaskInventory;
1782 if (taskIDict != null) 1927 if (taskIDict != null)
1783 { 1928 {
@@ -1797,6 +1942,7 @@ namespace OpenSim.Region.Framework.Scenes
1797 if (part.SitTargetAvatar == UUID) 1942 if (part.SitTargetAvatar == UUID)
1798 part.SitTargetAvatar = UUID.Zero; 1943 part.SitTargetAvatar = UUID.Zero;
1799 1944
1945 part.ParentGroup.DeleteAvatar(UUID);
1800 ParentPosition = part.GetWorldPosition(); 1946 ParentPosition = part.GetWorldPosition();
1801 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1947 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1802 1948
@@ -1805,6 +1951,10 @@ namespace OpenSim.Region.Framework.Scenes
1805 1951
1806 ParentID = 0; 1952 ParentID = 0;
1807 ParentPart = null; 1953 ParentPart = null;
1954
1955 if (PhysicsActor == null)
1956 AddToPhysicalScene(false);
1957
1808 SendAvatarDataToAllAgents(); 1958 SendAvatarDataToAllAgents();
1809 m_requestedSitTargetID = 0; 1959 m_requestedSitTargetID = 0;
1810 1960
@@ -1812,6 +1962,9 @@ namespace OpenSim.Region.Framework.Scenes
1812 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 1962 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1813 } 1963 }
1814 1964
1965 else if (PhysicsActor == null)
1966 AddToPhysicalScene(false);
1967
1815 Animator.TrySetMovementAnimation("STAND"); 1968 Animator.TrySetMovementAnimation("STAND");
1816 } 1969 }
1817 1970
@@ -1935,7 +2088,7 @@ namespace OpenSim.Region.Framework.Scenes
1935 forceMouselook = part.GetForceMouselook(); 2088 forceMouselook = part.GetForceMouselook();
1936 2089
1937 ControllingClient.SendSitResponse( 2090 ControllingClient.SendSitResponse(
1938 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2091 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
1939 2092
1940 m_requestedSitTargetUUID = targetID; 2093 m_requestedSitTargetUUID = targetID;
1941 2094
@@ -2217,14 +2370,36 @@ namespace OpenSim.Region.Framework.Scenes
2217 2370
2218 //Quaternion result = (sitTargetOrient * vq) * nq; 2371 //Quaternion result = (sitTargetOrient * vq) * nq;
2219 2372
2220 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2373 double x, y, z, m;
2374
2375 Quaternion r = sitTargetOrient;
2376 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2377
2378 if (Math.Abs(1.0 - m) > 0.000001)
2379 {
2380 m = 1.0 / Math.Sqrt(m);
2381 r.X *= (float)m;
2382 r.Y *= (float)m;
2383 r.Z *= (float)m;
2384 r.W *= (float)m;
2385 }
2386
2387 x = 2 * (r.X * r.Z + r.Y * r.W);
2388 y = 2 * (-r.X * r.W + r.Y * r.Z);
2389 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2390
2391 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2392 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2393 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2221 Rotation = sitTargetOrient; 2394 Rotation = sitTargetOrient;
2222 ParentPosition = part.AbsolutePosition; 2395 ParentPosition = part.AbsolutePosition;
2396 part.ParentGroup.AddAvatar(UUID);
2223 } 2397 }
2224 else 2398 else
2225 { 2399 {
2226 m_pos -= part.AbsolutePosition; 2400 m_pos -= part.AbsolutePosition;
2227 ParentPosition = part.AbsolutePosition; 2401 ParentPosition = part.AbsolutePosition;
2402 part.ParentGroup.AddAvatar(UUID);
2228 2403
2229// m_log.DebugFormat( 2404// m_log.DebugFormat(
2230// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2405// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2269,6 +2444,13 @@ namespace OpenSim.Region.Framework.Scenes
2269 Animator.RemoveAnimation(animID); 2444 Animator.RemoveAnimation(animID);
2270 } 2445 }
2271 2446
2447 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2448 {
2449 Animator.avnChangeAnim(animID, addRemove, sendPack);
2450 }
2451
2452
2453
2272 /// <summary> 2454 /// <summary>
2273 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2455 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2274 /// </summary> 2456 /// </summary>
@@ -2322,14 +2504,15 @@ namespace OpenSim.Region.Framework.Scenes
2322 direc.Z *= 2.6f; 2504 direc.Z *= 2.6f;
2323 2505
2324 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2506 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2325 Animator.TrySetMovementAnimation("PREJUMP"); 2507// Animator.TrySetMovementAnimation("PREJUMP");
2326 Animator.TrySetMovementAnimation("JUMP"); 2508// Animator.TrySetMovementAnimation("JUMP");
2327 } 2509 }
2328 } 2510 }
2329 } 2511 }
2330 2512
2331 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2513 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2332 m_forceToApply = direc; 2514 m_forceToApply = direc;
2515 Animator.UpdateMovementAnimations();
2333 } 2516 }
2334 2517
2335 #endregion 2518 #endregion
@@ -3064,6 +3247,9 @@ namespace OpenSim.Region.Framework.Scenes
3064 cAgent.AlwaysRun = SetAlwaysRun; 3247 cAgent.AlwaysRun = SetAlwaysRun;
3065 3248
3066 cAgent.Appearance = new AvatarAppearance(Appearance); 3249 cAgent.Appearance = new AvatarAppearance(Appearance);
3250
3251 cAgent.ParentPart = ParentUUID;
3252 cAgent.SitOffset = m_pos;
3067 3253
3068 lock (scriptedcontrols) 3254 lock (scriptedcontrols)
3069 { 3255 {
@@ -3072,7 +3258,7 @@ namespace OpenSim.Region.Framework.Scenes
3072 3258
3073 foreach (ScriptControllers c in scriptedcontrols.Values) 3259 foreach (ScriptControllers c in scriptedcontrols.Values)
3074 { 3260 {
3075 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3261 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3076 } 3262 }
3077 cAgent.Controllers = controls; 3263 cAgent.Controllers = controls;
3078 } 3264 }
@@ -3083,6 +3269,7 @@ namespace OpenSim.Region.Framework.Scenes
3083 cAgent.Anims = Animator.Animations.ToArray(); 3269 cAgent.Anims = Animator.Animations.ToArray();
3084 } 3270 }
3085 catch { } 3271 catch { }
3272 cAgent.DefaultAnim = Animator.Animations.DefaultAnimation;
3086 3273
3087 // Attachment objects 3274 // Attachment objects
3088 List<SceneObjectGroup> attachments = GetAttachments(); 3275 List<SceneObjectGroup> attachments = GetAttachments();
@@ -3126,6 +3313,8 @@ namespace OpenSim.Region.Framework.Scenes
3126 CameraAtAxis = cAgent.AtAxis; 3313 CameraAtAxis = cAgent.AtAxis;
3127 CameraLeftAxis = cAgent.LeftAxis; 3314 CameraLeftAxis = cAgent.LeftAxis;
3128 CameraUpAxis = cAgent.UpAxis; 3315 CameraUpAxis = cAgent.UpAxis;
3316 ParentUUID = cAgent.ParentPart;
3317 m_prevSitOffset = cAgent.SitOffset;
3129 3318
3130 // When we get to the point of re-computing neighbors everytime this 3319 // When we get to the point of re-computing neighbors everytime this
3131 // changes, then start using the agent's drawdistance rather than the 3320 // changes, then start using the agent's drawdistance rather than the
@@ -3163,6 +3352,7 @@ namespace OpenSim.Region.Framework.Scenes
3163 foreach (ControllerData c in cAgent.Controllers) 3352 foreach (ControllerData c in cAgent.Controllers)
3164 { 3353 {
3165 ScriptControllers sc = new ScriptControllers(); 3354 ScriptControllers sc = new ScriptControllers();
3355 sc.objectID = c.ObjectID;
3166 sc.itemID = c.ItemID; 3356 sc.itemID = c.ItemID;
3167 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3357 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3168 sc.eventControls = (ScriptControlled)c.EventControls; 3358 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3177,6 +3367,8 @@ namespace OpenSim.Region.Framework.Scenes
3177 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object? 3367 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object?
3178 if (cAgent.Anims != null) 3368 if (cAgent.Anims != null)
3179 Animator.Animations.FromArray(cAgent.Anims); 3369 Animator.Animations.FromArray(cAgent.Anims);
3370 if (cAgent.DefaultAnim != null)
3371 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero);
3180 3372
3181 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0) 3373 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0)
3182 { 3374 {
@@ -3249,7 +3441,7 @@ namespace OpenSim.Region.Framework.Scenes
3249 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3441 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3250 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3442 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3251 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3443 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3252 PhysicsActor.SubscribeEvents(500); 3444 PhysicsActor.SubscribeEvents(100);
3253 PhysicsActor.LocalID = LocalId; 3445 PhysicsActor.LocalID = LocalId;
3254 } 3446 }
3255 3447
@@ -3279,18 +3471,6 @@ namespace OpenSim.Region.Framework.Scenes
3279 if (IsChildAgent) 3471 if (IsChildAgent)
3280 return; 3472 return;
3281 3473
3282 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
3283 // The Physics Scene will send updates every 500 ms grep: PhysicsActor.SubscribeEvents(
3284 // as of this comment the interval is set in AddToPhysicalScene
3285 if (Animator != null)
3286 {
3287// if (m_updateCount > 0)
3288// {
3289 Animator.UpdateMovementAnimations();
3290// m_updateCount--;
3291// }
3292 }
3293
3294 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3474 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3295 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3475 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3296 3476
@@ -3665,10 +3845,15 @@ namespace OpenSim.Region.Framework.Scenes
3665 3845
3666 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 3846 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3667 { 3847 {
3848 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
3849 if (p == null)
3850 return;
3851
3668 ScriptControllers obj = new ScriptControllers(); 3852 ScriptControllers obj = new ScriptControllers();
3669 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 3853 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3670 obj.eventControls = ScriptControlled.CONTROL_ZERO; 3854 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3671 3855
3856 obj.objectID = p.ParentGroup.UUID;
3672 obj.itemID = Script_item_UUID; 3857 obj.itemID = Script_item_UUID;
3673 if (pass_on == 0 && accept == 0) 3858 if (pass_on == 0 && accept == 0)
3674 { 3859 {
@@ -3717,6 +3902,21 @@ namespace OpenSim.Region.Framework.Scenes
3717 ControllingClient.SendTakeControls(int.MaxValue, false, false); 3902 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3718 } 3903 }
3719 3904
3905 private void UnRegisterSeatControls(UUID obj)
3906 {
3907 List<UUID> takers = new List<UUID>();
3908
3909 foreach (ScriptControllers c in scriptedcontrols.Values)
3910 {
3911 if (c.objectID == obj)
3912 takers.Add(c.itemID);
3913 }
3914 foreach (UUID t in takers)
3915 {
3916 UnRegisterControlEventsToScript(0, t);
3917 }
3918 }
3919
3720 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 3920 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3721 { 3921 {
3722 ScriptControllers takecontrols; 3922 ScriptControllers takecontrols;
@@ -4035,6 +4235,12 @@ namespace OpenSim.Region.Framework.Scenes
4035 4235
4036 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4236 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4037 { 4237 {
4238 string reason;
4239
4240 // Honor bans
4241 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4242 return;
4243
4038 SceneObjectGroup telehub = null; 4244 SceneObjectGroup telehub = null;
4039 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4245 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4040 { 4246 {
@@ -4074,11 +4280,175 @@ namespace OpenSim.Region.Framework.Scenes
4074 pos = land.LandData.UserLocation; 4280 pos = land.LandData.UserLocation;
4075 } 4281 }
4076 } 4282 }
4077 4283
4078 land.SendLandUpdateToClient(ControllingClient); 4284 land.SendLandUpdateToClient(ControllingClient);
4079 } 4285 }
4080 } 4286 }
4081 4287
4288 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4289 {
4290 lock(m_collisionEventLock)
4291 {
4292 if (m_collisionEventFlag)
4293 return;
4294 m_collisionEventFlag = true;
4295 }
4296
4297 Util.FireAndForget(delegate(object x)
4298 {
4299 try
4300 {
4301 List<uint> thisHitColliders = new List<uint>();
4302 List<uint> endedColliders = new List<uint>();
4303 List<uint> startedColliders = new List<uint>();
4304
4305 foreach (uint localid in coldata.Keys)
4306 {
4307 thisHitColliders.Add(localid);
4308 if (!m_lastColliders.Contains(localid))
4309 {
4310 startedColliders.Add(localid);
4311 }
4312 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4313 }
4314
4315 // calculate things that ended colliding
4316 foreach (uint localID in m_lastColliders)
4317 {
4318 if (!thisHitColliders.Contains(localID))
4319 {
4320 endedColliders.Add(localID);
4321 }
4322 }
4323 //add the items that started colliding this time to the last colliders list.
4324 foreach (uint localID in startedColliders)
4325 {
4326 m_lastColliders.Add(localID);
4327 }
4328 // remove things that ended colliding from the last colliders list
4329 foreach (uint localID in endedColliders)
4330 {
4331 m_lastColliders.Remove(localID);
4332 }
4333
4334 // do event notification
4335 if (startedColliders.Count > 0)
4336 {
4337 CollisionSounds.AvatarCollisionSound(this, startedColliders);
4338
4339 ColliderArgs StartCollidingMessage = new ColliderArgs();
4340 List<DetectedObject> colliding = new List<DetectedObject>();
4341 foreach (uint localId in startedColliders)
4342 {
4343 if (localId == 0)
4344 continue;
4345
4346 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4347 string data = "";
4348 if (obj != null)
4349 {
4350 DetectedObject detobj = new DetectedObject();
4351 detobj.keyUUID = obj.UUID;
4352 detobj.nameStr = obj.Name;
4353 detobj.ownerUUID = obj.OwnerID;
4354 detobj.posVector = obj.AbsolutePosition;
4355 detobj.rotQuat = obj.GetWorldRotation();
4356 detobj.velVector = obj.Velocity;
4357 detobj.colliderType = 0;
4358 detobj.groupUUID = obj.GroupID;
4359 colliding.Add(detobj);
4360 }
4361 }
4362
4363 if (colliding.Count > 0)
4364 {
4365 StartCollidingMessage.Colliders = colliding;
4366
4367 foreach (SceneObjectGroup att in GetAttachments())
4368 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
4369 }
4370 }
4371
4372 if (endedColliders.Count > 0)
4373 {
4374 ColliderArgs EndCollidingMessage = new ColliderArgs();
4375 List<DetectedObject> colliding = new List<DetectedObject>();
4376 foreach (uint localId in endedColliders)
4377 {
4378 if (localId == 0)
4379 continue;
4380
4381 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4382 string data = "";
4383 if (obj != null)
4384 {
4385 DetectedObject detobj = new DetectedObject();
4386 detobj.keyUUID = obj.UUID;
4387 detobj.nameStr = obj.Name;
4388 detobj.ownerUUID = obj.OwnerID;
4389 detobj.posVector = obj.AbsolutePosition;
4390 detobj.rotQuat = obj.GetWorldRotation();
4391 detobj.velVector = obj.Velocity;
4392 detobj.colliderType = 0;
4393 detobj.groupUUID = obj.GroupID;
4394 colliding.Add(detobj);
4395 }
4396 }
4397
4398 if (colliding.Count > 0)
4399 {
4400 EndCollidingMessage.Colliders = colliding;
4401
4402 foreach (SceneObjectGroup att in GetAttachments())
4403 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
4404 }
4405 }
4406
4407 if (thisHitColliders.Count > 0)
4408 {
4409 ColliderArgs CollidingMessage = new ColliderArgs();
4410 List<DetectedObject> colliding = new List<DetectedObject>();
4411 foreach (uint localId in thisHitColliders)
4412 {
4413 if (localId == 0)
4414 continue;
4415
4416 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4417 string data = "";
4418 if (obj != null)
4419 {
4420 DetectedObject detobj = new DetectedObject();
4421 detobj.keyUUID = obj.UUID;
4422 detobj.nameStr = obj.Name;
4423 detobj.ownerUUID = obj.OwnerID;
4424 detobj.posVector = obj.AbsolutePosition;
4425 detobj.rotQuat = obj.GetWorldRotation();
4426 detobj.velVector = obj.Velocity;
4427 detobj.colliderType = 0;
4428 detobj.groupUUID = obj.GroupID;
4429 colliding.Add(detobj);
4430 }
4431 }
4432
4433 if (colliding.Count > 0)
4434 {
4435 CollidingMessage.Colliders = colliding;
4436
4437 lock (m_attachments)
4438 {
4439 foreach (SceneObjectGroup att in m_attachments)
4440 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
4441 }
4442 }
4443 }
4444 }
4445 finally
4446 {
4447 m_collisionEventFlag = false;
4448 }
4449 });
4450 }
4451
4082 private void TeleportFlagsDebug() { 4452 private void TeleportFlagsDebug() {
4083 4453
4084 // Some temporary debugging help to show all the TeleportFlags we have... 4454 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4103,6 +4473,5 @@ namespace OpenSim.Region.Framework.Scenes
4103 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4473 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4104 4474
4105 } 4475 }
4106
4107 } 4476 }
4108} 4477}