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 b737f91..99ad685 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;
@@ -806,10 +849,38 @@ namespace OpenSim.Region.Framework.Scenes
806 "[SCENE]: Upgrading child to root agent for {0} in {1}", 849 "[SCENE]: Upgrading child to root agent for {0} in {1}",
807 Name, m_scene.RegionInfo.RegionName); 850 Name, m_scene.RegionInfo.RegionName);
808 851
809 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
810
811 bool wasChild = IsChildAgent; 852 bool wasChild = IsChildAgent;
812 IsChildAgent = false; 853
854 if (ParentUUID != UUID.Zero)
855 {
856 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
857 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
858 if (part == null)
859 {
860 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
861 }
862 else
863 {
864 part.ParentGroup.AddAvatar(UUID);
865 if (part.SitTargetPosition != Vector3.Zero)
866 part.SitTargetAvatar = UUID;
867 ParentPosition = part.GetWorldPosition();
868 ParentID = part.LocalId;
869 ParentPart = part;
870 m_pos = m_prevSitOffset;
871 pos = ParentPosition;
872 }
873 ParentUUID = UUID.Zero;
874
875 IsChildAgent = false;
876
877 Animator.TrySetMovementAnimation("SIT");
878 }
879 else
880 {
881 IsChildAgent = false;
882 }
883
813 884
814 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 885 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
815 if (gm != null) 886 if (gm != null)
@@ -819,62 +890,72 @@ namespace OpenSim.Region.Framework.Scenes
819 890
820 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 891 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
821 892
822 // Moved this from SendInitialData to ensure that Appearance is initialized 893 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 { 894 {
828 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 895 // Moved this from SendInitialData to ensure that Appearance is initialized
829 pos.X = crossedBorder.BorderLine.Z - 1; 896 // before the inventory is processed in MakeRootAgent. This fixes a race condition
830 } 897 // related to the handling of attachments
898 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
899 if (m_scene.TestBorderCross(pos, Cardinals.E))
900 {
901 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
902 pos.X = crossedBorder.BorderLine.Z - 1;
903 }
831 904
832 if (m_scene.TestBorderCross(pos, Cardinals.N)) 905 if (m_scene.TestBorderCross(pos, Cardinals.N))
833 { 906 {
834 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 907 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
835 pos.Y = crossedBorder.BorderLine.Z - 1; 908 pos.Y = crossedBorder.BorderLine.Z - 1;
836 } 909 }
837 910
838 CheckAndAdjustLandingPoint(ref pos); 911 CheckAndAdjustLandingPoint(ref pos);
839 912
840 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 913 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
841 { 914 {
842 m_log.WarnFormat( 915 m_log.WarnFormat(
843 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 916 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
844 pos, Name, UUID); 917 pos, Name, UUID);
845 918
846 if (pos.X < 0f) pos.X = 0f; 919 if (pos.X < 0f) pos.X = 0f;
847 if (pos.Y < 0f) pos.Y = 0f; 920 if (pos.Y < 0f) pos.Y = 0f;
848 if (pos.Z < 0f) pos.Z = 0f; 921 if (pos.Z < 0f) pos.Z = 0f;
849 } 922 }
850 923
851 float localAVHeight = 1.56f; 924 float localAVHeight = 1.56f;
852 if (Appearance.AvatarHeight > 0) 925 if (Appearance.AvatarHeight > 0)
853 localAVHeight = Appearance.AvatarHeight; 926 localAVHeight = Appearance.AvatarHeight;
854 927
855 float posZLimit = 0; 928 float posZLimit = 0;
856 929
857 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 930 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
858 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 931 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
859 932
860 float newPosZ = posZLimit + localAVHeight / 2; 933 float newPosZ = posZLimit + localAVHeight / 2;
861 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 934 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
862 { 935 {
863 pos.Z = newPosZ; 936 pos.Z = newPosZ;
864 } 937 }
865 AbsolutePosition = pos; 938 AbsolutePosition = pos;
866 939
867 AddToPhysicalScene(isFlying); 940 if (m_teleportFlags == TeleportFlags.Default)
941 {
942 Vector3 vel = Velocity;
943 AddToPhysicalScene(isFlying);
944 if (PhysicsActor != null)
945 PhysicsActor.SetMomentum(vel);
946 }
947 else
948 AddToPhysicalScene(isFlying);
868 949
869 if (ForceFly) 950 if (ForceFly)
870 { 951 {
871 Flying = true; 952 Flying = true;
872 } 953 }
873 else if (FlyDisabled) 954 else if (FlyDisabled)
874 { 955 {
875 Flying = false; 956 Flying = false;
957 }
876 } 958 }
877
878 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 959 // 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 960 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
880 // elsewhere anyway 961 // elsewhere anyway
@@ -892,14 +973,19 @@ namespace OpenSim.Region.Framework.Scenes
892 { 973 {
893 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); 974 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments...");
894 // Resume scripts 975 // Resume scripts
895 foreach (SceneObjectGroup sog in m_attachments) 976 Util.FireAndForget(delegate(object x) {
896 { 977 foreach (SceneObjectGroup sog in m_attachments)
897 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 978 {
898 sog.ResumeScripts(); 979 sog.ScheduleGroupForFullUpdate();
899 } 980 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
981 sog.ResumeScripts();
982 }
983 });
900 } 984 }
901 } 985 }
902 986
987 SendAvatarDataToAllAgents();
988
903 // send the animations of the other presences to me 989 // send the animations of the other presences to me
904 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 990 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
905 { 991 {
@@ -910,9 +996,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 996 // 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 997 // 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. 998 // recorded, which stops the input from being processed.
999
913 MovementFlag = 0; 1000 MovementFlag = 0;
914 1001
915 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1002 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1003
1004 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
916 } 1005 }
917 1006
918 public int GetStateSource() 1007 public int GetStateSource()
@@ -940,12 +1029,16 @@ namespace OpenSim.Region.Framework.Scenes
940 /// </remarks> 1029 /// </remarks>
941 public void MakeChildAgent() 1030 public void MakeChildAgent()
942 { 1031 {
1032 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1033
943 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1034 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
944 1035
945 // Reset these so that teleporting in and walking out isn't seen 1036 // Reset these so that teleporting in and walking out isn't seen
946 // as teleporting back 1037 // as teleporting back
947 TeleportFlags = TeleportFlags.Default; 1038 TeleportFlags = TeleportFlags.Default;
948 1039
1040 MovementFlag = 0;
1041
949 // It looks like Animator is set to null somewhere, and MakeChild 1042 // It looks like Animator is set to null somewhere, and MakeChild
950 // is called after that. Probably in aborted teleports. 1043 // is called after that. Probably in aborted teleports.
951 if (Animator == null) 1044 if (Animator == null)
@@ -953,6 +1046,7 @@ namespace OpenSim.Region.Framework.Scenes
953 else 1046 else
954 Animator.ResetAnimations(); 1047 Animator.ResetAnimations();
955 1048
1049
956// m_log.DebugFormat( 1050// m_log.DebugFormat(
957// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1051// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
958// Name, UUID, m_scene.RegionInfo.RegionName); 1052// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -979,9 +1073,9 @@ namespace OpenSim.Region.Framework.Scenes
979 { 1073 {
980// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1074// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
981 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1075 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
982 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
983 PhysicsActor.UnSubscribeEvents();
984 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1076 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1077 PhysicsActor.UnSubscribeEvents();
1078 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
985 PhysicsActor = null; 1079 PhysicsActor = null;
986 } 1080 }
987// else 1081// else
@@ -998,7 +1092,7 @@ namespace OpenSim.Region.Framework.Scenes
998 /// <param name="pos"></param> 1092 /// <param name="pos"></param>
999 public void Teleport(Vector3 pos) 1093 public void Teleport(Vector3 pos)
1000 { 1094 {
1001 TeleportWithMomentum(pos, null); 1095 TeleportWithMomentum(pos, Vector3.Zero);
1002 } 1096 }
1003 1097
1004 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1098 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1022,6 +1116,41 @@ namespace OpenSim.Region.Framework.Scenes
1022 SendTerseUpdateToAllClients(); 1116 SendTerseUpdateToAllClients();
1023 } 1117 }
1024 1118
1119 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1120 {
1121 CheckLandingPoint(ref newpos);
1122 AbsolutePosition = newpos;
1123
1124 if (newvel.HasValue)
1125 {
1126 if ((Vector3)newvel == Vector3.Zero)
1127 {
1128 if (PhysicsActor != null)
1129 PhysicsActor.SetMomentum(Vector3.Zero);
1130 m_velocity = Vector3.Zero;
1131 }
1132 else
1133 {
1134 if (PhysicsActor != null)
1135 PhysicsActor.SetMomentum((Vector3)newvel);
1136 m_velocity = (Vector3)newvel;
1137
1138 if (rotateToVelXY)
1139 {
1140 Vector3 lookAt = (Vector3)newvel;
1141 lookAt.Z = 0;
1142 lookAt.Normalize();
1143 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1144 return;
1145 }
1146 }
1147 }
1148
1149 SendTerseUpdateToAllClients();
1150 }
1151
1152
1153
1025 public void StopFlying() 1154 public void StopFlying()
1026 { 1155 {
1027 ControllingClient.StopFlying(this); 1156 ControllingClient.StopFlying(this);
@@ -1331,8 +1460,18 @@ namespace OpenSim.Region.Framework.Scenes
1331 { 1460 {
1332 if (m_followCamAuto) 1461 if (m_followCamAuto)
1333 { 1462 {
1334 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1463 // Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
1335 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1464 // m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback);
1465
1466 Vector3 posAdjusted = AbsolutePosition + HEAD_ADJUSTMENT;
1467 Vector3 distTocam = CameraPosition - posAdjusted;
1468 float distTocamlen = distTocam.Length();
1469 if (distTocamlen > 0)
1470 {
1471 distTocam *= 1.0f / distTocamlen;
1472 m_scene.PhysicsScene.RaycastWorld(posAdjusted, distTocam, distTocamlen + 0.3f, RayCastCameraCallback);
1473 }
1474
1336 } 1475 }
1337 } 1476 }
1338 1477
@@ -1766,12 +1905,17 @@ namespace OpenSim.Region.Framework.Scenes
1766// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 1905// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1767 1906
1768 SitGround = false; 1907 SitGround = false;
1908
1909/* move this down so avatar gets physical in the new position and not where it is siting
1769 if (PhysicsActor == null) 1910 if (PhysicsActor == null)
1770 AddToPhysicalScene(false); 1911 AddToPhysicalScene(false);
1912 */
1771 1913
1772 if (ParentID != 0) 1914 if (ParentID != 0)
1773 { 1915 {
1774 SceneObjectPart part = ParentPart; 1916 SceneObjectPart part = ParentPart;
1917 UnRegisterSeatControls(part.ParentGroup.UUID);
1918
1775 TaskInventoryDictionary taskIDict = part.TaskInventory; 1919 TaskInventoryDictionary taskIDict = part.TaskInventory;
1776 if (taskIDict != null) 1920 if (taskIDict != null)
1777 { 1921 {
@@ -1791,6 +1935,7 @@ namespace OpenSim.Region.Framework.Scenes
1791 if (part.SitTargetAvatar == UUID) 1935 if (part.SitTargetAvatar == UUID)
1792 part.SitTargetAvatar = UUID.Zero; 1936 part.SitTargetAvatar = UUID.Zero;
1793 1937
1938 part.ParentGroup.DeleteAvatar(UUID);
1794 ParentPosition = part.GetWorldPosition(); 1939 ParentPosition = part.GetWorldPosition();
1795 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1940 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1796 1941
@@ -1799,6 +1944,10 @@ namespace OpenSim.Region.Framework.Scenes
1799 1944
1800 ParentID = 0; 1945 ParentID = 0;
1801 ParentPart = null; 1946 ParentPart = null;
1947
1948 if (PhysicsActor == null)
1949 AddToPhysicalScene(false);
1950
1802 SendAvatarDataToAllAgents(); 1951 SendAvatarDataToAllAgents();
1803 m_requestedSitTargetID = 0; 1952 m_requestedSitTargetID = 0;
1804 1953
@@ -1806,6 +1955,9 @@ namespace OpenSim.Region.Framework.Scenes
1806 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 1955 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1807 } 1956 }
1808 1957
1958 else if (PhysicsActor == null)
1959 AddToPhysicalScene(false);
1960
1809 Animator.TrySetMovementAnimation("STAND"); 1961 Animator.TrySetMovementAnimation("STAND");
1810 } 1962 }
1811 1963
@@ -1929,7 +2081,7 @@ namespace OpenSim.Region.Framework.Scenes
1929 forceMouselook = part.GetForceMouselook(); 2081 forceMouselook = part.GetForceMouselook();
1930 2082
1931 ControllingClient.SendSitResponse( 2083 ControllingClient.SendSitResponse(
1932 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2084 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
1933 2085
1934 m_requestedSitTargetUUID = targetID; 2086 m_requestedSitTargetUUID = targetID;
1935 2087
@@ -2211,14 +2363,36 @@ namespace OpenSim.Region.Framework.Scenes
2211 2363
2212 //Quaternion result = (sitTargetOrient * vq) * nq; 2364 //Quaternion result = (sitTargetOrient * vq) * nq;
2213 2365
2214 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2366 double x, y, z, m;
2367
2368 Quaternion r = sitTargetOrient;
2369 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2370
2371 if (Math.Abs(1.0 - m) > 0.000001)
2372 {
2373 m = 1.0 / Math.Sqrt(m);
2374 r.X *= (float)m;
2375 r.Y *= (float)m;
2376 r.Z *= (float)m;
2377 r.W *= (float)m;
2378 }
2379
2380 x = 2 * (r.X * r.Z + r.Y * r.W);
2381 y = 2 * (-r.X * r.W + r.Y * r.Z);
2382 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2383
2384 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2385 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2386 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2215 Rotation = sitTargetOrient; 2387 Rotation = sitTargetOrient;
2216 ParentPosition = part.AbsolutePosition; 2388 ParentPosition = part.AbsolutePosition;
2389 part.ParentGroup.AddAvatar(UUID);
2217 } 2390 }
2218 else 2391 else
2219 { 2392 {
2220 m_pos -= part.AbsolutePosition; 2393 m_pos -= part.AbsolutePosition;
2221 ParentPosition = part.AbsolutePosition; 2394 ParentPosition = part.AbsolutePosition;
2395 part.ParentGroup.AddAvatar(UUID);
2222 2396
2223// m_log.DebugFormat( 2397// m_log.DebugFormat(
2224// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2398// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2316,14 +2490,15 @@ namespace OpenSim.Region.Framework.Scenes
2316 direc.Z *= 2.6f; 2490 direc.Z *= 2.6f;
2317 2491
2318 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2492 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2319 Animator.TrySetMovementAnimation("PREJUMP"); 2493// Animator.TrySetMovementAnimation("PREJUMP");
2320 Animator.TrySetMovementAnimation("JUMP"); 2494// Animator.TrySetMovementAnimation("JUMP");
2321 } 2495 }
2322 } 2496 }
2323 } 2497 }
2324 2498
2325 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2499 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2326 m_forceToApply = direc; 2500 m_forceToApply = direc;
2501 Animator.UpdateMovementAnimations();
2327 } 2502 }
2328 2503
2329 #endregion 2504 #endregion
@@ -3058,6 +3233,9 @@ namespace OpenSim.Region.Framework.Scenes
3058 cAgent.AlwaysRun = SetAlwaysRun; 3233 cAgent.AlwaysRun = SetAlwaysRun;
3059 3234
3060 cAgent.Appearance = new AvatarAppearance(Appearance); 3235 cAgent.Appearance = new AvatarAppearance(Appearance);
3236
3237 cAgent.ParentPart = ParentUUID;
3238 cAgent.SitOffset = m_pos;
3061 3239
3062 lock (scriptedcontrols) 3240 lock (scriptedcontrols)
3063 { 3241 {
@@ -3066,7 +3244,7 @@ namespace OpenSim.Region.Framework.Scenes
3066 3244
3067 foreach (ScriptControllers c in scriptedcontrols.Values) 3245 foreach (ScriptControllers c in scriptedcontrols.Values)
3068 { 3246 {
3069 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3247 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3070 } 3248 }
3071 cAgent.Controllers = controls; 3249 cAgent.Controllers = controls;
3072 } 3250 }
@@ -3077,6 +3255,7 @@ namespace OpenSim.Region.Framework.Scenes
3077 cAgent.Anims = Animator.Animations.ToArray(); 3255 cAgent.Anims = Animator.Animations.ToArray();
3078 } 3256 }
3079 catch { } 3257 catch { }
3258 cAgent.DefaultAnim = Animator.Animations.DefaultAnimation;
3080 3259
3081 // Attachment objects 3260 // Attachment objects
3082 List<SceneObjectGroup> attachments = GetAttachments(); 3261 List<SceneObjectGroup> attachments = GetAttachments();
@@ -3117,6 +3296,8 @@ namespace OpenSim.Region.Framework.Scenes
3117 CameraAtAxis = cAgent.AtAxis; 3296 CameraAtAxis = cAgent.AtAxis;
3118 CameraLeftAxis = cAgent.LeftAxis; 3297 CameraLeftAxis = cAgent.LeftAxis;
3119 CameraUpAxis = cAgent.UpAxis; 3298 CameraUpAxis = cAgent.UpAxis;
3299 ParentUUID = cAgent.ParentPart;
3300 m_prevSitOffset = cAgent.SitOffset;
3120 3301
3121 // When we get to the point of re-computing neighbors everytime this 3302 // When we get to the point of re-computing neighbors everytime this
3122 // changes, then start using the agent's drawdistance rather than the 3303 // changes, then start using the agent's drawdistance rather than the
@@ -3154,6 +3335,7 @@ namespace OpenSim.Region.Framework.Scenes
3154 foreach (ControllerData c in cAgent.Controllers) 3335 foreach (ControllerData c in cAgent.Controllers)
3155 { 3336 {
3156 ScriptControllers sc = new ScriptControllers(); 3337 ScriptControllers sc = new ScriptControllers();
3338 sc.objectID = c.ObjectID;
3157 sc.itemID = c.ItemID; 3339 sc.itemID = c.ItemID;
3158 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3340 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3159 sc.eventControls = (ScriptControlled)c.EventControls; 3341 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3168,6 +3350,8 @@ namespace OpenSim.Region.Framework.Scenes
3168 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object? 3350 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object?
3169 if (cAgent.Anims != null) 3351 if (cAgent.Anims != null)
3170 Animator.Animations.FromArray(cAgent.Anims); 3352 Animator.Animations.FromArray(cAgent.Anims);
3353 if (cAgent.DefaultAnim != null)
3354 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero);
3171 3355
3172 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0) 3356 if (cAgent.AttachmentObjects != null && cAgent.AttachmentObjects.Count > 0)
3173 { 3357 {
@@ -3270,18 +3454,6 @@ namespace OpenSim.Region.Framework.Scenes
3270 if (IsChildAgent) 3454 if (IsChildAgent)
3271 return; 3455 return;
3272 3456
3273 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
3274 // The Physics Scene will send updates every 500 ms grep: PhysicsActor.SubscribeEvents(
3275 // as of this comment the interval is set in AddToPhysicalScene
3276 if (Animator != null)
3277 {
3278// if (m_updateCount > 0)
3279// {
3280 Animator.UpdateMovementAnimations();
3281// m_updateCount--;
3282// }
3283 }
3284
3285 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3457 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3286 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3458 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3287 3459
@@ -3656,10 +3828,15 @@ namespace OpenSim.Region.Framework.Scenes
3656 3828
3657 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 3829 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3658 { 3830 {
3831 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
3832 if (p == null)
3833 return;
3834
3659 ScriptControllers obj = new ScriptControllers(); 3835 ScriptControllers obj = new ScriptControllers();
3660 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 3836 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3661 obj.eventControls = ScriptControlled.CONTROL_ZERO; 3837 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3662 3838
3839 obj.objectID = p.ParentGroup.UUID;
3663 obj.itemID = Script_item_UUID; 3840 obj.itemID = Script_item_UUID;
3664 if (pass_on == 0 && accept == 0) 3841 if (pass_on == 0 && accept == 0)
3665 { 3842 {
@@ -3708,6 +3885,21 @@ namespace OpenSim.Region.Framework.Scenes
3708 ControllingClient.SendTakeControls(int.MaxValue, false, false); 3885 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3709 } 3886 }
3710 3887
3888 private void UnRegisterSeatControls(UUID obj)
3889 {
3890 List<UUID> takers = new List<UUID>();
3891
3892 foreach (ScriptControllers c in scriptedcontrols.Values)
3893 {
3894 if (c.objectID == obj)
3895 takers.Add(c.itemID);
3896 }
3897 foreach (UUID t in takers)
3898 {
3899 UnRegisterControlEventsToScript(0, t);
3900 }
3901 }
3902
3711 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 3903 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3712 { 3904 {
3713 ScriptControllers takecontrols; 3905 ScriptControllers takecontrols;
@@ -3962,6 +4154,12 @@ namespace OpenSim.Region.Framework.Scenes
3962 4154
3963 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4155 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
3964 { 4156 {
4157 string reason;
4158
4159 // Honor bans
4160 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4161 return;
4162
3965 SceneObjectGroup telehub = null; 4163 SceneObjectGroup telehub = null;
3966 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4164 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
3967 { 4165 {
@@ -4001,11 +4199,173 @@ namespace OpenSim.Region.Framework.Scenes
4001 pos = land.LandData.UserLocation; 4199 pos = land.LandData.UserLocation;
4002 } 4200 }
4003 } 4201 }
4004 4202
4005 land.SendLandUpdateToClient(ControllingClient); 4203 land.SendLandUpdateToClient(ControllingClient);
4006 } 4204 }
4007 } 4205 }
4008 4206
4207 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4208 {
4209 lock(m_collisionEventLock)
4210 {
4211 if (m_collisionEventFlag)
4212 return;
4213 m_collisionEventFlag = true;
4214 }
4215
4216 Util.FireAndForget(delegate(object x)
4217 {
4218 try
4219 {
4220 List<uint> thisHitColliders = new List<uint>();
4221 List<uint> endedColliders = new List<uint>();
4222 List<uint> startedColliders = new List<uint>();
4223
4224 foreach (uint localid in coldata.Keys)
4225 {
4226 thisHitColliders.Add(localid);
4227 if (!m_lastColliders.Contains(localid))
4228 {
4229 startedColliders.Add(localid);
4230 }
4231 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4232 }
4233
4234 // calculate things that ended colliding
4235 foreach (uint localID in m_lastColliders)
4236 {
4237 if (!thisHitColliders.Contains(localID))
4238 {
4239 endedColliders.Add(localID);
4240 }
4241 }
4242 //add the items that started colliding this time to the last colliders list.
4243 foreach (uint localID in startedColliders)
4244 {
4245 m_lastColliders.Add(localID);
4246 }
4247 // remove things that ended colliding from the last colliders list
4248 foreach (uint localID in endedColliders)
4249 {
4250 m_lastColliders.Remove(localID);
4251 }
4252
4253 // do event notification
4254 if (startedColliders.Count > 0)
4255 {
4256 ColliderArgs StartCollidingMessage = new ColliderArgs();
4257 List<DetectedObject> colliding = new List<DetectedObject>();
4258 foreach (uint localId in startedColliders)
4259 {
4260 if (localId == 0)
4261 continue;
4262
4263 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4264 string data = "";
4265 if (obj != null)
4266 {
4267 DetectedObject detobj = new DetectedObject();
4268 detobj.keyUUID = obj.UUID;
4269 detobj.nameStr = obj.Name;
4270 detobj.ownerUUID = obj.OwnerID;
4271 detobj.posVector = obj.AbsolutePosition;
4272 detobj.rotQuat = obj.GetWorldRotation();
4273 detobj.velVector = obj.Velocity;
4274 detobj.colliderType = 0;
4275 detobj.groupUUID = obj.GroupID;
4276 colliding.Add(detobj);
4277 }
4278 }
4279
4280 if (colliding.Count > 0)
4281 {
4282 StartCollidingMessage.Colliders = colliding;
4283
4284 foreach (SceneObjectGroup att in GetAttachments())
4285 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
4286 }
4287 }
4288
4289 if (endedColliders.Count > 0)
4290 {
4291 ColliderArgs EndCollidingMessage = new ColliderArgs();
4292 List<DetectedObject> colliding = new List<DetectedObject>();
4293 foreach (uint localId in endedColliders)
4294 {
4295 if (localId == 0)
4296 continue;
4297
4298 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4299 string data = "";
4300 if (obj != null)
4301 {
4302 DetectedObject detobj = new DetectedObject();
4303 detobj.keyUUID = obj.UUID;
4304 detobj.nameStr = obj.Name;
4305 detobj.ownerUUID = obj.OwnerID;
4306 detobj.posVector = obj.AbsolutePosition;
4307 detobj.rotQuat = obj.GetWorldRotation();
4308 detobj.velVector = obj.Velocity;
4309 detobj.colliderType = 0;
4310 detobj.groupUUID = obj.GroupID;
4311 colliding.Add(detobj);
4312 }
4313 }
4314
4315 if (colliding.Count > 0)
4316 {
4317 EndCollidingMessage.Colliders = colliding;
4318
4319 foreach (SceneObjectGroup att in GetAttachments())
4320 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
4321 }
4322 }
4323
4324 if (thisHitColliders.Count > 0)
4325 {
4326 ColliderArgs CollidingMessage = new ColliderArgs();
4327 List<DetectedObject> colliding = new List<DetectedObject>();
4328 foreach (uint localId in thisHitColliders)
4329 {
4330 if (localId == 0)
4331 continue;
4332
4333 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4334 string data = "";
4335 if (obj != null)
4336 {
4337 DetectedObject detobj = new DetectedObject();
4338 detobj.keyUUID = obj.UUID;
4339 detobj.nameStr = obj.Name;
4340 detobj.ownerUUID = obj.OwnerID;
4341 detobj.posVector = obj.AbsolutePosition;
4342 detobj.rotQuat = obj.GetWorldRotation();
4343 detobj.velVector = obj.Velocity;
4344 detobj.colliderType = 0;
4345 detobj.groupUUID = obj.GroupID;
4346 colliding.Add(detobj);
4347 }
4348 }
4349
4350 if (colliding.Count > 0)
4351 {
4352 CollidingMessage.Colliders = colliding;
4353
4354 lock (m_attachments)
4355 {
4356 foreach (SceneObjectGroup att in m_attachments)
4357 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
4358 }
4359 }
4360 }
4361 }
4362 finally
4363 {
4364 m_collisionEventFlag = false;
4365 }
4366 });
4367 }
4368
4009 private void TeleportFlagsDebug() { 4369 private void TeleportFlagsDebug() {
4010 4370
4011 // Some temporary debugging help to show all the TeleportFlags we have... 4371 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4030,6 +4390,5 @@ namespace OpenSim.Region.Framework.Scenes
4030 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4390 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4031 4391
4032 } 4392 }
4033
4034 } 4393 }
4035} 4394}