Example #1
0
        public void ProcessRemovedBodies()
        {
            bool flag = this._bodyRemoveList.Count > 0;

            if (flag)
            {
                foreach (Body current in this._bodyRemoveList)
                {
                    Debug.Assert(this.BodyList.Count > 0);
                    bool flag2 = this._bodyAddList.Contains(current);
                    bool flag3 = !this.BodyList.Contains(current) && !flag2;
                    if (!flag3)
                    {
                        JointEdge jointEdge = current.JointList;
                        while (jointEdge != null)
                        {
                            JointEdge jointEdge2 = jointEdge;
                            jointEdge = jointEdge.Next;
                            this.RemoveJoint(jointEdge2.Joint, false);
                        }
                        current.JointList = null;
                        ContactEdge contactEdge = current.ContactList;
                        while (contactEdge != null)
                        {
                            ContactEdge contactEdge2 = contactEdge;
                            contactEdge = contactEdge.Next;
                            this.ContactManager.Destroy(contactEdge2.Contact);
                        }
                        current.ContactList = null;
                        for (int i = 0; i < current.FixtureList.Count; i++)
                        {
                            current.FixtureList[i].DestroyProxies(this.ContactManager.BroadPhase);
                            current.FixtureList[i].Destroy();
                        }
                        current.FixtureList = null;
                        bool flag4 = flag2;
                        if (flag4)
                        {
                            this._bodyAddList.Remove(current);
                        }
                        else
                        {
                            this.BodyList.Remove(current);
                        }
                        bool flag5 = this.BodyRemoved != null && current._specialSensor == BodySpecialSensor.None;
                        if (flag5)
                        {
                            this.BodyRemoved(current);
                        }
                    }
                }
                this._bodyRemoveList.Clear();
            }
        }
Example #2
0
        internal bool ShouldCollide(Body other)
        {
            bool flag = this._specialSensor != BodySpecialSensor.None || other._specialSensor > BodySpecialSensor.None;
            bool result;

            if (flag)
            {
                result = true;
            }
            else
            {
                bool flag2 = this._bodyType == BodyType.Static && other._bodyType == BodyType.Static;
                if (flag2)
                {
                    result = false;
                }
                else
                {
                    for (JointEdge jointEdge = this.JointList; jointEdge != null; jointEdge = jointEdge.Next)
                    {
                        bool flag3 = jointEdge.Other == other;
                        if (flag3)
                        {
                            bool flag4 = !jointEdge.Joint.CollideConnected;
                            if (flag4)
                            {
                                result = false;
                                return(result);
                            }
                        }
                    }
                    result = true;
                }
            }
            return(result);
        }
Example #3
0
        private void Solve(ref TimeStep step)
        {
            this.Island.Reset(this.BodyList.Count, this.ContactManager.ContactList.Count, this.JointList.Count, this.ContactManager);
            foreach (Body current in this.BodyList)
            {
                current._island = false;
            }
            foreach (Contact current2 in this.ContactManager.ContactList)
            {
                current2.IslandFlag = false;
            }
            foreach (Joint current3 in this.JointList)
            {
                current3.IslandFlag = false;
            }
            int  count = this.BodyList.Count;
            bool flag  = count > this._stack.Length;

            if (flag)
            {
                this._stack = new Body[Math.Max(this._stack.Length * 2, count)];
            }
            for (int i = this.BodyList.Count - 1; i >= 0; i--)
            {
                Body body   = this.BodyList[i];
                bool island = body._island;
                if (!island)
                {
                    bool flag2 = !body.Awake || !body.Enabled;
                    if (!flag2)
                    {
                        bool flag3 = body.BodyType == BodyType.Static;
                        if (!flag3)
                        {
                            this.Island.Clear();
                            int j = 0;
                            this._stack[j++] = body;
                            body._island     = true;
                            while (j > 0)
                            {
                                Body body2 = this._stack[--j];
                                Debug.Assert(body2.Enabled);
                                this.Island.Add(body2);
                                body2.Awake = true;
                                bool flag4 = body2.BodyType == BodyType.Static;
                                if (!flag4)
                                {
                                    for (ContactEdge contactEdge = body2.ContactList; contactEdge != null; contactEdge = contactEdge.Next)
                                    {
                                        Contact contact    = contactEdge.Contact;
                                        bool    islandFlag = contact.IslandFlag;
                                        if (!islandFlag)
                                        {
                                            bool flag5 = !contactEdge.Contact.Enabled || !contactEdge.Contact.IsTouching;
                                            if (!flag5)
                                            {
                                                bool isSensor  = contact.FixtureA.IsSensor;
                                                bool isSensor2 = contact.FixtureB.IsSensor;
                                                bool flag6     = isSensor | isSensor2;
                                                if (!flag6)
                                                {
                                                    this.Island.Add(contact);
                                                    contact.IslandFlag = true;
                                                    Body other   = contactEdge.Other;
                                                    bool island2 = other._island;
                                                    if (!island2)
                                                    {
                                                        Debug.Assert(j < count);
                                                        this._stack[j++] = other;
                                                        other._island    = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    for (JointEdge jointEdge = body2.JointList; jointEdge != null; jointEdge = jointEdge.Next)
                                    {
                                        bool islandFlag2 = jointEdge.Joint.IslandFlag;
                                        if (!islandFlag2)
                                        {
                                            Body other2 = jointEdge.Other;
                                            bool flag7  = other2 != null;
                                            if (flag7)
                                            {
                                                bool flag8 = !other2.Enabled;
                                                if (!flag8)
                                                {
                                                    this.Island.Add(jointEdge.Joint);
                                                    jointEdge.Joint.IslandFlag = true;
                                                    bool island3 = other2._island;
                                                    if (!island3)
                                                    {
                                                        Debug.Assert(j < count);
                                                        this._stack[j++] = other2;
                                                        other2._island   = true;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                this.Island.Add(jointEdge.Joint);
                                                jointEdge.Joint.IslandFlag = true;
                                            }
                                        }
                                    }
                                }
                            }
                            this.Island.Solve(ref step, ref this.Gravity);
                            for (int k = 0; k < this.Island.BodyCount; k++)
                            {
                                Body body3 = this.Island.Bodies[k];
                                bool flag9 = body3.BodyType == BodyType.Static;
                                if (flag9)
                                {
                                    body3._island = false;
                                }
                            }
                        }
                    }
                }
            }
            foreach (Body current4 in this.BodyList)
            {
                bool flag10 = !current4._island;
                if (!flag10)
                {
                    bool flag11 = current4.BodyType == BodyType.Static;
                    if (!flag11)
                    {
                        current4.SynchronizeFixtures();
                    }
                }
            }
            this.ContactManager.FindNewContacts();
        }