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