fix simulation ownership infection

This commit is contained in:
Andrew Meadows 2015-05-01 16:56:00 -07:00
parent 42ec39c578
commit 0a102575ee
4 changed files with 21 additions and 29 deletions

View file

@ -432,6 +432,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
connect(nodeList.data(), &NodeList::nodeKilled, this, &Application::nodeKilled); connect(nodeList.data(), &NodeList::nodeKilled, this, &Application::nodeKilled);
connect(nodeList.data(), SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer))); connect(nodeList.data(), SIGNAL(nodeKilled(SharedNodePointer)), SLOT(nodeKilled(SharedNodePointer)));
connect(nodeList.data(), &NodeList::uuidChanged, _myAvatar, &MyAvatar::setSessionUUID); 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::limitOfSilentDomainCheckInsReached, nodeList.data(), &NodeList::reset);
connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &Application::notifyPacketVersionMismatch); connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &Application::notifyPacketVersionMismatch);
@ -3870,6 +3871,9 @@ bool Application::acceptURL(const QString& urlString) {
return false; return false;
} }
void Application::setSessionUUID(const QUuid& sessionUUID) {
_physicsEngine.setSessionUUID(sessionUUID);
}
bool Application::askToSetAvatarUrl(const QString& url) { bool Application::askToSetAvatarUrl(const QString& url) {
QUrl realUrl(url); QUrl realUrl(url);
@ -4482,3 +4486,4 @@ void Application::friendsWindowClosed() {
void Application::postLambdaEvent(std::function<void()> f) { void Application::postLambdaEvent(std::function<void()> f) {
QCoreApplication::postEvent(this, new LambdaEvent(f)); QCoreApplication::postEvent(this, new LambdaEvent(f));
} }

View file

@ -351,6 +351,7 @@ signals:
void beforeAboutToQuit(); void beforeAboutToQuit();
public slots: public slots:
void setSessionUUID(const QUuid& sessionUUID);
void domainChanged(const QString& domainHostname); void domainChanged(const QString& domainHostname);
void updateWindowTitle(); void updateWindowTitle();
void nodeAdded(SharedNodePointer node); void nodeAdded(SharedNodePointer node);

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <AABox.h>
#include "ObjectMotionState.h" #include "ObjectMotionState.h"
#include "PhysicsEngine.h" #include "PhysicsEngine.h"
#include "PhysicsHelpers.h" #include "PhysicsHelpers.h"
@ -245,41 +243,24 @@ void PhysicsEngine::stepSimulation() {
} }
void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const btCollisionObject* objectB) { void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const btCollisionObject* objectB) {
/* TODO: Andrew to make this work for ObjectMotionState
BT_PROFILE("ownershipInfection"); BT_PROFILE("ownershipInfection");
assert(objectA); if (_sessionID.isNull()) {
assert(objectB); return;
}
auto nodeList = DependencyManager::get<NodeList>();
QUuid myNodeID = nodeList->getSessionUUID();
const btCollisionObject* characterCollisionObject =
_characterController ? _characterController->getCollisionObject() : nullptr;
assert(!myNodeID.isNull());
const btCollisionObject* characterObject = _characterController ? _characterController->getCollisionObject() : nullptr;
ObjectMotionState* a = static_cast<ObjectMotionState*>(objectA->getUserPointer()); ObjectMotionState* a = static_cast<ObjectMotionState*>(objectA->getUserPointer());
ObjectMotionState* b = static_cast<ObjectMotionState*>(objectB->getUserPointer()); ObjectMotionState* b = static_cast<ObjectMotionState*>(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 if (b && ((a && !objectA->isStaticOrKinematicObject()) || (objectA == characterObject))) {
// ownership of anything that collides with our avatar. if (!objectB->isStaticOrKinematicObject()) {
if ((aIsDynamic && (entityA->getSimulatorID() == myNodeID)) || b->bump();
// (a && a->getShouldClaimSimulationOwnership()) ||
(objectA == characterCollisionObject)) {
if (bIsDynamic) {
b->setShouldClaimSimulationOwnership(true);
} }
} else if ((bIsDynamic && (entityB->getSimulatorID() == myNodeID)) || } else if (a && ((b && !objectB->isStaticOrKinematicObject()) || (objectB == characterObject))) {
// (b && b->getShouldClaimSimulationOwnership()) || if (!objectA->isStaticOrKinematicObject()) {
(objectB == characterCollisionObject)) { a->bump();
if (aIsDynamic) {
a->setShouldClaimSimulationOwnership(true);
} }
} }
*/
} }
void PhysicsEngine::computeCollisionEvents() { void PhysicsEngine::computeCollisionEvents() {

View file

@ -14,6 +14,7 @@
#include <stdint.h> #include <stdint.h>
#include <QUuid>
#include <QVector> #include <QVector>
#include <btBulletDynamicsCommon.h> #include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btGhostObject.h> #include <BulletCollision/CollisionDispatch/btGhostObject.h>
@ -51,6 +52,8 @@ public:
~PhysicsEngine(); ~PhysicsEngine();
void init(); void init();
void setSessionUUID(const QUuid& sessionID) { _sessionID = sessionID; }
void addObject(ObjectMotionState* motionState); void addObject(ObjectMotionState* motionState);
void removeObject(ObjectMotionState* motionState); void removeObject(ObjectMotionState* motionState);
@ -106,6 +109,8 @@ private:
bool _dumpNextStats = false; bool _dumpNextStats = false;
bool _hasOutgoingChanges = false; bool _hasOutgoingChanges = false;
QUuid _sessionID;
}; };
#endif // hifi_PhysicsEngine_h #endif // hifi_PhysicsEngine_h