aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
authorMelanie2012-05-29 17:24:17 +0200
committerMelanie2012-05-29 17:24:17 +0200
commit100d2968c4ebe3f544e770ef66826d7036d4ed77 (patch)
tree4f9b36f222bb27cbf4eb3dd1e412c4db563903ea /OpenSim/Region/Framework/Scenes/ScenePresence.cs
parentFix collision filtering (diff)
downloadopensim-SC-100d2968c4ebe3f544e770ef66826d7036d4ed77.zip
opensim-SC-100d2968c4ebe3f544e770ef66826d7036d4ed77.tar.gz
opensim-SC-100d2968c4ebe3f544e770ef66826d7036d4ed77.tar.bz2
opensim-SC-100d2968c4ebe3f544e770ef66826d7036d4ed77.tar.xz
Add advanced collision processing into ScenePresence
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs324
1 files changed, 162 insertions, 162 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 5a3b518..e2f32dd 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -3499,7 +3499,7 @@ namespace OpenSim.Region.Framework.Scenes
3499 3499
3500 RaiseCollisionScriptEvents(coldata); 3500 RaiseCollisionScriptEvents(coldata);
3501 3501
3502 if (Invulnerable) 3502 if (Invulnerable || GodLevel >= 200)
3503 return; 3503 return;
3504 3504
3505 float starthealth = Health; 3505 float starthealth = Health;
@@ -4096,199 +4096,199 @@ namespace OpenSim.Region.Framework.Scenes
4096 } 4096 }
4097 } 4097 }
4098 4098
4099 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata) 4099 private DetectedObject CreateDetObject(SceneObjectPart obj)
4100 { 4100 {
4101 /* 4101 DetectedObject detobj = new DetectedObject();
4102 lock(m_collisionEventLock) 4102 detobj.keyUUID = obj.UUID;
4103 { 4103 detobj.nameStr = obj.Name;
4104 if (m_collisionEventFlag) 4104 detobj.ownerUUID = obj.OwnerID;
4105 return; 4105 detobj.posVector = obj.AbsolutePosition;
4106 m_collisionEventFlag = true; 4106 detobj.rotQuat = obj.GetWorldRotation();
4107 } 4107 detobj.velVector = obj.Velocity;
4108 detobj.colliderType = 0;
4109 detobj.groupUUID = obj.GroupID;
4108 4110
4109 Util.FireAndForget(delegate(object x) 4111 return detobj;
4112 }
4113
4114 private DetectedObject CreateDetObject(ScenePresence av)
4115 {
4116 DetectedObject detobj = new DetectedObject();
4117 detobj.keyUUID = av.UUID;
4118 detobj.nameStr = av.ControllingClient.Name;
4119 detobj.ownerUUID = av.UUID;
4120 detobj.posVector = av.AbsolutePosition;
4121 detobj.rotQuat = av.Rotation;
4122 detobj.velVector = av.Velocity;
4123 detobj.colliderType = 0;
4124 detobj.groupUUID = av.ControllingClient.ActiveGroupId;
4125
4126 return detobj;
4127 }
4128
4129 private DetectedObject CreateDetObjectForGround()
4130 {
4131 DetectedObject detobj = new DetectedObject();
4132 detobj.keyUUID = UUID.Zero;
4133 detobj.nameStr = "";
4134 detobj.ownerUUID = UUID.Zero;
4135 detobj.posVector = AbsolutePosition;
4136 detobj.rotQuat = Quaternion.Identity;
4137 detobj.velVector = Vector3.Zero;
4138 detobj.colliderType = 0;
4139 detobj.groupUUID = UUID.Zero;
4140
4141 return detobj;
4142 }
4143
4144 private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
4145 {
4146 ColliderArgs colliderArgs = new ColliderArgs();
4147 List<DetectedObject> colliding = new List<DetectedObject>();
4148 foreach (uint localId in colliders)
4110 { 4149 {
4111 */ 4150 if (localId == 0)
4112 try 4151 continue;
4152
4153 SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
4154 if (obj != null)
4113 { 4155 {
4114 List<uint> thisHitColliders = new List<uint>(); 4156 if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
4115 List<uint> endedColliders = new List<uint>(); 4157 colliding.Add(CreateDetObject(obj));
4116 List<uint> startedColliders = new List<uint>(); 4158 }
4117 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>(); 4159 else
4118 CollisionForSoundInfo soundinfo; 4160 {
4119 ContactPoint curcontact; 4161 ScenePresence av = m_scene.GetScenePresence(localId);
4120 4162 if (av != null && (!av.IsChildAgent))
4121 if (coldata.Count == 0)
4122 { 4163 {
4123 if (m_lastColliders.Count == 0) 4164 if (!dest.CollisionFilteredOut(av.UUID, av.Name))
4124 return; // nothing to do 4165 colliding.Add(CreateDetObject(av));
4125
4126 foreach (uint localID in m_lastColliders)
4127 {
4128 endedColliders.Add(localID);
4129 }
4130 m_lastColliders.Clear();
4131 } 4166 }
4167 }
4168 }
4132 4169
4133 else 4170 colliderArgs.Colliders = colliding;
4134 {
4135 foreach (uint id in coldata.Keys)
4136 {
4137 thisHitColliders.Add(id);
4138 if (!m_lastColliders.Contains(id))
4139 {
4140 startedColliders.Add(id);
4141 curcontact = coldata[id];
4142 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4143 {
4144 soundinfo = new CollisionForSoundInfo();
4145 soundinfo.colliderID = id;
4146 soundinfo.position = curcontact.Position;
4147 soundinfo.relativeVel = curcontact.RelativeSpeed;
4148 soundinfolist.Add(soundinfo);
4149 }
4150 }
4151 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4152 }
4153 4171
4154 // calculate things that ended colliding 4172 return colliderArgs;
4155 foreach (uint localID in m_lastColliders) 4173 }
4156 {
4157 if (!thisHitColliders.Contains(localID))
4158 {
4159 endedColliders.Add(localID);
4160 }
4161 }
4162 //add the items that started colliding this time to the last colliders list.
4163 foreach (uint localID in startedColliders)
4164 {
4165 m_lastColliders.Add(localID);
4166 }
4167 // remove things that ended colliding from the last colliders list
4168 foreach (uint localID in endedColliders)
4169 {
4170 m_lastColliders.Remove(localID);
4171 }
4172 4174
4173 if (soundinfolist.Count > 0) 4175 private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
4174 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4175 4176
4176 // do event notification 4177 private void SendCollisionEvent(SceneObjectGroup dest, scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
4177 if (startedColliders.Count > 0) 4178 {
4178 { 4179 ColliderArgs CollidingMessage;
4179 4180
4180 ColliderArgs StartCollidingMessage = new ColliderArgs(); 4181 if (colliders.Count > 0)
4181 List<DetectedObject> colliding = new List<DetectedObject>(); 4182 {
4182 foreach (uint localId in startedColliders) 4183 if ((dest.RootPart.ScriptEvents & ev) != 0)
4183 { 4184 {
4184 if (localId == 0) 4185 CollidingMessage = CreateColliderArgs(dest.RootPart, colliders);
4185 continue;
4186 4186
4187 SceneObjectPart obj = Scene.GetSceneObjectPart(localId); 4187 if (CollidingMessage.Colliders.Count > 0)
4188 string data = ""; 4188 notify(dest.RootPart.LocalId, CollidingMessage);
4189 if (obj != null) 4189 }
4190 { 4190 }
4191 DetectedObject detobj = new DetectedObject(); 4191 }
4192 detobj.keyUUID = obj.UUID;
4193 detobj.nameStr = obj.Name;
4194 detobj.ownerUUID = obj.OwnerID;
4195 detobj.posVector = obj.AbsolutePosition;
4196 detobj.rotQuat = obj.GetWorldRotation();
4197 detobj.velVector = obj.Velocity;
4198 detobj.colliderType = 0;
4199 detobj.groupUUID = obj.GroupID;
4200 colliding.Add(detobj);
4201 }
4202 }
4203 4192
4204 if (colliding.Count > 0) 4193 private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
4205 { 4194 {
4206 StartCollidingMessage.Colliders = colliding; 4195 if ((dest.RootPart.ScriptEvents & ev) != 0)
4196 {
4197 ColliderArgs LandCollidingMessage = new ColliderArgs();
4198 List<DetectedObject> colliding = new List<DetectedObject>();
4207 4199
4208 foreach (SceneObjectGroup att in GetAttachments()) 4200 colliding.Add(CreateDetObjectForGround());
4209 Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage); 4201 LandCollidingMessage.Colliders = colliding;
4210 }
4211 }
4212 }
4213 4202
4214 if (endedColliders.Count > 0) 4203 notify(dest.RootPart.LocalId, LandCollidingMessage);
4215 { 4204 }
4216 ColliderArgs EndCollidingMessage = new ColliderArgs(); 4205 }
4217 List<DetectedObject> colliding = new List<DetectedObject>();
4218 foreach (uint localId in endedColliders)
4219 {
4220 if (localId == 0)
4221 continue;
4222 4206
4223 SceneObjectPart obj = Scene.GetSceneObjectPart(localId); 4207 private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata)
4224 string data = ""; 4208 {
4225 if (obj != null) 4209 try
4226 { 4210 {
4227 DetectedObject detobj = new DetectedObject(); 4211 List<uint> thisHitColliders = new List<uint>();
4228 detobj.keyUUID = obj.UUID; 4212 List<uint> endedColliders = new List<uint>();
4229 detobj.nameStr = obj.Name; 4213 List<uint> startedColliders = new List<uint>();
4230 detobj.ownerUUID = obj.OwnerID; 4214 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
4231 detobj.posVector = obj.AbsolutePosition; 4215 CollisionForSoundInfo soundinfo;
4232 detobj.rotQuat = obj.GetWorldRotation(); 4216 ContactPoint curcontact;
4233 detobj.velVector = obj.Velocity;
4234 detobj.colliderType = 0;
4235 detobj.groupUUID = obj.GroupID;
4236 colliding.Add(detobj);
4237 }
4238 }
4239 4217
4240 if (colliding.Count > 0) 4218 if (coldata.Count == 0)
4241 { 4219 {
4242 EndCollidingMessage.Colliders = colliding; 4220 if (m_lastColliders.Count == 0)
4221 return; // nothing to do
4243 4222
4244 foreach (SceneObjectGroup att in GetAttachments()) 4223 foreach (uint localID in m_lastColliders)
4245 Scene.EventManager.TriggerScriptCollidingEnd(att.LocalId, EndCollidingMessage); 4224 {
4246 } 4225 endedColliders.Add(localID);
4247 } 4226 }
4227 m_lastColliders.Clear();
4228 }
4248 4229
4249 if (thisHitColliders.Count > 0) 4230 else
4231 {
4232 foreach (uint id in coldata.Keys)
4250 { 4233 {
4251 ColliderArgs CollidingMessage = new ColliderArgs(); 4234 thisHitColliders.Add(id);
4252 List<DetectedObject> colliding = new List<DetectedObject>(); 4235 if (!m_lastColliders.Contains(id))
4253 foreach (uint localId in thisHitColliders)
4254 { 4236 {
4255 if (localId == 0) 4237 startedColliders.Add(id);
4256 continue; 4238 curcontact = coldata[id];
4257 4239 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
4258 SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
4259 string data = "";
4260 if (obj != null)
4261 { 4240 {
4262 DetectedObject detobj = new DetectedObject(); 4241 soundinfo = new CollisionForSoundInfo();
4263 detobj.keyUUID = obj.UUID; 4242 soundinfo.colliderID = id;
4264 detobj.nameStr = obj.Name; 4243 soundinfo.position = curcontact.Position;
4265 detobj.ownerUUID = obj.OwnerID; 4244 soundinfo.relativeVel = curcontact.RelativeSpeed;
4266 detobj.posVector = obj.AbsolutePosition; 4245 soundinfolist.Add(soundinfo);
4267 detobj.rotQuat = obj.GetWorldRotation();
4268 detobj.velVector = obj.Velocity;
4269 detobj.colliderType = 0;
4270 detobj.groupUUID = obj.GroupID;
4271 colliding.Add(detobj);
4272 } 4246 }
4273 } 4247 }
4248 //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
4249 }
4274 4250
4275 if (colliding.Count > 0) 4251 // calculate things that ended colliding
4252 foreach (uint localID in m_lastColliders)
4253 {
4254 if (!thisHitColliders.Contains(localID))
4276 { 4255 {
4277 CollidingMessage.Colliders = colliding; 4256 endedColliders.Add(localID);
4278
4279 lock (m_attachments)
4280 {
4281 foreach (SceneObjectGroup att in m_attachments)
4282 Scene.EventManager.TriggerScriptColliding(att.LocalId, CollidingMessage);
4283 }
4284 } 4257 }
4285 } 4258 }
4259 //add the items that started colliding this time to the last colliders list.
4260 foreach (uint localID in startedColliders)
4261 {
4262 m_lastColliders.Add(localID);
4263 }
4264 // remove things that ended colliding from the last colliders list
4265 foreach (uint localID in endedColliders)
4266 {
4267 m_lastColliders.Remove(localID);
4268 }
4269
4270 if (soundinfolist.Count > 0)
4271 CollisionSounds.AvatarCollisionSound(this, soundinfolist);
4286 } 4272 }
4287 finally 4273
4274 foreach (SceneObjectGroup att in GetAttachments())
4288 { 4275 {
4289 m_collisionEventFlag = false; 4276 SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart);
4277 SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding);
4278 SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd);
4279
4280 if (startedColliders.Contains(0))
4281 SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart);
4282 if (m_lastColliders.Contains(0))
4283 SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding);
4284 if (endedColliders.Contains(0))
4285 SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd);
4290 } 4286 }
4291// }); 4287 }
4288 finally
4289 {
4290 m_collisionEventFlag = false;
4291 }
4292 } 4292 }
4293 4293
4294 private void TeleportFlagsDebug() { 4294 private void TeleportFlagsDebug() {