use a flag to indicate that simulation ownership should be grabbed

This commit is contained in:
Seth Alves 2015-04-20 11:49:10 -07:00
parent 88f289f3c1
commit 08d300afcd
5 changed files with 21 additions and 7 deletions

View file

@ -76,6 +76,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) {
_changedOnServer = 0; _changedOnServer = 0;
_element = NULL; _element = NULL;
_simulatorIDChangedTime = 0; _simulatorIDChangedTime = 0;
_shouldClaimSimulationOwnership = false;
initFromEntityItemID(entityItemID); initFromEntityItemID(entityItemID);
} }

View file

@ -259,6 +259,8 @@ public:
QUuid getSimulatorID() const { return _simulatorID; } QUuid getSimulatorID() const { return _simulatorID; }
void setSimulatorID(const QUuid& value); void setSimulatorID(const QUuid& value);
quint64 getSimulatorIDChangedTime() const { return _simulatorIDChangedTime; } quint64 getSimulatorIDChangedTime() const { return _simulatorIDChangedTime; }
void setShouldClaimSimulationOwnership(bool value) { _shouldClaimSimulationOwnership = value; }
bool getShouldClaimSimulationOwnership() { return _shouldClaimSimulationOwnership; }
const QString& getMarketplaceID() const { return _marketplaceID; } const QString& getMarketplaceID() const { return _marketplaceID; }
void setMarketplaceID(const QString& value) { _marketplaceID = value; } void setMarketplaceID(const QString& value) { _marketplaceID = value; }
@ -355,6 +357,7 @@ protected:
QString _userData; QString _userData;
QUuid _simulatorID; // id of Node which is currently responsible for simulating this Entity QUuid _simulatorID; // id of Node which is currently responsible for simulating this Entity
quint64 _simulatorIDChangedTime; // when was _simulatorID last updated? quint64 _simulatorIDChangedTime; // when was _simulatorID last updated?
bool _shouldClaimSimulationOwnership;
QString _marketplaceID; QString _marketplaceID;
// NOTE: Damping is applied like this: v *= pow(1 - damping, dt) // NOTE: Damping is applied like this: v *= pow(1 - damping, dt)

View file

@ -147,6 +147,8 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro
properties.setPositionChanged(false); properties.setPositionChanged(false);
properties.setVelocityChanged(false); properties.setVelocityChanged(false);
properties.setAccelerationChanged(false); properties.setAccelerationChanged(false);
} else {
qCDebug(entities) << "allowing simulatorID change";
} }
} }

View file

@ -191,6 +191,10 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) {
return false; return false;
} }
if (_entity->getShouldClaimSimulationOwnership()) {
return true;
}
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
const QUuid& myNodeID = nodeList->getSessionUUID(); const QUuid& myNodeID = nodeList->getSessionUUID();
const QUuid& simulatorID = _entity->getSimulatorID(); const QUuid& simulatorID = _entity->getSimulatorID();
@ -262,7 +266,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
QUuid myNodeID = nodeList->getSessionUUID(); QUuid myNodeID = nodeList->getSessionUUID();
QUuid simulatorID = _entity->getSimulatorID(); QUuid simulatorID = _entity->getSimulatorID();
if (simulatorID.isNull() && !(zeroSpeed && zeroSpin)) { if (_entity->getShouldClaimSimulationOwnership()) {
_entity->setSimulatorID(myNodeID);
properties.setSimulatorID(myNodeID);
_entity->setShouldClaimSimulationOwnership(false);
}
else if (simulatorID.isNull() && !(zeroSpeed && zeroSpin)) {
// The object is moving and nobody thinks they own the motion. set this Node as the simulator // The object is moving and nobody thinks they own the motion. set this Node as the simulator
_entity->setSimulatorID(myNodeID); _entity->setSimulatorID(myNodeID);
properties.setSimulatorID(myNodeID); properties.setSimulatorID(myNodeID);

View file

@ -397,20 +397,19 @@ void PhysicsEngine::computeCollisionEvents() {
_contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0), _originOffset); _contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0), _originOffset);
// if our character capsule is colliding with something dynamic, claim simulation ownership. // if our character capsule is colliding with something dynamic, claim simulation ownership.
// do this by setting the entity's simulator-id to NULL, thereby causing EntityMotionState::sendUpdate // see EntityMotionState::sendUpdate
// to set ownership to us.
if (objectA == characterCollisionObject && !objectB->isStaticOrKinematicObject() && b) { if (objectA == characterCollisionObject && !objectB->isStaticOrKinematicObject() && b) {
EntityItem* entityB = static_cast<EntityMotionState*>(b)->getEntity(); EntityItem* entityB = static_cast<EntityMotionState*>(b)->getEntity();
if (!entityB->getSimulatorID().isNull() && entityB->getSimulatorID() != myNodeID) { if (entityB->getSimulatorID() != myNodeID && !entityB->getShouldClaimSimulationOwnership()) {
qDebug() << "CLAIMING B"; qDebug() << "CLAIMING B";
entityB->setSimulatorID(NULL); entityB->setShouldClaimSimulationOwnership(true);
} }
} }
if (objectB == characterCollisionObject && !objectA->isStaticOrKinematicObject() && a) { if (objectB == characterCollisionObject && !objectA->isStaticOrKinematicObject() && a) {
EntityItem* entityA = static_cast<EntityMotionState*>(a)->getEntity(); EntityItem* entityA = static_cast<EntityMotionState*>(a)->getEntity();
if (!entityA->getSimulatorID().isNull() && entityA->getSimulatorID() != myNodeID) { if (entityA->getSimulatorID() != myNodeID && !entityA->getShouldClaimSimulationOwnership()) {
qDebug() << "CLAIMING A"; qDebug() << "CLAIMING A";
entityA->setSimulatorID(NULL); entityA->setShouldClaimSimulationOwnership(true);
} }
} }
} }