Example #1
0
void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIterations, quint64 maxUsec) {
    ++_frameCount;
    if (!_ragdoll) {
        return;
    }
    quint64 now = usecTimestampNow();
    quint64 startTime = now;
    quint64 expiry = startTime + maxUsec;

    moveRagdolls(deltaTime);
    enforceContacts();
    int numDolls = _otherRagdolls.size();
    {
        PerformanceTimer perfTimer("enforce");
        _ragdoll->enforceConstraints();
        for (int i = 0; i < numDolls; ++i) {
            _otherRagdolls[i]->enforceConstraints();
        }
    }

    bool collidedWithOtherRagdoll = false;
    int iterations = 0;
    float error = 0.0f;
    do {
        collidedWithOtherRagdoll = computeCollisions() || collidedWithOtherRagdoll;
        updateContacts();
        resolveCollisions();

        { // enforce constraints
            PerformanceTimer perfTimer("enforce");
            error = _ragdoll->enforceConstraints();
            for (int i = 0; i < numDolls; ++i) {
                error = glm::max(error, _otherRagdolls[i]->enforceConstraints());
            }
        }
        applyContactFriction();
        ++iterations;

        now = usecTimestampNow();
    } while (_collisions.size() != 0 && (iterations < maxIterations) && (error > minError) && (now < expiry));

    // the collisions may have moved the main ragdoll from the simulation center
    // so we remove this offset (potentially storing it as movement of the Ragdoll owner)
    _ragdoll->removeRootOffset(collidedWithOtherRagdoll);

    // also remove any offsets from the other ragdolls
    for (int i = 0; i < numDolls; ++i) {
        _otherRagdolls[i]->removeRootOffset(false);
    }
    pruneContacts();
}
Example #2
0
void ContactListModel::Private::commit()
{
    SLOW_TIMER(100);

    commitTimerStartTime = QDateTime();

    commitTimer->stop();
    if (operationQueue.isEmpty())
        return;

    QHashIterator<PsiContact*, int> it(operationQueue);

    QList<PsiContact*> contactsForAdding;
    QList<PsiContact*> contactsForUpdate;


    while (it.hasNext()) {
        it.next();
        PsiContact *contact = it.key();

        int operations = simplifiedOperationList(it.value());
        if (operations & AddContact) {
            Q_ASSERT(!monitoredContacts.contains(contact));
            if (monitoredContacts.contains(contact))
                continue;

            contactsForAdding << contact;

        }
        if (operations & RemoveContact)
            Q_ASSERT(false);
        if (operations & UpdateContact)
            contactsForUpdate << contact;
        if (operations & ContactGroupsChanged) {
            removeContact(contact);
            if (!contactsForAdding.contains(contact)) {
                contactsForAdding << contact;
            }
        }
    }

    addContacts(contactsForAdding);
    updateContacts(contactsForUpdate);
    operationQueue.clear();
}
Example #3
0
void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIterations, quint64 maxUsec) {
    ++_frameCount;
    if (!_ragdoll) {
        return;
    }
    quint64 now = usecTimestampNow();
    quint64 startTime = now;
    quint64 expiry = startTime + maxUsec;

    moveRagdolls(deltaTime);
    buildContactConstraints();
    int numDolls = _otherRagdolls.size();
    {
        PerformanceTimer perfTimer("enforce");
        _ragdoll->enforceRagdollConstraints();
        for (int i = 0; i < numDolls; ++i) {
            _otherRagdolls[i]->enforceRagdollConstraints();
        }
    }

    int iterations = 0;
    float error = 0.0f;
    do {
        computeCollisions();
        updateContacts();
        resolveCollisions();

        { // enforce constraints
            PerformanceTimer perfTimer("enforce");
            error = _ragdoll->enforceRagdollConstraints();
            for (int i = 0; i < numDolls; ++i) {
                error = glm::max(error, _otherRagdolls[i]->enforceRagdollConstraints());
            }
        }
        enforceContactConstraints();
        ++iterations;

        now = usecTimestampNow();
    } while (_collisions.size() != 0 && (iterations < maxIterations) && (error > minError) && (now < expiry));

    pruneContacts();
}
Example #4
0
SeasideCache::SeasideCache()
    : m_manager(managerName())
#ifdef HAS_MLITE
    , m_displayLabelOrderConf(QLatin1String("/org/nemomobile/contacts/display_label_order"))
#endif
    , m_resultsRead(0)
    , m_populated(0)
    , m_cacheIndex(0)
    , m_queryIndex(0)
    , m_selfId(0)
    , m_fetchFilter(SeasideFilteredModel::FilterFavorites)
    , m_displayLabelOrder(SeasideFilteredModel::FirstNameFirst)
    , m_updatesPending(true)
    , m_refreshRequired(false)
{
    Q_ASSERT(!instance);
    instance = this;

    m_timer.start();

#ifdef HAS_MLITE
    connect(&m_displayLabelOrderConf, SIGNAL(valueChanged()), this, SLOT(displayLabelOrderChanged()));
    QVariant displayLabelOrder = m_displayLabelOrderConf.value();
    if (displayLabelOrder.isValid())
        m_displayLabelOrder = SeasideFilteredModel::DisplayLabelOrder(displayLabelOrder.toInt());
#endif

    connect(&m_manager, SIGNAL(dataChanged()), this, SLOT(updateContacts()));
    connect(&m_manager, SIGNAL(contactsChanged(QList<QContactLocalId>)),
            this, SLOT(updateContacts(QList<QContactLocalId>)));
    connect(&m_manager, SIGNAL(contactsAdded(QList<QContactLocalId>)),
            this, SLOT(updateContacts(QList<QContactLocalId>)));
    connect(&m_manager, SIGNAL(contactsRemoved(QList<QContactLocalId>)),
            this, SLOT(contactsRemoved(QList<QContactLocalId>)));

    connect(&m_fetchRequest, SIGNAL(resultsAvailable()), this, SLOT(contactsAvailable()));
    connect(&m_contactIdRequest, SIGNAL(resultsAvailable()), this, SLOT(contactIdsAvailable()));

    connect(&m_fetchRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
            this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
    connect(&m_contactIdRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
            this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
    connect(&m_removeRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
            this, SLOT(requestStateChanged(QContactAbstractRequest::State)));
    connect(&m_saveRequest, SIGNAL(stateChanged(QContactAbstractRequest::State)),
            this, SLOT(requestStateChanged(QContactAbstractRequest::State)));

    m_fetchRequest.setManager(&m_manager);
    m_removeRequest.setManager(&m_manager);
    m_saveRequest.setManager(&m_manager);

#ifdef SEASIDE_SPARQL_QUERIES
    m_contactIdRequest.setQueryData(true);
    m_contactIdRequest.setFavoritesOnly(true);
    m_contactIdRequest.setSortOnFirstName(m_displayLabelOrder == SeasideFilteredModel::FirstNameFirst);

    m_contactIdRequest.start();
#else
    m_selfId = m_manager.selfContactId();
    m_contactIdRequest.setManager(&m_manager);

    QContactFetchHint fetchHint;
    fetchHint.setOptimizationHints(QContactFetchHint::NoRelationships
            | QContactFetchHint::NoActionPreferences
            | QContactFetchHint::NoBinaryBlobs);
    fetchHint.setDetailDefinitionsHint(QStringList()
            << QContactName::DefinitionName
            << QContactAvatar::DefinitionName
            << QContactPhoneNumber::DefinitionName
            << QContactEmailAddress::DefinitionName
            << QContactOrganization::DefinitionName
            << QContactOnlineAccount::DefinitionName);

    m_fetchRequest.setFetchHint(fetchHint);
    m_fetchRequest.setFilter(QContactFavorite::match());

    QContactSortOrder firstLabelOrder;
    firstLabelOrder.setDetailDefinitionName(
                QContactName::DefinitionName, QContactName::FieldFirstName);
    firstLabelOrder.setCaseSensitivity(Qt::CaseInsensitive);
    firstLabelOrder.setDirection(Qt::AscendingOrder);
    firstLabelOrder.setBlankPolicy(QContactSortOrder::BlanksFirst);

    QContactSortOrder secondLabelOrder;
    secondLabelOrder.setDetailDefinitionName(
                QContactName::DefinitionName, QContactName::FieldLastName);
    secondLabelOrder.setCaseSensitivity(Qt::CaseInsensitive);
    secondLabelOrder.setDirection(Qt::AscendingOrder);
    secondLabelOrder.setBlankPolicy(QContactSortOrder::BlanksFirst);

    QList<QContactSortOrder> sorting = m_displayLabelOrder == SeasideFilteredModel::FirstNameFirst
            ? (QList<QContactSortOrder>() << firstLabelOrder << secondLabelOrder)
            : (QList<QContactSortOrder>() << secondLabelOrder << firstLabelOrder);

    m_fetchRequest.setSorting(sorting);
    m_contactIdRequest.setSorting(sorting);

    m_fetchRequest.start();
#endif

}
Example #5
0
void NounShip::updateShip( dword nTick )
{
	PROFILE_FUNCTION();

	// update despawn/docking logic..
	updateDespawn();
	// update the ships gadgets
	updateGadgets( nTick );
	// update high-level AI
	updateLogic( nTick );		

	// repair / reload ship when in orbit
	if ( nTick >= m_nRepairTick )
	{
		m_nRepairTick = nTick + DEFAULT_REPAIR_RATE;
		if ( inOrbit() )
		{
			// handle ship repairs when in orbit around friendly planet with a ship yard
			NounPlanet * pPlanet = WidgetCast<NounPlanet>( orbiting() );
			if ( pPlanet != NULL )
			{
				if ( pPlanet->isFriend( this ) )
				{
					repair( pPlanet, PLANET_REPAIR_RATE, true );
					reload( pPlanet );
				}
				else if ( (pPlanet->flags() & NounPlanet::FLAG_HYDROGEN) != 0 )
				{
					// if planet has hydrogen, then refuel the jump drive
					if ( jumpDrive() != NULL )
						jumpDrive()->reload( pPlanet );
				}
			}
		}
	}

	if ( nTick >= m_nUpdateTick )
	{
		m_nUpdateTick = nTick + SHIP_UPDATE_RATE;
		// update characteristics
		updateCharacter();
		// update low-level AI
		updateCommand();
		// update the repair queue
		updateRepairQueue();
		// update the contact list
		updateContacts();
		// drain off some damage from the damage list
		updateThreats();
	}

	if ( m_bIncoming )
	{
		ASSERT( userId() == 0 );
		avoidCollision();
		m_bIncoming = false;
	}

	updatePointDefense();
	updateFireCheck();

}