From 176cb103dcbc2d569e1f2451020d690f96f1aa20 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 25 Feb 2014 10:41:33 -0800 Subject: [PATCH] =?UTF-8?q?Add=20stochastic=20falloff=20for=20sending=20ot?= =?UTF-8?q?her=20avatar=E2=80=99s=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assignment-client/src/avatars/AvatarMixer.cpp | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 75265bdf10..ae2be64880 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -61,26 +61,36 @@ void broadcastAvatarData() { // reset packet pointers for this node mixedAvatarByteArray.resize(numPacketHeaderBytes); + AvatarMixerClientData* myData = reinterpret_cast(node->getLinkedData()); + glm::vec3 myPosition = myData->getPosition(); + // this is an AGENT we have received head data from // send back a packet with other active node data to this node foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) { if (otherNode->getLinkedData() && otherNode->getUUID() != node->getUUID()) { - QByteArray avatarByteArray; - avatarByteArray.append(otherNode->getUUID().toRfc4122()); - - AvatarMixerClientData* nodeData = reinterpret_cast(otherNode->getLinkedData()); - avatarByteArray.append(nodeData->toByteArray()); - - if (avatarByteArray.size() + mixedAvatarByteArray.size() > MAX_PACKET_SIZE) { - nodeList->writeDatagram(mixedAvatarByteArray, node); + AvatarMixerClientData* otherNodeData = reinterpret_cast(otherNode->getLinkedData()); + glm::vec3 otherPosition = otherNodeData->getPosition(); + float distanceToAvatar = glm::length(myPosition - otherPosition); + // The full rate distance is the distance at which EVERY update will be sent for this avatar + // at a distance of twice the full rate distance, there will be a 50% chance of sending this avatar's update + const float FULL_RATE_DISTANCE = 2.f; + // Decide whether to send this avatar's data based on it's distance from us + if ((distanceToAvatar == 0.f) || (randFloat() < FULL_RATE_DISTANCE / distanceToAvatar)) { + QByteArray avatarByteArray; + avatarByteArray.append(otherNode->getUUID().toRfc4122()); + avatarByteArray.append(otherNodeData->toByteArray()); - // reset the packet - mixedAvatarByteArray.resize(numPacketHeaderBytes); + if (avatarByteArray.size() + mixedAvatarByteArray.size() > MAX_PACKET_SIZE) { + nodeList->writeDatagram(mixedAvatarByteArray, node); + + // reset the packet + mixedAvatarByteArray.resize(numPacketHeaderBytes); + } + + // copy the avatar into the mixedAvatarByteArray packet + mixedAvatarByteArray.append(avatarByteArray); } - - // copy the avatar into the mixedAvatarByteArray packet - mixedAvatarByteArray.append(avatarByteArray); } }