From 0a102575ee5a10a485fdca7069966e331e2bd5ab Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 1 May 2015 16:56:00 -0700 Subject: [PATCH] fix simulation ownership infection --- interface/src/Application.cpp | 5 ++++ interface/src/Application.h | 1 + libraries/physics/src/PhysicsEngine.cpp | 39 +++++++------------------ libraries/physics/src/PhysicsEngine.h | 5 ++++ 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b34ab3ce79..f4496424ee 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -432,6 +432,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : connect(nodeList.data(), &NodeList::nodeKilled, this, &Application::nodeKilled); connect(nodeList.data(), SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer))); connect(nodeList.data(), &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID); + connect(nodeList.data(), &NodeList::uuidChanged, this, &Application::setSessionUUID); connect(nodeList.data(), &NodeList::limitOfSilentDomainCheckInsReached, nodeList.data(), &NodeList::reset); connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &Application::notifyPacketVersionMismatch); @@ -3870,6 +3871,9 @@ bool Application::acceptURL(const QString& urlString) { return false; } +void Application::setSessionUUID(const QUuid& sessionUUID) { + _physicsEngine.setSessionUUID(sessionUUID); +} bool Application::askToSetAvatarUrl(const QString& url) { QUrl realUrl(url); @@ -4482,3 +4486,4 @@ void Application::friendsWindowClosed() { void Application::postLambdaEvent(std::function f) { QCoreApplication::postEvent(this, new LambdaEvent(f)); } + diff --git a/interface/src/Application.h b/interface/src/Application.h index 192b9cec25..b1c50250ea 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -351,6 +351,7 @@ signals: void beforeAboutToQuit(); public slots: + void setSessionUUID(const QUuid& sessionUUID); void domainChanged(const QString& domainHostname); void updateWindowTitle(); void nodeAdded(SharedNodePointer node); diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 01f3b41604..92db98a03f 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "ObjectMotionState.h" #include "PhysicsEngine.h" #include "PhysicsHelpers.h" @@ -245,41 +243,24 @@ void PhysicsEngine::stepSimulation() { } void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const btCollisionObject* objectB) { - /* TODO: Andrew to make this work for ObjectMotionState BT_PROFILE("ownershipInfection"); - assert(objectA); - assert(objectB); - - auto nodeList = DependencyManager::get(); - QUuid myNodeID = nodeList->getSessionUUID(); - const btCollisionObject* characterCollisionObject = - _characterController ? _characterController->getCollisionObject() : nullptr; - - assert(!myNodeID.isNull()); + if (_sessionID.isNull()) { + return; + } + const btCollisionObject* characterObject = _characterController ? _characterController->getCollisionObject() : nullptr; ObjectMotionState* a = static_cast(objectA->getUserPointer()); ObjectMotionState* b = static_cast(objectB->getUserPointer()); - EntityItem* entityA = a ? a->getEntity() : nullptr; - EntityItem* entityB = b ? b->getEntity() : nullptr; - bool aIsDynamic = entityA && !objectA->isStaticOrKinematicObject(); - bool bIsDynamic = entityB && !objectB->isStaticOrKinematicObject(); - // collisions cause infectious spread of simulation-ownership. we also attempt to take - // ownership of anything that collides with our avatar. - if ((aIsDynamic && (entityA->getSimulatorID() == myNodeID)) || - // (a && a->getShouldClaimSimulationOwnership()) || - (objectA == characterCollisionObject)) { - if (bIsDynamic) { - b->setShouldClaimSimulationOwnership(true); + if (b && ((a && !objectA->isStaticOrKinematicObject()) || (objectA == characterObject))) { + if (!objectB->isStaticOrKinematicObject()) { + b->bump(); } - } else if ((bIsDynamic && (entityB->getSimulatorID() == myNodeID)) || - // (b && b->getShouldClaimSimulationOwnership()) || - (objectB == characterCollisionObject)) { - if (aIsDynamic) { - a->setShouldClaimSimulationOwnership(true); + } else if (a && ((b && !objectB->isStaticOrKinematicObject()) || (objectB == characterObject))) { + if (!objectA->isStaticOrKinematicObject()) { + a->bump(); } } - */ } void PhysicsEngine::computeCollisionEvents() { diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index b05ebd05db..c470bc0331 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -14,6 +14,7 @@ #include +#include #include #include #include @@ -51,6 +52,8 @@ public: ~PhysicsEngine(); void init(); + void setSessionUUID(const QUuid& sessionID) { _sessionID = sessionID; } + void addObject(ObjectMotionState* motionState); void removeObject(ObjectMotionState* motionState); @@ -106,6 +109,8 @@ private: bool _dumpNextStats = false; bool _hasOutgoingChanges = false; + + QUuid _sessionID; }; #endif // hifi_PhysicsEngine_h