From 00487fb175651069acb43cc6580b573adbb1b5fc Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 15 Jan 2015 09:45:51 -0800 Subject: [PATCH] Fix issue with avatar data being sent too often --- interface/src/Application.cpp | 7 ++++++- interface/src/Application.h | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index af29aff5ef..a431bbb404 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2135,12 +2135,17 @@ void Application::updateMyAvatar(float deltaTime) { _myAvatar->update(deltaTime); - { + quint64 now = usecTimestampNow(); + quint64 dt = now - _lastSendAvatarDataTime; + + if (dt > MIN_TIME_BETWEEN_MY_AVATAR_DATA_SENDS) { // send head/hand data to the avatar mixer and voxel server PerformanceTimer perfTimer("send"); QByteArray packet = byteArrayWithPopulatedHeader(PacketTypeAvatarData); packet.append(_myAvatar->toByteArray()); controlledBroadcastToNodes(packet, NodeSet() << NodeType::AvatarMixer); + + _lastSendAvatarDataTime = now; } } diff --git a/interface/src/Application.h b/interface/src/Application.h index 451bfdc5e1..d7a826d9ea 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -111,6 +111,10 @@ static const float MIRROR_REARVIEW_DISTANCE = 0.722f; static const float MIRROR_REARVIEW_BODY_DISTANCE = 2.56f; static const float MIRROR_FIELD_OF_VIEW = 30.0f; +// 70 times per second - target is 60hz, but this helps account for any small deviations +// in the update loop +static const quint64 MIN_TIME_BETWEEN_MY_AVATAR_DATA_SENDS = (1000 * 1000) / 70; + static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND; static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html"; @@ -567,6 +571,8 @@ private: quint64 _lastNackTime; quint64 _lastSendDownstreamAudioStats; + quint64 _lastSendAvatarDataTime; + bool _isVSyncOn; bool _aboutToQuit;