コード例 #1
0
        public virtual void SetActive(bool flag)
        {
            if (flag == IsActive())
            {
                return;
            }

            if (flag)
            {
                m_flags |= b2BodyFlags.e_activeFlag;

                // Create all proxies.
                b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase;
                for (b2Fixture f = m_fixtureList; f != null; f = f.Next)
                {
                    f.CreateProxies(broadPhase, m_xf);
                }

                // Contacts are created the next time step.
            }
            else
            {
                m_flags &= ~b2BodyFlags.e_activeFlag;

                // Destroy all proxies.
                b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase;
                for (b2Fixture f = m_fixtureList; f != null; f = f.Next)
                {
                    f.DestroyProxies(broadPhase);
                }

                // Destroy the attached contacts.
                b2ContactEdge ce = m_contactList;
                while (ce != null)
                {
                    b2ContactEdge ce0 = ce;
                    ce = ce.Next;
                    m_world.ContactManager.Destroy(ce0.Contact);
                }
                m_contactList = null;
            }
        }
コード例 #2
0
        public virtual void DestroyFixture(b2Fixture fixture)
        {
            Debug.Assert(m_world.IsLocked == false);
            if (m_world.IsLocked)
            {
                return;
            }

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

            // Remove the fixture from this body's singly linked list.
            Debug.Assert(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.
            Debug.Assert(found);

            // Destroy any contacts associated with the fixture.
            b2ContactEdge edge = m_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.
                    m_world.ContactManager.Destroy(c);
                }
            }


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

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

            --m_fixtureCount;

            // Reset the mass data.
            ResetMassData();
        }
コード例 #3
0
        public void DestroyBody(b2Body b)
        {
            if (IsLocked())
            {
                return;
            }

            // Delete the attached joints.
            b2JointEdge je = b.JointList;

            while (je)
            {
                b2JointEdge je0 = je;
                je = je.next;

                if (m_destructionListener != null)
                {
                    m_destructionListener.SayGoodbye(je0.joint);
                }

                DestroyJoint(je0.joint);

                b.JointList = je;
            }
            b.JointList = null;

            // Delete the attached contacts.
            b2ContactEdge ce = b.ContactList;

            while (ce)
            {
                b2ContactEdge ce0 = ce;
                ce = ce.next;
                m_contactManager.Destroy(ce0.contact);
            }
            b.ContactList = null;

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

            while (f != null)
            {
                b2Fixture f0 = f;
                f = f.Next;

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

                f0.DestroyProxies(m_contactManager.BroadPhase);

                b.FixtureList   = f;
                b.FixtureCount -= 1;
            }
            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 == m_bodyList)
            {
                m_bodyList = b.Next;
            }

            --m_bodyCount;
        }
コード例 #4
0
ファイル: b2Body.cs プロジェクト: homocury/cocos2d-xna
        public virtual void DestroyFixture(b2Fixture fixture)
        {
            Debug.Assert(m_world.IsLocked == false);
            if (m_world.IsLocked)
            {
                return;
            }

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

            // Remove the fixture from this body's singly linked list.
            Debug.Assert(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.
            Debug.Assert(found);

            // Destroy any contacts associated with the fixture.
            b2ContactEdge edge = m_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.
                    m_world.ContactManager.Destroy(c);
                }
            }

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

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

            --m_fixtureCount;

            // Reset the mass data.
            ResetMassData();
        }
コード例 #5
0
ファイル: b2Body.cs プロジェクト: Ratel13/cocos2d-x-for-xna
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();
}
コード例 #6
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();
        }