void PhysicsWorld::DestroyBody(RigidBody &body) { GV_ASSERT(body.mWorld == this); // destroy associated joints while (!body.mJointEdges.empty()) DestroyJoint(*body.mJointEdges.pop_front()->joint); body.~RigidBody(); mBodyAllocator.Free(&body); }
void b2World::CleanBodyList() { m_contactManager.m_destroyImmediate = true; b2Body* b = m_bodyDestroyList; while (b) { b2Assert((b->m_flags & b2Body::e_destroyFlag) != 0); // Preserve the next pointer. b2Body* b0 = b; b = b->m_next; // Delete the attached joints b2JointNode* jn = b0->m_jointList; while (jn) { b2JointNode* jn0 = jn; jn = jn->next; if (m_listener) { m_listener->NotifyJointDestroyed(jn0->joint); } DestroyJoint(jn0->joint); } b0->~b2Body(); m_blockAllocator.Free(b0, sizeof(b2Body)); } // Reset the list. m_bodyDestroyList = NULL; m_contactManager.m_destroyImmediate = false; }
void b2World::DestroyBody(b2Body* b) { b2Assert(m_bodyCount > 0); b2Assert(IsLocked() == false); if (IsLocked()) { return; } // Delete the attached joints. b2JointEdge* je = b->m_jointList; while (je) { b2JointEdge* je0 = je; je = je->next; if (m_destructionListener) { m_destructionListener->SayGoodbye(je0->joint); } DestroyJoint(je0->joint); b->m_jointList = je; } b->m_jointList = NULL; // Delete the attached contacts. b2ContactEdge* ce = b->m_contactList; while (ce) { b2ContactEdge* ce0 = ce; ce = ce->next; m_contactManager.Destroy(ce0->contact); } b->m_contactList = NULL; // Delete the attached fixtures. This destroys broad-phase proxies. b2Fixture* f = b->m_fixtureList; while (f) { b2Fixture* f0 = f; f = f->m_next; if (m_destructionListener) { m_destructionListener->SayGoodbye(f0); } f0->DestroyProxies(&m_contactManager.m_broadPhase); f0->Destroy(&m_blockAllocator); f0->~b2Fixture(); m_blockAllocator.Free(f0, sizeof(b2Fixture)); b->m_fixtureList = f; b->m_fixtureCount -= 1; } b->m_fixtureList = NULL; b->m_fixtureCount = 0; // Remove world body list. if (b->m_prev) { b->m_prev->m_next = b->m_next; } if (b->m_next) { b->m_next->m_prev = b->m_prev; } if (b == m_bodyList) { m_bodyList = b->m_next; } --m_bodyCount; b->~b2Body(); m_blockAllocator.Free(b, sizeof(b2Body)); }
void b2World::DestroyBody(b2Body* b) { b2Assert(m_bodyCount > 0); b2Assert(m_lock == false); if (m_lock == true) { return; } // Delete the attached joints. b2JointEdge* jn = b->m_jointList; while (jn) { b2JointEdge* jn0 = jn; jn = jn->next; if (m_destructionListener) { m_destructionListener->SayGoodbye(jn0->joint); } DestroyJoint(jn0->joint); } //Detach controllers attached to this body b2ControllerEdge* ce = b->m_controllerList; while(ce) { b2ControllerEdge* ce0 = ce; ce = ce->nextController; ce0->controller->RemoveBody(b); } // Delete the attached shapes. This destroys broad-phase // proxies and pairs, leading to the destruction of contacts. b2Shape* s = b->m_shapeList; while (s) { b2Shape* s0 = s; s = s->m_next; if (m_destructionListener) { m_destructionListener->SayGoodbye(s0); } s0->DestroyProxy(m_broadPhase); b2Shape::Destroy(s0, &m_blockAllocator); } // Remove world body list. if (b->m_prev) { b->m_prev->m_next = b->m_next; } if (b->m_next) { b->m_next->m_prev = b->m_prev; } if (b == m_bodyList) { m_bodyList = b->m_next; } --m_bodyCount; b->~b2Body(); m_blockAllocator.Free(b, sizeof(b2Body)); }