Destroy() public method

public Destroy ( BroadPhase broadPhase ) : void
broadPhase Box2DX.Collision.BroadPhase
return void
Exemplo n.º 1
0
        /// <summary>
        /// Destroy a fixture. This removes the fixture from the broad-phase and
        /// therefore destroys any contacts associated with this fixture. All fixtures
        /// attached to a body are implicitly destroyed when the body is destroyed.
        /// @warning This function is locked during callbacks.
        /// </summary>
        /// <param name="fixture">The fixture to be removed.</param>
        public void DestroyFixture(Fixture fixture)
        {
            Box2DXDebug.Assert(_world._lock == false);
            if (_world._lock == true)
            {
                return;
            }

            Box2DXDebug.Assert(fixture.Body == this);

            // Remove the fixture from this body's singly linked list.
            Box2DXDebug.Assert(_fixtureCount > 0);
            Fixture node  = _fixtureList;
            Fixture prev  = null;
            bool    found = false;

            while (node != null)
            {
                if (node == fixture)
                {
                    if (prev == null)                       //We are root
                    {
                        _fixtureList = fixture.Next;
                    }
                    else
                    {
                        prev._next = fixture.Next;
                    }
                    found = true;
                    break;
                }

                prev = node;
                node = node.Next;
            }

            // You tried to remove a shape that is not attached to this body.
            Box2DXDebug.Assert(found);

            BroadPhase broadPhase = _world._broadPhase;

            fixture.Destroy(broadPhase);
            fixture._body = null;
            fixture._next = null;

            --_fixtureCount;
        }
Exemplo n.º 2
0
Arquivo: Body.cs Projeto: vb0067/LGame
        /// Destroy a fixture. This removes the fixture from the broad-phase and
        /// therefore destroys any contacts associated with this fixture. All fixtures
        /// attached to a body are implicitly destroyed when the body is destroyed.
        /// @param fixture the fixture to be removed.
        /// @warning This function is locked during callbacks.
        public void DestroyFixture(ref Fixture fixture)
        {
            Box2DXDebug.Assert(_world.IsLocked() == false);
            if (_world.IsLocked() == true)
            {
                return;
            }

            Box2DXDebug.Assert(fixture.Body == this);

            // Remove the fixture from this body's singly linked list.
            Box2DXDebug.Assert(_fixtureCount > 0);
            Fixture node  = _fixtureList;
            bool    found = false;

            while (node != null)
            {
                if (node == fixture)
                {
                    _fixtureList = fixture._next;
                    found        = true;
                    break;
                }

                node = node._next;
            }

            // You tried to remove a shape that is not attached to this body.
            Box2DXDebug.Assert(found);

            // Destroy any contacts associated with the fixture.
            ContactEdge edge = _contactList;

            while (edge != null)
            {
                Contact c = edge.Contact;
                edge = edge.Next;

                Fixture fixtureA = c.GetFixtureA();
                Fixture fixtureB = c.GetFixtureB();

                if (fixture == fixtureA || fixture == fixtureB)
                {
                    // This destroys the contact and removes it from
                    // this body's contact list.
                    _world._contactManager.Destroy(c);
                }
            }

            bool needMassUpdate = fixture._massData.Mass > 0.0f || fixture._massData.I > 0.0f;

            BroadPhase broadPhase = _world._contactManager._broadPhase;

            fixture.Destroy(broadPhase);
            fixture.Body  = null;
            fixture._next = null;

            --_fixtureCount;

            // Adjust mass properties if needed.
            if (needMassUpdate)
            {
                ResetMass();
            }
        }
Exemplo n.º 3
0
        /// Destroy a fixture. This removes the fixture from the broad-phase and
        /// therefore destroys any contacts associated with this fixture. All fixtures
        /// attached to a body are implicitly destroyed when the body is destroyed.
        /// @param fixture the fixture to be removed.
        /// @warning This function is locked during callbacks.
        public void DestroyFixture(ref Fixture fixture)
        {
            Box2DXDebug.Assert(_world.IsLocked() == false);
            if (_world.IsLocked() == true)
            {
                return;
            }

            Box2DXDebug.Assert(fixture.Body == this);

            // Remove the fixture from this body's singly linked list.
            Box2DXDebug.Assert(_fixtureCount > 0);
            Fixture node = _fixtureList;
            bool found = false;
            while (node != null)
            {
                if (node == fixture)
                {
                    _fixtureList = fixture._next;
                    found = true;
                    break;
                }

                node = node._next;
            }

            // You tried to remove a shape that is not attached to this body.
            Box2DXDebug.Assert(found);

            // Destroy any contacts associated with the fixture.
            ContactEdge edge = _contactList;
            while (edge != null)
            {
                Contact c = edge.Contact;
                edge = edge.Next;

                Fixture fixtureA = c.GetFixtureA();
                Fixture fixtureB = c.GetFixtureB();

                if (fixture == fixtureA || fixture == fixtureB)
                {
                    // This destroys the contact and removes it from
                    // this body's contact list.
                    _world._contactManager.Destroy(c);
                }
            }

            bool needMassUpdate = fixture._massData.Mass > 0.0f || fixture._massData.I > 0.0f;

            BroadPhase broadPhase = _world._contactManager._broadPhase;

            fixture.Destroy(broadPhase);
            fixture.Body = null;
            fixture._next = null;

            --_fixtureCount;

            // Adjust mass properties if needed.
            if (needMassUpdate)
            {
                ResetMass();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Destroy a fixture. This removes the fixture from the broad-phase and
        /// therefore destroys any contacts associated with this fixture. All fixtures
        /// attached to a body are implicitly destroyed when the body is destroyed.
        /// @warning This function is locked during callbacks.
        /// </summary>
        /// <param name="fixture">The fixture to be removed.</param>
        public void DestroyFixture(Fixture fixture)
        {
            Box2DXDebug.Assert(_world._lock == false);
            if (_world._lock == true)
            {
                return;
            }

            Box2DXDebug.Assert(fixture.Body == this);

            // Remove the fixture from this body's singly linked list.
            Box2DXDebug.Assert(_fixtureCount > 0);
            Fixture node = _fixtureList;
            Fixture prev = null;
            bool found = false;
            while (node != null)
            {
                if (node == fixture)
                {
                    if (prev == null) { //We are root
                        _fixtureList = fixture.Next;
                    } else {
                        prev._next = fixture.Next;
                    }
                    found = true;
                    break;
                }

                prev = node;
                node = node.Next;
            }

            // You tried to remove a shape that is not attached to this body.
            Box2DXDebug.Assert(found);

            BroadPhase broadPhase = _world._broadPhase;

            fixture.Destroy(broadPhase);
            fixture._body = null;
            fixture._next = null;

            --_fixtureCount;
        }
Exemplo n.º 5
0
        public void DestroyBody(Body b)
        {
            Box2DXDebug.Assert(_bodyCount > 0);
            Box2DXDebug.Assert(IsLocked() == false);
            if (IsLocked())
            {
                return;
            }

            // Delete the attached joints.
            JointEdge je = b._jointList;

            while (je != null)
            {
                JointEdge je0 = je;
                je = je.Next;

                if (_destructionListener != null)
                {
                    _destructionListener.SayGoodbye(je0.Joint);
                }

                DestroyJoint(je0.Joint);
            }
            b._jointList = null;

            // Delete the attached contacts.
            ContactEdge ce = b._contactList;

            while (ce != null)
            {
                ContactEdge ce0 = ce;
                ce = ce.Next;
                _contactManager.Destroy(ce0.Contact);
            }
            b._contactList = null;

            // Delete the attached fixtures. This destroys broad-phase proxies.
            Fixture f = b._fixtureList;

            while (f != null)
            {
                Fixture f0 = f;
                f = f._next;

                if (_destructionListener != null)
                {
                    _destructionListener.SayGoodbye(f0);
                }

                f0.Destroy(_contactManager._broadPhase);
                f0 = null;
            }
            b._fixtureList  = null;
            b._fixtureCount = 0;

            // Remove world body list.
            if (b._prev != null)
            {
                b._prev._next = b._next;
            }

            if (b._next != null)
            {
                b._next._prev = b._prev;
            }

            if (b == _bodyList)
            {
                _bodyList = b._next;
            }

            --_bodyCount;
            b = null;
        }