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.cs599
1 files changed, 519 insertions, 80 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index aa82af4..285d1ae 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;
@@ -99,7 +100,7 @@ namespace OpenSim.Region.Framework.Scenes
99 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 100 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
100 /// issue #1716 101 /// issue #1716
101 /// </summary> 102 /// </summary>
102 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); 103 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.4f);
103 104
104 /// <summary> 105 /// <summary>
105 /// Movement updates for agents in neighboring regions are sent directly to clients. 106 /// Movement updates for agents in neighboring regions are sent directly to clients.
@@ -171,6 +172,7 @@ namespace OpenSim.Region.Framework.Scenes
171// private int m_lastColCount = -1; //KF: Look for Collision chnages 172// private int m_lastColCount = -1; //KF: Look for Collision chnages
172// private int m_updateCount = 0; //KF: Update Anims for a while 173// private int m_updateCount = 0; //KF: Update Anims for a while
173// private static readonly int UPDATE_COUNT = 10; // how many frames to update for 174// private static readonly int UPDATE_COUNT = 10; // how many frames to update for
175 private List<uint> m_lastColliders = new List<uint>();
174 176
175 private TeleportFlags m_teleportFlags; 177 private TeleportFlags m_teleportFlags;
176 public TeleportFlags TeleportFlags 178 public TeleportFlags TeleportFlags
@@ -232,6 +234,13 @@ namespace OpenSim.Region.Framework.Scenes
232 //private int m_moveToPositionStateStatus; 234 //private int m_moveToPositionStateStatus;
233 //***************************************************** 235 //*****************************************************
234 236
237 private bool m_collisionEventFlag = false;
238 private object m_collisionEventLock = new Object();
239
240 private int m_movementAnimationUpdateCounter = 0;
241
242 private Vector3 m_prevSitOffset;
243
235 protected AvatarAppearance m_appearance; 244 protected AvatarAppearance m_appearance;
236 245
237 public AvatarAppearance Appearance 246 public AvatarAppearance Appearance
@@ -426,7 +435,7 @@ namespace OpenSim.Region.Framework.Scenes
426 get { return (IClientCore)ControllingClient; } 435 get { return (IClientCore)ControllingClient; }
427 } 436 }
428 437
429 public Vector3 ParentPosition { get; set; } 438// public Vector3 ParentPosition { get; set; }
430 439
431 /// <summary> 440 /// <summary>
432 /// Position of this avatar relative to the region the avatar is in 441 /// Position of this avatar relative to the region the avatar is in
@@ -484,7 +493,7 @@ namespace OpenSim.Region.Framework.Scenes
484 if (ParentID == 0) 493 if (ParentID == 0)
485 { 494 {
486 m_pos = value; 495 m_pos = value;
487 ParentPosition = Vector3.Zero; 496// ParentPosition = Vector3.Zero;
488 } 497 }
489 498
490 //m_log.DebugFormat( 499 //m_log.DebugFormat(
@@ -573,6 +582,13 @@ namespace OpenSim.Region.Framework.Scenes
573 /// </summary> 582 /// </summary>
574 public uint ParentID { get; set; } 583 public uint ParentID { get; set; }
575 584
585 public UUID ParentUUID
586 {
587 get { return m_parentUUID; }
588 set { m_parentUUID = value; }
589 }
590 private UUID m_parentUUID = UUID.Zero;
591
576 /// <summary> 592 /// <summary>
577 /// Are we sitting on an object? 593 /// Are we sitting on an object?
578 /// </summary> 594 /// </summary>
@@ -739,6 +755,33 @@ namespace OpenSim.Region.Framework.Scenes
739 Appearance = appearance; 755 Appearance = appearance;
740 } 756 }
741 757
758 private void RegionHeartbeatEnd(Scene scene)
759 {
760 if (IsChildAgent)
761 return;
762
763 m_movementAnimationUpdateCounter ++;
764 if (m_movementAnimationUpdateCounter >= 2)
765 {
766 m_movementAnimationUpdateCounter = 0;
767 if (Animator != null)
768 {
769 // If the parentID == 0 we are not sitting
770 // if !SitGournd then we are not sitting on the ground
771 // Fairly straightforward, now here comes the twist
772 // if ParentUUID is NOT UUID.Zero, we are looking to
773 // be sat on an object that isn't there yet. Should
774 // be treated as if sat.
775 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
776 Animator.UpdateMovementAnimations();
777 }
778 else
779 {
780 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
781 }
782 }
783 }
784
742 public void RegisterToEvents() 785 public void RegisterToEvents()
743 { 786 {
744 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 787 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -748,6 +791,7 @@ namespace OpenSim.Region.Framework.Scenes
748 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 791 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
749 ControllingClient.OnStartAnim += HandleStartAnim; 792 ControllingClient.OnStartAnim += HandleStartAnim;
750 ControllingClient.OnStopAnim += HandleStopAnim; 793 ControllingClient.OnStopAnim += HandleStopAnim;
794 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
751 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 795 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
752 ControllingClient.OnAutoPilotGo += MoveToTarget; 796 ControllingClient.OnAutoPilotGo += MoveToTarget;
753 797
@@ -808,10 +852,39 @@ namespace OpenSim.Region.Framework.Scenes
808 "[SCENE]: Upgrading child to root agent for {0} in {1}", 852 "[SCENE]: Upgrading child to root agent for {0} in {1}",
809 Name, m_scene.RegionInfo.RegionName); 853 Name, m_scene.RegionInfo.RegionName);
810 854
811 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
812
813 bool wasChild = IsChildAgent; 855 bool wasChild = IsChildAgent;
814 IsChildAgent = false; 856
857 if (ParentUUID != UUID.Zero)
858 {
859 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
860 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
861 if (part == null)
862 {
863 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
864 }
865 else
866 {
867 part.ParentGroup.AddAvatar(UUID);
868 if (part.SitTargetPosition != Vector3.Zero)
869 part.SitTargetAvatar = UUID;
870// ParentPosition = part.GetWorldPosition();
871 ParentID = part.LocalId;
872 ParentPart = part;
873 m_pos = m_prevSitOffset;
874// pos = ParentPosition;
875 pos = part.GetWorldPosition();
876 }
877 ParentUUID = UUID.Zero;
878
879 IsChildAgent = false;
880
881// Animator.TrySetMovementAnimation("SIT");
882 }
883 else
884 {
885 IsChildAgent = false;
886 }
887
815 888
816 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>(); 889 IGroupsModule gm = m_scene.RequestModuleInterface<IGroupsModule>();
817 if (gm != null) 890 if (gm != null)
@@ -821,62 +894,72 @@ namespace OpenSim.Region.Framework.Scenes
821 894
822 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 895 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
823 896
824 // Moved this from SendInitialData to ensure that Appearance is initialized 897 if (ParentID == 0)
825 // before the inventory is processed in MakeRootAgent. This fixes a race condition
826 // related to the handling of attachments
827 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
828 if (m_scene.TestBorderCross(pos, Cardinals.E))
829 { 898 {
830 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 899 // Moved this from SendInitialData to ensure that Appearance is initialized
831 pos.X = crossedBorder.BorderLine.Z - 1; 900 // before the inventory is processed in MakeRootAgent. This fixes a race condition
832 } 901 // related to the handling of attachments
902 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
903 if (m_scene.TestBorderCross(pos, Cardinals.E))
904 {
905 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
906 pos.X = crossedBorder.BorderLine.Z - 1;
907 }
833 908
834 if (m_scene.TestBorderCross(pos, Cardinals.N)) 909 if (m_scene.TestBorderCross(pos, Cardinals.N))
835 { 910 {
836 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 911 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
837 pos.Y = crossedBorder.BorderLine.Z - 1; 912 pos.Y = crossedBorder.BorderLine.Z - 1;
838 } 913 }
839 914
840 CheckAndAdjustLandingPoint(ref pos); 915 CheckAndAdjustLandingPoint(ref pos);
841 916
842 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 917 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
843 { 918 {
844 m_log.WarnFormat( 919 m_log.WarnFormat(
845 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 920 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
846 pos, Name, UUID); 921 pos, Name, UUID);
847 922
848 if (pos.X < 0f) pos.X = 0f; 923 if (pos.X < 0f) pos.X = 0f;
849 if (pos.Y < 0f) pos.Y = 0f; 924 if (pos.Y < 0f) pos.Y = 0f;
850 if (pos.Z < 0f) pos.Z = 0f; 925 if (pos.Z < 0f) pos.Z = 0f;
851 } 926 }
852 927
853 float localAVHeight = 1.56f; 928 float localAVHeight = 1.56f;
854 if (Appearance.AvatarHeight > 0) 929 if (Appearance.AvatarHeight > 0)
855 localAVHeight = Appearance.AvatarHeight; 930 localAVHeight = Appearance.AvatarHeight;
856 931
857 float posZLimit = 0; 932 float posZLimit = 0;
858 933
859 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 934 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
860 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 935 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
861 936
862 float newPosZ = posZLimit + localAVHeight / 2; 937 float newPosZ = posZLimit + localAVHeight / 2;
863 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 938 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
864 { 939 {
865 pos.Z = newPosZ; 940 pos.Z = newPosZ;
866 } 941 }
867 AbsolutePosition = pos; 942 AbsolutePosition = pos;
868 943
869 AddToPhysicalScene(isFlying); 944 if (m_teleportFlags == TeleportFlags.Default)
945 {
946 Vector3 vel = Velocity;
947 AddToPhysicalScene(isFlying);
948 if (PhysicsActor != null)
949 PhysicsActor.SetMomentum(vel);
950 }
951 else
952 AddToPhysicalScene(isFlying);
870 953
871 if (ForceFly) 954 if (ForceFly)
872 { 955 {
873 Flying = true; 956 Flying = true;
874 } 957 }
875 else if (FlyDisabled) 958 else if (FlyDisabled)
876 { 959 {
877 Flying = false; 960 Flying = false;
961 }
878 } 962 }
879
880 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 963 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
881 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 964 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
882 // elsewhere anyway 965 // elsewhere anyway
@@ -896,14 +979,19 @@ namespace OpenSim.Region.Framework.Scenes
896 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name); 979 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
897 980
898 // Resume scripts 981 // Resume scripts
899 foreach (SceneObjectGroup sog in m_attachments) 982 Util.FireAndForget(delegate(object x) {
900 { 983 foreach (SceneObjectGroup sog in m_attachments)
901 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 984 {
902 sog.ResumeScripts(); 985 sog.ScheduleGroupForFullUpdate();
903 } 986 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
987 sog.ResumeScripts();
988 }
989 });
904 } 990 }
905 } 991 }
906 992
993 SendAvatarDataToAllAgents();
994
907 // send the animations of the other presences to me 995 // send the animations of the other presences to me
908 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 996 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
909 { 997 {
@@ -914,9 +1002,12 @@ namespace OpenSim.Region.Framework.Scenes
914 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1002 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
915 // stall on the border crossing since the existing child agent will still have the last movement 1003 // stall on the border crossing since the existing child agent will still have the last movement
916 // recorded, which stops the input from being processed. 1004 // recorded, which stops the input from being processed.
1005
917 MovementFlag = 0; 1006 MovementFlag = 0;
918 1007
919 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1008 m_scene.EventManager.TriggerOnMakeRootAgent(this);
1009
1010 m_scene.EventManager.OnRegionHeartbeatEnd += RegionHeartbeatEnd;
920 } 1011 }
921 1012
922 public int GetStateSource() 1013 public int GetStateSource()
@@ -944,12 +1035,16 @@ namespace OpenSim.Region.Framework.Scenes
944 /// </remarks> 1035 /// </remarks>
945 public void MakeChildAgent() 1036 public void MakeChildAgent()
946 { 1037 {
1038 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1039
947 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1040 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
948 1041
949 // Reset these so that teleporting in and walking out isn't seen 1042 // Reset these so that teleporting in and walking out isn't seen
950 // as teleporting back 1043 // as teleporting back
951 TeleportFlags = TeleportFlags.Default; 1044 TeleportFlags = TeleportFlags.Default;
952 1045
1046 MovementFlag = 0;
1047
953 // It looks like Animator is set to null somewhere, and MakeChild 1048 // It looks like Animator is set to null somewhere, and MakeChild
954 // is called after that. Probably in aborted teleports. 1049 // is called after that. Probably in aborted teleports.
955 if (Animator == null) 1050 if (Animator == null)
@@ -957,6 +1052,7 @@ namespace OpenSim.Region.Framework.Scenes
957 else 1052 else
958 Animator.ResetAnimations(); 1053 Animator.ResetAnimations();
959 1054
1055
960// m_log.DebugFormat( 1056// m_log.DebugFormat(
961// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1057// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
962// Name, UUID, m_scene.RegionInfo.RegionName); 1058// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -968,6 +1064,7 @@ namespace OpenSim.Region.Framework.Scenes
968 IsChildAgent = true; 1064 IsChildAgent = true;
969 m_scene.SwapRootAgentCount(true); 1065 m_scene.SwapRootAgentCount(true);
970 RemoveFromPhysicalScene(); 1066 RemoveFromPhysicalScene();
1067 ParentID = 0; // Child agents can't be sitting
971 1068
972 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1069 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
973 1070
@@ -983,9 +1080,9 @@ namespace OpenSim.Region.Framework.Scenes
983 { 1080 {
984// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1081// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
985 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1082 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
986 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
987 PhysicsActor.UnSubscribeEvents();
988 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1083 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1084 PhysicsActor.UnSubscribeEvents();
1085 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
989 PhysicsActor = null; 1086 PhysicsActor = null;
990 } 1087 }
991// else 1088// else
@@ -1002,7 +1099,7 @@ namespace OpenSim.Region.Framework.Scenes
1002 /// <param name="pos"></param> 1099 /// <param name="pos"></param>
1003 public void Teleport(Vector3 pos) 1100 public void Teleport(Vector3 pos)
1004 { 1101 {
1005 TeleportWithMomentum(pos, null); 1102 TeleportWithMomentum(pos, Vector3.Zero);
1006 } 1103 }
1007 1104
1008 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1105 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1026,6 +1123,41 @@ namespace OpenSim.Region.Framework.Scenes
1026 SendTerseUpdateToAllClients(); 1123 SendTerseUpdateToAllClients();
1027 } 1124 }
1028 1125
1126 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1127 {
1128 CheckLandingPoint(ref newpos);
1129 AbsolutePosition = newpos;
1130
1131 if (newvel.HasValue)
1132 {
1133 if ((Vector3)newvel == Vector3.Zero)
1134 {
1135 if (PhysicsActor != null)
1136 PhysicsActor.SetMomentum(Vector3.Zero);
1137 m_velocity = Vector3.Zero;
1138 }
1139 else
1140 {
1141 if (PhysicsActor != null)
1142 PhysicsActor.SetMomentum((Vector3)newvel);
1143 m_velocity = (Vector3)newvel;
1144
1145 if (rotateToVelXY)
1146 {
1147 Vector3 lookAt = (Vector3)newvel;
1148 lookAt.Z = 0;
1149 lookAt.Normalize();
1150 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1151 return;
1152 }
1153 }
1154 }
1155
1156 SendTerseUpdateToAllClients();
1157 }
1158
1159
1160
1029 public void StopFlying() 1161 public void StopFlying()
1030 { 1162 {
1031 ControllingClient.StopFlying(this); 1163 ControllingClient.StopFlying(this);
@@ -1135,7 +1267,8 @@ namespace OpenSim.Region.Framework.Scenes
1135 1267
1136 Vector3 look = Velocity; 1268 Vector3 look = Velocity;
1137 1269
1138 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1270 // if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1271 if ((Math.Abs(look.X) < 0.1) && (Math.Abs(look.Y) < 0.1) && (Math.Abs(look.Z) < 0.1))
1139 { 1272 {
1140 look = new Vector3(0.99f, 0.042f, 0); 1273 look = new Vector3(0.99f, 0.042f, 0);
1141 } 1274 }
@@ -1185,13 +1318,15 @@ namespace OpenSim.Region.Framework.Scenes
1185 // Create child agents in neighbouring regions 1318 // Create child agents in neighbouring regions
1186 if (openChildAgents && !IsChildAgent) 1319 if (openChildAgents && !IsChildAgent)
1187 { 1320 {
1321
1188 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1322 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1189 if (m_agentTransfer != null) 1323 if (m_agentTransfer != null)
1190 Util.FireAndForget(delegate { m_agentTransfer.EnableChildAgents(this); }); 1324 m_agentTransfer.EnableChildAgents(this);
1191 1325
1192 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1326 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1193 if (friendsModule != null) 1327 if (friendsModule != null)
1194 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1328 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1329
1195 } 1330 }
1196 1331
1197// m_log.DebugFormat( 1332// m_log.DebugFormat(
@@ -1341,8 +1476,18 @@ namespace OpenSim.Region.Framework.Scenes
1341 { 1476 {
1342 if (m_followCamAuto) 1477 if (m_followCamAuto)
1343 { 1478 {
1344 Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT; 1479 // Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
1345 m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback); 1480 // m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback);
1481
1482 Vector3 posAdjusted = AbsolutePosition + HEAD_ADJUSTMENT;
1483 Vector3 distTocam = CameraPosition - posAdjusted;
1484 float distTocamlen = distTocam.Length();
1485 if (distTocamlen > 0)
1486 {
1487 distTocam *= 1.0f / distTocamlen;
1488 m_scene.PhysicsScene.RaycastWorld(posAdjusted, distTocam, distTocamlen + 0.3f, RayCastCameraCallback);
1489 }
1490
1346 } 1491 }
1347 } 1492 }
1348 1493
@@ -1781,12 +1926,17 @@ namespace OpenSim.Region.Framework.Scenes
1781// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 1926// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
1782 1927
1783 SitGround = false; 1928 SitGround = false;
1929
1930/* move this down so avatar gets physical in the new position and not where it is siting
1784 if (PhysicsActor == null) 1931 if (PhysicsActor == null)
1785 AddToPhysicalScene(false); 1932 AddToPhysicalScene(false);
1933 */
1786 1934
1787 if (ParentID != 0) 1935 if (ParentID != 0)
1788 { 1936 {
1789 SceneObjectPart part = ParentPart; 1937 SceneObjectPart part = ParentPart;
1938 UnRegisterSeatControls(part.ParentGroup.UUID);
1939
1790 TaskInventoryDictionary taskIDict = part.TaskInventory; 1940 TaskInventoryDictionary taskIDict = part.TaskInventory;
1791 if (taskIDict != null) 1941 if (taskIDict != null)
1792 { 1942 {
@@ -1802,14 +1952,22 @@ namespace OpenSim.Region.Framework.Scenes
1802 } 1952 }
1803 } 1953 }
1804 1954
1805 ParentPosition = part.GetWorldPosition(); 1955 part.ParentGroup.DeleteAvatar(UUID);
1956// ParentPosition = part.GetWorldPosition();
1806 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1957 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1807 1958
1808 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 1959// m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
1809 ParentPosition = Vector3.Zero; 1960// ParentPosition = Vector3.Zero;
1961 m_pos = part.AbsolutePosition + (m_pos * part.GetWorldRotation()) + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
1962 if (part.SitTargetAvatar == UUID)
1963 m_bodyRot = part.GetWorldRotation() * part.SitTargetOrientation;
1810 1964
1811 ParentID = 0; 1965 ParentID = 0;
1812 ParentPart = null; 1966 ParentPart = null;
1967
1968 if (PhysicsActor == null)
1969 AddToPhysicalScene(false);
1970
1813 SendAvatarDataToAllAgents(); 1971 SendAvatarDataToAllAgents();
1814 m_requestedSitTargetID = 0; 1972 m_requestedSitTargetID = 0;
1815 1973
@@ -1819,6 +1977,9 @@ namespace OpenSim.Region.Framework.Scenes
1819 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 1977 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
1820 } 1978 }
1821 1979
1980 else if (PhysicsActor == null)
1981 AddToPhysicalScene(false);
1982
1822 Animator.TrySetMovementAnimation("STAND"); 1983 Animator.TrySetMovementAnimation("STAND");
1823 } 1984 }
1824 1985
@@ -1870,7 +2031,7 @@ namespace OpenSim.Region.Framework.Scenes
1870 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it 2031 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
1871 2032
1872 if (PhysicsActor != null) 2033 if (PhysicsActor != null)
1873 m_sitAvatarHeight = PhysicsActor.Size.Z; 2034 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
1874 2035
1875 bool canSit = false; 2036 bool canSit = false;
1876 Vector3 pos = part.AbsolutePosition + offset; 2037 Vector3 pos = part.AbsolutePosition + offset;
@@ -1919,7 +2080,7 @@ namespace OpenSim.Region.Framework.Scenes
1919 forceMouselook = part.GetForceMouselook(); 2080 forceMouselook = part.GetForceMouselook();
1920 2081
1921 ControllingClient.SendSitResponse( 2082 ControllingClient.SendSitResponse(
1922 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2083 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
1923 2084
1924 m_requestedSitTargetUUID = targetID; 2085 m_requestedSitTargetUUID = targetID;
1925 2086
@@ -1933,6 +2094,9 @@ namespace OpenSim.Region.Framework.Scenes
1933 2094
1934 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) 2095 public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset)
1935 { 2096 {
2097 if (IsChildAgent)
2098 return;
2099
1936 if (ParentID != 0) 2100 if (ParentID != 0)
1937 { 2101 {
1938 StandUp(); 2102 StandUp();
@@ -2210,14 +2374,39 @@ namespace OpenSim.Region.Framework.Scenes
2210 2374
2211 //Quaternion result = (sitTargetOrient * vq) * nq; 2375 //Quaternion result = (sitTargetOrient * vq) * nq;
2212 2376
2213 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2377 double x, y, z, m;
2378
2379 Quaternion r = sitTargetOrient;
2380 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2381
2382 if (Math.Abs(1.0 - m) > 0.000001)
2383 {
2384 m = 1.0 / Math.Sqrt(m);
2385 r.X *= (float)m;
2386 r.Y *= (float)m;
2387 r.Z *= (float)m;
2388 r.W *= (float)m;
2389 }
2390
2391 x = 2 * (r.X * r.Z + r.Y * r.W);
2392 y = 2 * (-r.X * r.W + r.Y * r.Z);
2393 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2394
2395 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2396 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2397
2398 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2399
2400// m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT - sitOffset;
2214 Rotation = sitTargetOrient; 2401 Rotation = sitTargetOrient;
2215 ParentPosition = part.AbsolutePosition; 2402// ParentPosition = part.AbsolutePosition;
2403 part.ParentGroup.AddAvatar(UUID);
2216 } 2404 }
2217 else 2405 else
2218 { 2406 {
2219 m_pos -= part.AbsolutePosition; 2407 m_pos -= part.AbsolutePosition;
2220 ParentPosition = part.AbsolutePosition; 2408// ParentPosition = part.AbsolutePosition;
2409 part.ParentGroup.AddAvatar(UUID);
2221 2410
2222// m_log.DebugFormat( 2411// m_log.DebugFormat(
2223// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2412// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2262,6 +2451,13 @@ namespace OpenSim.Region.Framework.Scenes
2262 Animator.RemoveAnimation(animID); 2451 Animator.RemoveAnimation(animID);
2263 } 2452 }
2264 2453
2454 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2455 {
2456 Animator.avnChangeAnim(animID, addRemove, sendPack);
2457 }
2458
2459
2460
2265 /// <summary> 2461 /// <summary>
2266 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2462 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2267 /// </summary> 2463 /// </summary>
@@ -2315,14 +2511,15 @@ namespace OpenSim.Region.Framework.Scenes
2315 direc.Z *= 2.6f; 2511 direc.Z *= 2.6f;
2316 2512
2317 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2513 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2318 Animator.TrySetMovementAnimation("PREJUMP"); 2514// Animator.TrySetMovementAnimation("PREJUMP");
2319 Animator.TrySetMovementAnimation("JUMP"); 2515// Animator.TrySetMovementAnimation("JUMP");
2320 } 2516 }
2321 } 2517 }
2322 } 2518 }
2323 2519
2324 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2520 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2325 m_forceToApply = direc; 2521 m_forceToApply = direc;
2522 Animator.UpdateMovementAnimations();
2326 } 2523 }
2327 2524
2328 #endregion 2525 #endregion
@@ -2714,8 +2911,9 @@ namespace OpenSim.Region.Framework.Scenes
2714 2911
2715 // If we don't have a PhysActor, we can't cross anyway 2912 // If we don't have a PhysActor, we can't cross anyway
2716 // Also don't do this while sat, sitting avatars cross with the 2913 // Also don't do this while sat, sitting avatars cross with the
2717 // object they sit on. 2914 // object they sit on. ParentUUID denoted a pending sit, don't
2718 if (ParentID != 0 || PhysicsActor == null) 2915 // interfere with it.
2916 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
2719 return; 2917 return;
2720 2918
2721 if (!IsInTransit) 2919 if (!IsInTransit)
@@ -3056,6 +3254,9 @@ namespace OpenSim.Region.Framework.Scenes
3056 cAgent.AlwaysRun = SetAlwaysRun; 3254 cAgent.AlwaysRun = SetAlwaysRun;
3057 3255
3058 cAgent.Appearance = new AvatarAppearance(Appearance); 3256 cAgent.Appearance = new AvatarAppearance(Appearance);
3257
3258 cAgent.ParentPart = ParentUUID;
3259 cAgent.SitOffset = m_pos;
3059 3260
3060 lock (scriptedcontrols) 3261 lock (scriptedcontrols)
3061 { 3262 {
@@ -3064,7 +3265,7 @@ namespace OpenSim.Region.Framework.Scenes
3064 3265
3065 foreach (ScriptControllers c in scriptedcontrols.Values) 3266 foreach (ScriptControllers c in scriptedcontrols.Values)
3066 { 3267 {
3067 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3268 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3068 } 3269 }
3069 cAgent.Controllers = controls; 3270 cAgent.Controllers = controls;
3070 } 3271 }
@@ -3075,6 +3276,7 @@ namespace OpenSim.Region.Framework.Scenes
3075 cAgent.Anims = Animator.Animations.ToArray(); 3276 cAgent.Anims = Animator.Animations.ToArray();
3076 } 3277 }
3077 catch { } 3278 catch { }
3279 cAgent.DefaultAnim = Animator.Animations.ImplicitDefaultAnimation;
3078 3280
3079 if (Scene.AttachmentsModule != null) 3281 if (Scene.AttachmentsModule != null)
3080 Scene.AttachmentsModule.CopyAttachments(this, cAgent); 3282 Scene.AttachmentsModule.CopyAttachments(this, cAgent);
@@ -3095,6 +3297,8 @@ namespace OpenSim.Region.Framework.Scenes
3095 CameraAtAxis = cAgent.AtAxis; 3297 CameraAtAxis = cAgent.AtAxis;
3096 CameraLeftAxis = cAgent.LeftAxis; 3298 CameraLeftAxis = cAgent.LeftAxis;
3097 CameraUpAxis = cAgent.UpAxis; 3299 CameraUpAxis = cAgent.UpAxis;
3300 ParentUUID = cAgent.ParentPart;
3301 m_prevSitOffset = cAgent.SitOffset;
3098 3302
3099 // When we get to the point of re-computing neighbors everytime this 3303 // When we get to the point of re-computing neighbors everytime this
3100 // changes, then start using the agent's drawdistance rather than the 3304 // changes, then start using the agent's drawdistance rather than the
@@ -3132,6 +3336,7 @@ namespace OpenSim.Region.Framework.Scenes
3132 foreach (ControllerData c in cAgent.Controllers) 3336 foreach (ControllerData c in cAgent.Controllers)
3133 { 3337 {
3134 ScriptControllers sc = new ScriptControllers(); 3338 ScriptControllers sc = new ScriptControllers();
3339 sc.objectID = c.ObjectID;
3135 sc.itemID = c.ItemID; 3340 sc.itemID = c.ItemID;
3136 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3341 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3137 sc.eventControls = (ScriptControlled)c.EventControls; 3342 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3146,6 +3351,8 @@ namespace OpenSim.Region.Framework.Scenes
3146 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object? 3351 // FIXME: Why is this null check necessary? Where are the cases where we get a null Anims object?
3147 if (cAgent.Anims != null) 3352 if (cAgent.Anims != null)
3148 Animator.Animations.FromArray(cAgent.Anims); 3353 Animator.Animations.FromArray(cAgent.Anims);
3354 if (cAgent.DefaultAnim != null)
3355 Animator.Animations.SetDefaultAnimation(cAgent.DefaultAnim.AnimID, cAgent.DefaultAnim.SequenceNum, UUID.Zero);
3149 3356
3150 if (Scene.AttachmentsModule != null) 3357 if (Scene.AttachmentsModule != null)
3151 Scene.AttachmentsModule.CopyAttachments(cAgent, this); 3358 Scene.AttachmentsModule.CopyAttachments(cAgent, this);
@@ -3208,7 +3415,7 @@ namespace OpenSim.Region.Framework.Scenes
3208 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3415 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3209 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3416 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3210 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3417 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3211 PhysicsActor.SubscribeEvents(500); 3418 PhysicsActor.SubscribeEvents(100);
3212 PhysicsActor.LocalID = LocalId; 3419 PhysicsActor.LocalID = LocalId;
3213 } 3420 }
3214 3421
@@ -3235,7 +3442,7 @@ namespace OpenSim.Region.Framework.Scenes
3235 /// <param name="e"></param> 3442 /// <param name="e"></param>
3236 public void PhysicsCollisionUpdate(EventArgs e) 3443 public void PhysicsCollisionUpdate(EventArgs e)
3237 { 3444 {
3238 if (IsChildAgent) 3445 if (IsChildAgent || Animator == null)
3239 return; 3446 return;
3240 3447
3241 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3448 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3290,6 +3497,8 @@ namespace OpenSim.Region.Framework.Scenes
3290 } 3497 }
3291 } 3498 }
3292 3499
3500 RaiseCollisionScriptEvents(coldata);
3501
3293 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3502 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3294 if (Invulnerable || GodLevel > 0) 3503 if (Invulnerable || GodLevel > 0)
3295 return; 3504 return;
@@ -3387,6 +3596,13 @@ namespace OpenSim.Region.Framework.Scenes
3387 // m_reprioritizationTimer.Dispose(); 3596 // m_reprioritizationTimer.Dispose();
3388 3597
3389 RemoveFromPhysicalScene(); 3598 RemoveFromPhysicalScene();
3599
3600 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
3601
3602// if (Animator != null)
3603// Animator.Close();
3604 Animator = null;
3605
3390 } 3606 }
3391 3607
3392 public void AddAttachment(SceneObjectGroup gobj) 3608 public void AddAttachment(SceneObjectGroup gobj)
@@ -3620,10 +3836,18 @@ namespace OpenSim.Region.Framework.Scenes
3620 3836
3621 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 3837 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
3622 { 3838 {
3839 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
3840 if (p == null)
3841 return;
3842
3843 ControllingClient.SendTakeControls(controls, false, false);
3844 ControllingClient.SendTakeControls(controls, true, false);
3845
3623 ScriptControllers obj = new ScriptControllers(); 3846 ScriptControllers obj = new ScriptControllers();
3624 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 3847 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
3625 obj.eventControls = ScriptControlled.CONTROL_ZERO; 3848 obj.eventControls = ScriptControlled.CONTROL_ZERO;
3626 3849
3850 obj.objectID = p.ParentGroup.UUID;
3627 obj.itemID = Script_item_UUID; 3851 obj.itemID = Script_item_UUID;
3628 if (pass_on == 0 && accept == 0) 3852 if (pass_on == 0 && accept == 0)
3629 { 3853 {
@@ -3672,6 +3896,21 @@ namespace OpenSim.Region.Framework.Scenes
3672 ControllingClient.SendTakeControls(int.MaxValue, false, false); 3896 ControllingClient.SendTakeControls(int.MaxValue, false, false);
3673 } 3897 }
3674 3898
3899 private void UnRegisterSeatControls(UUID obj)
3900 {
3901 List<UUID> takers = new List<UUID>();
3902
3903 foreach (ScriptControllers c in scriptedcontrols.Values)
3904 {
3905 if (c.objectID == obj)
3906 takers.Add(c.itemID);
3907 }
3908 foreach (UUID t in takers)
3909 {
3910 UnRegisterControlEventsToScript(0, t);
3911 }
3912 }
3913
3675 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 3914 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
3676 { 3915 {
3677 ScriptControllers takecontrols; 3916 ScriptControllers takecontrols;
@@ -3990,6 +4229,12 @@ namespace OpenSim.Region.Framework.Scenes
3990 4229
3991 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4230 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
3992 { 4231 {
4232 string reason;
4233
4234 // Honor bans
4235 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4236 return;
4237
3993 SceneObjectGroup telehub = null; 4238 SceneObjectGroup telehub = null;
3994 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4239 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
3995 { 4240 {
@@ -4029,11 +4274,206 @@ namespace OpenSim.Region.Framework.Scenes
4029 pos = land.LandData.UserLocation; 4274 pos = land.LandData.UserLocation;
4030 } 4275 }
4031 } 4276 }
4032 4277
4033 land.SendLandUpdateToClient(ControllingClient); 4278 land.SendLandUpdateToClient(ControllingClient);
4034 } 4279 }
4035 } 4280 }
4036 4281
4282 private DetectedObject CreateDetObject(SceneObjectPart obj)
4283 {
4284 DetectedObject detobj = new DetectedObject();
4285 detobj.keyUUID = obj.UUID;
4286 detobj.nameStr = obj.Name;
4287 detobj.ownerUUID = obj.OwnerID;
4288 detobj.posVector = obj.AbsolutePosition;
4289 detobj.rotQuat = obj.GetWorldRotation();
4290 detobj.velVector = obj.Velocity;
4291 detobj.colliderType = 0;
4292 detobj.groupUUID = obj.GroupID;
4293
4294 return detobj;
4295 }
4296
4297 private DetectedObject CreateDetObject(ScenePresence av)
4298 {
4299 DetectedObject detobj = new DetectedObject();
4300 detobj.keyUUID = av.UUID;
4301 detobj.nameStr = av.ControllingClient.Name;
4302 detobj.ownerUUID = av.UUID;
4303 detobj.posVector = av.AbsolutePosition;
4304 detobj.rotQuat = av.Rotation;
4305 detobj.velVector = av.Velocity;
4306 detobj.colliderType = 0;
4307 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4308
4309 return detobj;
4310 }
4311
4312 private DetectedObject CreateDetObjectForGround()
4313 {
4314 DetectedObject detobj = new DetectedObject();
4315 detobj.keyUUID = UUID.Zero;
4316 detobj.nameStr = "";
4317 detobj.ownerUUID = UUID.Zero;
4318 detobj.posVector = AbsolutePosition;
4319 detobj.rotQuat = Quaternion.Identity;
4320 detobj.velVector = Vector3.Zero;
4321 detobj.colliderType = 0;
4322 detobj.groupUUID = UUID.Zero;
4323
4324 return detobj;
4325 }
4326
4327 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4328 {
4329 ColliderArgs colliderArgs = new ColliderArgs();
4330 List<DetectedObject> colliding = new List<DetectedObject>();
4331 foreach (uint localId in colliders)
4332 {
4333 if (localId == 0)
4334 continue;
4335
4336 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4337 if (obj != null)
4338 {
4339 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4340 colliding.Add(CreateDetObject(obj));
4341 }
4342 else
4343 {
4344 ScenePresence av = m_scene.GetScenePresence(localId);
4345 if (av != null && (!av.IsChildAgent))
4346 {
4347 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4348 colliding.Add(CreateDetObject(av));
4349 }
4350 }
4351 }
4352
4353 colliderArgs.Colliders = colliding;
4354
4355 return colliderArgs;
4356 }
4357
4358 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4359
4360 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4361 {
4362 ColliderArgs CollidingMessage;
4363
4364 if (colliders.Count > 0)
4365 {
4366 if ((dest.RootPart.ScriptEvents & ev) != 0)
4367 {
4368 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4369
4370 if (CollidingMessage.Colliders.Count > 0)
4371 notify(dest.RootPart.LocalId, CollidingMessage);
4372 }
4373 }
4374 }
4375
4376 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4377 {
4378 if ((dest.RootPart.ScriptEvents & ev) != 0)
4379 {
4380 ColliderArgs LandCollidingMessage = new ColliderArgs();
4381 List<DetectedObject> colliding = new List<DetectedObject>();
4382
4383 colliding.Add(CreateDetObjectForGround());
4384 LandCollidingMessage.Colliders = colliding;
4385
4386 notify(dest.RootPart.LocalId, LandCollidingMessage);
4387 }
4388 }
4389
4390 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4391 {
4392 try
4393 {
4394 List<uint> thisHitColliders = new List<uint>();
4395 List<uint> endedColliders = new List<uint>();
4396 List<uint> startedColliders = new List<uint>();
4397 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4398 CollisionForSoundInfo soundinfo;
4399 ContactPoint curcontact;
4400
4401 if (coldata.Count == 0)
4402 {
4403 if (m_lastColliders.Count == 0)
4404 return; // nothing to do
4405
4406 foreach (uint localID in m_lastColliders)
4407 {
4408 endedColliders.Add(localID);
4409 }
4410 m_lastColliders.Clear();
4411 }
4412
4413 else
4414 {
4415 foreach (uint id in coldata.Keys)
4416 {
4417 thisHitColliders.Add(id);
4418 if (!m_lastColliders.Contains(id))
4419 {
4420 startedColliders.Add(id);
4421 curcontact = coldata[id];
4422 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4423 {
4424 soundinfo = new CollisionForSoundInfo();
4425 soundinfo.colliderID = id;
4426 soundinfo.position = curcontact.Position;
4427 soundinfo.relativeVel = curcontact.RelativeSpeed;
4428 soundinfolist.Add(soundinfo);
4429 }
4430 }
4431 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4432 }
4433
4434 // calculate things that ended colliding
4435 foreach (uint localID in m_lastColliders)
4436 {
4437 if (!thisHitColliders.Contains(localID))
4438 {
4439 endedColliders.Add(localID);
4440 }
4441 }
4442 //add the items that started colliding this time to the last colliders list.
4443 foreach (uint localID in startedColliders)
4444 {
4445 m_lastColliders.Add(localID);
4446 }
4447 // remove things that ended colliding from the last colliders list
4448 foreach (uint localID in endedColliders)
4449 {
4450 m_lastColliders.Remove(localID);
4451 }
4452
4453 if (soundinfolist.Count > 0)
4454 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4455 }
4456
4457 foreach (SceneObjectGroup att in GetAttachments())
4458 {
4459 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4460 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4461 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4462
4463 if (startedColliders.Contains(0))
4464 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4465 if (m_lastColliders.Contains(0))
4466 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4467 if (endedColliders.Contains(0))
4468 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4469 }
4470 }
4471 finally
4472 {
4473 m_collisionEventFlag = false;
4474 }
4475 }
4476
4037 private void TeleportFlagsDebug() { 4477 private void TeleportFlagsDebug() {
4038 4478
4039 // Some temporary debugging help to show all the TeleportFlags we have... 4479 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4058,6 +4498,5 @@ namespace OpenSim.Region.Framework.Scenes
4058 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4498 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4059 4499
4060 } 4500 }
4061
4062 } 4501 }
4063} 4502}