Exemple #1
0
        public virtual void DestroyFixture(b2Fixture fixture)
        {
            Debug.Assert(World.IsLocked == false);
            if (World.IsLocked)
            {
                return;
            }

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

            // Remove the fixture from this body's singly linked list.
            Debug.Assert(FixtureCount > 0);
            bool found = false;

            if (fixture == FixtureList)
            {
                FixtureList = fixture.Next;
                found       = true;
            }
            else
            {
                var node = FixtureList;
                while (node.Next != null)
                {
                    if (node.Next == fixture)
                    {
                        node.Next = fixture.Next;
                        found     = true;
                        break;
                    }
                }
            }

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

            // Destroy any contacts associated with the fixture.
            b2ContactEdge edge = ContactList;

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

                b2Fixture fixtureA = c.FixtureA;
                b2Fixture fixtureB = c.FixtureB;

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


            if ((BodyFlags & b2BodyFlags.e_activeFlag) != 0)
            {
                b2BroadPhase broadPhase = World.ContactManager.BroadPhase;
                fixture.DestroyProxies(broadPhase);
            }

            fixture.Destroy();

            fixture.Body = null;
            fixture.Next = null;

            --FixtureCount;

            // Reset the mass data.
            ResetMassData();
        }
Exemple #2
0
public virtual void DestroyFixture(b2Fixture fixture)
{
    b2Assert(m_world.IsLocked() == false);
    if (m_world.IsLocked() == true)
    {
        return;
    }

    b2Assert(fixture.m_body == this);

    // Remove the fixture from this body's singly linked list.
    b2Assert(m_fixtureCount > 0);
    b2Fixture* node = &m_fixtureList;
    bool found = false;
    while (*node != null)
    {
        if (*node == fixture)
        {
            *node = fixture.Next;
            found = true;
            break;
        }

        node = &(*node).Next;
    }

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

    // Destroy any contacts associated with the fixture.
    b2ContactEdge* edge = m_contactList;
    while (edge)
    {
        b2Contact* c = edge.contact;
        edge = edge.next;

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

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

    b2BlockAllocator* allocator = m_world.m_blockAllocator;

    if (m_flags & e_activeFlag)
    {
        b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase;
        fixture.DestroyProxies(broadPhase);
    }

    fixture.Destroy(allocator);
    fixture.m_body = null;
    fixture.Next = null;
    fixture.~b2Fixture();
    allocator.Free(fixture, sizeof(b2Fixture));

    --m_fixtureCount;

    // Reset the mass data.
    ResetMassData();
}
Exemple #3
0
        public virtual void DestroyFixture(b2Fixture fixture)
        {
            b2Assert(m_world.IsLocked() == false);
            if (m_world.IsLocked() == true)
            {
                return;
            }

            b2Assert(fixture.m_body == this);

            // Remove the fixture from this body's singly linked list.
            b2Assert(m_fixtureCount > 0);
            b2Fixture *node  = &m_fixtureList;
            bool       found = false;

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

                node = &(*node).Next;
            }

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

            // Destroy any contacts associated with the fixture.
            b2ContactEdge *edge = m_contactList;

            while (edge)
            {
                b2Contact *c = edge.contact;
                edge = edge.next;

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

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

            b2BlockAllocator *allocator = m_world.m_blockAllocator;

            if (m_flags & e_activeFlag)
            {
                b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase;
                fixture.DestroyProxies(broadPhase);
            }

            fixture.Destroy(allocator);
            fixture.m_body = null;
            fixture.Next   = null;
            fixture.~b2Fixture();
            allocator.Free(fixture, sizeof(b2Fixture));

            --m_fixtureCount;

            // Reset the mass data.
            ResetMassData();
        }