void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
{
    if (_delayAddBodies.getIndex(body) != CC_INVALID_INDEX)
    {
        _delayAddBodies.eraseObject(body);
        return;
    }
    
    if (cpSpaceIsLocked(_cpSpace))
    {
        if (_delayRemoveBodies.getIndex(body) == CC_INVALID_INDEX)
        {
            _delayRemoveBodies.pushBack(body);
        }
    }else
    {
        doRemoveBody(body);
    }
}
Esempio n. 2
0
void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
{
    if (_delayAddBodies.getIndex(body) != CC_INVALID_INDEX)
    {
        _delayAddBodies.eraseObject(body);
        return;
    }
    
    if (_info->isLocked())
    {
        if (_delayRemoveBodies.getIndex(body) == CC_INVALID_INDEX)
        {
            _delayRemoveBodies.pushBack(body);
            _delayDirty = true;
        }
    }else
    {
        doRemoveBody(body);
    }
}
Esempio n. 3
0
void PhysicsWorld::updateBodies()
{
    if (_info->isLocked())
    {
        return;
    }
    
    for (auto& body : _delayAddBodies)
    {
        doAddBody(body);
    }
    
    for (auto& body : _delayRemoveBodies)
    {
        doRemoveBody(body);
    }
    
    _delayAddBodies.clear();
    _delayRemoveBodies.clear();
}
void PhysicsWorld::updateBodies()
{
    if (_info->getSpace()->locked_private)
    {
        return;
    }
    
    for (auto body : *_delayAddBodies)
    {
        doAddBody(dynamic_cast<PhysicsBody*>(body));
    }
    
    for (auto body : *_delayRemoveBodies)
    {
        doRemoveBody(dynamic_cast<PhysicsBody*>(body));
    }
    
    _delayAddBodies->removeAllObjects();
    _delayRemoveBodies->removeAllObjects();
}
void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
{
    if (_delayAddBodies->getIndexOfObject(body) != CC_INVALID_INDEX)
    {
        _delayAddBodies->removeObject(body);
        return;
    }
    
    if (_info->getSpace()->locked_private)
    {
        if (_delayRemoveBodies->getIndexOfObject(body) == CC_INVALID_INDEX)
        {
            _delayRemoveBodies->addObject(body);
            _delayDirty = true;
        }
    }else
    {
        doRemoveBody(body);
    }
}
void PhysicsWorld::updateBodies()
{
    if (m_pInfo->getSpace()->locked)
    {
        return;
    }
    
    for (auto body : *m_pDelayAddBodies)
    {
        doAddBody(dynamic_cast<PhysicsBody*>(body));
    }
    
    for (auto body : *m_pDelayRemoveBodies)
    {
        doRemoveBody(dynamic_cast<PhysicsBody*>(body));
    }
    
    m_pDelayAddBodies->removeAllObjects();
    m_pDelayRemoveBodies->removeAllObjects();
}
void PhysicsWorld::updateBodies()
{
    if (cpSpaceIsLocked(_cpSpace))
    {
        return;
    }
    
    // issue #4944, contact callback will be invoked when add/remove body, _delayAddBodies maybe changed, so we need make a copy.
    auto addCopy = _delayAddBodies;
    _delayAddBodies.clear();
    for (auto& body : addCopy)
    {
        doAddBody(body);
    }
    
    auto removeCopy = _delayRemoveBodies;
    _delayRemoveBodies.clear();
    for (auto& body : removeCopy)
    {
        doRemoveBody(body);
    }
}