void PhysicsWorld::updateJoints() { if (_info->isLocked()) { return; } for (auto joint : _delayAddJoints) { doAddJoint(joint); } for (auto joint : _delayRemoveJoints) { doRemoveJoint(joint); if (joint->_destoryMark) { delete joint; } } _delayAddJoints.clear(); _delayRemoveJoints.clear(); }
void PhysicsWorld::updateJoints() { if (cpSpaceIsLocked(_cpSpace)) { return; } for (auto joint : _delayAddJoints) { joint->_world = this; if (joint->initJoint()) { _joints.push_back(joint); } else { delete joint; } } _delayAddJoints.clear(); for (auto joint : _delayRemoveJoints) { doRemoveJoint(joint); } _delayRemoveJoints.clear(); }
void PhysicsWorld::removeJoint(PhysicsJoint* joint, bool destroy) { if (joint) { if (joint->getWorld() != this && destroy) { CCLOG("physics warning: the joint is not in this world, it won't be destroyed until the body it connects is destroyed"); return; } joint->_destoryMark = destroy; bool removedFromDelayAdd = false; auto it = std::find(_delayAddJoints.begin(), _delayAddJoints.end(), joint); if (it != _delayAddJoints.end()) { _delayAddJoints.erase(it); removedFromDelayAdd = true; } if (cpSpaceIsLocked(_cpSpace)) { if (removedFromDelayAdd) return; if (std::find(_delayRemoveJoints.rbegin(), _delayRemoveJoints.rend(), joint) == _delayRemoveJoints.rend()) { _delayRemoveJoints.push_back(joint); } } else { doRemoveJoint(joint); } } }
void PhysicsWorld::updateJoints() { if (m_pInfo->getSpace()->locked) { return; } for (auto joint : m_aDelayAddJoints) { doAddJoint(joint); } for (auto joint : m_aDelayRemoveJoints) { doRemoveJoint(joint); if (joint->m_bDestoryMark) { delete joint; } } m_aDelayAddJoints.clear(); m_aDelayRemoveJoints.clear(); }
void PhysicsWorld::updateJoints() { if (_info->isLocked()) { return; } auto addCopy = _delayAddJoints; _delayAddJoints.clear(); for (auto joint : addCopy) { doAddJoint(joint); } auto removeCopy = _delayRemoveJoints; _delayRemoveJoints.clear(); for (auto joint : removeCopy) { doRemoveJoint(joint); if (joint->_destoryMark) { delete joint; } } }
void PhysicsWorld::removeJointOrDelay(PhysicsJoint* joint) { auto it = std::find(_delayAddJoints.begin(), _delayAddJoints.end(), joint); if (it != _delayAddJoints.end()) { _delayAddJoints.erase(it); return; } if (_info->isLocked()) { if (std::find(_delayRemoveJoints.begin(), _delayRemoveJoints.end(), joint) == _delayRemoveJoints.end()) { _delayRemoveJoints.push_back(joint); _delayDirty = true; } }else { doRemoveJoint(joint); } }
void PhysicsWorld::removeJointOrDelay(PhysicsJoint* joint) { auto it = std::find(m_aDelayAddJoints.begin(), m_aDelayAddJoints.end(), joint); if (it != m_aDelayAddJoints.end()) { m_aDelayAddJoints.erase(it); return; } if (m_pInfo->getSpace()->locked) { if (std::find(m_aDelayRemoveJoints.begin(), m_aDelayRemoveJoints.end(), joint) == m_aDelayRemoveJoints.end()) { m_aDelayRemoveJoints.push_back(joint); m_bDelayDirty = true; } }else { doRemoveJoint(joint); } }