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.cs327
1 files changed, 270 insertions, 57 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 77f7b32..429fc06 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -168,6 +168,7 @@ namespace OpenSim.Region.Framework.Scenes
168// private int m_lastColCount = -1; //KF: Look for Collision chnages 168// private int m_lastColCount = -1; //KF: Look for Collision chnages
169// private int m_updateCount = 0; //KF: Update Anims for a while 169// private int m_updateCount = 0; //KF: Update Anims for a while
170// private static readonly int UPDATE_COUNT = 10; // how many frames to update for 170// private static readonly int UPDATE_COUNT = 10; // how many frames to update for
171 private List<uint> m_lastColliders = new List<uint>();
171 172
172 private TeleportFlags m_teleportFlags; 173 private TeleportFlags m_teleportFlags;
173 public TeleportFlags TeleportFlags 174 public TeleportFlags TeleportFlags
@@ -229,6 +230,11 @@ namespace OpenSim.Region.Framework.Scenes
229 //private int m_moveToPositionStateStatus; 230 //private int m_moveToPositionStateStatus;
230 //***************************************************** 231 //*****************************************************
231 232
233 private bool m_collisionEventFlag = false;
234 private object m_collisionEventLock = new Object();
235
236 private Vector3 m_prevSitOffset;
237
232 protected AvatarAppearance m_appearance; 238 protected AvatarAppearance m_appearance;
233 239
234 public AvatarAppearance Appearance 240 public AvatarAppearance Appearance
@@ -640,6 +646,13 @@ namespace OpenSim.Region.Framework.Scenes
640 } 646 }
641 private uint m_parentID; 647 private uint m_parentID;
642 648
649 public UUID ParentUUID
650 {
651 get { return m_parentUUID; }
652 set { m_parentUUID = value; }
653 }
654 private UUID m_parentUUID = UUID.Zero;
655
643 public float Health 656 public float Health
644 { 657 {
645 get { return m_health; } 658 get { return m_health; }
@@ -861,7 +874,26 @@ namespace OpenSim.Region.Framework.Scenes
861 "[SCENE]: Upgrading child to root agent for {0} in {1}", 874 "[SCENE]: Upgrading child to root agent for {0} in {1}",
862 Name, m_scene.RegionInfo.RegionName); 875 Name, m_scene.RegionInfo.RegionName);
863 876
864 //m_log.DebugFormat("[SCENE]: known regions in {0}: {1}", Scene.RegionInfo.RegionName, KnownChildRegionHandles.Count); 877 if (ParentUUID != UUID.Zero)
878 {
879 m_log.DebugFormat("[SCENE PRESENCE]: Sitting avatar back on prim {0}", ParentUUID);
880 SceneObjectPart part = m_scene.GetSceneObjectPart(ParentUUID);
881 if (part == null)
882 {
883 m_log.ErrorFormat("[SCENE PRESENCE]: Can't find prim {0} to sit on", ParentUUID);
884 }
885 else
886 {
887 part.ParentGroup.AddAvatar(UUID);
888 if (part.SitTargetPosition != Vector3.Zero)
889 part.SitTargetAvatar = UUID;
890 ParentPosition = part.GetWorldPosition();
891 ParentID = part.LocalId;
892 m_pos = m_prevSitOffset;
893 pos = ParentPosition;
894 }
895 ParentUUID = UUID.Zero;
896 }
865 897
866 bool wasChild = IsChildAgent; 898 bool wasChild = IsChildAgent;
867 IsChildAgent = false; 899 IsChildAgent = false;
@@ -874,62 +906,64 @@ namespace OpenSim.Region.Framework.Scenes
874 906
875 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene); 907 m_scene.EventManager.TriggerSetRootAgentScene(m_uuid, m_scene);
876 908
877 // Moved this from SendInitialData to ensure that Appearance is initialized 909 if (ParentID == 0)
878 // before the inventory is processed in MakeRootAgent. This fixes a race condition
879 // related to the handling of attachments
880 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
881 if (m_scene.TestBorderCross(pos, Cardinals.E))
882 { 910 {
883 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E); 911 // Moved this from SendInitialData to ensure that Appearance is initialized
884 pos.X = crossedBorder.BorderLine.Z - 1; 912 // before the inventory is processed in MakeRootAgent. This fixes a race condition
885 } 913 // related to the handling of attachments
914 //m_scene.GetAvatarAppearance(ControllingClient, out Appearance);
915 if (m_scene.TestBorderCross(pos, Cardinals.E))
916 {
917 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.E);
918 pos.X = crossedBorder.BorderLine.Z - 1;
919 }
886 920
887 if (m_scene.TestBorderCross(pos, Cardinals.N)) 921 if (m_scene.TestBorderCross(pos, Cardinals.N))
888 { 922 {
889 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N); 923 Border crossedBorder = m_scene.GetCrossedBorder(pos, Cardinals.N);
890 pos.Y = crossedBorder.BorderLine.Z - 1; 924 pos.Y = crossedBorder.BorderLine.Z - 1;
891 } 925 }
892 926
893 CheckAndAdjustLandingPoint(ref pos); 927 CheckAndAdjustLandingPoint(ref pos);
894 928
895 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 929 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
896 { 930 {
897 m_log.WarnFormat( 931 m_log.WarnFormat(
898 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping", 932 "[SCENE PRESENCE]: MakeRootAgent() was given an illegal position of {0} for avatar {1}, {2}. Clamping",
899 pos, Name, UUID); 933 pos, Name, UUID);
900 934
901 if (pos.X < 0f) pos.X = 0f; 935 if (pos.X < 0f) pos.X = 0f;
902 if (pos.Y < 0f) pos.Y = 0f; 936 if (pos.Y < 0f) pos.Y = 0f;
903 if (pos.Z < 0f) pos.Z = 0f; 937 if (pos.Z < 0f) pos.Z = 0f;
904 } 938 }
905 939
906 float localAVHeight = 1.56f; 940 float localAVHeight = 1.56f;
907 if (Appearance.AvatarHeight > 0) 941 if (Appearance.AvatarHeight > 0)
908 localAVHeight = Appearance.AvatarHeight; 942 localAVHeight = Appearance.AvatarHeight;
909 943
910 float posZLimit = 0; 944 float posZLimit = 0;
911 945
912 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize) 946 if (pos.X < Constants.RegionSize && pos.Y < Constants.RegionSize)
913 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y]; 947 posZLimit = (float)m_scene.Heightmap[(int)pos.X, (int)pos.Y];
914 948
915 float newPosZ = posZLimit + localAVHeight / 2; 949 float newPosZ = posZLimit + localAVHeight / 2;
916 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ))) 950 if (posZLimit >= (pos.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
917 { 951 {
918 pos.Z = newPosZ; 952 pos.Z = newPosZ;
919 } 953 }
920 AbsolutePosition = pos; 954 AbsolutePosition = pos;
921 955
922 AddToPhysicalScene(isFlying); 956 AddToPhysicalScene(isFlying);
923 957
924 if (ForceFly) 958 if (ForceFly)
925 { 959 {
926 Flying = true; 960 Flying = true;
927 } 961 }
928 else if (FlyDisabled) 962 else if (FlyDisabled)
929 { 963 {
930 Flying = false; 964 Flying = false;
965 }
931 } 966 }
932
933 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying 967 // Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
934 // avatar to return to the standing position in mid-air. On login it looks like this is being sent 968 // avatar to return to the standing position in mid-air. On login it looks like this is being sent
935 // elsewhere anyway 969 // elsewhere anyway
@@ -947,11 +981,13 @@ namespace OpenSim.Region.Framework.Scenes
947 { 981 {
948 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments..."); 982 m_log.DebugFormat("[SCENE PRESENCE]: Restarting scripts in attachments...");
949 // Resume scripts 983 // Resume scripts
950 foreach (SceneObjectGroup sog in m_attachments) 984 Util.FireAndForget(delegate(object x) {
951 { 985 foreach (SceneObjectGroup sog in m_attachments)
952 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource()); 986 {
953 sog.ResumeScripts(); 987 sog.RootPart.ParentGroup.CreateScriptInstances(0, false, m_scene.DefaultScriptEngine, GetStateSource());
954 } 988 sog.ResumeScripts();
989 }
990 });
955 } 991 }
956 } 992 }
957 993
@@ -1748,9 +1784,9 @@ namespace OpenSim.Region.Framework.Scenes
1748 if (pos.Z - terrainHeight < 0.2) 1784 if (pos.Z - terrainHeight < 0.2)
1749 pos.Z = terrainHeight; 1785 pos.Z = terrainHeight;
1750 1786
1751 m_log.DebugFormat( 1787// m_log.DebugFormat(
1752 "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", 1788// "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}",
1753 Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); 1789// Name, pos, terrainHeight, m_scene.RegionInfo.RegionName);
1754 1790
1755 if (noFly) 1791 if (noFly)
1756 Flying = false; 1792 Flying = false;
@@ -1834,6 +1870,7 @@ namespace OpenSim.Region.Framework.Scenes
1834 if (part.SitTargetAvatar == UUID) 1870 if (part.SitTargetAvatar == UUID)
1835 part.SitTargetAvatar = UUID.Zero; 1871 part.SitTargetAvatar = UUID.Zero;
1836 1872
1873 part.ParentGroup.DeleteAvatar(UUID);
1837 ParentPosition = part.GetWorldPosition(); 1874 ParentPosition = part.GetWorldPosition();
1838 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1875 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1839 } 1876 }
@@ -1972,7 +2009,7 @@ namespace OpenSim.Region.Framework.Scenes
1972 forceMouselook = part.GetForceMouselook(); 2009 forceMouselook = part.GetForceMouselook();
1973 2010
1974 ControllingClient.SendSitResponse( 2011 ControllingClient.SendSitResponse(
1975 targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); 2012 part.UUID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook);
1976 2013
1977 m_requestedSitTargetUUID = targetID; 2014 m_requestedSitTargetUUID = targetID;
1978 2015
@@ -2257,11 +2294,13 @@ namespace OpenSim.Region.Framework.Scenes
2257 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2294 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT;
2258 Rotation = sitTargetOrient; 2295 Rotation = sitTargetOrient;
2259 ParentPosition = part.AbsolutePosition; 2296 ParentPosition = part.AbsolutePosition;
2297 part.ParentGroup.AddAvatar(UUID);
2260 } 2298 }
2261 else 2299 else
2262 { 2300 {
2263 m_pos -= part.AbsolutePosition; 2301 m_pos -= part.AbsolutePosition;
2264 ParentPosition = part.AbsolutePosition; 2302 ParentPosition = part.AbsolutePosition;
2303 part.ParentGroup.AddAvatar(UUID);
2265 2304
2266// m_log.DebugFormat( 2305// m_log.DebugFormat(
2267// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2306// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -3102,6 +3141,9 @@ namespace OpenSim.Region.Framework.Scenes
3102 cAgent.AlwaysRun = SetAlwaysRun; 3141 cAgent.AlwaysRun = SetAlwaysRun;
3103 3142
3104 cAgent.Appearance = new AvatarAppearance(Appearance); 3143 cAgent.Appearance = new AvatarAppearance(Appearance);
3144
3145 cAgent.ParentPart = ParentUUID;
3146 cAgent.SitOffset = m_pos;
3105 3147
3106 lock (scriptedcontrols) 3148 lock (scriptedcontrols)
3107 { 3149 {
@@ -3161,6 +3203,8 @@ namespace OpenSim.Region.Framework.Scenes
3161 CameraAtAxis = cAgent.AtAxis; 3203 CameraAtAxis = cAgent.AtAxis;
3162 CameraLeftAxis = cAgent.LeftAxis; 3204 CameraLeftAxis = cAgent.LeftAxis;
3163 m_CameraUpAxis = cAgent.UpAxis; 3205 m_CameraUpAxis = cAgent.UpAxis;
3206 ParentUUID = cAgent.ParentPart;
3207 m_prevSitOffset = cAgent.SitOffset;
3164 3208
3165 // When we get to the point of re-computing neighbors everytime this 3209 // When we get to the point of re-computing neighbors everytime this
3166 // changes, then start using the agent's drawdistance rather than the 3210 // changes, then start using the agent's drawdistance rather than the
@@ -3367,6 +3411,8 @@ namespace OpenSim.Region.Framework.Scenes
3367 } 3411 }
3368 } 3412 }
3369 3413
3414 RaiseCollisionScriptEvents(coldata);
3415
3370 if (Invulnerable) 3416 if (Invulnerable)
3371 return; 3417 return;
3372 3418
@@ -3878,6 +3924,12 @@ namespace OpenSim.Region.Framework.Scenes
3878 3924
3879 private void CheckAndAdjustLandingPoint(ref Vector3 pos) 3925 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
3880 { 3926 {
3927 string reason;
3928
3929 // Honor bans
3930 if (!m_scene.TestLandRestrictions(UUID, out reason, ref pos.X, ref pos.Y))
3931 return;
3932
3881 SceneObjectGroup telehub = null; 3933 SceneObjectGroup telehub = null;
3882 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null) 3934 if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero && (telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject)) != null)
3883 { 3935 {
@@ -3917,11 +3969,173 @@ namespace OpenSim.Region.Framework.Scenes
3917 pos = land.LandData.UserLocation; 3969 pos = land.LandData.UserLocation;
3918 } 3970 }
3919 } 3971 }
3920 3972
3921 land.SendLandUpdateToClient(ControllingClient); 3973 land.SendLandUpdateToClient(ControllingClient);
3922 } 3974 }
3923 } 3975 }
3924 3976
3977 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
3978 {
3979 lock(m_collisionEventLock)
3980 {
3981 if (m_collisionEventFlag)
3982 return;
3983 m_collisionEventFlag = true;
3984 }
3985
3986 Util.FireAndForget(delegate(object x)
3987 {
3988 try
3989 {
3990 List<uint> thisHitColliders = new List<uint>();
3991 List<uint> endedColliders = new List<uint>();
3992 List<uint> startedColliders = new List<uint>();
3993
3994 foreach (uint localid in coldata.Keys)
3995 {
3996 thisHitColliders.Add(localid);
3997 if (!m_lastColliders.Contains(localid))
3998 {
3999 startedColliders.Add(localid);
4000 }
4001 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4002 }
4003
4004 // calculate things that ended colliding
4005 foreach (uint localID in m_lastColliders)
4006 {
4007 if (!thisHitColliders.Contains(localID))
4008 {
4009 endedColliders.Add(localID);
4010 }
4011 }
4012 //add the items that started colliding this time to the last colliders list.
4013 foreach (uint localID in startedColliders)
4014 {
4015 m_lastColliders.Add(localID);
4016 }
4017 // remove things that ended colliding from the last colliders list
4018 foreach (uint localID in endedColliders)
4019 {
4020 m_lastColliders.Remove(localID);
4021 }
4022
4023 // do event notification
4024 if (startedColliders.Count > 0)
4025 {
4026 ColliderArgs StartCollidingMessage = new ColliderArgs();
4027 List<DetectedObject> colliding = new List<DetectedObject>();
4028 foreach (uint localId in startedColliders)
4029 {
4030 if (localId == 0)
4031 continue;
4032
4033 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4034 string data = "";
4035 if (obj != null)
4036 {
4037 DetectedObject detobj = new DetectedObject();
4038 detobj.keyUUID = obj.UUID;
4039 detobj.nameStr = obj.Name;
4040 detobj.ownerUUID = obj.OwnerID;
4041 detobj.posVector = obj.AbsolutePosition;
4042 detobj.rotQuat = obj.GetWorldRotation();
4043 detobj.velVector = obj.Velocity;
4044 detobj.colliderType = 0;
4045 detobj.groupUUID = obj.GroupID;
4046 colliding.Add(detobj);
4047 }
4048 }
4049
4050 if (colliding.Count > 0)
4051 {
4052 StartCollidingMessage.Colliders = colliding;
4053
4054 foreach (SceneObjectGroup att in GetAttachments())
4055 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
4056 }
4057 }
4058
4059 if (endedColliders.Count > 0)
4060 {
4061 ColliderArgs EndCollidingMessage = new ColliderArgs();
4062 List<DetectedObject> colliding = new List<DetectedObject>();
4063 foreach (uint localId in endedColliders)
4064 {
4065 if (localId == 0)
4066 continue;
4067
4068 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4069 string data = "";
4070 if (obj != null)
4071 {
4072 DetectedObject detobj = new DetectedObject();
4073 detobj.keyUUID = obj.UUID;
4074 detobj.nameStr = obj.Name;
4075 detobj.ownerUUID = obj.OwnerID;
4076 detobj.posVector = obj.AbsolutePosition;
4077 detobj.rotQuat = obj.GetWorldRotation();
4078 detobj.velVector = obj.Velocity;
4079 detobj.colliderType = 0;
4080 detobj.groupUUID = obj.GroupID;
4081 colliding.Add(detobj);
4082 }
4083 }
4084
4085 if (colliding.Count > 0)
4086 {
4087 EndCollidingMessage.Colliders = colliding;
4088
4089 foreach (SceneObjectGroup att in GetAttachments())
4090 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
4091 }
4092 }
4093
4094 if (thisHitColliders.Count > 0)
4095 {
4096 ColliderArgs CollidingMessage = new ColliderArgs();
4097 List<DetectedObject> colliding = new List<DetectedObject>();
4098 foreach (uint localId in thisHitColliders)
4099 {
4100 if (localId == 0)
4101 continue;
4102
4103 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4104 string data = "";
4105 if (obj != null)
4106 {
4107 DetectedObject detobj = new DetectedObject();
4108 detobj.keyUUID = obj.UUID;
4109 detobj.nameStr = obj.Name;
4110 detobj.ownerUUID = obj.OwnerID;
4111 detobj.posVector = obj.AbsolutePosition;
4112 detobj.rotQuat = obj.GetWorldRotation();
4113 detobj.velVector = obj.Velocity;
4114 detobj.colliderType = 0;
4115 detobj.groupUUID = obj.GroupID;
4116 colliding.Add(detobj);
4117 }
4118 }
4119
4120 if (colliding.Count > 0)
4121 {
4122 CollidingMessage.Colliders = colliding;
4123
4124 lock (m_attachments)
4125 {
4126 foreach (SceneObjectGroup att in m_attachments)
4127 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
4128 }
4129 }
4130 }
4131 }
4132 finally
4133 {
4134 m_collisionEventFlag = false;
4135 }
4136 });
4137 }
4138
3925 private void TeleportFlagsDebug() { 4139 private void TeleportFlagsDebug() {
3926 4140
3927 // Some temporary debugging help to show all the TeleportFlags we have... 4141 // Some temporary debugging help to show all the TeleportFlags we have...
@@ -3946,6 +4160,5 @@ namespace OpenSim.Region.Framework.Scenes
3946 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************"); 4160 m_log.InfoFormat("[SCENE PRESENCE]: TELEPORT ******************");
3947 4161
3948 } 4162 }
3949
3950 } 4163 }
3951} 4164}