private void RaiseCollisionScriptEvents(Dictionary<uint, ContactPoint> coldata) { try { List<uint> thisHitColliders = new List<uint>(); List<uint> endedColliders = new List<uint>(); List<uint> startedColliders = new List<uint>(); List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>(); CollisionForSoundInfo soundinfo; ContactPoint curcontact; if (coldata.Count == 0) { if (m_lastColliders.Count == 0) return; // nothing to do foreach (uint localID in m_lastColliders) { endedColliders.Add(localID); } m_lastColliders.Clear(); } else { bool candoparcelSound = ParcelAllowThisAvatarSounds; foreach (uint id in coldata.Keys) { thisHitColliders.Add(id); if (!m_lastColliders.Contains(id)) { startedColliders.Add(id); curcontact = coldata[id]; if (candoparcelSound && Math.Abs(curcontact.RelativeSpeed) > 0.2) { soundinfo = new CollisionForSoundInfo(); soundinfo.colliderID = id; soundinfo.position = curcontact.Position; soundinfo.relativeVel = curcontact.RelativeSpeed; soundinfolist.Add(soundinfo); } } //m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString()); } // calculate things that ended colliding foreach (uint localID in m_lastColliders) { if (!thisHitColliders.Contains(localID)) { endedColliders.Add(localID); } } //add the items that started colliding this time to the last colliders list. foreach (uint localID in startedColliders) { m_lastColliders.Add(localID); } // remove things that ended colliding from the last colliders list foreach (uint localID in endedColliders) { m_lastColliders.Remove(localID); } if (soundinfolist.Count > 0) CollisionSounds.AvatarCollisionSound(this, soundinfolist); } foreach (SceneObjectGroup att in GetAttachments()) { SendCollisionEvent(att, scriptEvents.collision_start, startedColliders, m_scene.EventManager.TriggerScriptCollidingStart); SendCollisionEvent(att, scriptEvents.collision , m_lastColliders , m_scene.EventManager.TriggerScriptColliding); SendCollisionEvent(att, scriptEvents.collision_end , endedColliders , m_scene.EventManager.TriggerScriptCollidingEnd); if (startedColliders.Contains(0)) SendLandCollisionEvent(att, scriptEvents.land_collision_start, m_scene.EventManager.TriggerScriptLandCollidingStart); if (m_lastColliders.Contains(0)) SendLandCollisionEvent(att, scriptEvents.land_collision, m_scene.EventManager.TriggerScriptLandColliding); if (endedColliders.Contains(0)) SendLandCollisionEvent(att, scriptEvents.land_collision_end, m_scene.EventManager.TriggerScriptLandCollidingEnd); } } finally { m_collisionEventFlag = false; } }
public void PhysicsCollision(EventArgs e) { if (ParentGroup.Scene == null || ParentGroup.IsDeleted) return; // single threaded here CollisionEventUpdate a = (CollisionEventUpdate)e; Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList; List<uint> thisHitColliders = new List<uint>(); List<uint> endedColliders = new List<uint>(); List<uint> startedColliders = new List<uint>(); if (collissionswith.Count == 0) { if (m_lastColliders.Count == 0) return; // nothing to do foreach (uint localID in m_lastColliders) { endedColliders.Add(localID); } m_lastColliders.Clear(); } else { List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>(); // calculate things that started colliding this time // and build up list of colliders this time if (!VolumeDetectActive && CollisionSoundType >= 0) { CollisionForSoundInfo soundinfo; ContactPoint curcontact; foreach (uint id in collissionswith.Keys) { thisHitColliders.Add(id); if (!m_lastColliders.Contains(id)) { startedColliders.Add(id); curcontact = collissionswith[id]; if (Math.Abs(curcontact.RelativeSpeed) > 0.2) { soundinfo = new CollisionForSoundInfo(); soundinfo.colliderID = id; soundinfo.position = curcontact.Position; soundinfo.relativeVel = curcontact.RelativeSpeed; soundinfolist.Add(soundinfo); } } } } else { foreach (uint id in collissionswith.Keys) { thisHitColliders.Add(id); if (!m_lastColliders.Contains(id)) startedColliders.Add(id); } } // calculate things that ended colliding foreach (uint localID in m_lastColliders) { if (!thisHitColliders.Contains(localID)) endedColliders.Add(localID); } //add the items that started colliding this time to the last colliders list. foreach (uint localID in startedColliders) m_lastColliders.Add(localID); // remove things that ended colliding from the last colliders list foreach (uint localID in endedColliders) m_lastColliders.Remove(localID); // play sounds. if (soundinfolist.Count > 0) CollisionSounds.PartCollisionSound(this, soundinfolist); } SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); if (!VolumeDetectActive) SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding); SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); if (startedColliders.Contains(0)) SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart); if (m_lastColliders.Contains(0)) SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding); if (endedColliders.Contains(0)) SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd); }