diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index f2588d0493..9129cd875e 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -27,7 +27,13 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties) { + + qDebug() << "EntityEditPacketSender::queueEditEntityMessage()..."; + qDebug() << " ID:" << modelID; + qDebug() << " properties:" << properties; + if (!_shouldSend) { + qDebug() << " BAIL EARLY! _shouldSend:" << _shouldSend; return; // bail early } @@ -36,6 +42,7 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI int sizeOut = 0; if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { + qDebug() << " queueOctreeEditMessage() sizeOut:" << sizeOut; queueOctreeEditMessage(type, bufferOut, sizeOut); } } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 7e3e982fb8..b413ea2b23 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1064,6 +1064,9 @@ const float MIN_SPIN_DELTA = 0.0003f; void EntityItem::updatePosition(const glm::vec3& value) { if (glm::distance(_position, value) * (float)TREE_SCALE > MIN_POSITION_DELTA) { + qDebug() << "EntityItem::updatePosition()... "; + qDebug() << " new position:" << value; + qDebug() << " in meters:" << (value * (float) TREE_SCALE); _position = value; recalculateCollisionShape(); _dirtyFlags |= EntityItem::DIRTY_POSITION; @@ -1073,6 +1076,9 @@ void EntityItem::updatePosition(const glm::vec3& value) { void EntityItem::updatePositionInMeters(const glm::vec3& value) { glm::vec3 position = glm::clamp(value / (float) TREE_SCALE, 0.0f, 1.0f); if (glm::distance(_position, position) * (float)TREE_SCALE > MIN_POSITION_DELTA) { + qDebug() << "EntityItem::updatePositionInMeters()... "; + qDebug() << " new position:" << position; + qDebug() << " in meters:" << value; _position = position; recalculateCollisionShape(); _dirtyFlags |= EntityItem::DIRTY_POSITION; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 580fed8790..1e6fe51916 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -305,6 +305,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) /// we're not changing the content of the tree, we're only changing the internal IDs that map entities from creator /// based to known IDs. This means we don't have to recurse the tree to mark the changed path as dirty. void EntityTree::handleAddEntityResponse(const QByteArray& packet) { + qDebug() << "EntityTree::handleAddEntityResponse()"; if (!getIsClient()) { qDebug() << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; @@ -329,6 +330,9 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) { searchEntityID.id = entityID; searchEntityID.creatorTokenID = creatorTokenID; + qDebug() << " creatorTokenID:" << creatorTokenID; + qDebug() << " entityID:" << entityID; + lockForWrite(); // find the creator token version, it's containing element, and the entity itself diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index aff6e64f57..923ab8a9ca 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -795,11 +795,13 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int } } else { + qDebug() << "EntityTreeElement::readElementDataFromBuffer() about to construct entity item"; entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args); if (entityItem) { bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); addEntityItem(entityItem); // add this new entity to this elements entities entityItemID = entityItem->getEntityItemID(); + qDebug() << " entityItemID:" << entityItemID; _myTree->setContainingElement(entityItemID, this); _myTree->postAddEntity(entityItem); } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 8b6fb1ea9f..f08683455c 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -159,15 +159,23 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ return; // never update entities that are unknown } if (_outgoingPacketFlags) { + qDebug() << "EntityMotionState::sendUpdate()..."; + qDebug() << " _outgoingPacketFlags:" << _outgoingPacketFlags; + EntityItemProperties properties = _entity->getProperties(); + qDebug() << " _entity->getProperties():" << properties << "line:" << __LINE__; if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) { btTransform worldTrans = _body->getWorldTransform(); _sentPosition = bulletToGLM(worldTrans.getOrigin()); properties.setPosition(_sentPosition + ObjectMotionState::getWorldOffset()); + qDebug() << " _sentPosition:" << _sentPosition << "line:" << __LINE__; + qDebug() << " ObjectMotionState::getWorldOffset():" << ObjectMotionState::getWorldOffset() << "line:" << __LINE__; _sentRotation = bulletToGLM(worldTrans.getRotation()); properties.setRotation(_sentRotation); + + qDebug() << " after position properties:" << properties << "line:" << __LINE__; } if (_outgoingPacketFlags & EntityItem::DIRTY_VELOCITY) { @@ -197,6 +205,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ properties.setGravity(_sentAcceleration); // DANGER! EntityItem stores angularVelocity in degrees/sec!!! properties.setAngularVelocity(glm::degrees(_sentAngularVelocity)); + + qDebug() << " after velocity properties:" << properties << "line:" << __LINE__; } // RELIABLE_SEND_HACK: count number of updates for entities at rest so we can stop sending them after some limit. @@ -217,6 +227,9 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ EntityItemID id(_entity->getID()); EntityEditPacketSender* entityPacketSender = static_cast(packetSender); + qDebug() << "EntityMotionState::sendUpdate()... about to call queueEditEntityMessage()"; + qDebug() << " id:" << id; + qDebug() << " properties:" << properties; entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); // The outgoing flags only itemized WHAT to send, not WHETHER to send, hence we always set them diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index cab36b8370..cacaab614f 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -108,6 +108,18 @@ bool ObjectMotionState::doesNotNeedToSendUpdate() const { bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { assert(_body); + + + // if we've never checked before, our _sentFrame will be 0, and we need to initialize our state + if (_sentFrame == 0) { + _sentPosition = bulletToGLM(_body->getWorldTransform().getOrigin()); + _sentVelocity = bulletToGLM(_body->getLinearVelocity()); + _sentAngularVelocity = bulletToGLM(_body->getAngularVelocity()); + _sentFrame = simulationFrame; + return false; + } + + uint32_t wasSentFrame = _sentFrame; float dt = (float)(simulationFrame - _sentFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP; _sentFrame = simulationFrame; bool isActive = _body->isActive(); @@ -131,6 +143,10 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { // NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. + + glm::vec3 wasPosition = _sentPosition; + glm::vec3 wasVelocity = _sentVelocity; + glm::vec3 wasAcceleration = _sentAcceleration; // compute position error if (glm::length2(_sentVelocity) > 0.0f) { @@ -141,11 +157,40 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { btTransform worldTrans = _body->getWorldTransform(); glm::vec3 position = bulletToGLM(worldTrans.getOrigin()); - + float dx2 = glm::distance2(position, _sentPosition); const float MAX_POSITION_ERROR_SQUARED = 0.001f; // 0.001 m^2 ~~> 0.03 m if (dx2 > MAX_POSITION_ERROR_SQUARED) { - return true; +qDebug() << "ObjectMotionState::shouldSendUpdate()... computing position error"; + + glm::vec3 bulletVelocity = bulletToGLM(_body->getLinearVelocity()); + +qDebug() << " was _sentFrame:" << wasSentFrame; +qDebug() << " now _sentFrame:" << _sentFrame; +qDebug() << " dt:" << dt; + +qDebug() << " was _sentAcceleration:" << wasAcceleration; +qDebug() << " now _sentAcceleration:" << _sentAcceleration; + +qDebug() << " bulletVelocity:" << bulletVelocity; +qDebug() << " was _sentVelocity:" << wasVelocity; +qDebug() << " now _sentVelocity:" << _sentVelocity; + +qDebug() << " was _sentPosition:" << wasPosition; +qDebug() << " now _sentPosition:" << _sentPosition; +qDebug() << " bullet position:" << position; + +qDebug() << " dx2:" << dx2; +qDebug() << " (dx2 > MAX_POSITION_ERROR_SQUARED)... considering"; + if (wasSentFrame > 0) { +qDebug() << " (wasSentFrame > 0)... return TRUE"; + return true; + } else { +qDebug() << " (wasSentFrame == 0)... ignore use bullet position for next _sentPosition"; + _sentPosition = position; + } + } else { + //qDebug() << " (dx2 <= MAX_POSITION_ERROR_SQUARED)... FALL THROUGH... likely return false"; } if (glm::length2(_sentAngularVelocity) > 0.0f) { diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 7f2b139058..58253d1bd4 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -35,6 +35,9 @@ void PhysicsEngine::updateEntitiesInternal(const quint64& now) { // (3) synchronize outgoing motion states // (4) send outgoing packets + + //qDebug() << "_numSubsteps:" << _numSubsteps; + // this is step (4) QSet::iterator stateItr = _outgoingPackets.begin(); while (stateItr != _outgoingPackets.end()) {