fix logic with infectious simulation ownership

This commit is contained in:
Seth Alves 2015-04-23 10:02:29 -07:00
parent 10e5378396
commit 2ca592de8b
3 changed files with 31 additions and 24 deletions

View file

@ -62,14 +62,13 @@ public:
virtual uint32_t getIncomingDirtyFlags() const;
virtual void clearIncomingDirtyFlags(uint32_t flags) { _entity->clearDirtyFlags(flags); }
EntityItem* getEntity() const { return _entity; }
void incrementAccelerationNearlyGravityCount() { _accelerationNearlyGravityCount++; }
void resetAccelerationNearlyGravityCount() { _accelerationNearlyGravityCount = 0; }
quint8 getAccelerationNearlyGravityCount() { return _accelerationNearlyGravityCount; }
void setShouldClaimSimulationOwnership(bool value) { _shouldClaimSimulationOwnership = value; }
bool getShouldClaimSimulationOwnership() { return _shouldClaimSimulationOwnership; }
virtual EntityItem* getEntity() const { return _entity; }
virtual void setShouldClaimSimulationOwnership(bool value) { _shouldClaimSimulationOwnership = value; }
virtual bool getShouldClaimSimulationOwnership() { return _shouldClaimSimulationOwnership; }
protected:
EntityItem* _entity;

View file

@ -111,6 +111,12 @@ public:
virtual bool isMoving() const = 0;
friend class PhysicsEngine;
// these are here so we can call into EntityMotionObject with a base-class pointer
virtual EntityItem* getEntity() const { return NULL; }
virtual void setShouldClaimSimulationOwnership(bool value) { }
virtual bool getShouldClaimSimulationOwnership() { return false; }
protected:
void setRigidBody(btRigidBody* body);

View file

@ -391,29 +391,31 @@ void PhysicsEngine::computeCollisionEvents() {
continue;
}
void* a = objectA->getUserPointer();
EntityMotionState* entityMotionStateA = static_cast<EntityMotionState*>(a);
EntityItem* entityA = entityMotionStateA ? entityMotionStateA->getEntity() : NULL;
void* b = objectB->getUserPointer();
EntityMotionState* entityMotionStateB = static_cast<EntityMotionState*>(b);
EntityItem* entityB = entityMotionStateB ? entityMotionStateB->getEntity() : NULL;
ObjectMotionState* a = static_cast<ObjectMotionState*>(objectA->getUserPointer());
ObjectMotionState* b = static_cast<ObjectMotionState*>(objectB->getUserPointer());
EntityItem* entityA = a ? a->getEntity() : NULL;
EntityItem* entityB = b ? b->getEntity() : NULL;
bool aIsDynamic = entityA && !objectA->isStaticOrKinematicObject();
bool bIsDynamic = entityB && !objectB->isStaticOrKinematicObject();
if (a || b) {
// the manifold has up to 4 distinct points, but only extract info from the first
_contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0), _originOffset);
// collisions cause infectious spread of simulation-ownership. we also attempt to take
// ownership of anything that collides with our avatar.
if (entityA && entityB && !objectA->isStaticOrKinematicObject() && !objectB->isStaticOrKinematicObject()) {
if (entityA->getSimulatorID() == myNodeID ||
entityMotionStateA->getShouldClaimSimulationOwnership() ||
objectA == characterCollisionObject) {
entityMotionStateB->setShouldClaimSimulationOwnership(true);
}
if (entityB->getSimulatorID() == myNodeID ||
entityMotionStateB->getShouldClaimSimulationOwnership() ||
objectB == characterCollisionObject) {
entityMotionStateA->setShouldClaimSimulationOwnership(true);
}
}
// 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 ((bIsDynamic && entityB->getSimulatorID() == myNodeID) ||
(b && b->getShouldClaimSimulationOwnership()) ||
(objectB == characterCollisionObject)) {
if (aIsDynamic) {
a->setShouldClaimSimulationOwnership(true);
}
}
}