Esempio n. 1
0
 public void TriggerScriptColliding(SceneObjectPart part, ColliderArgs colliders)
 {
     ScriptColliding handlerColliding = OnScriptColliding;
     if (handlerColliding != null)
     {
         foreach (ScriptColliding d in handlerColliding.GetInvocationList())
         {
             try
             {
                 d(part, colliders);
             }
             catch (Exception e)
             {
                 m_log.ErrorFormat(
                     "[EVENT MANAGER]: Delegate for TriggerScriptColliding failed - continuing.  {0} {1}",
                     e.ToString(), e.StackTrace);
             }
         }
     }
 }
Esempio n. 2
0
        private void HandleGenericCollisionEvent(CollisionEventUpdate update, Scenes.ScriptEvents eventType, EventManager.ScriptColliding callback,
            bool playSound)
        {
            // play the sound.
            if (playSound && CollisionSound != UUID.Zero && eventType == ScriptEvents.collision_start && CollisionSoundVolume > 0.0f)
            {
                SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0);
            }

            SceneObjectPart handlingPart = FindCollisionHandlingPart(eventType);
            if (handlingPart == null) return; //no one to handle the event

            ColliderArgs colliderArgs = new ColliderArgs();
            List<DetectedObject> colliding = new List<DetectedObject>();

            bool otherIsPrim;
            if (update.Type == CollisionEventUpdateType.CollisionBegan ||
                update.Type == CollisionEventUpdateType.CollisionContinues ||
                update.Type == CollisionEventUpdateType.BulkCollisionsContinue ||
                update.Type == CollisionEventUpdateType.CollisionEnded)
            {
                otherIsPrim = true;
            }
            else
            {
                otherIsPrim = false;
            }

            if (update.BulkCollisionData == null)
            {
                TryExtractCollider(update.OtherColliderLocalId, colliding, otherIsPrim, update.OtherColliderUUID);
            }
            else
            {
                foreach (uint localId in update.BulkCollisionData)
                {
                    TryExtractCollider(localId, colliding, otherIsPrim, update.OtherColliderUUID);
                }
            }
            

            if (colliding.Count > 0)
            {
                colliderArgs.Colliders = colliding;
                // always running this check because if the user deletes the object it would return a null reference.
                if (m_parentGroup == null)
                    return;
                if (m_parentGroup.Scene == null)
                    return;
                callback(handlingPart.LocalId, colliderArgs);
            }
        }
Esempio n. 3
0
        private void DoNotify(ScriptCollidingNotification notify, uint id, ColliderArgs collargs)
        {
            if (m_parentGroup != null && ParentGroup.Scene != null && ParentGroup.Scene.ShouldUseFireAndForgetForCollisions)
            {
                // For those learning C#, FireAndForget takes a function, an object to pass
                //    to that function and an ID string. The "oo => {}" construct is a lambda expression
                //    for a function with one arguement ('oo'). The 'new Object[] {}" construct creates an Object
                //    that is an object array and initializes it with three items (the parameters
                //    being passed). The parameters passed are the function to call ('notify') and
                //    its two arguements. Finally, once in the function (called later by the FireAndForget
                //    thread scheduler), the passed object is cast to an object array and then each
                //    of its items (aoo[0] to aoo[2]) are individually cast to what they are and
                //    then used in a call of the passed ScriptCollidingNotification function.
                Util.FireAndForget(oo =>
                {
                    Object[] aoo = (Object[])oo;
                    ((ScriptCollidingNotification)aoo[0])((uint)aoo[1], (ColliderArgs)aoo[2]);

                }, new Object[] { notify, id, collargs }, "SOP.Collision");
            }
            else
            {
                notify(id, collargs);
            }
        }
Esempio n. 4
0
 public void TriggerScriptCollidingEnd(uint localId, ColliderArgs colliders)
 {
     handlerCollidingEnd = OnScriptCollidingEnd;
     if (handlerCollidingEnd != null)
         handlerCollidingEnd(localId, colliders);
 }
Esempio n. 5
0
        private void SendLandCollisionEvent(SceneObjectGroup dest, scriptEvents ev, ScriptCollidingNotification notify)
        {
            if ((dest.RootPart.ScriptEvents & ev) != 0)
            {
                ColliderArgs LandCollidingMessage = new ColliderArgs();
                List<DetectedObject> colliding = new List<DetectedObject>();

                colliding.Add(CreateDetObjectForGround());
                LandCollidingMessage.Colliders = colliding;

                notify(dest.RootPart.LocalId, LandCollidingMessage);
            }
        }
Esempio n. 6
0
        public void collision_start (ISceneChildEntity part, ColliderArgs col)
        {
            // Add to queue for all scripts in ObjectID object
            List<DetectParams> det = new List<DetectParams>();

            foreach (DetectedObject detobj in col.Colliders)
            {
                DetectParams d = new DetectParams();
                d.Key = detobj.keyUUID;
                d.Populate(part.ParentEntity.Scene);
                d.LinkNum = part.LinkNum;
                det.Add(d);
            }

            if (det.Count > 0)
            {
                ScriptData[] datas = ScriptEngine.ScriptProtection.GetScripts(part.UUID);

                if (datas == null || datas.Length == 0)
                {
                    //datas = ScriptEngine.ScriptProtection.GetScripts(part.ParentGroup.RootPart.UUID);
                    //if (datas == null || datas.Length == 0)
                        return;
                }
                string functionName = "collision_start";
                object[] param = new Object[] { new LSL_Types.LSLInteger(det.Count) };

                foreach (ScriptData ID in datas)
                {
                    if (CheckIfEventShouldFire(ID, functionName, param))
                        m_scriptEngine.AddToScriptQueue(ID, functionName, det.ToArray(), EventPriority.FirstStart, param);
                }
            }
        }
Esempio n. 7
0
        public void collision_end(uint localID, ColliderArgs col)
        {
            // Add to queue for all scripts in ObjectID object
            List<DetectParams> det = new List<DetectParams>();

            foreach (DetectedObject detobj in col.Colliders)
            {
                DetectParams d = new DetectParams();
                d.Key =detobj.keyUUID;
                d.Populate(myScriptEngine.World);
                det.Add(d);
            }

            if (det.Count > 0)
                myScriptEngine.PostObjectEvent(localID, new EventParams(
                        "collision_end",
                        new Object[] { new LSL_Types.LSLInteger(det.Count) },
                        det.ToArray()));
        }
Esempio n. 8
0
 public void TriggerScriptLandCollidingEnd(uint localId, ColliderArgs colliders)
 {
     ScriptColliding handlerLandCollidingEnd = OnScriptLandColliderEnd;
     if (handlerLandCollidingEnd != null)
     {
         foreach (ScriptColliding d in handlerLandCollidingEnd.GetInvocationList())
         {
             try
             {
                 d(localId, colliders);
             }
             catch (Exception e)
             {
                 m_log.ErrorFormat(
                     "[EVENT MANAGER]: Delegate for TriggerScriptLandCollidingEnd failed - continuing.  {0} {1}", 
                     e.Message, e.StackTrace);
             }
         }
     }
 }
Esempio n. 9
0
 private void HandleScriptColliding(uint localID, ColliderArgs colliders)
 {
     SceneObjectPart part = m_scriptEngine.World.GetSceneObjectPart(localID);
     if (part != null)
     {
         //filter out regular collision
         //might be fun though later on
         if (part.VolumeDetectActive)
         {
             foreach (DetectedObject obj in colliders.Colliders)
             {
                 EntityBase eb = null;
                 if (m_scriptEngine.World.Entities.TryGetValue(obj.keyUUID, out eb))
                 {
                     OnPrimVolumeCollision(localID, eb.LocalId);
                 }
                 else
                     m_log.Warn("[RexScriptEngine]: Could not find object with id " + obj.keyUUID);
             }
         }
     }
     else
         m_log.Warn("[RexScriptEngine]: Could not find object with id "+localID);
 }
Esempio n. 10
0
 public void TriggerScriptLandColliding (ISceneChildEntity part, ColliderArgs colliders)
 {
     ScriptColliding handlerLandColliding = OnScriptLandColliding;
     if (handlerLandColliding != null)
     {
         foreach (ScriptColliding d in handlerLandColliding.GetInvocationList ())
         {
             try
             {
                 d (part, colliders);
             }
             catch (Exception e)
             {
                 MainConsole.Instance.ErrorFormat (
                     "[EVENT MANAGER]: Delegate for TriggerScriptLandColliding failed - continuing.  {0} {1}",
                     e, e.StackTrace);
             }
         }
     }
 }
Esempio n. 11
0
        public void PhysicsCollision(EventArgs e)
        {
            // single threaded here
            if (e == null)
            {
                return;
            }

            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>();

            // calculate things that started colliding this time
            // and build up list of colliders this time
            foreach (uint localID in collissionswith.Keys)
            {
                thisHitColliders.Add(localID);
                if (!m_lastColliders.Contains(localID))
                {
                    startedColliders.Add(localID);
                }
                //m_log.Debug("[OBJECT]: 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.
            m_lastColliders.AddRange(startedColliders);
            // remove things that ended colliding from the last colliders list
            foreach (uint localID in endedColliders)
            {
                m_lastColliders.Remove(localID);
            }

            if (m_parentGroup == null)
                return;
            if (m_parentGroup.IsDeleted)
                return;

            const string SoundGlassCollision = "6a45ba0b-5775-4ea8-8513-26008a17f873";
            const string SoundMetalCollision = "9e5c1297-6eed-40c0-825a-d9bcd86e3193";
            const string SoundStoneCollision = "9538f37c-456e-4047-81be-6435045608d4";
            const string SoundFleshCollision = "dce5fdd4-afe4-4ea1-822f-dd52cac46b08";
            const string SoundPlasticCollision = "0e24a717-b97e-4b77-9c94-b59a5a88b2da";
            const string SoundRubberCollision = "153c8bf7-fb89-4d89-b263-47e58b1b4774";
            const string SoundWoodCollision = "063c97d3-033a-4e9b-98d8-05c8074922cb";
            
            // play the sound.
            if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f)
            {
                SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false);
            }
            else if (startedColliders.Count > 0)
            {
                switch (a.collidertype)
                {
                    case (int)ActorTypes.Agent:
                        break; // Agents will play the sound so we don't

                    case (int)ActorTypes.Ground:
                        if (collissionswith[startedColliders[0]].PenetrationDepth < 0.17)
                            SendSound(SoundWoodCollision, 1, true, 0, 0, false, false);
                        else
                            SendSound(Sounds.OBJECT_COLLISION.ToString(), 1, true, 0, 0, false, false);
                        break; //Always play the click or thump sound when hitting ground

                    case (int)ActorTypes.Prim:
                        if (m_material == OpenMetaverse.Material.Flesh)
                            SendSound(SoundFleshCollision.ToString(), 1, true, 0, 0, false, false);
                        else if (m_material == OpenMetaverse.Material.Glass)
                            SendSound(SoundGlassCollision, 1, true, 0, 0, false, false);
                        else if (m_material == OpenMetaverse.Material.Metal)
                            SendSound(SoundMetalCollision, 1, true, 0, 0, false, false);
                        else if (m_material == OpenMetaverse.Material.Plastic)
                            SendSound(SoundPlasticCollision, 1, true, 0, 0, false, false);
                        else if (m_material == OpenMetaverse.Material.Rubber)
                            SendSound(SoundRubberCollision, 1, true, 0, 0, false, false);
                        else if (m_material == OpenMetaverse.Material.Stone)
                            SendSound(SoundStoneCollision, 1, true, 0, 0, false, false);
                        else if (m_material == OpenMetaverse.Material.Wood)
                            SendSound(SoundWoodCollision, 1, true, 0, 0, false, false);
                        break; //Play based on material type in prim2prim collisions

                    default:
                        break; //Unclear of what this object is, no sounds
                }
            }
            if (CollisionSprite != UUID.Zero && CollisionSoundVolume > 0.0f) // The collision volume isn't a mistake, its an SL feature/bug
            {
                // TODO: make a sprite!

            }
            if (((AggregateScriptEvents & scriptEvents.collision) != 0) ||
               ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
               ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
               ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
               ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
               ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
               (CollisionSound != UUID.Zero) ||
                PassCollisions != 2)
            {

                if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_start) != 0)
                {
                    // do event notification
                    if (startedColliders.Count > 0)
                    {
                        ColliderArgs StartCollidingMessage = new ColliderArgs();
                        List<DetectedObject> colliding = new List<DetectedObject>();
                        foreach (uint localId in startedColliders)
                        {
                            if (localId == 0)
                                continue;
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;

                            SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
                            string data = "";
                            if (obj != null)
                            {
                                if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
                                {
                                    bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                    //If it is 1, it is to accept ONLY collisions from this object
                                    if (found)
                                    {
                                        DetectedObject detobj = new DetectedObject();
                                        detobj.keyUUID = obj.UUID;
                                        detobj.nameStr = obj.Name;
                                        detobj.ownerUUID = obj._ownerID;
                                        detobj.posVector = obj.AbsolutePosition;
                                        detobj.rotQuat = obj.GetWorldRotation();
                                        detobj.velVector = obj.Velocity;
                                        detobj.colliderType = 0;
                                        detobj.groupUUID = obj._groupID;
                                        colliding.Add(detobj);
                                    }
                                    //If it is 0, it is to not accept collisions from this object
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                    bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                    //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
                                    if (!found)
                                    {
                                        DetectedObject detobj = new DetectedObject();
                                        detobj.keyUUID = obj.UUID;
                                        detobj.nameStr = obj.Name;
                                        detobj.ownerUUID = obj._ownerID;
                                        detobj.posVector = obj.AbsolutePosition;
                                        detobj.rotQuat = obj.GetWorldRotation();
                                        detobj.velVector = obj.Velocity;
                                        detobj.colliderType = 0;
                                        detobj.groupUUID = obj._groupID;
                                        colliding.Add(detobj);
                                    }
                                }
                            }
                            else
                            {
                                ScenePresence av = ParentGroup.Scene.GetScenePresence(localId);
                                if(av != null)
                                {
                                    if (av.LocalId == localId)
                                    {
                                        if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
                                        {
                                            bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                            //If it is 1, it is to accept ONLY collisions from this avatar
                                            if (found)
                                            {
                                                DetectedObject detobj = new DetectedObject();
                                                detobj.keyUUID = av.UUID;
                                                detobj.nameStr = av.ControllingClient.Name;
                                                detobj.ownerUUID = av.UUID;
                                                detobj.posVector = av.AbsolutePosition;
                                                detobj.rotQuat = av.Rotation;
                                                detobj.velVector = av.Velocity;
                                                detobj.colliderType = 0;
                                                detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                                colliding.Add(detobj);
                                            }
                                            //If it is 0, it is to not accept collisions from this avatar
                                            else
                                            {
                                            }
                                        }
                                        else
                                        {
                                            bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                            //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
                                            if (!found)
                                            {
                                                DetectedObject detobj = new DetectedObject();
                                                detobj.keyUUID = av.UUID;
                                                detobj.nameStr = av.ControllingClient.Name;
                                                detobj.ownerUUID = av.UUID;
                                                detobj.posVector = av.AbsolutePosition;
                                                detobj.rotQuat = av.Rotation;
                                                detobj.velVector = av.Velocity;
                                                detobj.colliderType = 0;
                                                detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                                colliding.Add(detobj);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (colliding.Count > 0)
                        {
                            StartCollidingMessage.Colliders = colliding;
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;
                            //Always send to the prim it is occuring to
                            m_parentGroup.Scene.EventManager.TriggerScriptCollidingStart(this, StartCollidingMessage);
                            if ((this.UUID != this.ParentGroup.RootPart.UUID))
                            {
                                const int PASS_IF_NOT_HANDLED = 0;
                                const int PASS_ALWAYS = 1;
                                const int PASS_NEVER = 2;
                                if (this.PassCollisions == PASS_NEVER)
                                {
                                }
                                if (this.PassCollisions == PASS_ALWAYS)
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptCollidingStart(this.ParentGroup.RootPart, StartCollidingMessage);
                                }
                                else if (((this.ScriptEvents & scriptEvents.collision_start) == 0) && this.PassCollisions == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptCollidingStart(this.ParentGroup.RootPart, StartCollidingMessage);
                                }
                            }
                        }
                    }
                }

                if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision) != 0)
                {
                    if (m_lastColliders.Count > 0)
                    {
                        ColliderArgs CollidingMessage = new ColliderArgs();
                        List<DetectedObject> colliding = new List<DetectedObject>();
                        foreach (uint localId in m_lastColliders)
                        {
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (localId == 0)
                                continue;

                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;

                            SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
                            string data = "";
                            if (obj != null)
                            {
                                if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
                                {
                                    bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                    //If it is 1, it is to accept ONLY collisions from this object
                                    if (found)
                                    {
                                        DetectedObject detobj = new DetectedObject();
                                        detobj.keyUUID = obj.UUID;
                                        detobj.nameStr = obj.Name;
                                        detobj.ownerUUID = obj._ownerID;
                                        detobj.posVector = obj.AbsolutePosition;
                                        detobj.rotQuat = obj.GetWorldRotation();
                                        detobj.velVector = obj.Velocity;
                                        detobj.colliderType = 0;
                                        detobj.groupUUID = obj._groupID;
                                        colliding.Add(detobj);
                                    }
                                    //If it is 0, it is to not accept collisions from this object
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                    bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                    //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
                                    if (!found)
                                    {
                                        DetectedObject detobj = new DetectedObject();
                                        detobj.keyUUID = obj.UUID;
                                        detobj.nameStr = obj.Name;
                                        detobj.ownerUUID = obj._ownerID;
                                        detobj.posVector = obj.AbsolutePosition;
                                        detobj.rotQuat = obj.GetWorldRotation();
                                        detobj.velVector = obj.Velocity;
                                        detobj.colliderType = 0;
                                        detobj.groupUUID = obj._groupID;
                                        colliding.Add(detobj);
                                    }
                                }
                            }
                            else
                            {
                                ScenePresence av = ParentGroup.Scene.GetScenePresence(localId);
                                if (av.LocalId == localId)
                                {
                                    if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
                                    {
                                        bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar
                                        if (found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                        //If it is 0, it is to not accept collisions from this avatar
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                        bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
                                        if (!found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                    }

                                }
                            }
                        }
                        if (colliding.Count > 0)
                        {
                            CollidingMessage.Colliders = colliding;
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;

                            m_parentGroup.Scene.EventManager.TriggerScriptColliding(this, CollidingMessage);
                            
                            if ((this.UUID != this.ParentGroup.RootPart.UUID))
                            {
                                const int PASS_IF_NOT_HANDLED = 0;
                                const int PASS_ALWAYS = 1;
                                const int PASS_NEVER = 2;
                                if (this.PassCollisions == PASS_NEVER)
                                {
                                }
                                if (this.PassCollisions == PASS_ALWAYS)
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptColliding(this.ParentGroup.RootPart, CollidingMessage);
                                }
                                else if (((this.ScriptEvents & scriptEvents.collision) == 0) && this.PassCollisions == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptColliding(this.ParentGroup.RootPart, CollidingMessage);
                                }
                            }
                        }
                    }
                }

                if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_end) != 0)
                {
                    if (endedColliders.Count > 0)
                    {
                        ColliderArgs EndCollidingMessage = new ColliderArgs();
                        List<DetectedObject> colliding = new List<DetectedObject>();
                        foreach (uint localId in endedColliders)
                        {
                            if (localId == 0)
                                continue;

                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;
                            if (m_parentGroup.Scene == null)
                                return;
                            SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
                            string data = "";
                            if (obj != null)
                            {
                                if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
                                {
                                    bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                    //If it is 1, it is to accept ONLY collisions from this object
                                    if (found)
                                    {
                                        DetectedObject detobj = new DetectedObject();
                                        detobj.keyUUID = obj.UUID;
                                        detobj.nameStr = obj.Name;
                                        detobj.ownerUUID = obj._ownerID;
                                        detobj.posVector = obj.AbsolutePosition;
                                        detobj.rotQuat = obj.GetWorldRotation();
                                        detobj.velVector = obj.Velocity;
                                        detobj.colliderType = 0;
                                        detobj.groupUUID = obj._groupID;
                                        colliding.Add(detobj);
                                    }
                                    //If it is 0, it is to not accept collisions from this object
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                    bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                    //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
                                    if (!found)
                                    {
                                        DetectedObject detobj = new DetectedObject();
                                        detobj.keyUUID = obj.UUID;
                                        detobj.nameStr = obj.Name;
                                        detobj.ownerUUID = obj._ownerID;
                                        detobj.posVector = obj.AbsolutePosition;
                                        detobj.rotQuat = obj.GetWorldRotation();
                                        detobj.velVector = obj.Velocity;
                                        detobj.colliderType = 0;
                                        detobj.groupUUID = obj._groupID;
                                        colliding.Add(detobj);
                                    }
                                }
                            }
                            else
                            {
                                ScenePresence av = ParentGroup.Scene.GetScenePresence(localId);
                                if(av != null)
                                {
                                    if (av.LocalId == localId)
                                    {
                                        if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
                                        {
                                            bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                            //If it is 1, it is to accept ONLY collisions from this avatar
                                            if (found)
                                            {
                                                DetectedObject detobj = new DetectedObject();
                                                detobj.keyUUID = av.UUID;
                                                detobj.nameStr = av.ControllingClient.Name;
                                                detobj.ownerUUID = av.UUID;
                                                detobj.posVector = av.AbsolutePosition;
                                                detobj.rotQuat = av.Rotation;
                                                detobj.velVector = av.Velocity;
                                                detobj.colliderType = 0;
                                                detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                                colliding.Add(detobj);
                                            }
                                            //If it is 0, it is to not accept collisions from this avatar
                                            else
                                            {
                                            }
                                        }
                                        else
                                        {
                                            bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                            //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
                                            if (!found)
                                            {
                                                DetectedObject detobj = new DetectedObject();
                                                detobj.keyUUID = av.UUID;
                                                detobj.nameStr = av.ControllingClient.Name;
                                                detobj.ownerUUID = av.UUID;
                                                detobj.posVector = av.AbsolutePosition;
                                                detobj.rotQuat = av.Rotation;
                                                detobj.velVector = av.Velocity;
                                                detobj.colliderType = 0;
                                                detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                                colliding.Add(detobj);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (colliding.Count > 0)
                        {
                            EndCollidingMessage.Colliders = colliding;
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;

                            m_parentGroup.Scene.EventManager.TriggerScriptCollidingEnd(this, EndCollidingMessage);

                            if ((this.UUID != this.ParentGroup.RootPart.UUID))
                            {
                                const int PASS_IF_NOT_HANDLED = 0;
                                const int PASS_ALWAYS = 1;
                                const int PASS_NEVER = 2;
                                if (this.PassCollisions == PASS_NEVER)
                                {
                                }
                                if (this.PassCollisions == PASS_ALWAYS)
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptCollidingEnd(this.ParentGroup.RootPart, EndCollidingMessage);
                                }
                                else if (((this.ScriptEvents & scriptEvents.collision_end) == 0) && this.PassCollisions == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptCollidingEnd(this.ParentGroup.RootPart, EndCollidingMessage);
                                }
                            }
                        }
                    }
                }
                if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_start) != 0)
                {
                    if (startedColliders.Count > 0)
                    {
                        ColliderArgs LandStartCollidingMessage = new ColliderArgs();
                        List<DetectedObject> colliding = new List<DetectedObject>();
                        foreach (uint localId in startedColliders)
                        {
                            if (localId == 0)
                            {
                                //Hope that all is left is ground!
                                DetectedObject detobj = new DetectedObject();
                                detobj.keyUUID = UUID.Zero;
                                detobj.nameStr = "";
                                detobj.ownerUUID = UUID.Zero;
                                detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
                                detobj.rotQuat = Quaternion.Identity;
                                detobj.velVector = Vector3.Zero;
                                detobj.colliderType = 0;
                                detobj.groupUUID = UUID.Zero;
                                colliding.Add(detobj);
                            }
                        }

                        if (colliding.Count > 0)
                        {
                            LandStartCollidingMessage.Colliders = colliding;
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;

                            m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingStart(this, LandStartCollidingMessage);

                            if ((this.UUID != this.ParentGroup.RootPart.UUID))
                            {
                                const int PASS_IF_NOT_HANDLED = 0;
                                const int PASS_ALWAYS = 1;
                                const int PASS_NEVER = 2;
                                if (this.PassCollisions == PASS_NEVER)
                                {
                                }
                                if (this.PassCollisions == PASS_ALWAYS)
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingStart(this.ParentGroup.RootPart, LandStartCollidingMessage);
                                }
                                else if (((this.ScriptEvents & scriptEvents.land_collision_start) == 0) && this.PassCollisions == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingStart(this.ParentGroup.RootPart, LandStartCollidingMessage);
                                }
                            }
                        }
                    }
                }
                if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision) != 0)
                {
                    if (m_lastColliders.Count > 0)
                    {
                        ColliderArgs LandCollidingMessage = new ColliderArgs();
                        List<DetectedObject> colliding = new List<DetectedObject>();
                        foreach (uint localId in startedColliders)
                        {
                            if (localId == 0)
                            {
                                //Hope that all is left is ground!
                                DetectedObject detobj = new DetectedObject();
                                detobj.keyUUID = UUID.Zero;
                                detobj.nameStr = "";
                                detobj.ownerUUID = UUID.Zero;
                                detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
                                detobj.rotQuat = Quaternion.Identity;
                                detobj.velVector = Vector3.Zero;
                                detobj.colliderType = 0;
                                detobj.groupUUID = UUID.Zero;
                                colliding.Add(detobj);
                            }
                        }

                        if (colliding.Count > 0)
                        {
                            LandCollidingMessage.Colliders = colliding;
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;

                            m_parentGroup.Scene.EventManager.TriggerScriptLandColliding(this, LandCollidingMessage);

                            if ((this.UUID != this.ParentGroup.RootPart.UUID))
                            {
                                const int PASS_IF_NOT_HANDLED = 0;
                                const int PASS_ALWAYS = 1;
                                const int PASS_NEVER = 2;
                                if (this.PassCollisions == PASS_NEVER)
                                {
                                }
                                if (this.PassCollisions == PASS_ALWAYS)
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptColliding(this.ParentGroup.RootPart, LandCollidingMessage);
                                }
                                else if (((this.ScriptEvents & scriptEvents.land_collision) == 0) && this.PassCollisions == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptColliding(this.ParentGroup.RootPart, LandCollidingMessage);
                                }
                            }
                        }
                    }
                }
                if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_end) != 0)
                {
                    if (endedColliders.Count > 0)
                    {
                        ColliderArgs LandEndCollidingMessage = new ColliderArgs();
                        List<DetectedObject> colliding = new List<DetectedObject>();
                        foreach (uint localId in startedColliders)
                        {
                            if (localId == 0)
                            {
                                //Hope that all is left is ground!
                                DetectedObject detobj = new DetectedObject();
                                detobj.keyUUID = UUID.Zero;
                                detobj.nameStr = "";
                                detobj.ownerUUID = UUID.Zero;
                                detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
                                detobj.rotQuat = Quaternion.Identity;
                                detobj.velVector = Vector3.Zero;
                                detobj.colliderType = 0;
                                detobj.groupUUID = UUID.Zero;
                                colliding.Add(detobj);
                            }
                        }

                        if (colliding.Count > 0)
                        {
                            LandEndCollidingMessage.Colliders = colliding;
                            // always running this check because if the user deletes the object it would return a null reference.
                            if (m_parentGroup == null)
                                return;

                            if (m_parentGroup.Scene == null)
                                return;

                            m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd(this, LandEndCollidingMessage);

                            if ((this.UUID != this.ParentGroup.RootPart.UUID))
                            {
                                const int PASS_IF_NOT_HANDLED = 0;
                                const int PASS_ALWAYS = 1;
                                const int PASS_NEVER = 2;
                                if (this.PassCollisions == PASS_NEVER)
                                {
                                }
                                if (this.PassCollisions == PASS_ALWAYS)
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd(this.ParentGroup.RootPart, LandEndCollidingMessage);
                                }
                                else if (((this.ScriptEvents & scriptEvents.land_collision_end) == 0) && this.PassCollisions == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
                                {
                                    m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd(this.ParentGroup.RootPart, LandEndCollidingMessage);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        public void collision_end(uint localID, ColliderArgs col)
        {
            // Add to queue for all scripts in ObjectID object
            List<DetectParams> det = new List<DetectParams>();

            foreach (DetectedObject detobj in col.Colliders)
            {
                DetectParams d = DetectParams.FromDetectedObject(detobj);
                det.Add(d);
            }

            if (det.Count > 0)
                myScriptEngine.PostObjectEvent(localID, new EventParams(
                        "collision_end",
                        new Object[] { det.Count },
                        det.ToArray()));
        }
Esempio n. 13
0
        public void PhysicsCollision(EventArgs e)
        {
            // single threaded here
            if (e == null)
            {
                return;
            }

            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>();

            // calculate things that started colliding this time
            // and build up list of colliders this time
            foreach (uint localid in collissionswith.Keys)
            {
                if (localid != 0)
                {
                    thisHitColliders.Add(localid);
                    if (!m_lastColliders.Contains(localid))
                    {
                        startedColliders.Add(localid);
                    }

                    //m_log.Debug("[OBJECT]: 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 (m_parentGroup == null)
                return;
            if (m_parentGroup.IsDeleted)
                return;

            // play the sound.
            if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f)
            {
                SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0);
            }

            if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_start) != 0)
            {
                // do event notification
                if (startedColliders.Count > 0)
                {
                    ColliderArgs StartCollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in startedColliders)
                    {
                        // always running this check because if the user deletes the object it would return a null reference.
                        if (m_parentGroup == null)
                            return;
                        
                        if (m_parentGroup.Scene == null)
                            return;
                        
                        SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
                        if (obj != null)
                        {
                            DetectedObject detobj = new DetectedObject();
                            detobj.keyUUID = obj.UUID;
                            detobj.nameStr = obj.Name;
                            detobj.ownerUUID = obj._ownerID;
                            detobj.posVector = obj.AbsolutePosition;
                            detobj.rotQuat = obj.GetWorldRotation();
                            detobj.velVector = obj.Velocity;
                            detobj.colliderType = 0;
                            detobj.groupUUID = obj._groupID;
                            colliding.Add(detobj);
                        }
                        else
                        {
                            ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences();

                            for (int i = 0; i < avlist.Length; i++)
                            {
                                ScenePresence av = avlist[i];

                                if (av.LocalId == localId)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = av.UUID;
                                    detobj.nameStr = av.ControllingClient.Name;
                                    detobj.ownerUUID = av.UUID;
                                    detobj.posVector = av.AbsolutePosition;
                                    detobj.rotQuat = av.Rotation;
                                    detobj.velVector = av.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                    colliding.Add(detobj);
                                }
                            }
                        }
                    }
                    if (colliding.Count > 0)
                    {
                        StartCollidingMessage.Colliders = colliding;
                        // always running this check because if the user deletes the object it would return a null reference.
                        if (m_parentGroup == null)
                            return;
                        
                        if (m_parentGroup.Scene == null)
                            return;
                        
                        m_parentGroup.Scene.EventManager.TriggerScriptCollidingStart(LocalId, StartCollidingMessage);
                    }
                }
            }
            
            if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision) != 0)
            {
                if (m_lastColliders.Count > 0)
                {
                    ColliderArgs CollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in m_lastColliders)
                    {
                        // always running this check because if the user deletes the object it would return a null reference.
                        if (localId == 0)
                            continue;

                        if (m_parentGroup == null)
                            return;
                        
                        if (m_parentGroup.Scene == null)
                            return;
                        
                        SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
                        if (obj != null)
                        {
                            DetectedObject detobj = new DetectedObject();
                            detobj.keyUUID = obj.UUID;
                            detobj.nameStr = obj.Name;
                            detobj.ownerUUID = obj._ownerID;
                            detobj.posVector = obj.AbsolutePosition;
                            detobj.rotQuat = obj.GetWorldRotation();
                            detobj.velVector = obj.Velocity;
                            detobj.colliderType = 0;
                            detobj.groupUUID = obj._groupID;
                            colliding.Add(detobj);
                        }
                        else
                        {
                            ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences();
                            
                            for (int i = 0; i < avlist.Length; i++)
                            {
                                ScenePresence av = avlist[i];

                                if (av.LocalId == localId)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = av.UUID;
                                    detobj.nameStr = av.Name;
                                    detobj.ownerUUID = av.UUID;
                                    detobj.posVector = av.AbsolutePosition;
                                    detobj.rotQuat = av.Rotation;
                                    detobj.velVector = av.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                    colliding.Add(detobj);
                                }
                            }
                        }
                    }
                    if (colliding.Count > 0)
                    {
                        CollidingMessage.Colliders = colliding;
                        // always running this check because if the user deletes the object it would return a null reference.
                        if (m_parentGroup == null)
                            return;
                        
                        if (m_parentGroup.Scene == null)
                            return;
                        
                        m_parentGroup.Scene.EventManager.TriggerScriptColliding(LocalId, CollidingMessage);
                    }
                }
            }
            
            if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_end) != 0)
            {
                if (endedColliders.Count > 0)
                {
                    ColliderArgs EndCollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in endedColliders)
                    {
                        if (localId == 0)
                            continue;

                        // always running this check because if the user deletes the object it would return a null reference.
                        if (m_parentGroup == null)
                            return;
                        if (m_parentGroup.Scene == null)
                            return;
                        SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
                        if (obj != null)
                        {
                            DetectedObject detobj = new DetectedObject();
                            detobj.keyUUID = obj.UUID;
                            detobj.nameStr = obj.Name;
                            detobj.ownerUUID = obj._ownerID;
                            detobj.posVector = obj.AbsolutePosition;
                            detobj.rotQuat = obj.GetWorldRotation();
                            detobj.velVector = obj.Velocity;
                            detobj.colliderType = 0;
                            detobj.groupUUID = obj._groupID;
                            colliding.Add(detobj);
                        }
                        else
                        {
                            ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences();

                            for (int i = 0; i < avlist.Length; i++)
                            {
                                ScenePresence av = avlist[i];

                                if (av.LocalId == localId)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = av.UUID;
                                    detobj.nameStr = av.Name;
                                    detobj.ownerUUID = av.UUID;
                                    detobj.posVector = av.AbsolutePosition;
                                    detobj.rotQuat = av.Rotation;
                                    detobj.velVector = av.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                    colliding.Add(detobj);
                                }
                            }
                        }
                    }
                    
                    if (colliding.Count > 0)
                    {
                        EndCollidingMessage.Colliders = colliding;
                        // always running this check because if the user deletes the object it would return a null reference.
                        if (m_parentGroup == null)
                            return;
                        
                        if (m_parentGroup.Scene == null)
                            return;
                        
                        m_parentGroup.Scene.EventManager.TriggerScriptCollidingEnd(LocalId, EndCollidingMessage);
                    }
                }
            }
        }
Esempio n. 14
0
        public void land_collision_end(uint localID, ColliderArgs col)
        {
            List<DetectParams> det = new List<DetectParams>();

            foreach (DetectedObject detobj in col.Colliders)
            {
                DetectParams d = new DetectParams();
                d.Position = detobj.posVector;
                d.Populate(myScriptEngine.World);
                det.Add(d);
                myScriptEngine.PostObjectEvent(localID, new EventParams(
                        "land_collision_end",
                        new Object[] { new LSL_Types.Vector3(d.Position) },
                        det.ToArray()));
            }
         }
Esempio n. 15
0
 public void TriggerScriptLandCollidingEnd (ISceneChildEntity part, ColliderArgs colliders)
 {
     ScriptColliding handlerLandCollidingEnd = OnScriptLandColliderEnd;
     if (handlerLandCollidingEnd != null)
     {
         foreach (ScriptColliding d in handlerLandCollidingEnd.GetInvocationList ())
         {
             try
             {
                 d (part, colliders);
             }
             catch (Exception e)
             {
                 m_log.ErrorFormat (
                     "[EVENT MANAGER]: Delegate for TriggerScriptLandCollidingEnd failed - continuing.  {0} {1}",
                     e.ToString (), e.StackTrace);
             }
         }
     }
 }
Esempio n. 16
0
        private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify)
        {
            bool sendToRoot = true;

            ColliderArgs LandCollidingMessage = new ColliderArgs();
            List<DetectedObject> colliding = new List<DetectedObject>();
                
            colliding.Add(CreateDetObjectForGround());
            LandCollidingMessage.Colliders = colliding;

            if (Inventory.ContainsScripts())
            {
                if (!PassCollisions)
                    sendToRoot = false;
            }
            if ((ScriptEvents & ev) != 0)
                notify(LocalId, LandCollidingMessage);

            if ((ParentGroup.RootPart.ScriptEvents & ev) != 0 && sendToRoot)
            {
                notify(ParentGroup.RootPart.LocalId, LandCollidingMessage);
            }
        }
Esempio n. 17
0
        private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
        {
            ColliderArgs colliderArgs = new ColliderArgs();
            List<DetectedObject> colliding = new List<DetectedObject>();
            foreach (uint localId in colliders)
            {
                if (localId == 0)
                    continue;

                SceneObjectPart obj = m_scene.GetSceneObjectPart(localId);
                if (obj != null)
                {
                    if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
                        colliding.Add(CreateDetObject(obj));
                }
                else
                {
                    ScenePresence av = m_scene.GetScenePresence(localId);
                    if (av != null && (!av.IsChildAgent))
                    {
                        if (!dest.CollisionFilteredOut(av.UUID, av.Name))
                            colliding.Add(CreateDetObject(av));
                    }
                }
            }

            colliderArgs.Colliders = colliding;

            return colliderArgs;
        }
Esempio n. 18
0
 public void TriggerScriptCollidingStart(uint localId, ColliderArgs colliders)
 {
     handlerCollidingStart = OnScriptColliderStart;
     if (handlerCollidingStart != null)
         handlerCollidingStart(localId, colliders);
 }
Esempio n. 19
0
        public void PhysicsCollision(EventArgs e)
        {
//            m_log.DebugFormat("Invoking PhysicsCollision on {0} {1} {2}", Name, LocalId, UUID);

            // 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>();

            // calculate things that started colliding this time
            // and build up list of colliders this time
            foreach (uint localid in collissionswith.Keys)
            {
                thisHitColliders.Add(localid);
                if (!m_lastColliders.Contains(localid))
                {
                    startedColliders.Add(localid);
                }
                //m_log.Debug("[OBJECT]: 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 (ParentGroup.IsDeleted)
                return;

            // play the sound.
            if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f)
            {
                SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false);
            }

            if ((ParentGroup.RootPart.ScriptEvents & scriptEvents.collision_start) != 0)
            {
                // do event notification
                if (startedColliders.Count > 0)
                {
                    ColliderArgs StartCollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in startedColliders)
                    {
                        if (localId == 0)
                            continue;

                        if (ParentGroup.Scene == null)
                            return;

                        SceneObjectPart obj = ParentGroup.Scene.GetSceneObjectPart(localId);
                        string data = "";
                        if (obj != null)
                        {
                            if (ParentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString())
                                || ParentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
                            {
                                bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                //If it is 1, it is to accept ONLY collisions from this object
                                if (found)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = obj.UUID;
                                    detobj.nameStr = obj.Name;
                                    detobj.ownerUUID = obj.OwnerID;
                                    detobj.posVector = obj.AbsolutePosition;
                                    detobj.rotQuat = obj.GetWorldRotation();
                                    detobj.velVector = obj.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = obj.GroupID;
                                    colliding.Add(detobj);
                                }
                                //If it is 0, it is to not accept collisions from this object
                                else
                                {
                                }
                            }
                            else
                            {
                                bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
                                if (!found)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = obj.UUID;
                                    detobj.nameStr = obj.Name;
                                    detobj.ownerUUID = obj.OwnerID;
                                    detobj.posVector = obj.AbsolutePosition;
                                    detobj.rotQuat = obj.GetWorldRotation();
                                    detobj.velVector = obj.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = obj.GroupID;
                                    colliding.Add(detobj);
                                }
                            }
                        }
                        else
                        {
                            ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence av)
                            {
                                if (av.LocalId == localId)
                                {
                                    if (ParentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
                                        || ParentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
                                    {
                                        bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar
                                        if (found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                        //If it is 0, it is to not accept collisions from this avatar
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                        bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
                                        if (!found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                    }

                                }
                            });
                        }
                    }

                    if (colliding.Count > 0)
                    {
                        StartCollidingMessage.Colliders = colliding;

                        if (ParentGroup.Scene == null)
                            return;

//                        if (m_parentGroup.PassCollision == true)
//                        {
//                            //TODO: Add pass to root prim!
//                        }

                        ParentGroup.Scene.EventManager.TriggerScriptCollidingStart(LocalId, StartCollidingMessage);
                    }
                }
            }

            if ((ParentGroup.RootPart.ScriptEvents & scriptEvents.collision) != 0)
            {
                if (m_lastColliders.Count > 0)
                {
                    ColliderArgs CollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in m_lastColliders)
                    {
                        // always running this check because if the user deletes the object it would return a null reference.
                        if (localId == 0)
                            continue;
                        
                        if (ParentGroup.Scene == null)
                            return;
                        
                        SceneObjectPart obj = ParentGroup.Scene.GetSceneObjectPart(localId);
                        string data = "";
                        if (obj != null)
                        {
                            if (ParentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString())
                                || ParentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
                            {
                                bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
                                //If it is 1, it is to accept ONLY collisions from this object
                                if (found)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = obj.UUID;
                                    detobj.nameStr = obj.Name;
                                    detobj.ownerUUID = obj.OwnerID;
                                    detobj.posVector = obj.AbsolutePosition;
                                    detobj.rotQuat = obj.GetWorldRotation();
                                    detobj.velVector = obj.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = obj.GroupID;
                                    colliding.Add(detobj);
                                }
                                //If it is 0, it is to not accept collisions from this object
                                else
                                {
                                }
                            }
                            else
                            {
                                bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
                                //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
                                if (!found)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = obj.UUID;
                                    detobj.nameStr = obj.Name;
                                    detobj.ownerUUID = obj.OwnerID;
                                    detobj.posVector = obj.AbsolutePosition;
                                    detobj.rotQuat = obj.GetWorldRotation();
                                    detobj.velVector = obj.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = obj.GroupID;
                                    colliding.Add(detobj);
                                }
                            }
                        }
                        else
                        {
                            ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence av)
                            {
                                if (av.LocalId == localId)
                                {
                                    if (ParentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
                                        || ParentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
                                    {
                                        bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar
                                        if (found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                        //If it is 0, it is to not accept collisions from this avatar
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                        bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
                                        if (!found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                    }

                                }
                            });
                        }
                    }
                    if (colliding.Count > 0)
                    {
                        CollidingMessage.Colliders = colliding;
                        
                        if (ParentGroup.Scene == null)
                            return;
                        
                        ParentGroup.Scene.EventManager.TriggerScriptColliding(LocalId, CollidingMessage);
                    }
                }
            }
            
            if ((ParentGroup.RootPart.ScriptEvents & scriptEvents.collision_end) != 0)
            {
                if (endedColliders.Count > 0)
                {
                    ColliderArgs EndCollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in endedColliders)
                    {
                        if (localId == 0)
                            continue;

                        if (ParentGroup.Scene == null)
                            return;

                        SceneObjectPart obj = ParentGroup.Scene.GetSceneObjectPart(localId);
                        string data = "";
                        if (obj != null)
                        {
                            if (ParentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || ParentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
                            {
                                bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
                                //If it is 1, it is to accept ONLY collisions from this object
                                if (found)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = obj.UUID;
                                    detobj.nameStr = obj.Name;
                                    detobj.ownerUUID = obj.OwnerID;
                                    detobj.posVector = obj.AbsolutePosition;
                                    detobj.rotQuat = obj.GetWorldRotation();
                                    detobj.velVector = obj.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = obj.GroupID;
                                    colliding.Add(detobj);
                                }
                                //If it is 0, it is to not accept collisions from this object
                                else
                                {
                                }
                            }
                            else
                            {
                                bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
                                //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
                                if (!found)
                                {
                                    DetectedObject detobj = new DetectedObject();
                                    detobj.keyUUID = obj.UUID;
                                    detobj.nameStr = obj.Name;
                                    detobj.ownerUUID = obj.OwnerID;
                                    detobj.posVector = obj.AbsolutePosition;
                                    detobj.rotQuat = obj.GetWorldRotation();
                                    detobj.velVector = obj.Velocity;
                                    detobj.colliderType = 0;
                                    detobj.groupUUID = obj.GroupID;
                                    colliding.Add(detobj);
                                }
                            }
                        }
                        else
                        {
                            ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence av)
                            {
                                if (av.LocalId == localId)
                                {
                                    if (ParentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
                                        || ParentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
                                    {
                                        bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar
                                        if (found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                        //If it is 0, it is to not accept collisions from this avatar
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                        bool found = ParentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
                                        //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
                                        if (!found)
                                        {
                                            DetectedObject detobj = new DetectedObject();
                                            detobj.keyUUID = av.UUID;
                                            detobj.nameStr = av.ControllingClient.Name;
                                            detobj.ownerUUID = av.UUID;
                                            detobj.posVector = av.AbsolutePosition;
                                            detobj.rotQuat = av.Rotation;
                                            detobj.velVector = av.Velocity;
                                            detobj.colliderType = 0;
                                            detobj.groupUUID = av.ControllingClient.ActiveGroupId;
                                            colliding.Add(detobj);
                                        }
                                    }

                                }
                            });
                        }
                    }
                    
                    if (colliding.Count > 0)
                    {
                        EndCollidingMessage.Colliders = colliding;
                        
                        if (ParentGroup.Scene == null)
                            return;
                        
                        ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd(LocalId, EndCollidingMessage);
                    }
                }
            }

            if ((ParentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_start) != 0)
            {
                if (startedColliders.Count > 0)
                {
                    ColliderArgs LandStartCollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in startedColliders)
                    {
                        if (localId == 0)
                        {
                            //Hope that all is left is ground!
                            DetectedObject detobj = new DetectedObject();
                            detobj.keyUUID = UUID.Zero;
                            detobj.nameStr = "";
                            detobj.ownerUUID = UUID.Zero;
                            detobj.posVector = ParentGroup.RootPart.AbsolutePosition;
                            detobj.rotQuat = Quaternion.Identity;
                            detobj.velVector = Vector3.Zero;
                            detobj.colliderType = 0;
                            detobj.groupUUID = UUID.Zero;
                            colliding.Add(detobj);
                        }
                    }

                    if (colliding.Count > 0)
                    {
                        LandStartCollidingMessage.Colliders = colliding;

                        if (ParentGroup.Scene == null)
                            return;

                        ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart(LocalId, LandStartCollidingMessage);
                    }
                }
            }

            if ((ParentGroup.RootPart.ScriptEvents & scriptEvents.land_collision) != 0)
            {
                if (m_lastColliders.Count > 0)
                {
                    ColliderArgs LandCollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in startedColliders)
                    {
                        if (localId == 0)
                        {
                            //Hope that all is left is ground!
                            DetectedObject detobj = new DetectedObject();
                            detobj.keyUUID = UUID.Zero;
                            detobj.nameStr = "";
                            detobj.ownerUUID = UUID.Zero;
                            detobj.posVector = ParentGroup.RootPart.AbsolutePosition;
                            detobj.rotQuat = Quaternion.Identity;
                            detobj.velVector = Vector3.Zero;
                            detobj.colliderType = 0;
                            detobj.groupUUID = UUID.Zero;
                            colliding.Add(detobj);
                        }
                    }

                    if (colliding.Count > 0)
                    {
                        LandCollidingMessage.Colliders = colliding;

                        if (ParentGroup.Scene == null)
                            return;

                        ParentGroup.Scene.EventManager.TriggerScriptLandColliding(LocalId, LandCollidingMessage);
                    }
                }
            }

            if ((ParentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_end) != 0)
            {
                if (endedColliders.Count > 0)
                {
                    ColliderArgs LandEndCollidingMessage = new ColliderArgs();
                    List<DetectedObject> colliding = new List<DetectedObject>();
                    foreach (uint localId in startedColliders)
                    {
                        if (localId == 0)
                        {
                            //Hope that all is left is ground!
                            DetectedObject detobj = new DetectedObject();
                            detobj.keyUUID = UUID.Zero;
                            detobj.nameStr = "";
                            detobj.ownerUUID = UUID.Zero;
                            detobj.posVector = ParentGroup.RootPart.AbsolutePosition;
                            detobj.rotQuat = Quaternion.Identity;
                            detobj.velVector = Vector3.Zero;
                            detobj.colliderType = 0;
                            detobj.groupUUID = UUID.Zero;
                            colliding.Add(detobj);
                        }
                    }

                    if (colliding.Count > 0)
                    {
                        LandEndCollidingMessage.Colliders = colliding;

                        if (ParentGroup.Scene == null)
                            return;

                        ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd(LocalId, LandEndCollidingMessage);
                    }
                }
            }
        }
Esempio n. 20
0
 public void TriggerScriptColliding(uint localId, ColliderArgs colliders)
 {
     handlerColliding = OnScriptColliding;
     if (handlerColliding != null)
         handlerColliding(localId, colliders);
 }
Esempio n. 21
0
        public void land_collision_end (ISceneChildEntity part, ColliderArgs col)
        {
            List<DetectParams> det = new List<DetectParams>();

            foreach (DetectedObject detobj in col.Colliders)
            {
                DetectParams d = new DetectParams();
                d.Position = new LSL_Types.Vector3(detobj.posVector.X,
                    detobj.posVector.Y,
                    detobj.posVector.Z);
                d.Key = detobj.keyUUID;
                d.Populate(part.ParentEntity.Scene);
                d.LinkNum = part.LinkNum;
                det.Add(d);
            }
            if (det.Count != 0)
            {
                ScriptData[] datas = ScriptEngine.ScriptProtection.GetScripts(part.UUID);

                if (datas == null || datas.Length == 0)
                {
                    //datas = ScriptEngine.ScriptProtection.GetScripts(part.ParentGroup.RootPart.UUID);
                    //if (datas == null || datas.Length == 0)
                        return;
                }
                string functionName = "land_collision_end";
                object[] param = new Object[] { new LSL_Types.Vector3(det[0].Position) };

                foreach (ScriptData ID in datas)
                {
                    if (CheckIfEventShouldFire(ID, functionName, param))
                        m_scriptEngine.AddToScriptQueue(ID, functionName, det.ToArray(), EventPriority.FirstStart, param);
                }
            }
        }
Esempio n. 22
0
        public override bool HandleIn(RegionSyncModule pRegionContext)
        {
            if (base.HandleIn(pRegionContext))
            {
            ColliderArgs CollidingMessage = new ColliderArgs();
            CollidingMessage.Colliders = Colliders;

            // m_log.DebugFormat("ScriptLandCollidingStart received for {0}", CollideeID);
            pRegionContext.RememberLocallyGeneratedEvent(MType, CollideeID, CollidingMessage);
            pRegionContext.Scene.EventManager.TriggerScriptLandCollidingStart(CollideeID, CollidingMessage);
            pRegionContext.ForgetLocallyGeneratedEvent();
            }
            return true;
        }