send minimum data for out of view avatars

This commit is contained in:
Brad Hefta-Gaub 2016-12-14 18:17:11 -08:00
parent 2443b2d6d9
commit c8fb467579
2 changed files with 30 additions and 23 deletions

View file

@ -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();
});

View file

@ -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<AvatarDataPacket::Header*>(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;
}