Send both frustums to Avatar Mixer

This commit is contained in:
Clement 2018-04-23 15:47:05 -07:00
parent 21213e81f4
commit 1b2b70b769
5 changed files with 23 additions and 13 deletions

View file

@ -521,11 +521,9 @@ void AvatarMixer::handleViewFrustumPacket(QSharedPointer<ReceivedMessage> messag
auto start = usecTimestampNow(); auto start = usecTimestampNow();
getOrCreateClientData(senderNode); getOrCreateClientData(senderNode);
if (senderNode->getLinkedData()) { AvatarMixerClientData* nodeData = dynamic_cast<AvatarMixerClientData*>(senderNode->getLinkedData());
AvatarMixerClientData* nodeData = dynamic_cast<AvatarMixerClientData*>(senderNode->getLinkedData()); if (nodeData) {
if (nodeData != nullptr) { nodeData->readViewFrustumPacket(message->getMessage());
nodeData->readViewFrustumPacket(message->getMessage());
}
} }
auto end = usecTimestampNow(); auto end = usecTimestampNow();

View file

@ -19,8 +19,6 @@
AvatarMixerClientData::AvatarMixerClientData(const QUuid& nodeID) : AvatarMixerClientData::AvatarMixerClientData(const QUuid& nodeID) :
NodeData(nodeID) NodeData(nodeID)
{ {
_currentViewFrustum.invalidate();
// in case somebody calls getSessionUUID on the AvatarData instance, make sure it has the right ID // in case somebody calls getSessionUUID on the AvatarData instance, make sure it has the right ID
_avatar->setID(nodeID); _avatar->setID(nodeID);
} }
@ -129,11 +127,21 @@ void AvatarMixerClientData::removeFromRadiusIgnoringSet(SharedNodePointer self,
} }
void AvatarMixerClientData::readViewFrustumPacket(const QByteArray& message) { void AvatarMixerClientData::readViewFrustumPacket(const QByteArray& message) {
_currentViewFrustum.fromByteArray(message); _currentViewFrustums.clear();
auto offset = 0;
while (offset < message.size()) {
ViewFrustum frustum;
offset += frustum.fromByteArray(message);
_currentViewFrustums.push_back(frustum);
}
} }
bool AvatarMixerClientData::otherAvatarInView(const AABox& otherAvatarBox) { bool AvatarMixerClientData::otherAvatarInView(const AABox& otherAvatarBox) {
return _currentViewFrustum.boxIntersectsKeyhole(otherAvatarBox); return std::any_of(std::begin(_currentViewFrustums), std::end(_currentViewFrustums),
[&](const ViewFrustum& viewFrustum) {
return viewFrustum.boxIntersectsKeyhole(otherAvatarBox);
});
} }
void AvatarMixerClientData::loadJSONStats(QJsonObject& jsonObject) const { void AvatarMixerClientData::loadJSONStats(QJsonObject& jsonObject) const {

View file

@ -110,7 +110,7 @@ public:
bool getRequestsDomainListData() { return _requestsDomainListData; } bool getRequestsDomainListData() { return _requestsDomainListData; }
void setRequestsDomainListData(bool requesting) { _requestsDomainListData = requesting; } void setRequestsDomainListData(bool requesting) { _requestsDomainListData = requesting; }
ViewFrustum getViewFrustum() const { return _currentViewFrustum; } const std::vector<ViewFrustum>& getViewFrustums() const { return _currentViewFrustums; }
uint64_t getLastOtherAvatarEncodeTime(QUuid otherAvatar) const; uint64_t getLastOtherAvatarEncodeTime(QUuid otherAvatar) const;
void setLastOtherAvatarEncodeTime(const QUuid& otherAvatar, uint64_t time); void setLastOtherAvatarEncodeTime(const QUuid& otherAvatar, uint64_t time);
@ -150,7 +150,7 @@ private:
SimpleMovingAverage _avgOtherAvatarDataRate; SimpleMovingAverage _avgOtherAvatarDataRate;
std::unordered_set<QUuid> _radiusIgnoredOthers; std::unordered_set<QUuid> _radiusIgnoredOthers;
ViewFrustum _currentViewFrustum; std::vector<ViewFrustum> _currentViewFrustums;
int _recentOtherAvatarsInView { 0 }; int _recentOtherAvatarsInView { 0 };
int _recentOtherAvatarsOutOfView { 0 }; int _recentOtherAvatarsOutOfView { 0 };

View file

@ -222,8 +222,8 @@ void AvatarMixerSlave::broadcastAvatarDataToAgent(const SharedNodePointer& node)
}; };
// prepare to sort // prepare to sort
ViewFrustum cameraView = nodeData->getViewFrustum(); const auto& cameraViews = nodeData->getViewFrustums();
PrioritySortUtil::PriorityQueue<SortableAvatar> sortedAvatars({cameraView}, PrioritySortUtil::PriorityQueue<SortableAvatar> sortedAvatars(cameraViews,
AvatarData::_avatarSortCoefficientSize, AvatarData::_avatarSortCoefficientSize,
AvatarData::_avatarSortCoefficientCenter, AvatarData::_avatarSortCoefficientCenter,
AvatarData::_avatarSortCoefficientAge); AvatarData::_avatarSortCoefficientAge);

View file

@ -5806,6 +5806,10 @@ void Application::update(float deltaTime) {
void Application::sendAvatarViewFrustum() { void Application::sendAvatarViewFrustum() {
QByteArray viewFrustumByteArray = _viewFrustum.toByteArray(); QByteArray viewFrustumByteArray = _viewFrustum.toByteArray();
if (hasSecondaryViewFrustum()) {
viewFrustumByteArray += _viewFrustum.toByteArray();
}
auto avatarPacket = NLPacket::create(PacketType::ViewFrustum, viewFrustumByteArray.size()); auto avatarPacket = NLPacket::create(PacketType::ViewFrustum, viewFrustumByteArray.size());
avatarPacket->write(viewFrustumByteArray); avatarPacket->write(viewFrustumByteArray);