mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:27:48 +02:00
use HRC clock timings in avatar mixer
This commit is contained in:
parent
925c1ce26b
commit
38481aac53
3 changed files with 30 additions and 27 deletions
|
@ -36,14 +36,7 @@ const unsigned int AVATAR_DATA_SEND_INTERVAL_MSECS = (1.0f / (float) AVATAR_MIXE
|
||||||
|
|
||||||
AvatarMixer::AvatarMixer(ReceivedMessage& message) :
|
AvatarMixer::AvatarMixer(ReceivedMessage& message) :
|
||||||
ThreadedAssignment(message),
|
ThreadedAssignment(message),
|
||||||
_broadcastThread(),
|
_broadcastThread()
|
||||||
_lastFrameTimestamp(QDateTime::currentMSecsSinceEpoch()),
|
|
||||||
_trailingSleepRatio(1.0f),
|
|
||||||
_performanceThrottlingRatio(0.0f),
|
|
||||||
_sumListeners(0),
|
|
||||||
_numStatFrames(0),
|
|
||||||
_sumBillboardPackets(0),
|
|
||||||
_sumIdentityPackets(0)
|
|
||||||
{
|
{
|
||||||
// make sure we hear about node kills so we can tell the other nodes
|
// make sure we hear about node kills so we can tell the other nodes
|
||||||
connect(DependencyManager::get<NodeList>().data(), &NodeList::nodeKilled, this, &AvatarMixer::nodeKilled);
|
connect(DependencyManager::get<NodeList>().data(), &NodeList::nodeKilled, this, &AvatarMixer::nodeKilled);
|
||||||
|
@ -72,7 +65,12 @@ const float BILLBOARD_AND_IDENTITY_SEND_PROBABILITY = 1.0f / 187.0f;
|
||||||
// 1) use the view frustum to cull those avatars that are out of view. Since avatar data doesn't need to be present
|
// 1) use the view frustum to cull those avatars that are out of view. Since avatar data doesn't need to be present
|
||||||
// if the avatar is not in view or in the keyhole.
|
// if the avatar is not in view or in the keyhole.
|
||||||
void AvatarMixer::broadcastAvatarData() {
|
void AvatarMixer::broadcastAvatarData() {
|
||||||
int idleTime = QDateTime::currentMSecsSinceEpoch() - _lastFrameTimestamp;
|
int idleTime = AVATAR_DATA_SEND_INTERVAL_MSECS;
|
||||||
|
|
||||||
|
if (_lastFrameTimestamp.time_since_epoch().count() > 0) {
|
||||||
|
auto idleDuration = p_high_resolution_clock::now() - _lastFrameTimestamp;
|
||||||
|
idleTime = std::chrono::duration_cast<std::chrono::microseconds>(idleDuration).count();
|
||||||
|
}
|
||||||
|
|
||||||
++_numStatFrames;
|
++_numStatFrames;
|
||||||
|
|
||||||
|
@ -250,7 +248,7 @@ void AvatarMixer::broadcastAvatarData() {
|
||||||
|
|
||||||
// we will also force a send of billboard or identity packet
|
// we will also force a send of billboard or identity packet
|
||||||
// if either has changed in the last frame
|
// if either has changed in the last frame
|
||||||
if (otherNodeData->getBillboardChangeTimestamp() > 0
|
if (otherNodeData->getBillboardChangeTimestamp().time_since_epoch().count() > 0
|
||||||
&& (forceSend
|
&& (forceSend
|
||||||
|| otherNodeData->getBillboardChangeTimestamp() > _lastFrameTimestamp
|
|| otherNodeData->getBillboardChangeTimestamp() > _lastFrameTimestamp
|
||||||
|| distribution(generator) < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
|
|| distribution(generator) < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
|
||||||
|
@ -267,7 +265,7 @@ void AvatarMixer::broadcastAvatarData() {
|
||||||
++_sumBillboardPackets;
|
++_sumBillboardPackets;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (otherNodeData->getIdentityChangeTimestamp() > 0
|
if (otherNodeData->getIdentityChangeTimestamp().time_since_epoch().count() > 0
|
||||||
&& (forceSend
|
&& (forceSend
|
||||||
|| otherNodeData->getIdentityChangeTimestamp() > _lastFrameTimestamp
|
|| otherNodeData->getIdentityChangeTimestamp() > _lastFrameTimestamp
|
||||||
|| distribution(generator) < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
|
|| distribution(generator) < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
|
||||||
|
@ -385,7 +383,7 @@ void AvatarMixer::broadcastAvatarData() {
|
||||||
otherAvatar.doneEncoding(false);
|
otherAvatar.doneEncoding(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
_lastFrameTimestamp = QDateTime::currentMSecsSinceEpoch();
|
_lastFrameTimestamp = p_high_resolution_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarMixer::nodeKilled(SharedNodePointer killedNode) {
|
void AvatarMixer::nodeKilled(SharedNodePointer killedNode) {
|
||||||
|
@ -438,7 +436,7 @@ void AvatarMixer::handleAvatarIdentityPacket(QSharedPointer<ReceivedMessage> mes
|
||||||
// parse the identity packet and update the change timestamp if appropriate
|
// parse the identity packet and update the change timestamp if appropriate
|
||||||
if (avatar.hasIdentityChangedAfterParsing(message->getMessage())) {
|
if (avatar.hasIdentityChangedAfterParsing(message->getMessage())) {
|
||||||
QMutexLocker nodeDataLocker(&nodeData->getMutex());
|
QMutexLocker nodeDataLocker(&nodeData->getMutex());
|
||||||
nodeData->setIdentityChangeTimestamp(QDateTime::currentMSecsSinceEpoch());
|
nodeData->flagIdentityChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -452,7 +450,7 @@ void AvatarMixer::handleAvatarBillboardPacket(QSharedPointer<ReceivedMessage> me
|
||||||
// parse the billboard packet and update the change timestamp if appropriate
|
// parse the billboard packet and update the change timestamp if appropriate
|
||||||
if (avatar.hasBillboardChangedAfterParsing(message->getMessage())) {
|
if (avatar.hasBillboardChangedAfterParsing(message->getMessage())) {
|
||||||
QMutexLocker nodeDataLocker(&nodeData->getMutex());
|
QMutexLocker nodeDataLocker(&nodeData->getMutex());
|
||||||
nodeData->setBillboardChangeTimestamp(QDateTime::currentMSecsSinceEpoch());
|
nodeData->flagBillboardChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#ifndef hifi_AvatarMixer_h
|
#ifndef hifi_AvatarMixer_h
|
||||||
#define hifi_AvatarMixer_h
|
#define hifi_AvatarMixer_h
|
||||||
|
|
||||||
|
#include <PortableHighResolutionClock.h>
|
||||||
|
|
||||||
#include <ThreadedAssignment.h>
|
#include <ThreadedAssignment.h>
|
||||||
|
|
||||||
/// Handles assignments of type AvatarMixer - distribution of avatar data to various clients
|
/// Handles assignments of type AvatarMixer - distribution of avatar data to various clients
|
||||||
|
@ -44,15 +46,15 @@ private:
|
||||||
|
|
||||||
QThread _broadcastThread;
|
QThread _broadcastThread;
|
||||||
|
|
||||||
quint64 _lastFrameTimestamp;
|
p_high_resolution_clock::time_point _lastFrameTimestamp;
|
||||||
|
|
||||||
float _trailingSleepRatio;
|
float _trailingSleepRatio { 1.0f };
|
||||||
float _performanceThrottlingRatio;
|
float _performanceThrottlingRatio { 0.0f };
|
||||||
|
|
||||||
int _sumListeners;
|
int _sumListeners { 0 };
|
||||||
int _numStatFrames;
|
int _numStatFrames { 0 };
|
||||||
int _sumBillboardPackets;
|
int _sumBillboardPackets { 0 };
|
||||||
int _sumIdentityPackets;
|
int _sumIdentityPackets { 0 };
|
||||||
|
|
||||||
float _maxKbpsPerNode = 0.0f;
|
float _maxKbpsPerNode = 0.0f;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <NodeData.h>
|
#include <NodeData.h>
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
#include <udt/PacketHeaders.h>
|
#include <udt/PacketHeaders.h>
|
||||||
|
#include <PortableHighResolutionClock.h>
|
||||||
#include <SimpleMovingAverage.h>
|
#include <SimpleMovingAverage.h>
|
||||||
#include <UUIDHasher.h>
|
#include <UUIDHasher.h>
|
||||||
|
|
||||||
|
@ -33,6 +34,8 @@ const QString INBOUND_AVATAR_DATA_STATS_KEY = "inbound_av_data_kbps";
|
||||||
class AvatarMixerClientData : public NodeData {
|
class AvatarMixerClientData : public NodeData {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
using HRCTime = p_high_resolution_clock::time_point;
|
||||||
|
|
||||||
int parseData(ReceivedMessage& message) override;
|
int parseData(ReceivedMessage& message) override;
|
||||||
AvatarData& getAvatar() { return *_avatar; }
|
AvatarData& getAvatar() { return *_avatar; }
|
||||||
|
|
||||||
|
@ -45,11 +48,11 @@ public:
|
||||||
|
|
||||||
uint16_t getLastReceivedSequenceNumber() const { return _lastReceivedSequenceNumber; }
|
uint16_t getLastReceivedSequenceNumber() const { return _lastReceivedSequenceNumber; }
|
||||||
|
|
||||||
quint64 getBillboardChangeTimestamp() const { return _billboardChangeTimestamp; }
|
HRCTime getBillboardChangeTimestamp() const { return _billboardChangeTimestamp; }
|
||||||
void setBillboardChangeTimestamp(quint64 billboardChangeTimestamp) { _billboardChangeTimestamp = billboardChangeTimestamp; }
|
void flagBillboardChange() { _billboardChangeTimestamp = p_high_resolution_clock::now(); }
|
||||||
|
|
||||||
quint64 getIdentityChangeTimestamp() const { return _identityChangeTimestamp; }
|
HRCTime getIdentityChangeTimestamp() const { return _identityChangeTimestamp; }
|
||||||
void setIdentityChangeTimestamp(quint64 identityChangeTimestamp) { _identityChangeTimestamp = identityChangeTimestamp; }
|
void flagIdentityChange() { _identityChangeTimestamp = p_high_resolution_clock::now(); }
|
||||||
|
|
||||||
void setFullRateDistance(float fullRateDistance) { _fullRateDistance = fullRateDistance; }
|
void setFullRateDistance(float fullRateDistance) { _fullRateDistance = fullRateDistance; }
|
||||||
float getFullRateDistance() const { return _fullRateDistance; }
|
float getFullRateDistance() const { return _fullRateDistance; }
|
||||||
|
@ -86,8 +89,8 @@ private:
|
||||||
std::unordered_map<QUuid, uint16_t> _lastBroadcastSequenceNumbers;
|
std::unordered_map<QUuid, uint16_t> _lastBroadcastSequenceNumbers;
|
||||||
std::unordered_set<QUuid> _hasReceivedFirstPacketsFrom;
|
std::unordered_set<QUuid> _hasReceivedFirstPacketsFrom;
|
||||||
|
|
||||||
quint64 _billboardChangeTimestamp = 0;
|
p_high_resolution_clock::time_point _billboardChangeTimestamp;
|
||||||
quint64 _identityChangeTimestamp = 0;
|
p_high_resolution_clock::time_point _identityChangeTimestamp;
|
||||||
|
|
||||||
float _fullRateDistance = FLT_MAX;
|
float _fullRateDistance = FLT_MAX;
|
||||||
float _maxAvatarDistance = FLT_MAX;
|
float _maxAvatarDistance = FLT_MAX;
|
||||||
|
|
Loading…
Reference in a new issue