Ejemplo n.º 1
0
 public void PrepareSensorInteractions()
 {
     foreach (var dv in m_Interactions)
     {
         MySensorInteraction si = dv.Value;
         if (Active ||
             //si.m_RBElement.GetRigidBody() == null ||
             si.m_RBElement.GetRigidBody() != null &&
             (si.m_RBElement.GetRigidBody().ReadFlag(RigidBodyFlag.RBF_ACTIVE) || !si.m_RBElement.GetRigidBody().ReadFlag(RigidBodyFlag.RBF_INSERTED)))
         {
             si.m_IsInside = false;
         }
     }
 }
        public void RemoveSensorInteraction(MySensorInteraction si)
        {
            Debug.Assert(si.m_IsInUse);
            m_CurrentInteractions.Remove(si.m_Guid);
            m_InteractionsInUse.Remove(si.m_Guid);
            si.Close();
            switch (si.GetInteractionType())
            {
            case MySensorInteractionEnum.SI_SPHERE_SPHERE:
            {
                m_FreeSSSi.Push((MySphereSphereSensorInteraction)si);
            }
            break;

            case MySensorInteractionEnum.SI_SPHERE_BOX:
            {
                m_FreeSBSi.Push((MySphereBoxSensorInteraction)si);
            }
            break;

            case MySensorInteractionEnum.SI_BOX_SPHERE:
            {
                m_FreeBSSi.Push((MyBoxSphereSensorInteraction)si);
            }
            break;

            case MySensorInteractionEnum.SI_BOX_BOX:
            {
                m_FreeBBSi.Push((MyBoxBoxSensorInteraction)si);
            }
            break;

            case MySensorInteractionEnum.SI_BOX_OTHER:
            {
                m_FreeBOSi.Push((MyBoxOtherSensorInteraction)si);
            }
            break;

            case MySensorInteractionEnum.SI_SPHERE_OTHER:
            {
                m_FreeSOSi.Push((MySphereOtherSensorInteraction)si);
            }
            break;

            default:
                break;
            }
            m_interactionsInUse--;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if some interactions are not used anymore and removes them
        /// </summary>
        public void ParseSensorInteractions()
        {
            foreach (var sensor in m_Sensors)
            {
                m_RemoveList.Clear();
                foreach (var dv in sensor.m_Interactions)
                {
                    MySensorInteraction si = dv.Value;
                    if (si.m_IsInside == false)
                    {
                        // leave event
                        sensor.GetHandler().OnLeave(si.m_SensorElement.Sensor, si.m_RBElement.GetRigidBody(), si.m_RBElement);
                        m_RemoveList.Add(si.m_Guid);
                        MyPhysics.physicsSystem.GetSensorInteractionModule().RemoveSensorInteraction(si);
                    }
                }

                foreach (var guid in m_RemoveList)
                {
                    sensor.m_Interactions.Remove(guid);
                }
            }
        }
        /// <summary>
        /// adds new sensor interaction between sensor and rigid
        /// </summary>
        public void AddSensorInteraction(MySensorElement sensorElement, MyRBElement rbElement)
        {
            if (sensorElement.DetectRigidBodyTypes != null && rbElement.GetRigidBody().Type != sensorElement.DetectRigidBodyTypes.Value)
            {
                return;
            }

            MySensorInteraction si = null;

            int guid1 = sensorElement.GUID;
            int guid2 = rbElement.GUID;

            if (guid1 > guid2)
            {
                int tm = guid2;
                guid2 = guid1;
                guid1 = tm;
            }

            int guid = guid1 + (guid2 << 16);

            // if this interaction is in current interactions
            if (m_CurrentInteractions.ContainsKey(guid))
            {
                return;
            }

            //if (sensorElement.Sensor.m_Interactions.TryGetValue(guid, out si))
            //{
            //    Debug.Assert(guid == si.m_Guid);
            //    m_CurrentInteractions.Add(guid, si);
            //    return;
            //}

            if (m_InteractionsInUse.TryGetValue(guid, out si))
            {
                Debug.Assert(guid == si.m_Guid);
                m_CurrentInteractions.Add(guid, si);
                return;
            }

            switch (sensorElement.GetElementType())
            {
            case MySensorElementType.ET_SPHERE:
            {
                switch (rbElement.GetElementType())
                {
                case MyRBElementType.ET_SPHERE:
                {
                    if (m_FreeSSSi.Count == 0)
                    {
                        m_FreeSSSi.Push(new MySphereSphereSensorInteraction());
                        m_newAllocatedInteractions++;
                    }
                    si = m_FreeSSSi.Pop();
                }
                break;

                case MyRBElementType.ET_BOX:
                {
                    if (m_FreeSBSi.Count == 0)
                    {
                        m_FreeSBSi.Push(new MySphereBoxSensorInteraction());
                        m_newAllocatedInteractions++;
                    }
                    si = m_FreeSBSi.Pop();
                }
                break;

                default:
                {
                    if (m_FreeSOSi.Count == 0)
                    {
                        m_FreeSOSi.Push(new MySphereOtherSensorInteraction());
                        m_newAllocatedInteractions++;
                    }
                    si = m_FreeSOSi.Pop();
                }
                break;
                }
            }
            break;

            case MySensorElementType.ET_BOX:
                switch (rbElement.GetElementType())
                {
                case MyRBElementType.ET_SPHERE:
                {
                    if (m_FreeBSSi.Count == 0)
                    {
                        m_FreeBSSi.Push(new MyBoxSphereSensorInteraction());
                        m_newAllocatedInteractions++;
                    }
                    si = m_FreeBSSi.Pop();
                }
                break;

                case MyRBElementType.ET_BOX:
                {
                    if (m_FreeBBSi.Count == 0)
                    {
                        m_FreeBBSi.Push(new MyBoxBoxSensorInteraction());
                        m_newAllocatedInteractions++;
                    }
                    si = m_FreeBBSi.Pop();
                }
                break;

                default:
                {
                    if (m_FreeBOSi.Count == 0)
                    {
                        m_FreeBOSi.Push(new MyBoxOtherSensorInteraction());
                        m_newAllocatedInteractions++;
                    }
                    si = m_FreeBOSi.Pop();
                }
                break;
                }
                break;

            default:
                break;
            }

            if (si == null)
            {
                return;
            }

            Debug.Assert(!si.m_IsInUse);
            si.Init(sensorElement, rbElement);
            Debug.Assert(guid == si.m_Guid);
            m_CurrentInteractions.Add(guid, si);
            m_InteractionsInUse.Add(guid, si);
            m_interactionsInUse++;
            if (m_interactionsInUse > m_interactionsInUseMax)
            {
                m_interactionsInUseMax = m_interactionsInUse;
            }
        }
 public void RemoveSensorInteraction(MySensorInteraction si)
 {            
     Debug.Assert(si.m_IsInUse);            
     m_CurrentInteractions.Remove(si.m_Guid);
     m_InteractionsInUse.Remove(si.m_Guid);
     si.Close();
     switch (si.GetInteractionType())
     {
         case MySensorInteractionEnum.SI_SPHERE_SPHERE:
             {
                 m_FreeSSSi.Push((MySphereSphereSensorInteraction)si);
             }
             break;
         case MySensorInteractionEnum.SI_SPHERE_BOX:
             {
                 m_FreeSBSi.Push((MySphereBoxSensorInteraction)si);
             }
             break;
         case MySensorInteractionEnum.SI_BOX_SPHERE:
             {
                 m_FreeBSSi.Push((MyBoxSphereSensorInteraction)si);
             }
             break;
         case MySensorInteractionEnum.SI_BOX_BOX:
             {
                 m_FreeBBSi.Push((MyBoxBoxSensorInteraction)si);
             }
             break;
         case MySensorInteractionEnum.SI_BOX_OTHER:
             {
                 m_FreeBOSi.Push((MyBoxOtherSensorInteraction)si);
             }
             break;
         case MySensorInteractionEnum.SI_SPHERE_OTHER:
             { 
                 m_FreeSOSi.Push((MySphereOtherSensorInteraction)si);
             }
             break;
         default:
             break;
     }
     m_interactionsInUse--;
 }