diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index fb8e430959..da98b4f350 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1194,10 +1194,3 @@ void EntityItem::updateLifetime(float value) { _dirtyFlags |= EntityItem::DIRTY_LIFETIME; } } - -void EntityItem::updateSimulatorID(QString value) { - if (_simulatorID != value) { - _simulatorID = value; - _dirtyFlags |= EntityItem::DIRTY_UPDATEABLE; - } -} diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 8388985432..8f7feb2ed8 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -294,7 +294,6 @@ public: void updateCollisionsWillMove(bool value); void updateLifetime(float value); virtual void updateShapeType(ShapeType type) { /* do nothing */ } - void updateSimulatorID(QString value); uint32_t getDirtyFlags() const { return _dirtyFlags; } void clearDirtyFlags(uint32_t mask = 0xffff) { _dirtyFlags &= ~mask; } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index ca22831d38..17cc06267d 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -191,13 +191,13 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) { QString myNodeID = nodeList->getSessionUUID().toString(); QString simulatorID = _entity->getSimulatorID(); - if (simulatorID.isEmpty() && _body->isActive()) { + if (simulatorID.isEmpty() && _sentMoving) { // The object is moving and nobody thinks they own the motion. set this Node as the simulator - _entity->updateSimulatorID(myNodeID); + // _entity->updateSimulatorID(myNodeID); simulatorID = myNodeID; - } else if (simulatorID == myNodeID && !_body->isActive()) { + } else if (simulatorID == myNodeID && !_sentMoving) { // we are the simulator and the object has stopped. give up "simulator" status - _entity->updateSimulatorID(""); + // _entity->updateSimulatorID(""); simulatorID = ""; } @@ -219,9 +219,9 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ if (_outgoingPacketFlags) { EntityItemProperties properties = _entity->getProperties(); - // if (_outgoingPacketFlags & EntityItem::DIRTY_UPDATEABLE) { - // properties.setSimulatorID(_entity->getSimulatorID()); - // } + + + if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) { btTransform worldTrans = _body->getWorldTransform(); @@ -250,9 +250,6 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ } _sentMoving = ! (zeroSpeed && zeroSpin); - - qDebug() << "EntityMotionState::sendUpdate" << _sentMoving << _body->isActive(); - } else { _sentVelocity = _sentAngularVelocity = glm::vec3(0.0f); _sentMoving = false; @@ -263,6 +260,24 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ properties.setAngularVelocity(_sentAngularVelocity); } + + qDebug() << "EntityMotionState::sendUpdate" << _sentMoving << _body->isActive(); + + auto nodeList = DependencyManager::get(); + QString myNodeID = nodeList->getSessionUUID().toString(); + QString simulatorID = _entity->getSimulatorID(); + + if (simulatorID.isEmpty() && _sentMoving) { + // The object is moving and nobody thinks they own the motion. set this Node as the simulator + _entity->setSimulatorID(myNodeID); + properties.setSimulatorID(myNodeID); + } else if (simulatorID == myNodeID && !_sentMoving) { + // we are the simulator and the object has stopped. give up "simulator" status + _entity->setSimulatorID(""); + properties.setSimulatorID(""); + } + + // RELIABLE_SEND_HACK: count number of updates for entities at rest so we can stop sending them after some limit. if (_sentMoving) { _numNonMovingUpdates = 0;