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.cs1113
1 files changed, 794 insertions, 319 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index b4e8f09..88ecda2 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -65,6 +65,7 @@ namespace OpenSim.Region.Framework.Scenes
65 65
66 struct ScriptControllers 66 struct ScriptControllers
67 { 67 {
68 public UUID objectID;
68 public UUID itemID; 69 public UUID itemID;
69 public ScriptControlled ignoreControls; 70 public ScriptControlled ignoreControls;
70 public ScriptControlled eventControls; 71 public ScriptControlled eventControls;
@@ -120,7 +121,7 @@ namespace OpenSim.Region.Framework.Scenes
120 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis 121 /// rotation, prim cut, prim twist, prim taper, and prim shear. See mantis
121 /// issue #1716 122 /// issue #1716
122 /// </summary> 123 /// </summary>
123 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.418f); 124 public static readonly Vector3 SIT_TARGET_ADJUSTMENT = new Vector3(0.0f, 0.0f, 0.4f);
124 125
125 /// <summary> 126 /// <summary>
126 /// Movement updates for agents in neighboring regions are sent directly to clients. 127 /// Movement updates for agents in neighboring regions are sent directly to clients.
@@ -142,8 +143,6 @@ namespace OpenSim.Region.Framework.Scenes
142 /// <remarks> 143 /// <remarks>
143 /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is 144 /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is
144 /// necessary. 145 /// necessary.
145 /// NOTE: To avoid deadlocks, do not lock m_attachments and then perform other tasks under that lock. Take a copy
146 /// of the list and act on that instead.
147 /// </remarks> 146 /// </remarks>
148 private List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); 147 private List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
149 148
@@ -162,6 +161,10 @@ namespace OpenSim.Region.Framework.Scenes
162 private Vector3 m_lastPosition; 161 private Vector3 m_lastPosition;
163 private Quaternion m_lastRotation; 162 private Quaternion m_lastRotation;
164 private Vector3 m_lastVelocity; 163 private Vector3 m_lastVelocity;
164 private Vector3 m_lastSize = new Vector3(0.45f,0.6f,1.9f);
165
166 private bool m_followCamAuto = false;
167
165 168
166 private Vector3? m_forceToApply; 169 private Vector3? m_forceToApply;
167 private int m_userFlags; 170 private int m_userFlags;
@@ -194,6 +197,7 @@ namespace OpenSim.Region.Framework.Scenes
194// private int m_lastColCount = -1; //KF: Look for Collision chnages 197// private int m_lastColCount = -1; //KF: Look for Collision chnages
195// private int m_updateCount = 0; //KF: Update Anims for a while 198// private int m_updateCount = 0; //KF: Update Anims for a while
196// private static readonly int UPDATE_COUNT = 10; // how many frames to update for 199// private static readonly int UPDATE_COUNT = 10; // how many frames to update for
200 private List<uint> m_lastColliders = new List<uint>();
197 201
198 private TeleportFlags m_teleportFlags; 202 private TeleportFlags m_teleportFlags;
199 public TeleportFlags TeleportFlags 203 public TeleportFlags TeleportFlags
@@ -249,8 +253,6 @@ namespace OpenSim.Region.Framework.Scenes
249 /// </summary> 253 /// </summary>
250 public bool LandAtTarget { get; private set; } 254 public bool LandAtTarget { get; private set; }
251 255
252 private bool m_followCamAuto;
253
254 private int m_movementUpdateCount; 256 private int m_movementUpdateCount;
255 private const int NumMovementsBetweenRayCast = 5; 257 private const int NumMovementsBetweenRayCast = 5;
256 258
@@ -258,6 +260,13 @@ namespace OpenSim.Region.Framework.Scenes
258 //private int m_moveToPositionStateStatus; 260 //private int m_moveToPositionStateStatus;
259 //***************************************************** 261 //*****************************************************
260 262
263 private bool m_collisionEventFlag = false;
264 private object m_collisionEventLock = new Object();
265
266 private int m_movementAnimationUpdateCounter = 0;
267
268 private Vector3 m_prevSitOffset;
269
261 protected AvatarAppearance m_appearance; 270 protected AvatarAppearance m_appearance;
262 271
263 public AvatarAppearance Appearance 272 public AvatarAppearance Appearance
@@ -386,6 +395,9 @@ namespace OpenSim.Region.Framework.Scenes
386 /// </summary> 395 /// </summary>
387 protected Vector3 m_lastCameraPosition; 396 protected Vector3 m_lastCameraPosition;
388 397
398 private Vector4 m_lastCameraCollisionPlane = new Vector4(0f, 0f, 0f, 1);
399 private bool m_doingCamRayCast = false;
400
389 public Vector3 CameraPosition { get; set; } 401 public Vector3 CameraPosition { get; set; }
390 402
391 public Quaternion CameraRotation 403 public Quaternion CameraRotation
@@ -466,7 +478,9 @@ namespace OpenSim.Region.Framework.Scenes
466 get { return (IClientCore)ControllingClient; } 478 get { return (IClientCore)ControllingClient; }
467 } 479 }
468 480
469 public Vector3 ParentPosition { get; set; } 481 public UUID COF { get; set; }
482
483// public Vector3 ParentPosition { get; set; }
470 484
471 /// <summary> 485 /// <summary>
472 /// Position of this avatar relative to the region the avatar is in 486 /// Position of this avatar relative to the region the avatar is in
@@ -527,7 +541,7 @@ namespace OpenSim.Region.Framework.Scenes
527 if (ParentID == 0) 541 if (ParentID == 0)
528 { 542 {
529 m_pos = value; 543 m_pos = value;
530 ParentPosition = Vector3.Zero; 544// ParentPosition = Vector3.Zero;
531 } 545 }
532 546
533 //m_log.DebugFormat( 547 //m_log.DebugFormat(
@@ -596,7 +610,24 @@ namespace OpenSim.Region.Framework.Scenes
596// Scene.RegionInfo.RegionName, Name, m_velocity); 610// Scene.RegionInfo.RegionName, Name, m_velocity);
597 } 611 }
598 } 612 }
613/*
614 public override Vector3 AngularVelocity
615 {
616 get
617 {
618 if (PhysicsActor != null)
619 {
620 m_rotationalvelocity = PhysicsActor.RotationalVelocity;
599 621
622 // m_log.DebugFormat(
623 // "[SCENE PRESENCE]: Set velocity {0} for {1} in {2} via getting Velocity!",
624 // m_velocity, Name, Scene.RegionInfo.RegionName);
625 }
626
627 return m_rotationalvelocity;
628 }
629 }
630*/
600 private Quaternion m_bodyRot = Quaternion.Identity; 631 private Quaternion m_bodyRot = Quaternion.Identity;
601 632
602 /// <summary> 633 /// <summary>
@@ -619,8 +650,16 @@ namespace OpenSim.Region.Framework.Scenes
619 m_bodyRot = value; 650 m_bodyRot = value;
620 651
621 if (PhysicsActor != null) 652 if (PhysicsActor != null)
622 PhysicsActor.Orientation = m_bodyRot; 653 {
623 654 try
655 {
656 PhysicsActor.Orientation = m_bodyRot;
657 }
658 catch (Exception e)
659 {
660 m_log.Error("[SCENE PRESENCE]: Orientation " + e.Message);
661 }
662 }
624// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot); 663// m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, m_bodyRot);
625 } 664 }
626 } 665 }
@@ -634,12 +673,20 @@ namespace OpenSim.Region.Framework.Scenes
634 } 673 }
635 674
636 public bool IsChildAgent { get; set; } 675 public bool IsChildAgent { get; set; }
676 public bool IsLoggingIn { get; set; }
637 677
638 /// <summary> 678 /// <summary>
639 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero. 679 /// If the avatar is sitting, the local ID of the prim that it's sitting on. If not sitting then zero.
640 /// </summary> 680 /// </summary>
641 public uint ParentID { get; set; } 681 public uint ParentID { get; set; }
642 682
683 public UUID ParentUUID
684 {
685 get { return m_parentUUID; }
686 set { m_parentUUID = value; }
687 }
688 private UUID m_parentUUID = UUID.Zero;
689
643 /// <summary> 690 /// <summary>
644 /// Are we sitting on an object? 691 /// Are we sitting on an object?
645 /// </summary> 692 /// </summary>
@@ -789,6 +836,7 @@ namespace OpenSim.Region.Framework.Scenes
789 AttachmentsSyncLock = new Object(); 836 AttachmentsSyncLock = new Object();
790 AllowMovement = true; 837 AllowMovement = true;
791 IsChildAgent = true; 838 IsChildAgent = true;
839 IsLoggingIn = false;
792 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault; 840 m_sendCoarseLocationsMethod = SendCoarseLocationsDefault;
793 Animator = new ScenePresenceAnimator(this); 841 Animator = new ScenePresenceAnimator(this);
794 PresenceType = type; 842 PresenceType = type;
@@ -834,6 +882,33 @@ namespace OpenSim.Region.Framework.Scenes
834 m_stateMachine = new ScenePresenceStateMachine(this); 882 m_stateMachine = new ScenePresenceStateMachine(this);
835 } 883 }
836 884
885 private void RegionHeartbeatEnd(Scene scene)
886 {
887 if (IsChildAgent)
888 return;
889
890 m_movementAnimationUpdateCounter ++;
891 if (m_movementAnimationUpdateCounter >= 2)
892 {
893 m_movementAnimationUpdateCounter = 0;
894 if (Animator != null)
895 {
896 // If the parentID == 0 we are not sitting
897 // if !SitGournd then we are not sitting on the ground
898 // Fairly straightforward, now here comes the twist
899 // if ParentUUID is NOT UUID.Zero, we are looking to
900 // be sat on an object that isn't there yet. Should
901 // be treated as if sat.
902 if(ParentID == 0 && !SitGround && ParentUUID == UUID.Zero) // skip it if sitting
903 Animator.UpdateMovementAnimations();
904 }
905 else
906 {
907 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
908 }
909 }
910 }
911
837 public void RegisterToEvents() 912 public void RegisterToEvents()
838 { 913 {
839 ControllingClient.OnCompleteMovementToRegion += CompleteMovement; 914 ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -844,8 +919,10 @@ namespace OpenSim.Region.Framework.Scenes
844 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun; 919 ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
845 ControllingClient.OnStartAnim += HandleStartAnim; 920 ControllingClient.OnStartAnim += HandleStartAnim;
846 ControllingClient.OnStopAnim += HandleStopAnim; 921 ControllingClient.OnStopAnim += HandleStopAnim;
922 ControllingClient.OnChangeAnim += avnHandleChangeAnim;
847 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; 923 ControllingClient.OnForceReleaseControls += HandleForceReleaseControls;
848 ControllingClient.OnAutoPilotGo += MoveToTarget; 924 ControllingClient.OnAutoPilotGo += MoveToTarget;
925 ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles;
849 926
850 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); 927 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
851 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); 928 // ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
@@ -904,6 +981,38 @@ namespace OpenSim.Region.Framework.Scenes
904 "[SCENE]: Upgrading child to root agent for {0} in {1}", 981 "[SCENE]: Upgrading child to root agent for {0} in {1}",
905 Name, m_scene.RegionInfo.RegionName); 982 Name, m_scene.RegionInfo.RegionName);
906 983
984 if (ParentUUID != UUID.Zero)
985 {
986 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
987 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
988 if (part == null)
989 {
990 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
991 }
992 else
993 {
994 part.ParentGroup.AddAvatar(UUID);
995 if (part.SitTargetPosition != Vector3.Zero)
996 part.SitTargetAvatar = UUID;
997// ParentPosition = part.GetWorldPosition();
998 ParentID = part.LocalId;
999 ParentPart = part;
1000 m_pos = m_prevSitOffset;
1001// pos = ParentPosition;
1002 pos = part.GetWorldPosition();
1003 }
1004 ParentUUID = UUID.Zero;
1005
1006 IsChildAgent = false;
1007
1008// Animator.TrySetMovementAnimation("SIT");
1009 }
1010 else
1011 {
1012 IsChildAgent = false;
1013 IsLoggingIn = false;
1014 }
1015
907 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); 1016 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count);
908 1017
909 IsChildAgent = false; 1018 IsChildAgent = false;
@@ -921,70 +1030,106 @@ namespace OpenSim.Region.Framework.Scenes
921 1030
922 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 1031 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
923 1032
924 // Moved this from SendInitialData to ensure that Appearance is initialized 1033 UUID groupUUID = UUID.Zero;
925 // before the inventory is processed in MakeRootAgent. This fixes a race condition 1034 string GroupName = string.Empty;
926 // related to the handling of attachments 1035 ulong groupPowers = 0;
927 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
928 1036
929 if (m_scene.TestBorderCross(pos, Cardinals.E)) 1037 // ----------------------------------
1038 // Previous Agent Difference - AGNI sends an unsolicited AgentDataUpdate upon root agent status
1039 try
930 { 1040 {
931 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 1041 if (gm != null)
932 pos.X = crossedBorder.BorderLine.Z - 1; 1042 {
1043 groupUUID = ControllingClient.ActiveGroupId;
1044 GroupRecord record = gm.GetGroupRecord(groupUUID);
1045 if (record != null)
1046 GroupName = record.GroupName;
1047 GroupMembershipData groupMembershipData = gm.GetMembershipData(groupUUID, m_uuid);
1048 if (groupMembershipData != null)
1049 groupPowers = groupMembershipData.GroupPowers;
1050 }
1051 ControllingClient.SendAgentDataUpdate(m_uuid, groupUUID, Firstname, Lastname, groupPowers, GroupName,
1052 Grouptitle);
933 } 1053 }
934 1054 catch (Exception e)
935 if (m_scene.TestBorderCross(pos, Cardinals.N))
936 { 1055 {
937 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 1056 m_log.Debug("[AGENTUPDATE]: " + e.ToString());
938 pos.Y = crossedBorder.BorderLine.Z - 1;
939 } 1057 }
1058 // ------------------------------------
940 1059
941 CheckAndAdjustLandingPoint(ref pos); 1060 if (ParentID == 0)
942
943 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
944 { 1061 {
945 m_log.WarnFormat( 1062 // Moved this from SendInitialData to ensure that Appearance is initialized
946 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 1063 // before the inventory is processed in MakeRootAgent. This fixes a race condition
947 pos, Name, UUID); 1064 // related to the handling of attachments
1065 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
1066 if (m_scene.TestBorderCross(pos, Cardinals.E))
1067 {
1068 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
1069 pos.X = crossedBorder.BorderLine.Z - 1;
1070 }
948 1071
949 if (pos.X < 0f) pos.X = 0f; 1072 if (m_scene.TestBorderCross(pos, Cardinals.N))
950 if (pos.Y < 0f) pos.Y = 0f; 1073 {
951 if (pos.Z < 0f) pos.Z = 0f; 1074 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
952 } 1075 pos.Y = crossedBorder.BorderLine.Z - 1;
1076 }
953 1077
954 float localAVHeight = 1.56f; 1078 CheckAndAdjustLandingPoint(ref pos);
955 if (Appearance.AvatarHeight > 0)
956 localAVHeight = Appearance.AvatarHeight;
957 1079
958 float posZLimit = 0; 1080 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
1081 {
1082 m_log.WarnFormat(
1083 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
1084 pos, Name, UUID);
959 1085
960 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 1086 if (pos.X < 0f) pos.X = 0f;
961 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 1087 if (pos.Y < 0f) pos.Y = 0f;
962 1088 if (pos.Z < 0f) pos.Z = 0f;
963 float newPosZ = posZLimit + localAVHeight / 2; 1089 }
964 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
965 {
966 pos.Z = newPosZ;
967 }
968 AbsolutePosition = pos;
969 1090
970 AddToPhysicalScene(isFlying); 1091 float localAVHeight = 1.56f;
1092 if (Appearance.AvatarHeight > 0)
1093 localAVHeight = Appearance.AvatarHeight;
971 1094
972 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a 1095 float posZLimit = 0;
973 // location outside the 'root region' (the south-west 256x256 corner). This is the earlist we can do it
974 // since it requires a physics actor to be present. If it is left any later, then physics appears to reset
975 // the value to a negative position which does not trigger the border cross.
976 // This may not be the best location for this.
977 CheckForBorderCrossing();
978 1096
979 if (ForceFly) 1097 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
980 { 1098 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
981 Flying = true; 1099
982 } 1100 float newPosZ = posZLimit + localAVHeight / 2;
983 else if (FlyDisabled) 1101 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
984 { 1102 {
985 Flying = false; 1103 pos.Z = newPosZ;
986 } 1104 }
1105 AbsolutePosition = pos;
1106
1107 if (m_teleportFlags == TeleportFlags.Default)
1108 {
1109 Vector3 vel = Velocity;
1110 AddToPhysicalScene(isFlying);
1111 if (PhysicsActor != null)
1112 PhysicsActor.SetMomentum(vel);
1113 }
1114 else
1115 AddToPhysicalScene(isFlying);
1116
1117 // XXX: This is to trigger any secondary teleport needed for a megaregion when the user has teleported to a
1118 // location outside the 'root region' (the south-west 256x256 corner). This is the earlist we can do it
1119 // since it requires a physics actor to be present. If it is left any later, then physics appears to reset
1120 // the value to a negative position which does not trigger the border cross.
1121 // This may not be the best location for this.
1122 CheckForBorderCrossing();
987 1123
1124 if (ForceFly)
1125 {
1126 Flying = true;
1127 }
1128 else if (FlyDisabled)
1129 {
1130 Flying = false;
1131 }
1132 }
988 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 1133 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
989 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 1134 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
990 // elsewhere anyway 1135 // elsewhere anyway
@@ -1016,31 +1161,28 @@ namespace OpenSim.Region.Framework.Scenes
1016 // and CHANGED_REGION) when the attachments have been rezzed in the new region. This cannot currently 1161 // and CHANGED_REGION) when the attachments have been rezzed in the new region. This cannot currently
1017 // be done in AttachmentsModule.CopyAttachments(AgentData ad, IScenePresence sp) itself since we are 1162 // be done in AttachmentsModule.CopyAttachments(AgentData ad, IScenePresence sp) itself since we are
1018 // not transporting the required data. 1163 // not transporting the required data.
1019 // 1164 lock (m_attachments)
1020 // We must take a copy of the attachments list here (rather than locking) to avoid a deadlock where a script in one of
1021 // the attachments may start processing an event (which locks ScriptInstance.m_Script) that then calls a method here
1022 // which needs to lock m_attachments. ResumeScripts() needs to take a ScriptInstance.m_Script lock to try to unset the Suspend status.
1023 //
1024 // FIXME: In theory, this deadlock should not arise since scripts should not be processing events until ResumeScripts().
1025 // But XEngine starts all scripts unsuspended. Starting them suspended will not currently work because script rezzing
1026 // is placed in an asynchronous queue in XEngine and so the ResumeScripts() call will almost certainly execute before the
1027 // script is rezzed. This means the ResumeScripts() does absolutely nothing when using XEngine.
1028 List<SceneObjectGroup> attachments = GetAttachments();
1029
1030 if (attachments.Count > 0)
1031 { 1165 {
1032 m_log.DebugFormat( 1166 if (HasAttachments())
1033 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
1034
1035 // Resume scripts
1036 foreach (SceneObjectGroup sog in attachments)
1037 { 1167 {
1038 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 1168 m_log.DebugFormat(
1039 sog.ResumeScripts(); 1169 "[SCENE PRESENCE]: Restarting scripts in attachments for {0} in {1}", Name, Scene.Name);
1170
1171 // Resume scripts
1172 Util.FireAndForget(delegate(object x) {
1173 foreach (SceneObjectGroup sog in m_attachments)
1174 {
1175 sog.ScheduleGroupForFullUpdate();
1176 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
1177 sog.ResumeScripts();
1178 }
1179 });
1040 } 1180 }
1041 } 1181 }
1042 } 1182 }
1043 1183
1184 SendAvatarDataToAllAgents();
1185
1044 // send the animations of the other presences to me 1186 // send the animations of the other presences to me
1045 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence) 1187 m_scene.ForEachRootScenePresence(delegate(ScenePresence presence)
1046 { 1188 {
@@ -1051,6 +1193,7 @@ namespace OpenSim.Region.Framework.Scenes
1051 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will 1193 // If we don't reset the movement flag here, an avatar that crosses to a neighbouring sim and returns will
1052 // stall on the border crossing since the existing child agent will still have the last movement 1194 // stall on the border crossing since the existing child agent will still have the last movement
1053 // recorded, which stops the input from being processed. 1195 // recorded, which stops the input from being processed.
1196
1054 MovementFlag = 0; 1197 MovementFlag = 0;
1055 1198
1056 m_scene.EventManager.TriggerOnMakeRootAgent(this); 1199 m_scene.EventManager.TriggerOnMakeRootAgent(this);
@@ -1082,12 +1225,16 @@ namespace OpenSim.Region.Framework.Scenes
1082 /// </remarks> 1225 /// </remarks>
1083 public void MakeChildAgent() 1226 public void MakeChildAgent()
1084 { 1227 {
1228 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
1229
1085 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName); 1230 m_log.DebugFormat("[SCENE PRESENCE]: Making {0} a child agent in {1}", Name, Scene.RegionInfo.RegionName);
1086 1231
1087 // Reset these so that teleporting in and walking out isn't seen 1232 // Reset these so that teleporting in and walking out isn't seen
1088 // as teleporting back 1233 // as teleporting back
1089 TeleportFlags = TeleportFlags.Default; 1234 TeleportFlags = TeleportFlags.Default;
1090 1235
1236 MovementFlag = 0;
1237
1091 // It looks like Animator is set to null somewhere, and MakeChild 1238 // It looks like Animator is set to null somewhere, and MakeChild
1092 // is called after that. Probably in aborted teleports. 1239 // is called after that. Probably in aborted teleports.
1093 if (Animator == null) 1240 if (Animator == null)
@@ -1095,6 +1242,7 @@ namespace OpenSim.Region.Framework.Scenes
1095 else 1242 else
1096 Animator.ResetAnimations(); 1243 Animator.ResetAnimations();
1097 1244
1245
1098// m_log.DebugFormat( 1246// m_log.DebugFormat(
1099// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}", 1247// "[SCENE PRESENCE]: Downgrading root agent {0}, {1} to a child agent in {2}",
1100// Name, UUID, m_scene.RegionInfo.RegionName); 1248// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -1106,6 +1254,7 @@ namespace OpenSim.Region.Framework.Scenes
1106 IsChildAgent = true; 1254 IsChildAgent = true;
1107 m_scene.SwapRootAgentCount(true); 1255 m_scene.SwapRootAgentCount(true);
1108 RemoveFromPhysicalScene(); 1256 RemoveFromPhysicalScene();
1257 ParentID = 0; // Child agents can't be sitting
1109 1258
1110 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into 1259 // FIXME: Set RegionHandle to the region handle of the scene this agent is moving into
1111 1260
@@ -1121,9 +1270,9 @@ namespace OpenSim.Region.Framework.Scenes
1121 { 1270 {
1122// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; 1271// PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients;
1123 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; 1272 PhysicsActor.OnOutOfBounds -= OutOfBoundsCall;
1124 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1125 PhysicsActor.UnSubscribeEvents();
1126 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; 1273 PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate;
1274 PhysicsActor.UnSubscribeEvents();
1275 m_scene.PhysicsScene.RemoveAvatar(PhysicsActor);
1127 PhysicsActor = null; 1276 PhysicsActor = null;
1128 } 1277 }
1129// else 1278// else
@@ -1140,7 +1289,7 @@ namespace OpenSim.Region.Framework.Scenes
1140 /// <param name="pos"></param> 1289 /// <param name="pos"></param>
1141 public void Teleport(Vector3 pos) 1290 public void Teleport(Vector3 pos)
1142 { 1291 {
1143 TeleportWithMomentum(pos, null); 1292 TeleportWithMomentum(pos, Vector3.Zero);
1144 } 1293 }
1145 1294
1146 public void TeleportWithMomentum(Vector3 pos, Vector3? v) 1295 public void TeleportWithMomentum(Vector3 pos, Vector3? v)
@@ -1164,6 +1313,41 @@ namespace OpenSim.Region.Framework.Scenes
1164 SendTerseUpdateToAllClients(); 1313 SendTerseUpdateToAllClients();
1165 } 1314 }
1166 1315
1316 public void avnLocalTeleport(Vector3 newpos, Vector3? newvel, bool rotateToVelXY)
1317 {
1318 CheckLandingPoint(ref newpos);
1319 AbsolutePosition = newpos;
1320
1321 if (newvel.HasValue)
1322 {
1323 if ((Vector3)newvel == Vector3.Zero)
1324 {
1325 if (PhysicsActor != null)
1326 PhysicsActor.SetMomentum(Vector3.Zero);
1327 m_velocity = Vector3.Zero;
1328 }
1329 else
1330 {
1331 if (PhysicsActor != null)
1332 PhysicsActor.SetMomentum((Vector3)newvel);
1333 m_velocity = (Vector3)newvel;
1334
1335 if (rotateToVelXY)
1336 {
1337 Vector3 lookAt = (Vector3)newvel;
1338 lookAt.Z = 0;
1339 lookAt.Normalize();
1340 ControllingClient.SendLocalTeleport(newpos, lookAt, (uint)TeleportFlags.ViaLocation);
1341 return;
1342 }
1343 }
1344 }
1345
1346 SendTerseUpdateToAllClients();
1347 }
1348
1349
1350
1167 public void StopFlying() 1351 public void StopFlying()
1168 { 1352 {
1169 Vector3 pos = AbsolutePosition; 1353 Vector3 pos = AbsolutePosition;
@@ -1352,6 +1536,13 @@ namespace OpenSim.Region.Framework.Scenes
1352 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height); 1536 PhysicsActor.Size = new Vector3(0.45f, 0.6f, height);
1353 } 1537 }
1354 1538
1539 public void SetSize(Vector3 size, float feetoffset)
1540 {
1541 if (PhysicsActor != null && !IsChildAgent)
1542 PhysicsActor.setAvatarSize(size, feetoffset);
1543
1544 }
1545
1355 private bool WaitForUpdateAgent(IClientAPI client) 1546 private bool WaitForUpdateAgent(IClientAPI client)
1356 { 1547 {
1357 // Before UpdateAgent, m_originRegionID is UUID.Zero; after, it's non-Zero 1548 // Before UpdateAgent, m_originRegionID is UUID.Zero; after, it's non-Zero
@@ -1400,7 +1591,8 @@ namespace OpenSim.Region.Framework.Scenes
1400 1591
1401 Vector3 look = Velocity; 1592 Vector3 look = Velocity;
1402 1593
1403 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) 1594 // if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
1595 if ((Math.Abs(look.X) < 0.1) && (Math.Abs(look.Y) < 0.1) && (Math.Abs(look.Z) < 0.1))
1404 { 1596 {
1405 look = new Vector3(0.99f, 0.042f, 0); 1597 look = new Vector3(0.99f, 0.042f, 0);
1406 } 1598 }
@@ -1458,11 +1650,12 @@ namespace OpenSim.Region.Framework.Scenes
1458 { 1650 {
1459 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1651 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1460 if (m_agentTransfer != null) 1652 if (m_agentTransfer != null)
1461 Util.FireAndForget(delegate { m_agentTransfer.EnableChildAgents(this); }); 1653 m_agentTransfer.EnableChildAgents(this);
1462 1654
1463 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1655 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1464 if (friendsModule != null) 1656 if (friendsModule != null)
1465 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); 1657 friendsModule.SendFriendsOnlineIfNeeded(ControllingClient);
1658
1466 } 1659 }
1467 1660
1468 // XXX: If we force an update here, then multiple attachments do appear correctly on a destination region 1661 // XXX: If we force an update here, then multiple attachments do appear correctly on a destination region
@@ -1488,36 +1681,69 @@ namespace OpenSim.Region.Framework.Scenes
1488 /// <param name="collisionPoint"></param> 1681 /// <param name="collisionPoint"></param>
1489 /// <param name="localid"></param> 1682 /// <param name="localid"></param>
1490 /// <param name="distance"></param> 1683 /// <param name="distance"></param>
1684 ///
1685
1686 private void UpdateCameraCollisionPlane(Vector4 plane)
1687 {
1688 if (m_lastCameraCollisionPlane != plane)
1689 {
1690 m_lastCameraCollisionPlane = plane;
1691 ControllingClient.SendCameraConstraint(plane);
1692 }
1693 }
1694
1491 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal) 1695 public void RayCastCameraCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 pNormal)
1492 { 1696 {
1493 const float POSITION_TOLERANCE = 0.02f; 1697 const float POSITION_TOLERANCE = 0.02f;
1494 const float VELOCITY_TOLERANCE = 0.02f;
1495 const float ROTATION_TOLERANCE = 0.02f; 1698 const float ROTATION_TOLERANCE = 0.02f;
1496 1699
1497 if (m_followCamAuto) 1700 m_doingCamRayCast = false;
1701 if (hitYN && localid != LocalId)
1498 { 1702 {
1499 if (hitYN) 1703 SceneObjectGroup group = m_scene.GetGroupByPrim(localid);
1704 bool IsPrim = group != null;
1705 if (IsPrim)
1500 { 1706 {
1501 CameraConstraintActive = true; 1707 SceneObjectPart part = group.GetPart(localid);
1502 //m_log.DebugFormat("[RAYCASTRESULT]: {0}, {1}, {2}, {3}", hitYN, collisionPoint, localid, distance); 1708 if (part != null && !part.VolumeDetectActive)
1503 1709 {
1504 Vector3 normal = Vector3.Normalize(new Vector3(0f, 0f, collisionPoint.Z) - collisionPoint); 1710 CameraConstraintActive = true;
1505 ControllingClient.SendCameraConstraint(new Vector4(normal.X, normal.Y, normal.Z, -1 * Vector3.Distance(new Vector3(0,0,collisionPoint.Z),collisionPoint))); 1711 pNormal.X = (float) Math.Round(pNormal.X, 2);
1712 pNormal.Y = (float) Math.Round(pNormal.Y, 2);
1713 pNormal.Z = (float) Math.Round(pNormal.Z, 2);
1714 pNormal.Normalize();
1715 collisionPoint.X = (float) Math.Round(collisionPoint.X, 1);
1716 collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1);
1717 collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1);
1718
1719 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z,
1720 Vector3.Dot(collisionPoint, pNormal));
1721 UpdateCameraCollisionPlane(plane);
1722 }
1506 } 1723 }
1507 else 1724 else
1508 { 1725 {
1509 if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) || 1726 CameraConstraintActive = true;
1510 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || 1727 pNormal.X = (float) Math.Round(pNormal.X, 2);
1511 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)) 1728 pNormal.Y = (float) Math.Round(pNormal.Y, 2);
1512 { 1729 pNormal.Z = (float) Math.Round(pNormal.Z, 2);
1513 if (CameraConstraintActive) 1730 pNormal.Normalize();
1514 { 1731 collisionPoint.X = (float) Math.Round(collisionPoint.X, 1);
1515 ControllingClient.SendCameraConstraint(new Vector4(0f, 0.5f, 0.9f, -3000f)); 1732 collisionPoint.Y = (float) Math.Round(collisionPoint.Y, 1);
1516 CameraConstraintActive = false; 1733 collisionPoint.Z = (float) Math.Round(collisionPoint.Z, 1);
1517 } 1734
1518 } 1735 Vector4 plane = new Vector4(pNormal.X, pNormal.Y, pNormal.Z,
1736 Vector3.Dot(collisionPoint, pNormal));
1737 UpdateCameraCollisionPlane(plane);
1519 } 1738 }
1520 } 1739 }
1740 else if (!m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
1741 !Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE))
1742 {
1743 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -9000f); // not right...
1744 UpdateCameraCollisionPlane(plane);
1745 CameraConstraintActive = false;
1746 }
1521 } 1747 }
1522 1748
1523 /// <summary> 1749 /// <summary>
@@ -1591,6 +1817,41 @@ namespace OpenSim.Region.Framework.Scenes
1591 StandUp(); 1817 StandUp();
1592 } 1818 }
1593 1819
1820 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1821 // this exclude checks may not be complete
1822
1823 if (m_movementUpdateCount % NumMovementsBetweenRayCast == 0 && m_scene.PhysicsScene.SupportsRayCast())
1824 {
1825 if (!m_doingCamRayCast && !m_mouseLook && ParentID == 0)
1826 {
1827 Vector3 posAdjusted = AbsolutePosition;
1828// posAdjusted.Z += 0.5f * Appearance.AvatarSize.Z - 0.5f;
1829 posAdjusted.Z += 1.0f; // viewer current camera focus point
1830 Vector3 tocam = CameraPosition - posAdjusted;
1831 tocam.X = (float)Math.Round(tocam.X, 1);
1832 tocam.Y = (float)Math.Round(tocam.Y, 1);
1833 tocam.Z = (float)Math.Round(tocam.Z, 1);
1834
1835 float distTocamlen = tocam.Length();
1836 if (distTocamlen > 0.3f)
1837 {
1838 tocam *= (1.0f / distTocamlen);
1839 posAdjusted.X = (float)Math.Round(posAdjusted.X, 1);
1840 posAdjusted.Y = (float)Math.Round(posAdjusted.Y, 1);
1841 posAdjusted.Z = (float)Math.Round(posAdjusted.Z, 1);
1842
1843 m_doingCamRayCast = true;
1844 m_scene.PhysicsScene.RaycastWorld(posAdjusted, tocam, distTocamlen + 1.0f, RayCastCameraCallback);
1845 }
1846 }
1847 else if (CameraConstraintActive && (m_mouseLook || ParentID != 0))
1848 {
1849 Vector4 plane = new Vector4(0.9f, 0.0f, 0.361f, -10000f); // not right...
1850 UpdateCameraCollisionPlane(plane);
1851 CameraConstraintActive = false;
1852 }
1853 }
1854
1594 uint flagsForScripts = (uint)flags; 1855 uint flagsForScripts = (uint)flags;
1595 flags = RemoveIgnoredControls(flags, IgnoredControls); 1856 flags = RemoveIgnoredControls(flags, IgnoredControls);
1596 1857
@@ -2126,7 +2387,8 @@ namespace OpenSim.Region.Framework.Scenes
2126// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); 2387// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name);
2127 2388
2128 MovingToTarget = false; 2389 MovingToTarget = false;
2129 MoveToPositionTarget = Vector3.Zero; 2390// MoveToPositionTarget = Vector3.Zero;
2391 m_forceToApply = null; // cancel possible last action
2130 2392
2131 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct 2393 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct
2132 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag. 2394 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag.
@@ -2144,12 +2406,17 @@ namespace OpenSim.Region.Framework.Scenes
2144// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); 2406// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name);
2145 2407
2146 SitGround = false; 2408 SitGround = false;
2409
2410/* move this down so avatar gets physical in the new position and not where it is siting
2147 if (PhysicsActor == null) 2411 if (PhysicsActor == null)
2148 AddToPhysicalScene(false); 2412 AddToPhysicalScene(false);
2413 */
2149 2414
2150 if (ParentID != 0) 2415 if (ParentID != 0)
2151 { 2416 {
2152 SceneObjectPart part = ParentPart; 2417 SceneObjectPart part = ParentPart;
2418 UnRegisterSeatControls(part.ParentGroup.UUID);
2419
2153 TaskInventoryDictionary taskIDict = part.TaskInventory; 2420 TaskInventoryDictionary taskIDict = part.TaskInventory;
2154 if (taskIDict != null) 2421 if (taskIDict != null)
2155 { 2422 {
@@ -2165,14 +2432,22 @@ namespace OpenSim.Region.Framework.Scenes
2165 } 2432 }
2166 } 2433 }
2167 2434
2168 ParentPosition = part.GetWorldPosition(); 2435 part.ParentGroup.DeleteAvatar(UUID);
2436// ParentPosition = part.GetWorldPosition();
2169 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 2437 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
2170 2438
2171 m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); 2439// m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2172 ParentPosition = Vector3.Zero; 2440// ParentPosition = Vector3.Zero;
2441 m_pos = part.AbsolutePosition + (m_pos * part.GetWorldRotation()) + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight);
2442 if (part.SitTargetAvatar == UUID)
2443 m_bodyRot = part.GetWorldRotation() * part.SitTargetOrientation;
2173 2444
2174 ParentID = 0; 2445 ParentID = 0;
2175 ParentPart = null; 2446 ParentPart = null;
2447
2448 if (PhysicsActor == null)
2449 AddToPhysicalScene(false);
2450
2176 SendAvatarDataToAllAgents(); 2451 SendAvatarDataToAllAgents();
2177 m_requestedSitTargetID = 0; 2452 m_requestedSitTargetID = 0;
2178 2453
@@ -2182,6 +2457,9 @@ namespace OpenSim.Region.Framework.Scenes
2182 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); 2457 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2183 } 2458 }
2184 2459
2460 else if (PhysicsActor == null)
2461 AddToPhysicalScene(false);
2462
2185 Animator.TrySetMovementAnimation("STAND"); 2463 Animator.TrySetMovementAnimation("STAND");
2186 TriggerScenePresenceUpdated(); 2464 TriggerScenePresenceUpdated();
2187 } 2465 }
@@ -2230,11 +2508,8 @@ namespace OpenSim.Region.Framework.Scenes
2230 if (part == null) 2508 if (part == null)
2231 return; 2509 return;
2232 2510
2233 // TODO: determine position to sit at based on scene geometry; don't trust offset from client
2234 // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it
2235
2236 if (PhysicsActor != null) 2511 if (PhysicsActor != null)
2237 m_sitAvatarHeight = PhysicsActor.Size.Z; 2512 m_sitAvatarHeight = PhysicsActor.Size.Z * 0.5f;
2238 2513
2239 bool canSit = false; 2514 bool canSit = false;
2240 Vector3 pos = part.AbsolutePosition + offset; 2515 Vector3 pos = part.AbsolutePosition + offset;
@@ -2251,31 +2526,31 @@ namespace OpenSim.Region.Framework.Scenes
2251 } 2526 }
2252 else 2527 else
2253 { 2528 {
2529 if (PhysicsSit(part,offset)) // physics engine
2530 return;
2531
2254 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) 2532 if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10)
2255 { 2533 {
2256// m_log.DebugFormat(
2257// "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m",
2258// Name, part.Name, part.LocalId);
2259 2534
2260 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); 2535 AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight);
2261 canSit = true; 2536 canSit = true;
2262 } 2537 }
2263// else
2264// {
2265// m_log.DebugFormat(
2266// "[SCENE PRESENCE]: Ignoring sit request of {0} on {1} {2} because sit target is unset and outside 10m",
2267// Name, part.Name, part.LocalId);
2268// }
2269 } 2538 }
2270 2539
2271 if (canSit) 2540 if (canSit)
2272 { 2541 {
2542
2273 if (PhysicsActor != null) 2543 if (PhysicsActor != null)
2274 { 2544 {
2275 // We can remove the physicsActor until they stand up. 2545 // We can remove the physicsActor until they stand up.
2276 RemoveFromPhysicalScene(); 2546 RemoveFromPhysicalScene();
2277 } 2547 }
2278 2548
2549 if (MovingToTarget)
2550 ResetMoveToTarget();
2551
2552 Velocity = Vector3.Zero;
2553
2279 part.AddSittingAvatar(UUID); 2554 part.AddSittingAvatar(UUID);
2280 2555
2281 cameraAtOffset = part.GetCameraAtOffset(); 2556 cameraAtOffset = part.GetCameraAtOffset();
@@ -2315,14 +2590,6 @@ namespace OpenSim.Region.Framework.Scenes
2315 m_requestedSitTargetID = part.LocalId; 2590 m_requestedSitTargetID = part.LocalId;
2316 m_requestedSitTargetUUID = part.UUID; 2591 m_requestedSitTargetUUID = part.UUID;
2317 2592
2318// m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset);
2319
2320 if (m_scene.PhysicsScene.SupportsRayCast())
2321 {
2322 //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback());
2323 //SitRayCastAvatarPosition(part);
2324 //return;
2325 }
2326 } 2593 }
2327 else 2594 else
2328 { 2595 {
@@ -2332,197 +2599,111 @@ namespace OpenSim.Region.Framework.Scenes
2332 SendSitResponse(targetID, offset, Quaternion.Identity); 2599 SendSitResponse(targetID, offset, Quaternion.Identity);
2333 } 2600 }
2334 2601
2335 /* 2602 // returns false if does not suport so older sit can be tried
2336 public void SitRayCastAvatarPosition(SceneObjectPart part) 2603 public bool PhysicsSit(SceneObjectPart part, Vector3 offset)
2337 { 2604 {
2338 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2605 if (part == null || part.ParentGroup.IsAttachment)
2339 Vector3 StartRayCastPosition = AbsolutePosition;
2340 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2341 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2342 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse);
2343 }
2344
2345 public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal)
2346 {
2347 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2348 if (part != null)
2349 {
2350 if (hitYN)
2351 {
2352 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2353 {
2354 SitRaycastFindEdge(collisionPoint, normal);
2355 m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2356 }
2357 else
2358 {
2359 SitRayCastAvatarPositionCameraZ(part);
2360 }
2361 }
2362 else
2363 {
2364 SitRayCastAvatarPositionCameraZ(part);
2365 }
2366 }
2367 else
2368 { 2606 {
2369 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2607 return true;
2370 m_requestedSitTargetUUID = UUID.Zero;
2371 m_requestedSitTargetID = 0;
2372 m_requestedSitOffset = Vector3.Zero;
2373 } 2608 }
2374 2609
2375 } 2610 if ( m_scene.PhysicsScene == null)
2376 2611 return false;
2377 public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part)
2378 {
2379 // Next, try to raycast from the camera Z position
2380 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2381 Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z;
2382 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2383 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2384 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse);
2385 }
2386 2612
2387 public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2613 if (part.PhysActor == null)
2388 {
2389 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2390 if (part != null)
2391 { 2614 {
2392 if (hitYN) 2615 // none physcis shape
2393 { 2616 if (part.PhysicsShapeType == (byte)PhysicsShapeType.None)
2394 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) 2617 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2395 {
2396 SitRaycastFindEdge(collisionPoint, normal);
2397 m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2398 }
2399 else
2400 {
2401 SitRayCastCameraPosition(part);
2402 }
2403 }
2404 else 2618 else
2405 { 2619 { // non physical phantom TODO
2406 SitRayCastCameraPosition(part); 2620 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2621 return false;
2407 } 2622 }
2408 } 2623 return true;
2409 else
2410 {
2411 ControllingClient.SendAlertMessage("Sit position no longer exists");
2412 m_requestedSitTargetUUID = UUID.Zero;
2413 m_requestedSitTargetID = 0;
2414 m_requestedSitOffset = Vector3.Zero;
2415 } 2624 }
2416 2625
2417 }
2418 2626
2419 public void SitRayCastCameraPosition(SceneObjectPart part) 2627 // not doing autopilot
2420 { 2628 m_requestedSitTargetID = 0;
2421 // Next, try to raycast from the camera position
2422 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2423 Vector3 StartRayCastPosition = CameraPosition;
2424 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2425 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2426 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse);
2427 }
2428 2629
2429 public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2630 if (m_scene.PhysicsScene.SitAvatar(part.PhysActor, AbsolutePosition, CameraPosition, offset, new Vector3(0.35f, 0, 0.65f), PhysicsSitResponse) != 0)
2430 { 2631 return true;
2431 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID);
2432 if (part != null)
2433 {
2434 if (hitYN)
2435 {
2436 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2437 {
2438 SitRaycastFindEdge(collisionPoint, normal);
2439 m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2440 }
2441 else
2442 {
2443 SitRayHorizontal(part);
2444 }
2445 }
2446 else
2447 {
2448 SitRayHorizontal(part);
2449 }
2450 }
2451 else
2452 {
2453 ControllingClient.SendAlertMessage("Sit position no longer exists");
2454 m_requestedSitTargetUUID = UUID.Zero;
2455 m_requestedSitTargetID = 0;
2456 m_requestedSitOffset = Vector3.Zero;
2457 }
2458 2632
2633 return false;
2459 } 2634 }
2460 2635
2461 public void SitRayHorizontal(SceneObjectPart part) 2636
2637 private bool CanEnterLandPosition(Vector3 testPos)
2462 { 2638 {
2463 // Next, try to raycast from the avatar position to fwd 2639 ILandObject land = m_scene.LandChannel.GetLandObject(testPos.X, testPos.Y);
2464 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; 2640
2465 Vector3 StartRayCastPosition = CameraPosition; 2641 if (land == null || land.LandData.Name == "NO_LAND")
2466 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); 2642 return true;
2467 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); 2643
2468 m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); 2644 return land.CanBeOnThisLand(UUID,testPos.Z);
2469 } 2645 }
2470 2646
2471 public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) 2647 // status
2648 // < 0 ignore
2649 // 0 bad sit spot
2650 public void PhysicsSitResponse(int status, uint partID, Vector3 offset, Quaternion Orientation)
2472 { 2651 {
2473 SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); 2652 if (status < 0)
2474 if (part != null) 2653 return;
2654
2655 if (status == 0)
2475 { 2656 {
2476 if (hitYN) 2657 ControllingClient.SendAlertMessage(" There is no suitable surface to sit on, try another spot.");
2477 { 2658 return;
2478 if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f))
2479 {
2480 SitRaycastFindEdge(collisionPoint, normal);
2481 m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal);
2482 // Next, try to raycast from the camera position
2483 Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset;
2484 Vector3 StartRayCastPosition = CameraPosition;
2485 Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition);
2486 float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition);
2487 //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition);
2488 }
2489 else
2490 {
2491 ControllingClient.SendAlertMessage("Sit position not accessable.");
2492 m_requestedSitTargetUUID = UUID.Zero;
2493 m_requestedSitTargetID = 0;
2494 m_requestedSitOffset = Vector3.Zero;
2495 }
2496 }
2497 else
2498 {
2499 ControllingClient.SendAlertMessage("Sit position not accessable.");
2500 m_requestedSitTargetUUID = UUID.Zero;
2501 m_requestedSitTargetID = 0;
2502 m_requestedSitOffset = Vector3.Zero;
2503 }
2504 } 2659 }
2505 else 2660
2661 SceneObjectPart part = m_scene.GetSceneObjectPart(partID);
2662 if (part == null)
2663 return;
2664
2665 Vector3 targetPos = part.GetWorldPosition() + offset * part.GetWorldRotation();
2666 if(!CanEnterLandPosition(targetPos))
2506 { 2667 {
2507 ControllingClient.SendAlertMessage("Sit position no longer exists"); 2668 ControllingClient.SendAlertMessage(" Sit position on restricted land, try another spot");
2508 m_requestedSitTargetUUID = UUID.Zero; 2669 return;
2509 m_requestedSitTargetID = 0;
2510 m_requestedSitOffset = Vector3.Zero;
2511 } 2670 }
2512 2671
2513 } 2672 RemoveFromPhysicalScene();
2514 2673
2515 private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) 2674 if (MovingToTarget)
2516 { 2675 ResetMoveToTarget();
2517 int i = 0;
2518 //throw new NotImplementedException();
2519 //m_requestedSitTargetUUID = UUID.Zero;
2520 //m_requestedSitTargetID = 0;
2521 //m_requestedSitOffset = Vector3.Zero;
2522 2676
2523 SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); 2677 Velocity = Vector3.Zero;
2678
2679 part.AddSittingAvatar(UUID);
2680
2681 Vector3 cameraAtOffset = part.GetCameraAtOffset();
2682 Vector3 cameraEyeOffset = part.GetCameraEyeOffset();
2683 bool forceMouselook = part.GetForceMouselook();
2684
2685 ControllingClient.SendSitResponse(
2686 part.UUID, offset, Orientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
2687
2688 // not using autopilot
2689
2690 Rotation = Orientation;
2691 m_pos = offset;
2692
2693 m_requestedSitTargetID = 0;
2694 part.ParentGroup.AddAvatar(UUID);
2695
2696 ParentPart = part;
2697 ParentID = part.LocalId;
2698 if(status == 3)
2699 Animator.TrySetMovementAnimation("SIT_GROUND");
2700 else
2701 Animator.TrySetMovementAnimation("SIT");
2702 SendAvatarDataToAllAgents();
2703
2704 part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
2524 } 2705 }
2525 */ 2706
2526 2707
2527 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) 2708 public void HandleAgentSit(IClientAPI remoteClient, UUID agentID)
2528 { 2709 {
@@ -2542,6 +2723,7 @@ namespace OpenSim.Region.Framework.Scenes
2542 return; 2723 return;
2543 } 2724 }
2544 2725
2726
2545 if (part.SitTargetAvatar == UUID) 2727 if (part.SitTargetAvatar == UUID)
2546 { 2728 {
2547 Vector3 sitTargetPos = part.SitTargetPosition; 2729 Vector3 sitTargetPos = part.SitTargetPosition;
@@ -2556,14 +2738,39 @@ namespace OpenSim.Region.Framework.Scenes
2556 2738
2557 //Quaternion result = (sitTargetOrient * vq) * nq; 2739 //Quaternion result = (sitTargetOrient * vq) * nq;
2558 2740
2559 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2741 double x, y, z, m;
2742
2743 Quaternion r = sitTargetOrient;
2744 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2745
2746 if (Math.Abs(1.0 - m) > 0.000001)
2747 {
2748 m = 1.0 / Math.Sqrt(m);
2749 r.X *= (float)m;
2750 r.Y *= (float)m;
2751 r.Z *= (float)m;
2752 r.W *= (float)m;
2753 }
2754
2755 x = 2 * (r.X * r.Z + r.Y * r.W);
2756 y = 2 * (-r.X * r.W + r.Y * r.Z);
2757 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
2758
2759 Vector3 up = new Vector3((float)x, (float)y, (float)z);
2760 Vector3 sitOffset = up * Appearance.AvatarHeight * 0.02638f;
2761
2762 m_pos = sitTargetPos + sitOffset + SIT_TARGET_ADJUSTMENT;
2763
2764// m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT - sitOffset;
2560 Rotation = sitTargetOrient; 2765 Rotation = sitTargetOrient;
2561 ParentPosition = part.AbsolutePosition; 2766// ParentPosition = part.AbsolutePosition;
2767 part.ParentGroup.AddAvatar(UUID);
2562 } 2768 }
2563 else 2769 else
2564 { 2770 {
2565 m_pos -= part.AbsolutePosition; 2771 m_pos -= part.AbsolutePosition;
2566 ParentPosition = part.AbsolutePosition; 2772// ParentPosition = part.AbsolutePosition;
2773 part.ParentGroup.AddAvatar(UUID);
2567 2774
2568// m_log.DebugFormat( 2775// m_log.DebugFormat(
2569// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2776// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2621,6 +2828,13 @@ namespace OpenSim.Region.Framework.Scenes
2621 TriggerScenePresenceUpdated(); 2828 TriggerScenePresenceUpdated();
2622 } 2829 }
2623 2830
2831 public void avnHandleChangeAnim(UUID animID, bool addRemove,bool sendPack)
2832 {
2833 Animator.avnChangeAnim(animID, addRemove, sendPack);
2834 }
2835
2836
2837
2624 /// <summary> 2838 /// <summary>
2625 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2839 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2626 /// </summary> 2840 /// </summary>
@@ -2677,8 +2891,8 @@ namespace OpenSim.Region.Framework.Scenes
2677 direc.Z *= 2.6f; 2891 direc.Z *= 2.6f;
2678 2892
2679 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored. 2893 // TODO: PreJump and jump happen too quickly. Many times prejump gets ignored.
2680 Animator.TrySetMovementAnimation("PREJUMP"); 2894// Animator.TrySetMovementAnimation("PREJUMP");
2681 Animator.TrySetMovementAnimation("JUMP"); 2895// Animator.TrySetMovementAnimation("JUMP");
2682 } 2896 }
2683 } 2897 }
2684 } 2898 }
@@ -2687,6 +2901,7 @@ namespace OpenSim.Region.Framework.Scenes
2687 2901
2688 // TODO: Add the force instead of only setting it to support multiple forces per frame? 2902 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2689 m_forceToApply = direc; 2903 m_forceToApply = direc;
2904 Animator.UpdateMovementAnimations();
2690 } 2905 }
2691 2906
2692 #endregion 2907 #endregion
@@ -2704,16 +2919,12 @@ namespace OpenSim.Region.Framework.Scenes
2704 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to 2919 // NOTE: Velocity is not the same as m_velocity. Velocity will attempt to
2705 // grab the latest PhysicsActor velocity, whereas m_velocity is often 2920 // grab the latest PhysicsActor velocity, whereas m_velocity is often
2706 // storing a requested force instead of an actual traveling velocity 2921 // storing a requested force instead of an actual traveling velocity
2922 if (Appearance.AvatarSize != m_lastSize && !IsLoggingIn)
2923 SendAvatarDataToAllAgents();
2707 2924
2708 // Throw away duplicate or insignificant updates 2925 if (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
2709 if ( 2926 !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
2710 // If the velocity has become zero, send it no matter what. 2927 !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
2711 (Velocity != m_lastVelocity && Velocity == Vector3.Zero)
2712 // otherwise, if things have changed reasonably, send the update
2713 || (!Rotation.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
2714 || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE)
2715 || !m_pos.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)))
2716
2717 { 2928 {
2718 SendTerseUpdateToAllClients(); 2929 SendTerseUpdateToAllClients();
2719 2930
@@ -2872,9 +3083,7 @@ namespace OpenSim.Region.Framework.Scenes
2872 // again here... this comes after the cached appearance check because the avatars 3083 // again here... this comes after the cached appearance check because the avatars
2873 // appearance goes into the avatar update packet 3084 // appearance goes into the avatar update packet
2874 SendAvatarDataToAllAgents(); 3085 SendAvatarDataToAllAgents();
2875 3086 SendAppearanceToAgent(this);
2876 // This invocation always shows up in the viewer logs as an error.
2877 // SendAppearanceToAgent(this);
2878 3087
2879 // If we are using the the cached appearance then send it out to everyone 3088 // If we are using the the cached appearance then send it out to everyone
2880 if (cachedappearance) 3089 if (cachedappearance)
@@ -2905,6 +3114,8 @@ namespace OpenSim.Region.Framework.Scenes
2905 return; 3114 return;
2906 } 3115 }
2907 3116
3117 m_lastSize = Appearance.AvatarSize;
3118
2908 int count = 0; 3119 int count = 0;
2909 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) 3120 m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
2910 { 3121 {
@@ -3012,6 +3223,8 @@ namespace OpenSim.Region.Framework.Scenes
3012 3223
3013 avatar.ControllingClient.SendAppearance( 3224 avatar.ControllingClient.SendAppearance(
3014 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes()); 3225 UUID, Appearance.VisualParams, Appearance.Texture.GetBytes());
3226
3227
3015 } 3228 }
3016 3229
3017 #endregion 3230 #endregion
@@ -3085,8 +3298,9 @@ namespace OpenSim.Region.Framework.Scenes
3085 3298
3086 // If we don't have a PhysActor, we can't cross anyway 3299 // If we don't have a PhysActor, we can't cross anyway
3087 // Also don't do this while sat, sitting avatars cross with the 3300 // Also don't do this while sat, sitting avatars cross with the
3088 // object they sit on. 3301 // object they sit on. ParentUUID denoted a pending sit, don't
3089 if (ParentID != 0 || PhysicsActor == null) 3302 // interfere with it.
3303 if (ParentID != 0 || PhysicsActor == null || ParentUUID != UUID.Zero)
3090 return; 3304 return;
3091 3305
3092 if (!IsInTransit) 3306 if (!IsInTransit)
@@ -3348,6 +3562,10 @@ namespace OpenSim.Region.Framework.Scenes
3348 } 3562 }
3349 3563
3350 private static Vector3 marker = new Vector3(-1f, -1f, -1f); 3564 private static Vector3 marker = new Vector3(-1f, -1f, -1f);
3565 private void RaiseUpdateThrottles()
3566 {
3567 m_scene.EventManager.TriggerThrottleUpdate(this);
3568 }
3351 /// <summary> 3569 /// <summary>
3352 /// This updates important decision making data about a child agent 3570 /// This updates important decision making data about a child agent
3353 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region 3571 /// The main purpose is to figure out what objects to send to a child agent that's in a neighboring region
@@ -3429,6 +3647,9 @@ namespace OpenSim.Region.Framework.Scenes
3429 cAgent.AlwaysRun = SetAlwaysRun; 3647 cAgent.AlwaysRun = SetAlwaysRun;
3430 3648
3431 cAgent.Appearance = new AvatarAppearance(Appearance); 3649 cAgent.Appearance = new AvatarAppearance(Appearance);
3650
3651 cAgent.ParentPart = ParentUUID;
3652 cAgent.SitOffset = m_pos;
3432 3653
3433 lock (scriptedcontrols) 3654 lock (scriptedcontrols)
3434 { 3655 {
@@ -3437,7 +3658,7 @@ namespace OpenSim.Region.Framework.Scenes
3437 3658
3438 foreach (ScriptControllers c in scriptedcontrols.Values) 3659 foreach (ScriptControllers c in scriptedcontrols.Values)
3439 { 3660 {
3440 controls[i++] = new ControllerData(c.itemID, (uint)c.ignoreControls, (uint)c.eventControls); 3661 controls[i++] = new ControllerData(c.objectID, c.itemID, (uint)c.ignoreControls, (uint)c.eventControls);
3441 } 3662 }
3442 cAgent.Controllers = controls; 3663 cAgent.Controllers = controls;
3443 } 3664 }
@@ -3470,6 +3691,8 @@ namespace OpenSim.Region.Framework.Scenes
3470 CameraAtAxis = cAgent.AtAxis; 3691 CameraAtAxis = cAgent.AtAxis;
3471 CameraLeftAxis = cAgent.LeftAxis; 3692 CameraLeftAxis = cAgent.LeftAxis;
3472 CameraUpAxis = cAgent.UpAxis; 3693 CameraUpAxis = cAgent.UpAxis;
3694 ParentUUID = cAgent.ParentPart;
3695 m_prevSitOffset = cAgent.SitOffset;
3473 3696
3474 // When we get to the point of re-computing neighbors everytime this 3697 // When we get to the point of re-computing neighbors everytime this
3475 // changes, then start using the agent's drawdistance rather than the 3698 // changes, then start using the agent's drawdistance rather than the
@@ -3507,6 +3730,7 @@ namespace OpenSim.Region.Framework.Scenes
3507 foreach (ControllerData c in cAgent.Controllers) 3730 foreach (ControllerData c in cAgent.Controllers)
3508 { 3731 {
3509 ScriptControllers sc = new ScriptControllers(); 3732 ScriptControllers sc = new ScriptControllers();
3733 sc.objectID = c.ObjectID;
3510 sc.itemID = c.ItemID; 3734 sc.itemID = c.ItemID;
3511 sc.ignoreControls = (ScriptControlled)c.IgnoreControls; 3735 sc.ignoreControls = (ScriptControlled)c.IgnoreControls;
3512 sc.eventControls = (ScriptControlled)c.EventControls; 3736 sc.eventControls = (ScriptControlled)c.EventControls;
@@ -3574,20 +3798,27 @@ namespace OpenSim.Region.Framework.Scenes
3574 } 3798 }
3575 3799
3576 if (Appearance.AvatarHeight == 0) 3800 if (Appearance.AvatarHeight == 0)
3577 Appearance.SetHeight(); 3801// Appearance.SetHeight();
3802 Appearance.SetSize(new Vector3(0.45f,0.6f,1.9f));
3578 3803
3579 PhysicsScene scene = m_scene.PhysicsScene; 3804 PhysicsScene scene = m_scene.PhysicsScene;
3580 3805
3581 Vector3 pVec = AbsolutePosition; 3806 Vector3 pVec = AbsolutePosition;
3582 3807
3808/*
3583 PhysicsActor = scene.AddAvatar( 3809 PhysicsActor = scene.AddAvatar(
3584 LocalId, Firstname + "." + Lastname, pVec, 3810 LocalId, Firstname + "." + Lastname, pVec,
3585 new Vector3(0f, 0f, Appearance.AvatarHeight), isFlying); 3811 new Vector3(0.45f, 0.6f, Appearance.AvatarHeight), isFlying);
3812*/
3813
3814 PhysicsActor = scene.AddAvatar(
3815 LocalId, Firstname + "." + Lastname, pVec,
3816 Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying);
3586 3817
3587 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; 3818 //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients;
3588 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; 3819 PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
3589 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong 3820 PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
3590 PhysicsActor.SubscribeEvents(500); 3821 PhysicsActor.SubscribeEvents(100);
3591 PhysicsActor.LocalID = LocalId; 3822 PhysicsActor.LocalID = LocalId;
3592 } 3823 }
3593 3824
@@ -3601,6 +3832,7 @@ namespace OpenSim.Region.Framework.Scenes
3601 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true); 3832 ControllingClient.SendAgentAlertMessage("Physics is having a problem with your avatar. You may not be able to move until you relog.", true);
3602 } 3833 }
3603 3834
3835
3604 /// <summary> 3836 /// <summary>
3605 /// Event called by the physics plugin to tell the avatar about a collision. 3837 /// Event called by the physics plugin to tell the avatar about a collision.
3606 /// </summary> 3838 /// </summary>
@@ -3614,7 +3846,7 @@ namespace OpenSim.Region.Framework.Scenes
3614 /// <param name="e"></param> 3846 /// <param name="e"></param>
3615 public void PhysicsCollisionUpdate(EventArgs e) 3847 public void PhysicsCollisionUpdate(EventArgs e)
3616 { 3848 {
3617 if (IsChildAgent) 3849 if (IsChildAgent || Animator == null)
3618 return; 3850 return;
3619 3851
3620 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f)) 3852 //if ((Math.Abs(Velocity.X) > 0.1e-9f) || (Math.Abs(Velocity.Y) > 0.1e-9f))
@@ -3631,7 +3863,6 @@ namespace OpenSim.Region.Framework.Scenes
3631 CollisionEventUpdate collisionData = (CollisionEventUpdate)e; 3863 CollisionEventUpdate collisionData = (CollisionEventUpdate)e;
3632 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList; 3864 Dictionary<uint, ContactPoint> coldata = collisionData.m_objCollisionList;
3633 3865
3634 CollisionPlane = Vector4.UnitW;
3635 3866
3636// // No collisions at all means we may be flying. Update always 3867// // No collisions at all means we may be flying. Update always
3637// // to make falling work 3868// // to make falling work
@@ -3643,6 +3874,7 @@ namespace OpenSim.Region.Framework.Scenes
3643 3874
3644 if (coldata.Count != 0) 3875 if (coldata.Count != 0)
3645 { 3876 {
3877/*
3646 switch (Animator.CurrentMovementAnimation) 3878 switch (Animator.CurrentMovementAnimation)
3647 { 3879 {
3648 case "STAND": 3880 case "STAND":
@@ -3651,24 +3883,38 @@ namespace OpenSim.Region.Framework.Scenes
3651 case "CROUCH": 3883 case "CROUCH":
3652 case "CROUCHWALK": 3884 case "CROUCHWALK":
3653 { 3885 {
3886 */
3654 ContactPoint lowest; 3887 ContactPoint lowest;
3655 lowest.SurfaceNormal = Vector3.Zero; 3888 lowest.SurfaceNormal = Vector3.Zero;
3656 lowest.Position = Vector3.Zero; 3889 lowest.Position = Vector3.Zero;
3657 lowest.Position.Z = Single.NaN; 3890 lowest.Position.Z = float.MaxValue;
3658 3891
3659 foreach (ContactPoint contact in coldata.Values) 3892 foreach (ContactPoint contact in coldata.Values)
3660 { 3893 {
3661 if (Single.IsNaN(lowest.Position.Z) || contact.Position.Z < lowest.Position.Z) 3894
3895 if (contact.CharacterFeet && contact.Position.Z < lowest.Position.Z)
3662 { 3896 {
3663 lowest = contact; 3897 lowest = contact;
3664 } 3898 }
3665 } 3899 }
3666 3900
3667 CollisionPlane = new Vector4(-lowest.SurfaceNormal, -Vector3.Dot(lowest.Position, lowest.SurfaceNormal)); 3901 if (lowest.Position.Z != float.MaxValue)
3902 {
3903 lowest.SurfaceNormal = -lowest.SurfaceNormal;
3904 CollisionPlane = new Vector4(lowest.SurfaceNormal, Vector3.Dot(lowest.Position, lowest.SurfaceNormal));
3905 }
3906 else
3907 CollisionPlane = Vector4.UnitW;
3908/*
3668 } 3909 }
3669 break; 3910 break;
3670 } 3911 }
3912*/
3671 } 3913 }
3914 else
3915 CollisionPlane = Vector4.UnitW;
3916
3917 RaiseCollisionScriptEvents(coldata);
3672 3918
3673 // Gods do not take damage and Invulnerable is set depending on parcel/region flags 3919 // Gods do not take damage and Invulnerable is set depending on parcel/region flags
3674 if (Invulnerable || GodLevel > 0) 3920 if (Invulnerable || GodLevel > 0)
@@ -3767,6 +4013,12 @@ namespace OpenSim.Region.Framework.Scenes
3767 // m_reprioritizationTimer.Dispose(); 4013 // m_reprioritizationTimer.Dispose();
3768 4014
3769 RemoveFromPhysicalScene(); 4015 RemoveFromPhysicalScene();
4016
4017 m_scene.EventManager.OnRegionHeartbeatEnd -= RegionHeartbeatEnd;
4018
4019// if (Animator != null)
4020// Animator.Close();
4021 Animator = null;
3770 4022
3771 LifecycleState = ScenePresenceState.Removed; 4023 LifecycleState = ScenePresenceState.Removed;
3772 } 4024 }
@@ -4002,10 +4254,18 @@ namespace OpenSim.Region.Framework.Scenes
4002 4254
4003 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID) 4255 public void RegisterControlEventsToScript(int controls, int accept, int pass_on, uint Obj_localID, UUID Script_item_UUID)
4004 { 4256 {
4257 SceneObjectPart p = m_scene.GetSceneObjectPart(Obj_localID);
4258 if (p == null)
4259 return;
4260
4261 ControllingClient.SendTakeControls(controls, false, false);
4262 ControllingClient.SendTakeControls(controls, true, false);
4263
4005 ScriptControllers obj = new ScriptControllers(); 4264 ScriptControllers obj = new ScriptControllers();
4006 obj.ignoreControls = ScriptControlled.CONTROL_ZERO; 4265 obj.ignoreControls = ScriptControlled.CONTROL_ZERO;
4007 obj.eventControls = ScriptControlled.CONTROL_ZERO; 4266 obj.eventControls = ScriptControlled.CONTROL_ZERO;
4008 4267
4268 obj.objectID = p.ParentGroup.UUID;
4009 obj.itemID = Script_item_UUID; 4269 obj.itemID = Script_item_UUID;
4010 if (pass_on == 0 && accept == 0) 4270 if (pass_on == 0 && accept == 0)
4011 { 4271 {
@@ -4054,6 +4314,21 @@ namespace OpenSim.Region.Framework.Scenes
4054 ControllingClient.SendTakeControls(int.MaxValue, false, false); 4314 ControllingClient.SendTakeControls(int.MaxValue, false, false);
4055 } 4315 }
4056 4316
4317 private void UnRegisterSeatControls(UUID obj)
4318 {
4319 List<UUID> takers = new List<UUID>();
4320
4321 foreach (ScriptControllers c in scriptedcontrols.Values)
4322 {
4323 if (c.objectID == obj)
4324 takers.Add(c.itemID);
4325 }
4326 foreach (UUID t in takers)
4327 {
4328 UnRegisterControlEventsToScript(0, t);
4329 }
4330 }
4331
4057 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID) 4332 public void UnRegisterControlEventsToScript(uint Obj_localID, UUID Script_item_UUID)
4058 { 4333 {
4059 ScriptControllers takecontrols; 4334 ScriptControllers takecontrols;
@@ -4383,6 +4658,12 @@ namespace OpenSim.Region.Framework.Scenes
4383 4658
4384 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 4659 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
4385 { 4660 {
4661 string reason;
4662
4663 // Honor bans
4664 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
4665 return;
4666
4386 SceneObjectGroup telehub = null; 4667 SceneObjectGroup telehub = null;
4387 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 4668 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
4388 { 4669 {
@@ -4422,11 +4703,206 @@ namespace OpenSim.Region.Framework.Scenes
4422 pos = land.LandData.UserLocation; 4703 pos = land.LandData.UserLocation;
4423 } 4704 }
4424 } 4705 }
4425 4706
4426 land.SendLandUpdateToClient(ControllingClient); 4707 land.SendLandUpdateToClient(ControllingClient);
4427 } 4708 }
4428 } 4709 }
4429 4710
4711 private DetectedObject CreateDetObject(SceneObjectPart obj)
4712 {
4713 DetectedObject detobj = new DetectedObject();
4714 detobj.keyUUID = obj.UUID;
4715 detobj.nameStr = obj.Name;
4716 detobj.ownerUUID = obj.OwnerID;
4717 detobj.posVector = obj.AbsolutePosition;
4718 detobj.rotQuat = obj.GetWorldRotation();
4719 detobj.velVector = obj.Velocity;
4720 detobj.colliderType = 0;
4721 detobj.groupUUID = obj.GroupID;
4722
4723 return detobj;
4724 }
4725
4726 private DetectedObject CreateDetObject(ScenePresence av)
4727 {
4728 DetectedObject detobj = new DetectedObject();
4729 detobj.keyUUID = av.UUID;
4730 detobj.nameStr = av.ControllingClient.Name;
4731 detobj.ownerUUID = av.UUID;
4732 detobj.posVector = av.AbsolutePosition;
4733 detobj.rotQuat = av.Rotation;
4734 detobj.velVector = av.Velocity;
4735 detobj.colliderType = 0;
4736 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4737
4738 return detobj;
4739 }
4740
4741 private DetectedObject CreateDetObjectForGround()
4742 {
4743 DetectedObject detobj = new DetectedObject();
4744 detobj.keyUUID = UUID.Zero;
4745 detobj.nameStr = "";
4746 detobj.ownerUUID = UUID.Zero;
4747 detobj.posVector = AbsolutePosition;
4748 detobj.rotQuat = Quaternion.Identity;
4749 detobj.velVector = Vector3.Zero;
4750 detobj.colliderType = 0;
4751 detobj.groupUUID = UUID.Zero;
4752
4753 return detobj;
4754 }
4755
4756 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4757 {
4758 ColliderArgs colliderArgs = new ColliderArgs();
4759 List<DetectedObject> colliding = new List<DetectedObject>();
4760 foreach (uint localId in colliders)
4761 {
4762 if (localId == 0)
4763 continue;
4764
4765 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4766 if (obj != null)
4767 {
4768 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4769 colliding.Add(CreateDetObject(obj));
4770 }
4771 else
4772 {
4773 ScenePresence av = m_scene.GetScenePresence(localId);
4774 if (av != null && (!av.IsChildAgent))
4775 {
4776 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4777 colliding.Add(CreateDetObject(av));
4778 }
4779 }
4780 }
4781
4782 colliderArgs.Colliders = colliding;
4783
4784 return colliderArgs;
4785 }
4786
4787 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4788
4789 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4790 {
4791 ColliderArgs CollidingMessage;
4792
4793 if (colliders.Count > 0)
4794 {
4795 if ((dest.RootPart.ScriptEvents & ev) != 0)
4796 {
4797 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4798
4799 if (CollidingMessage.Colliders.Count > 0)
4800 notify(dest.RootPart.LocalId, CollidingMessage);
4801 }
4802 }
4803 }
4804
4805 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4806 {
4807 if ((dest.RootPart.ScriptEvents & ev) != 0)
4808 {
4809 ColliderArgs LandCollidingMessage = new ColliderArgs();
4810 List<DetectedObject> colliding = new List<DetectedObject>();
4811
4812 colliding.Add(CreateDetObjectForGround());
4813 LandCollidingMessage.Colliders = colliding;
4814
4815 notify(dest.RootPart.LocalId, LandCollidingMessage);
4816 }
4817 }
4818
4819 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4820 {
4821 try
4822 {
4823 List<uint> thisHitColliders = new List<uint>();
4824 List<uint> endedColliders = new List<uint>();
4825 List<uint> startedColliders = new List<uint>();
4826 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4827 CollisionForSoundInfo soundinfo;
4828 ContactPoint curcontact;
4829
4830 if (coldata.Count == 0)
4831 {
4832 if (m_lastColliders.Count == 0)
4833 return; // nothing to do
4834
4835 foreach (uint localID in m_lastColliders)
4836 {
4837 endedColliders.Add(localID);
4838 }
4839 m_lastColliders.Clear();
4840 }
4841
4842 else
4843 {
4844 foreach (uint id in coldata.Keys)
4845 {
4846 thisHitColliders.Add(id);
4847 if (!m_lastColliders.Contains(id))
4848 {
4849 startedColliders.Add(id);
4850 curcontact = coldata[id];
4851 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4852 {
4853 soundinfo = new CollisionForSoundInfo();
4854 soundinfo.colliderID = id;
4855 soundinfo.position = curcontact.Position;
4856 soundinfo.relativeVel = curcontact.RelativeSpeed;
4857 soundinfolist.Add(soundinfo);
4858 }
4859 }
4860 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4861 }
4862
4863 // calculate things that ended colliding
4864 foreach (uint localID in m_lastColliders)
4865 {
4866 if (!thisHitColliders.Contains(localID))
4867 {
4868 endedColliders.Add(localID);
4869 }
4870 }
4871 //add the items that started colliding this time to the last colliders list.
4872 foreach (uint localID in startedColliders)
4873 {
4874 m_lastColliders.Add(localID);
4875 }
4876 // remove things that ended colliding from the last colliders list
4877 foreach (uint localID in endedColliders)
4878 {
4879 m_lastColliders.Remove(localID);
4880 }
4881
4882 if (soundinfolist.Count > 0)
4883 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4884 }
4885
4886 foreach (SceneObjectGroup att in GetAttachments())
4887 {
4888 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4889 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4890 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4891
4892 if (startedColliders.Contains(0))
4893 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4894 if (m_lastColliders.Contains(0))
4895 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4896 if (endedColliders.Contains(0))
4897 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4898 }
4899 }
4900 finally
4901 {
4902 m_collisionEventFlag = false;
4903 }
4904 }
4905
4430 private void TeleportFlagsDebug() { 4906 private void TeleportFlagsDebug() {
4431 4907
4432 // Some temporary debugging help to show all the TeleportFlags we have... 4908 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -4451,6 +4927,5 @@ namespace OpenSim.Region.Framework.Scenes
4451 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4927 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
4452 4928
4453 } 4929 }
4454
4455 } 4930 }
4456} 4931}