void CCPhysicsWorld::step(float dt) { cpSpaceStep(m_space, dt); for (CCPhysicsBodyMapIterator it = m_bodies.begin(); it != m_bodies.end(); ++it) { it->second->update(dt); } CCPhysicsBody *body; cpBody *cpbody; unsigned int count = m_removedShapes->count(); if (count) { for (unsigned int i = 0; i < count; ++i) { cpSpaceRemoveShape(m_space, static_cast<CCPhysicsShape*>(m_removedShapes->objectAtIndex(i))->getShape()); } m_removedShapes->removeAllObjects(); } count = m_addedBodies->count(); if (count) { for (unsigned int i = 0; i < count; ++i) { body = static_cast<CCPhysicsBody*>(m_addedBodies->objectAtIndex(i)); cpbody = body->getBody(); if (!cpBodyIsStatic(cpbody)) cpSpaceAddBody(m_space, cpbody); m_bodies[cpbody] = body; m_bodiesArray->addObject(body); } m_addedBodies->removeAllObjects(); } count = m_removedBodies->count(); if (count) { for (unsigned int i = 0; i < count; ++i) { cpbody = static_cast<CCPhysicsBody*>(m_removedBodies->objectAtIndex(i))->getBody(); if (!cpBodyIsRogue(cpbody)) { cpSpaceRemoveBody(m_space, cpbody); } } m_removedBodies->removeAllObjects(); } count = m_addedShapes->count(); if (count) { for (unsigned int i = 0; i < count; ++i) { cpSpaceAddShape(m_space, static_cast<CCPhysicsShape*>(m_addedShapes->objectAtIndex(i))->getShape()); } m_addedShapes->removeAllObjects(); } }
CCPhysicsBody *CCPhysicsWorld::getBodyByCpBody(cpBody *cpBody) { CCPhysicsBodyMapIterator it = m_bodies.find(cpBody); if (it != m_bodies.end()) { return it->second; } unsigned int count = m_removedBodies->count(); for (unsigned int i = 0; i < count; ++i) { CCPhysicsBody *body = static_cast<CCPhysicsBody*>(m_removedBodies->objectAtIndex(i)); if (body->getBody() == cpBody) { return body; } } CCLOG("NOT FOUND BODY 0x%08x", (unsigned int)cpBody); return NULL; }