add check in AvatarMixer for next adjustment

This commit is contained in:
Stephen Birarda 2015-04-30 15:36:31 -07:00
parent 3e842d7e34
commit 5b55a52a04
4 changed files with 25 additions and 16 deletions

View file

@ -30,7 +30,8 @@
const QString AVATAR_MIXER_LOGGING_NAME = "avatar-mixer";
const unsigned int AVATAR_DATA_SEND_INTERVAL_MSECS = (1.0f / 60.0f) * 1000;
const int AVATAR_MIXER_BROADCAST_FRAMES_PER_SECOND = 60;
const unsigned int AVATAR_DATA_SEND_INTERVAL_MSECS = (1.0f / (float) AVATAR_MIXER_BROADCAST_FRAMES_PER_SECOND) * 1000;
AvatarMixer::AvatarMixer(const QByteArray& packet) :
ThreadedAssignment(packet),
@ -54,6 +55,8 @@ AvatarMixer::~AvatarMixer() {
void attachAvatarDataToNode(Node* newNode) {
if (!newNode->getLinkedData()) {
// setup the client linked data - default the number of frames since adjustment
// to our number of frames per second
newNode->setLinkedData(new AvatarMixerClientData());
}
}
@ -166,6 +169,17 @@ void AvatarMixer::broadcastAvatarData() {
// reset the number of sent avatars
nodeData->resetNumAvatarsSentLastFrame();
// Check if it is time to adjust what we send this client based on the observed
// bandwidth to this node. We do this once a second, which is also the window for
// the bandwidth reported by node->getOutboundBandwidth();
if (nodeData->getNumFramesSinceAdjustment() > AVATAR_MIXER_BROADCAST_FRAMES_PER_SECOND) {
qDebug() << "Consider adjustment for avatar whose current send rate is" << node->getOutboundBandwidth();
nodeData->resetNumFramesSinceAdjustment();
} else {
nodeData->increaseNumFramesSinceAdjustment();
}
// this is an AGENT we have received head data from
// send back a packet with other active node data to this node
nodeList->eachMatchingNode(
@ -185,6 +199,7 @@ void AvatarMixer::broadcastAvatarData() {
if (!lock.isLocked()) {
return;
}
AvatarData& otherAvatar = otherNodeData->getAvatar();
// Decide whether to send this avatar's data based on it's distance from us

View file

@ -13,15 +13,6 @@
#include "AvatarMixerClientData.h"
AvatarMixerClientData::AvatarMixerClientData() :
NodeData(),
_hasReceivedFirstPackets(false),
_billboardChangeTimestamp(0),
_identityChangeTimestamp(0)
{
}
int AvatarMixerClientData::parseData(const QByteArray& packet) {
// compute the offset to the data payload
int offset = numBytesForPacketHeader(packet);

View file

@ -24,8 +24,6 @@
class AvatarMixerClientData : public NodeData {
Q_OBJECT
public:
AvatarMixerClientData();
int parseData(const QByteArray& packet);
AvatarData& getAvatar() { return _avatar; }
@ -44,15 +42,20 @@ public:
void increaseNumAvatarsSentLastFrame() { ++_numAvatarsSentLastFrame; }
int getNumAvatarsSentLastFrame() const { return _numAvatarsSentLastFrame; }
int getNumFramesSinceAdjustment() const { return _numFramesSinceAdjustment; }
void increaseNumFramesSinceAdjustment() { ++_numFramesSinceAdjustment; }
void resetNumFramesSinceAdjustment() { _numFramesSinceAdjustment = 0; }
void loadJSONStats(QJsonObject& jsonObject) const;
private:
AvatarData _avatar;
bool _hasReceivedFirstPackets;
quint64 _billboardChangeTimestamp;
quint64 _identityChangeTimestamp;
bool _hasReceivedFirstPackets = false;
quint64 _billboardChangeTimestamp = 0;
quint64 _identityChangeTimestamp = 0;
float _fullRateDistance = FLT_MAX;
float _maxFullRateDistance = FLT_MAX;
int _numAvatarsSentLastFrame = 0;
int _numFramesSinceAdjustment = 0;
};
#endif // hifi_AvatarMixerClientData_h

View file

@ -154,7 +154,7 @@ QVariantMap JSONBreakableMarshal::fromStringList(const QStringList& stringList)
QString keypath = marshalString.left(equalityIndex);
// setup for array index checking
const QString ARRAY_INDEX_REGEX_STRING = "^[\\d+]";
const QString ARRAY_INDEX_REGEX_STRING = "^\[\\d+\\]";
QRegExp arrayRegex(ARRAY_INDEX_REGEX_STRING);
// as long as we have a keypath we need to recurse downwards