From c8fb467579104955fce9bcce5cad78a4112413c7 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 14 Dec 2016 18:17:11 -0800 Subject: [PATCH] send minimum data for out of view avatars --- assignment-client/src/avatars/AvatarMixer.cpp | 21 ++++-------- libraries/avatars/src/AvatarData.cpp | 32 +++++++++++++------ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 5f031e537e..1fe71cf59e 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -276,19 +276,6 @@ void AvatarMixer::broadcastAvatarData() { } // Not close enough to ignore nodeData->removeFromRadiusIgnoringSet(otherNode->getUUID()); - - - // Also check to see if the other node is in our view - glm::vec3 otherNodeBoxScale = (otherData->getPosition() - otherData->getGlobalBoundingBoxCorner()) * 2.0f; - AABox otherNodeBox(otherData->getGlobalBoundingBoxCorner(), otherNodeBoxScale); - - if (!nodeData->otherAvatarInView(otherNodeBox)) { - //qDebug() << "Avatar out of view!"; - return false; - } else { - //qDebug() << "Avatar in view!"; - } - return true; } }, @@ -368,9 +355,15 @@ void AvatarMixer::broadcastAvatarData() { // start a new segment in the PacketList for this avatar avatarPacketList->startSegment(); + // determine if avatar is in view, to determine how much data to include... + glm::vec3 otherNodeBoxScale = (otherNodeData->getPosition() - otherNodeData->getGlobalBoundingBoxCorner()) * 2.0f; + AABox otherNodeBox(otherNodeData->getGlobalBoundingBoxCorner(), otherNodeBoxScale); + + bool sendMinimumForOutOfView = !nodeData->otherAvatarInView(otherNodeBox); + numAvatarDataBytes += avatarPacketList->write(otherNode->getUUID().toRfc4122()); numAvatarDataBytes += - avatarPacketList->write(otherAvatar.toByteArray(false, distribution(generator) < AVATAR_SEND_FULL_UPDATE_RATIO)); + avatarPacketList->write(otherAvatar.toByteArray(false, distribution(generator) < AVATAR_SEND_FULL_UPDATE_RATIO), sendMinimumForOutOfView); avatarPacketList->endSegment(); }); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index f29d2d9df0..00db9ae943 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -213,7 +213,12 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll, bool sen memcpy(destinationBuffer, &packetStateFlags, sizeof(packetStateFlags)); destinationBuffer += sizeof(packetStateFlags); - if (!sendMinimum) { + if (sendMinimum) { + memcpy(destinationBuffer, &_globalPosition, sizeof(_globalPosition)); + destinationBuffer += sizeof(_globalPosition); + qDebug() << __FUNCTION__ << "minimum... included global position!!"; + } + else { //qDebug() << __FUNCTION__ << "not minimum... sending actual content!!"; auto header = reinterpret_cast(destinationBuffer); @@ -515,14 +520,6 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { bool minimumSent = oneAtBit(packetStateFlags, AVATARDATA_FLAGS_MINIMUM); bool packetIsCompressed = oneAtBit(packetStateFlags, AVATARDATA_FLAGS_COMPRESSED); - // if this is the minimum, then it only includes the flags - if (minimumSent) { - //qDebug() << __FUNCTION__ << "minimum... not expecting actual content!!"; - - int numBytesRead = sizeof(packetStateFlags); - _averageBytesReceived.updateAverage(numBytesRead); - return numBytesRead; - } //qDebug() << __FUNCTION__ << "NOT minimum... expecting actual content!!"; QByteArray uncompressBuffer; @@ -538,6 +535,20 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { //qDebug() << __FUNCTION__ << "uncompressing compressed data was:" << buffer.size() << "now:" << uncompressBuffer.size(); } + // if this is the minimum, then it only includes the flags + if (minimumSent) { + //qDebug() << __FUNCTION__ << "minimum... not expecting actual content!!"; + + memcpy(&_globalPosition, sourceBuffer, sizeof(_globalPosition)); + sourceBuffer += sizeof(_globalPosition); + int numBytesRead = (sourceBuffer - startPosition) + sizeof(packetStateFlags); + _averageBytesReceived.updateAverage(numBytesRead); + + qDebug() << __FUNCTION__ << "minimum... included global position!! numBytesRead:" << numBytesRead; + + return numBytesRead; + } + quint64 now = usecTimestampNow(); PACKET_READ_CHECK(Header, sizeof(AvatarDataPacket::Header)); @@ -750,6 +761,9 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { sourceBuffer = unpackFauxJoint(sourceBuffer, _controllerRightHandMatrixCache); int numBytesRead = sourceBuffer - startPosition; + if (packetIsCompressed) { + numBytesRead += sizeof(packetStateFlags); + } _averageBytesReceived.updateAverage(numBytesRead); return numBytesRead; }