void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
    if (_ownerEntity.expired()) {
        qDebug() << "warning -- action with no entity removing self from btCollisionWorld.";
        btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
        dynamicsWorld->removeAction(this);
        return;
    }

    if (_expires > 0) {
        quint64 now = usecTimestampNow();
        if (now > _expires) {
            EntityItemPointer ownerEntity = _ownerEntity.lock();
            _active = false;
            if (ownerEntity) {
                ownerEntity->removeAction(nullptr, getID());
            }
        }
    }

    if (!_active) {
        return;
    }

    updateActionWorker(deltaTimeStep);
}
Beispiel #2
0
void ObjectAction::updateAction(btCollisionWorld* collisionWorld, btScalar deltaTimeStep) {
    quint64 expiresWhen = 0;
    EntityItemPointer ownerEntity = nullptr;

    withReadLock([&]{
        ownerEntity = _ownerEntity.lock();
        expiresWhen = _expires;
    });

    if (!ownerEntity) {
        qCDebug(physics) << "warning -- action [" << _tag << "] with no entity removing self from btCollisionWorld.";
        btDynamicsWorld* dynamicsWorld = static_cast<btDynamicsWorld*>(collisionWorld);
        if (dynamicsWorld) {
            dynamicsWorld->removeAction(this);
        }
        return;
    }

    if (expiresWhen > 0) {
        quint64 now = usecTimestampNow();
        if (now > expiresWhen) {
            QUuid myID;
            withWriteLock([&]{
                _active = false;
                myID = getID();
            });
            if (ownerEntity) {
                ownerEntity->removeAction(nullptr, myID);
            }
        }
    }

    if (!_active) {
        return;
    }

    if (ownerEntity->getLocked()) {
        return;
    }

    updateActionWorker(deltaTimeStep);
}