diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index e5e70d72ff..b243a575bd 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include @@ -157,16 +158,14 @@ void AvatarMixer::broadcastAvatarData() { AvatarData& avatar = nodeData->getAvatar(); glm::vec3 myPosition = avatar.getPosition(); - // TODO use this along with the distance in the calculation of whether to send an update - // about a given otherNode to this node - // FIXME does this mean we should sort the othernodes by distance before iterating - // over them? - // float outputBandwidth = - node->getOutboundBandwidth(); // reset the internal state for correct random number distribution distribution.reset(); - + // reset the max distance for this frame + float maxDistanceThisFrame = 0.0f; + // reset the number of sent avatars + nodeData->resetNumAvatarsSentLastFrame(); + // this is an AGENT we have received head data from // send back a packet with other active node data to this node nodeList->eachMatchingNode( @@ -193,7 +192,10 @@ void AvatarMixer::broadcastAvatarData() { // at twice the full rate distance, there will be a 50% chance of sending this avatar's update glm::vec3 otherPosition = otherAvatar.getPosition(); float distanceToAvatar = glm::length(myPosition - otherPosition); - + + // potentially update the max full rate distance for this frame + maxDistanceThisFrame = std::max(maxDistanceThisFrame, distanceToAvatar); + if (distanceToAvatar != 0.0f && distribution(generator) > (nodeData->getFullRateDistance() / distanceToAvatar)) { return; @@ -249,7 +251,15 @@ void AvatarMixer::broadcastAvatarData() { } }); nodeList->writeDatagram(mixedAvatarByteArray, node); - }); + + if (nodeData->getNumAvatarsSentLastFrame() == 0) { + // update the full rate distance to FLOAT_MAX since we didn't have any other avatars to send + nodeData->setMaxFullRateDistance(FLT_MAX); + } else { + nodeData->setMaxFullRateDistance(maxDistanceThisFrame); + } + } + ); _lastFrameTimestamp = QDateTime::currentMSecsSinceEpoch(); } diff --git a/assignment-client/src/avatars/AvatarMixerClientData.cpp b/assignment-client/src/avatars/AvatarMixerClientData.cpp index 3999256c6b..658586610e 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.cpp +++ b/assignment-client/src/avatars/AvatarMixerClientData.cpp @@ -37,4 +37,6 @@ bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() { void AvatarMixerClientData::loadJSONStats(QJsonObject& jsonObject) const { jsonObject["display_name"] = _avatar.getDisplayName(); jsonObject["full_rate_distance"] = _fullRateDistance; + jsonObject["max_full_rate_distance"] = _maxFullRateDistance; + jsonObject["num_avatars_sent_last_frame"] = _numAvatarsSentLastFrame; } diff --git a/assignment-client/src/avatars/AvatarMixerClientData.h b/assignment-client/src/avatars/AvatarMixerClientData.h index 346bf6a9e8..a239a8d6fa 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.h +++ b/assignment-client/src/avatars/AvatarMixerClientData.h @@ -12,6 +12,7 @@ #ifndef hifi_AvatarMixerClientData_h #define hifi_AvatarMixerClientData_h +#include #include #include @@ -37,6 +38,11 @@ public: void setIdentityChangeTimestamp(quint64 identityChangeTimestamp) { _identityChangeTimestamp = identityChangeTimestamp; } float getFullRateDistance() const { return _fullRateDistance; } + void setMaxFullRateDistance(float distance) { _maxFullRateDistance = distance; } + + void resetNumAvatarsSentLastFrame() { _numAvatarsSentLastFrame = 0; } + void increaseNumAvatarsSentLastFrame() { ++_numAvatarsSentLastFrame; } + int getNumAvatarsSentLastFrame() const { return _numAvatarsSentLastFrame; } void loadJSONStats(QJsonObject& jsonObject) const; private: @@ -45,6 +51,8 @@ private: quint64 _billboardChangeTimestamp; quint64 _identityChangeTimestamp; float _fullRateDistance = FLT_MAX; + float _maxFullRateDistance = FLT_MAX; + int _numAvatarsSentLastFrame = 0; }; #endif // hifi_AvatarMixerClientData_h diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 05f834255c..26ada89d90 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -715,11 +715,11 @@ void Avatar::renderDisplayName() { QString renderedDisplayName = _displayName; if (DependencyManager::get()->shouldShowReceiveStats()) { - const float BYTES_PER_KILOBYTE = 1000.0f; - float kilobytesPerSecond = getAverageBytesReceivedPerSecond() / BYTES_PER_KILOBYTE; + const float KILOBITS_PER_BYTE = 125.0f; + float kilobitsPerSecond = getAverageBytesReceivedPerSecond() / KILOBITS_PER_BYTE; - renderedDisplayName += QString(" - (%1 KBps, %2 Hz)") - .arg(QString::number(kilobytesPerSecond, 'f', 2)) + renderedDisplayName += QString(" - (%1 Kbps, %2 Hz)") + .arg(QString::number(kilobitsPerSecond, 'f', 2)) .arg(getReceiveRate()); }