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.cs322
1 files changed, 283 insertions, 39 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index beff239..49acc02 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -118,7 +118,7 @@ namespace OpenSim.Region.Framework.Scenes
118 /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is 118 /// TODO: For some reason, we effectively have a list both here and in Appearance. Need to work out if this is
119 /// necessary. 119 /// necessary.
120 /// </remarks> 120 /// </remarks>
121 protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>(); 121 private List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
122 122
123 public Object AttachmentsSyncLock { get; private set; } 123 public Object AttachmentsSyncLock { get; private set; }
124 124
@@ -167,6 +167,7 @@ namespace OpenSim.Region.Framework.Scenes
167// private int m_lastColCount = -1; //KF: Look for Collision chnages 167// private int m_lastColCount = -1; //KF: Look for Collision chnages
168// private int m_updateCount = 0; //KF: Update Anims for a while 168// private int m_updateCount = 0; //KF: Update Anims for a while
169// private static readonly int UPDATE_COUNT = 10; // how many frames to update for 169// private static readonly int UPDATE_COUNT = 10; // how many frames to update for
170 private List<uint> m_lastColliders = new List<uint>();
170 171
171 private TeleportFlags m_teleportFlags; 172 private TeleportFlags m_teleportFlags;
172 public TeleportFlags TeleportFlags 173 public TeleportFlags TeleportFlags
@@ -228,6 +229,9 @@ namespace OpenSim.Region.Framework.Scenes
228 //private int m_moveToPositionStateStatus; 229 //private int m_moveToPositionStateStatus;
229 //***************************************************** 230 //*****************************************************
230 231
232 private bool m_collisionEventFlag = false;
233 private object m_collisionEventLock = new Object();
234
231 protected AvatarAppearance m_appearance; 235 protected AvatarAppearance m_appearance;
232 236
233 public AvatarAppearance Appearance 237 public AvatarAppearance Appearance
@@ -557,8 +561,12 @@ namespace OpenSim.Region.Framework.Scenes
557 } 561 }
558 } 562 }
559 563
560 m_pos = value; 564 // Don't update while sitting
561 ParentPosition = Vector3.Zero; 565 if (ParentID == 0)
566 {
567 m_pos = value;
568 ParentPosition = Vector3.Zero;
569 }
562 570
563// m_log.DebugFormat( 571// m_log.DebugFormat(
564// "[ENTITY BASE]: In {0} set AbsolutePosition of {1} to {2}", 572// "[ENTITY BASE]: In {0} set AbsolutePosition of {1} to {2}",
@@ -573,6 +581,13 @@ namespace OpenSim.Region.Framework.Scenes
573 public Vector3 OffsetPosition 581 public Vector3 OffsetPosition
574 { 582 {
575 get { return m_pos; } 583 get { return m_pos; }
584 set
585 {
586 // There is no offset position when not seated
587 if (ParentID == 0)
588 return;
589 m_pos = value;
590 }
576 } 591 }
577 592
578 /// <summary> 593 /// <summary>
@@ -892,6 +907,8 @@ namespace OpenSim.Region.Framework.Scenes
892 pos.Y = crossedBorder.BorderLine.Z - 1; 907 pos.Y = crossedBorder.BorderLine.Z - 1;
893 } 908 }
894 909
910 CheckAndAdjustLandingPoint(ref pos);
911
895 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f) 912 if (pos.X < 0f || pos.Y < 0f || pos.Z < 0f)
896 { 913 {
897 m_log.WarnFormat( 914 m_log.WarnFormat(
@@ -1055,6 +1072,7 @@ namespace OpenSim.Region.Framework.Scenes
1055 bool isFlying = Flying; 1072 bool isFlying = Flying;
1056 RemoveFromPhysicalScene(); 1073 RemoveFromPhysicalScene();
1057 Velocity = Vector3.Zero; 1074 Velocity = Vector3.Zero;
1075 CheckLandingPoint(ref pos);
1058 AbsolutePosition = pos; 1076 AbsolutePosition = pos;
1059 AddToPhysicalScene(isFlying); 1077 AddToPhysicalScene(isFlying);
1060 1078
@@ -1065,6 +1083,7 @@ namespace OpenSim.Region.Framework.Scenes
1065 { 1083 {
1066 bool isFlying = Flying; 1084 bool isFlying = Flying;
1067 RemoveFromPhysicalScene(); 1085 RemoveFromPhysicalScene();
1086 CheckLandingPoint(ref pos);
1068 AbsolutePosition = pos; 1087 AbsolutePosition = pos;
1069 AddToPhysicalScene(isFlying); 1088 AddToPhysicalScene(isFlying);
1070 1089
@@ -1832,6 +1851,7 @@ namespace OpenSim.Region.Framework.Scenes
1832 if (part.SitTargetAvatar == UUID) 1851 if (part.SitTargetAvatar == UUID)
1833 part.SitTargetAvatar = UUID.Zero; 1852 part.SitTargetAvatar = UUID.Zero;
1834 1853
1854 part.ParentGroup.DeleteAvatar(UUID);
1835 ParentPosition = part.GetWorldPosition(); 1855 ParentPosition = part.GetWorldPosition();
1836 ControllingClient.SendClearFollowCamProperties(part.ParentUUID); 1856 ControllingClient.SendClearFollowCamProperties(part.ParentUUID);
1837 } 1857 }
@@ -2255,11 +2275,13 @@ namespace OpenSim.Region.Framework.Scenes
2255 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; 2275 m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT;
2256 Rotation = sitTargetOrient; 2276 Rotation = sitTargetOrient;
2257 ParentPosition = part.AbsolutePosition; 2277 ParentPosition = part.AbsolutePosition;
2278 part.ParentGroup.AddAvatar(UUID);
2258 } 2279 }
2259 else 2280 else
2260 { 2281 {
2261 m_pos -= part.AbsolutePosition; 2282 m_pos -= part.AbsolutePosition;
2262 ParentPosition = part.AbsolutePosition; 2283 ParentPosition = part.AbsolutePosition;
2284 part.ParentGroup.AddAvatar(UUID);
2263 2285
2264// m_log.DebugFormat( 2286// m_log.DebugFormat(
2265// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", 2287// "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target",
@@ -2749,6 +2771,9 @@ namespace OpenSim.Region.Framework.Scenes
2749 if (IsChildAgent) 2771 if (IsChildAgent)
2750 return; 2772 return;
2751 2773
2774 if (ParentID != 0)
2775 return;
2776
2752 Vector3 pos2 = AbsolutePosition; 2777 Vector3 pos2 = AbsolutePosition;
2753 Vector3 vel = Velocity; 2778 Vector3 vel = Velocity;
2754 int neighbor = 0; 2779 int neighbor = 0;
@@ -3110,30 +3135,28 @@ namespace OpenSim.Region.Framework.Scenes
3110 catch { } 3135 catch { }
3111 3136
3112 // Attachment objects 3137 // Attachment objects
3113 lock (m_attachments) 3138 List<SceneObjectGroup> attachments = GetAttachments();
3139 if (attachments.Count > 0)
3114 { 3140 {
3115 if (m_attachments.Count > 0) 3141 cAgent.AttachmentObjects = new List<ISceneObject>();
3116 { 3142 cAgent.AttachmentObjectStates = new List<string>();
3117 cAgent.AttachmentObjects = new List<ISceneObject>(); 3143// IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
3118 cAgent.AttachmentObjectStates = new List<string>(); 3144 InTransitScriptStates.Clear();
3119 // IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>();
3120 InTransitScriptStates.Clear();
3121 3145
3122 foreach (SceneObjectGroup sog in m_attachments) 3146 foreach (SceneObjectGroup sog in attachments)
3123 { 3147 {
3124 // We need to make a copy and pass that copy 3148 // We need to make a copy and pass that copy
3125 // because of transfers withn the same sim 3149 // because of transfers withn the same sim
3126 ISceneObject clone = sog.CloneForNewScene(); 3150 ISceneObject clone = sog.CloneForNewScene();
3127 // Attachment module assumes that GroupPosition holds the offsets...! 3151 // Attachment module assumes that GroupPosition holds the offsets...!
3128 ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos; 3152 ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos;
3129 ((SceneObjectGroup)clone).IsAttachment = false; 3153 ((SceneObjectGroup)clone).IsAttachment = false;
3130 cAgent.AttachmentObjects.Add(clone); 3154 cAgent.AttachmentObjects.Add(clone);
3131 string state = sog.GetStateSnapshot(); 3155 string state = sog.GetStateSnapshot();
3132 cAgent.AttachmentObjectStates.Add(state); 3156 cAgent.AttachmentObjectStates.Add(state);
3133 InTransitScriptStates.Add(state); 3157 InTransitScriptStates.Add(state);
3134 // Let's remove the scripts of the original object here 3158 // Let's remove the scripts of the original object here
3135 sog.RemoveScriptInstances(true); 3159 sog.RemoveScriptInstances(true);
3136 }
3137 } 3160 }
3138 } 3161 }
3139 } 3162 }
@@ -3352,6 +3375,8 @@ namespace OpenSim.Region.Framework.Scenes
3352 } 3375 }
3353 } 3376 }
3354 3377
3378 RaiseCollisionScriptEvents(coldata);
3379
3355 if (Invulnerable) 3380 if (Invulnerable)
3356 return; 3381 return;
3357 3382
@@ -3537,26 +3562,29 @@ namespace OpenSim.Region.Framework.Scenes
3537 /// <param name="args">The arguments for the event</param> 3562 /// <param name="args">The arguments for the event</param>
3538 public void SendScriptEventToAttachments(string eventName, Object[] args) 3563 public void SendScriptEventToAttachments(string eventName, Object[] args)
3539 { 3564 {
3540 if (m_scriptEngines.Length == 0) 3565 Util.FireAndForget(delegate(object x)
3541 return;
3542
3543 lock (m_attachments)
3544 { 3566 {
3545 foreach (SceneObjectGroup grp in m_attachments) 3567 if (m_scriptEngines.Length == 0)
3568 return;
3569
3570 lock (m_attachments)
3546 { 3571 {
3547 // 16384 is CHANGED_ANIMATION 3572 foreach (SceneObjectGroup grp in m_attachments)
3548 //
3549 // Send this to all attachment root prims
3550 //
3551 foreach (IScriptModule m in m_scriptEngines)
3552 { 3573 {
3553 if (m == null) // No script engine loaded 3574 // 16384 is CHANGED_ANIMATION
3554 continue; 3575 //
3576 // Send this to all attachment root prims
3577 //
3578 foreach (IScriptModule m in m_scriptEngines)
3579 {
3580 if (m == null) // No script engine loaded
3581 continue;
3555 3582
3556 m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION }); 3583 m.PostObjectEvent(grp.RootPart.UUID, "changed", new Object[] { (int)Changed.ANIMATION });
3584 }
3557 } 3585 }
3558 } 3586 }
3559 } 3587 });
3560 } 3588 }
3561 3589
3562 internal void PushForce(Vector3 impulse) 3590 internal void PushForce(Vector3 impulse)
@@ -3788,5 +3816,221 @@ namespace OpenSim.Region.Framework.Scenes
3788 m_reprioritization_called = false; 3816 m_reprioritization_called = false;
3789 } 3817 }
3790 } 3818 }
3819
3820 private void CheckLandingPoint(ref Vector3 pos)
3821 {
3822 // Never constrain lures
3823 if ((TeleportFlags & TeleportFlags.ViaLure) != 0)
3824 return;
3825
3826 if (m_scene.RegionInfo.EstateSettings.AllowDirectTeleport)
3827 return;
3828
3829 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
3830
3831 if (land.LandData.LandingType == (byte)LandingType.LandingPoint &&
3832 land.LandData.UserLocation != Vector3.Zero &&
3833 land.LandData.OwnerID != m_uuid &&
3834 (!m_scene.Permissions.IsGod(m_uuid)) &&
3835 (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid)))
3836 {
3837 float curr = Vector3.Distance(AbsolutePosition, pos);
3838 if (Vector3.Distance(land.LandData.UserLocation, pos) < curr)
3839 pos = land.LandData.UserLocation;
3840 else
3841 ControllingClient.SendAlertMessage("Can't teleport closer to destination");
3842 }
3843 }
3844
3845 private void CheckAndAdjustLandingPoint(ref Vector3 pos)
3846 {
3847 ILandObject land = m_scene.LandChannel.GetLandObject(pos.X, pos.Y);
3848 if (land != null)
3849 {
3850 // If we come in via login, landmark or map, we want to
3851 // honor landing points. If we come in via Lure, we want
3852 // to ignore them.
3853 if ((m_teleportFlags & (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID)) == (TeleportFlags.ViaLogin | TeleportFlags.ViaRegionID) ||
3854 (m_teleportFlags & TeleportFlags.ViaLandmark) != 0 ||
3855 (m_teleportFlags & TeleportFlags.ViaLocation) != 0)
3856 {
3857 // Don't restrict gods, estate managers, or land owners to
3858 // the TP point. This behaviour mimics agni.
3859 if (land.LandData.LandingType == (byte)LandingType.LandingPoint &&
3860 land.LandData.UserLocation != Vector3.Zero &&
3861 GodLevel < 200 &&
3862 ((land.LandData.OwnerID != m_uuid &&
3863 (!m_scene.Permissions.IsGod(m_uuid)) &&
3864 (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid))) || (m_teleportFlags & TeleportFlags.ViaLocation) != 0))
3865 {
3866 pos = land.LandData.UserLocation;
3867 }
3868 }
3869
3870 land.SendLandUpdateToClient(ControllingClient);
3871 }
3872 }
3873
3874 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
3875 {
3876 lock(m_collisionEventLock)
3877 {
3878 if (m_collisionEventFlag)
3879 return;
3880 m_collisionEventFlag = true;
3881 }
3882
3883 Util.FireAndForget(delegate(object x)
3884 {
3885 try
3886 {
3887 List<uint> thisHitColliders = new List<uint>();
3888 List<uint> endedColliders = new List<uint>();
3889 List<uint> startedColliders = new List<uint>();
3890
3891 foreach (uint localid in coldata.Keys)
3892 {
3893 thisHitColliders.Add(localid);
3894 if (!m_lastColliders.Contains(localid))
3895 {
3896 startedColliders.Add(localid);
3897 }
3898 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
3899 }
3900
3901 // calculate things that ended colliding
3902 foreach (uint localID in m_lastColliders)
3903 {
3904 if (!thisHitColliders.Contains(localID))
3905 {
3906 endedColliders.Add(localID);
3907 }
3908 }
3909 //add the items that started colliding this time to the last colliders list.
3910 foreach (uint localID in startedColliders)
3911 {
3912 m_lastColliders.Add(localID);
3913 }
3914 // remove things that ended colliding from the last colliders list
3915 foreach (uint localID in endedColliders)
3916 {
3917 m_lastColliders.Remove(localID);
3918 }
3919
3920 // do event notification
3921 if (startedColliders.Count > 0)
3922 {
3923 ColliderArgs StartCollidingMessage = new ColliderArgs();
3924 List<DetectedObject> colliding = new List<DetectedObject>();
3925 foreach (uint localId in startedColliders)
3926 {
3927 if (localId == 0)
3928 continue;
3929
3930 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3931 string data = "";
3932 if (obj != null)
3933 {
3934 DetectedObject detobj = new DetectedObject();
3935 detobj.keyUUID = obj.UUID;
3936 detobj.nameStr = obj.Name;
3937 detobj.ownerUUID = obj.OwnerID;
3938 detobj.posVector = obj.AbsolutePosition;
3939 detobj.rotQuat = obj.GetWorldRotation();
3940 detobj.velVector = obj.Velocity;
3941 detobj.colliderType = 0;
3942 detobj.groupUUID = obj.GroupID;
3943 colliding.Add(detobj);
3944 }
3945 }
3946
3947 if (colliding.Count > 0)
3948 {
3949 StartCollidingMessage.Colliders = colliding;
3950
3951 foreach (SceneObjectGroup att in GetAttachments())
3952 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
3953 }
3954 }
3955
3956 if (endedColliders.Count > 0)
3957 {
3958 ColliderArgs EndCollidingMessage = new ColliderArgs();
3959 List<DetectedObject> colliding = new List<DetectedObject>();
3960 foreach (uint localId in endedColliders)
3961 {
3962 if (localId == 0)
3963 continue;
3964
3965 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
3966 string data = "";
3967 if (obj != null)
3968 {
3969 DetectedObject detobj = new DetectedObject();
3970 detobj.keyUUID = obj.UUID;
3971 detobj.nameStr = obj.Name;
3972 detobj.ownerUUID = obj.OwnerID;
3973 detobj.posVector = obj.AbsolutePosition;
3974 detobj.rotQuat = obj.GetWorldRotation();
3975 detobj.velVector = obj.Velocity;
3976 detobj.colliderType = 0;
3977 detobj.groupUUID = obj.GroupID;
3978 colliding.Add(detobj);
3979 }
3980 }
3981
3982 if (colliding.Count > 0)
3983 {
3984 EndCollidingMessage.Colliders = colliding;
3985
3986 foreach (SceneObjectGroup att in GetAttachments())
3987 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage);
3988 }
3989 }
3990
3991 if (thisHitColliders.Count > 0)
3992 {
3993 ColliderArgs CollidingMessage = new ColliderArgs();
3994 List<DetectedObject> colliding = new List<DetectedObject>();
3995 foreach (uint localId in thisHitColliders)
3996 {
3997 if (localId == 0)
3998 continue;
3999
4000 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4001 string data = "";
4002 if (obj != null)
4003 {
4004 DetectedObject detobj = new DetectedObject();
4005 detobj.keyUUID = obj.UUID;
4006 detobj.nameStr = obj.Name;
4007 detobj.ownerUUID = obj.OwnerID;
4008 detobj.posVector = obj.AbsolutePosition;
4009 detobj.rotQuat = obj.GetWorldRotation();
4010 detobj.velVector = obj.Velocity;
4011 detobj.colliderType = 0;
4012 detobj.groupUUID = obj.GroupID;
4013 colliding.Add(detobj);
4014 }
4015 }
4016
4017 if (colliding.Count > 0)
4018 {
4019 CollidingMessage.Colliders = colliding;
4020
4021 lock (m_attachments)
4022 {
4023 foreach (SceneObjectGroup att in m_attachments)
4024 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
4025 }
4026 }
4027 }
4028 }
4029 finally
4030 {
4031 m_collisionEventFlag = false;
4032 }
4033 });
4034 }
3791 } 4035 }
3792} 4036}