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(), 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<void()> f) {
QCoreApplication::postEvent(this, new LambdaEvent(f));
}

View file

@ -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);

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <AABox.h>
#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<NodeList>();
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<ObjectMotionState*>(objectA->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
// 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() {

View file

@ -14,6 +14,7 @@
#include <stdint.h>
#include <QUuid>
#include <QVector>
#include <btBulletDynamicsCommon.h>
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
@ -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