Only sort an estimated number of avatars

This commit is contained in:
Simon Walton 2018-09-14 12:19:55 -07:00
parent 81a69c7769
commit 6a1c76d14d
2 changed files with 17 additions and 3 deletions

View file

@ -244,6 +244,9 @@ void AvatarMixerSlave::broadcastAvatarDataToAgent(const SharedNodePointer& node)
// reset the internal state for correct random number distribution
distribution.reset();
// Base number to sort on number previously sent.
const int numToSendEst = std::max(nodeData->getNumAvatarsSentLastFrame() * 2, 20);
// reset the number of sent avatars
nodeData->resetNumAvatarsSentLastFrame();
@ -399,7 +402,7 @@ void AvatarMixerSlave::broadcastAvatarDataToAgent(const SharedNodePointer& node)
int remainingAvatars = (int)sortedAvatars.size();
auto traitsPacketList = NLPacketList::create(PacketType::BulkAvatarTraits, QByteArray(), true, true);
const auto& sortedAvatarVector = sortedAvatars.getSortedVector();
const auto& sortedAvatarVector = sortedAvatars.getSortedVector(numToSendEst);
for (const auto& sortedAvatar : sortedAvatarVector) {
const Node* otherNode = sortedAvatar.getNode();
auto lastEncodeForOther = sortedAvatar.getTimestamp();
@ -524,6 +527,11 @@ void AvatarMixerSlave::broadcastAvatarDataToAgent(const SharedNodePointer& node)
remainingAvatars--;
}
if (nodeData->getNumAvatarsSentLastFrame() > numToSendEst) {
qCWarning(avatars) << "More avatars sent than upper estimate" << nodeData->getNumAvatarsSentLastFrame()
<< " / " << numToSendEst;
}
quint64 startPacketSending = usecTimestampNow();
// close the current packet so that we're always sending something

View file

@ -66,8 +66,14 @@ namespace PrioritySortUtil {
void reserve(size_t num) {
_vector.reserve(num);
}
const std::vector<T>& getSortedVector() {
std::sort(_vector.begin(), _vector.end(), [](const T& left, const T& right) { return left.getPriority() > right.getPriority(); });
const std::vector<T>& getSortedVector(int numToSort = 0) {
if (numToSort == 0 || numToSort >= (int)_vector.size()) {
std::sort(_vector.begin(), _vector.end(),
[](const T& left, const T& right) { return left.getPriority() > right.getPriority(); });
} else {
std::partial_sort(_vector.begin(), _vector.begin() + numToSort, _vector.end(),
[](const T& left, const T& right) { return left.getPriority() > right.getPriority(); });
}
return _vector;
}