From 2d86e807b0358d6a3abca100f93b55ba925edad5 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 15 Jul 2015 15:00:59 -0700 Subject: [PATCH 01/10] Move PACKET_WRITE_ERROR to Packet class --- libraries/networking/src/udt/Packet.cpp | 3 ++- libraries/networking/src/udt/Packet.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/Packet.cpp b/libraries/networking/src/udt/Packet.cpp index 31c861dc3c..27093dfddd 100644 --- a/libraries/networking/src/udt/Packet.cpp +++ b/libraries/networking/src/udt/Packet.cpp @@ -11,6 +11,8 @@ #include "Packet.h" +const qint64 Packet::PACKET_WRITE_ERROR = -1; + qint64 Packet::localHeaderSize(PacketType::Value type) { qint64 size = numBytesForArithmeticCodedPacketType(type) + sizeof(PacketVersion) + ((SEQUENCE_NUMBERED_PACKETS.contains(type)) ? sizeof(SequenceNumber) : 0); @@ -208,7 +210,6 @@ void Packet::writeSequenceNumber(SequenceNumber seqNum) { &seqNum, sizeof(seqNum)); } -static const qint64 PACKET_WRITE_ERROR = -1; qint64 Packet::writeData(const char* data, qint64 maxSize) { // make sure we have the space required to write this block diff --git a/libraries/networking/src/udt/Packet.h b/libraries/networking/src/udt/Packet.h index 40d021f2fc..c124e314f9 100644 --- a/libraries/networking/src/udt/Packet.h +++ b/libraries/networking/src/udt/Packet.h @@ -24,6 +24,8 @@ class Packet : public QIODevice { public: using SequenceNumber = uint16_t; + static const qint64 PACKET_WRITE_ERROR; + static std::unique_ptr create(PacketType::Value type, qint64 size = -1); static std::unique_ptr fromReceivedPacket(std::unique_ptr data, qint64 size, const HifiSockAddr& senderSockAddr); From ad61c3db41afd59fa2cfbd16f2e8820c6c4a8dab Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 15 Jul 2015 15:01:27 -0700 Subject: [PATCH 02/10] Fix bytesLeftToRead --- libraries/networking/src/udt/Packet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/Packet.h b/libraries/networking/src/udt/Packet.h index c124e314f9..7518923a4f 100644 --- a/libraries/networking/src/udt/Packet.h +++ b/libraries/networking/src/udt/Packet.h @@ -63,7 +63,7 @@ public: // Returns the number of bytes allocated for the payload qint64 getPayloadCapacity() const { return _payloadCapacity; } - qint64 bytesLeftToRead() const { return _payloadCapacity - pos(); } + qint64 bytesLeftToRead() const { return _payloadSize - pos(); } qint64 bytesAvailableForWrite() const { return _payloadCapacity - pos(); } HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; } From 07e3cf1348b320a13aace2581527941c15819ac3 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 15 Jul 2015 15:01:56 -0700 Subject: [PATCH 03/10] Add COMPARE_DATA to QTestExtensions --- libraries/networking/src/udt/Packet.h | 1 - tests/QTestExtensions.h | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/udt/Packet.h b/libraries/networking/src/udt/Packet.h index 7518923a4f..47861751d2 100644 --- a/libraries/networking/src/udt/Packet.h +++ b/libraries/networking/src/udt/Packet.h @@ -116,7 +116,6 @@ protected: HifiSockAddr _senderSockAddr; // sender address for packet (only used on receiving end) }; - template qint64 Packet::peekPrimitive(T* data) { return QIODevice::peek(reinterpret_cast(data), sizeof(T)); } diff --git a/tests/QTestExtensions.h b/tests/QTestExtensions.h index 213fe6d7b5..c374a9a507 100644 --- a/tests/QTestExtensions.h +++ b/tests/QTestExtensions.h @@ -251,6 +251,31 @@ do { \ #endif +#define QCOMPARE_WITH_EXPR(actual, expected, testExpr) \ + do { \ + if (!(testExpr)) { \ + QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \ + } \ + } while(0) +struct ByteData { + ByteData (const char* data, size_t length) + : data(data), length(length) {} + const char* data; + size_t length; +}; +QTextStream & operator << (QTextStream& stream, const ByteData & wrapper) { + // Print bytes as hex + stream << QByteArray::fromRawData(wrapper.data, wrapper.length).toHex(); + + return stream; +} + +bool compareData (const char* data, const char* expectedData, size_t length) { + return memcmp(data, expectedData, length) == 0; +} + +#define COMPARE_DATA(actual, expected, length) \ + QCOMPARE_WITH_EXPR((ByteData ( actual, length )), (ByteData ( expected, length )), compareData(actual, expected, length)) From d9b962c4d9cb46cd013fae3d4cae21552459f481 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 15 Jul 2015 15:02:08 -0700 Subject: [PATCH 04/10] Add packet tests --- tests/networking/src/PacketTests.cpp | 168 +++++++++++++++++++++++++++ tests/networking/src/PacketTests.h | 16 +++ 2 files changed, 184 insertions(+) diff --git a/tests/networking/src/PacketTests.cpp b/tests/networking/src/PacketTests.cpp index c8c88679fb..8ac4a6d94e 100644 --- a/tests/networking/src/PacketTests.cpp +++ b/tests/networking/src/PacketTests.cpp @@ -10,5 +10,173 @@ // #include "PacketTests.h" +#include "../QTestExtensions.h" + +#include QTEST_MAIN(PacketTests) + +std::unique_ptr copyToReadPacket(std::unique_ptr& packet) { + auto size = packet->getDataSize(); + auto data = std::unique_ptr(new char[size]); + memcpy(data.get(), packet->getData(), size); + return Packet::fromReceivedPacket(std::move(data), size, HifiSockAddr()); +} + +void PacketTests::emptyPacketTest() { + auto packet = Packet::create(PacketType::Unknown); + + QCOMPARE(packet->getType(), PacketType::Unknown); + QCOMPARE(packet->getPayloadSize(), 0); + QCOMPARE(packet->getDataSize(), packet->totalHeadersSize()); + QCOMPARE(packet->bytesLeftToRead(), 0); + QCOMPARE(packet->bytesAvailableForWrite(), packet->getPayloadCapacity()); +} + +void PacketTests::packetTypeTest() { + auto packet = Packet::create(PacketType::EntityAdd); + + QCOMPARE(packet->getType(), PacketType::EntityAdd); + + packet->setType(PacketType::MixedAudio); + QCOMPARE(packet->getType(), PacketType::MixedAudio); + + packet->setType(PacketType::MuteEnvironment); + QCOMPARE(packet->getType(), PacketType::MuteEnvironment); +} + +void PacketTests::writeTest() { + auto packet = Packet::create(PacketType::Unknown); + + QCOMPARE(packet->getPayloadSize(), 0); + + QCOMPARE(packet->write("somedata"), 8); + QCOMPARE(packet->getPayloadSize(), 8); + + QCOMPARE(packet->write("moredata"), 8); + QCOMPARE(packet->getPayloadSize(), 16); + + COMPARE_DATA(packet->getPayload(), "somedatamoredata", 16); +} + +void PacketTests::readTest() { + // Test reads for several different size packets + for (int i = 1; i < 4; i++) { + auto packet = Packet::create(PacketType::Unknown); + + auto size = packet->getPayloadCapacity(); + size /= i; + + char* data = new char[size]; + + // Fill with "random" data + for (qint64 i = 0; i < size; i++) { + data[i] = i; + } + + QCOMPARE(packet->write(data, size), size); + + auto readPacket = copyToReadPacket(packet); + + QCOMPARE(readPacket->getDataSize(), packet->getDataSize()); + QCOMPARE(readPacket->getPayloadSize(), packet->getPayloadSize()); + COMPARE_DATA(readPacket->getData(), packet->getData(), packet->getDataSize()); + COMPARE_DATA(readPacket->getPayload(), packet->getPayload(), packet->getPayloadSize()); + + auto payloadSize = readPacket->getPayloadSize(); + char* readData = new char[payloadSize]; + QCOMPARE(readPacket->read(readData, payloadSize), payloadSize); + COMPARE_DATA(readData, data, payloadSize); + } +} + +void PacketTests::writePastCapacityTest() { + auto packet = Packet::create(PacketType::Unknown); + + auto size = packet->getPayloadCapacity(); + char* data = new char[size]; + + // Fill with "random" data + for (qint64 i = 0; i < size; i++) { + data[i] = i; + } + + QCOMPARE(packet->getPayloadSize(), 0); + + QCOMPARE(packet->write(data, size), size); + + QCOMPARE(packet->getPayloadSize(), size); + COMPARE_DATA(packet->getPayload(), data, size); + + QCOMPARE(packet->bytesAvailableForWrite(), 0); + QCOMPARE(packet->getPayloadSize(), size); + + QCOMPARE(Packet::PACKET_WRITE_ERROR, packet->write("data")); + + // Packet::write() shouldn't allow the caller to write if no space is left + QCOMPARE(packet->getPayloadSize(), size); +} + +void PacketTests::primitiveTest() { + auto packet = Packet::create(PacketType::Unknown); + + int value1 = 5; + char value2 = 10; + bool value3 = true; + qint64 value4 = -93404; + + packet->writePrimitive(value1); + packet->writePrimitive(value2); + packet->writePrimitive(value3); + packet->writePrimitive(value4); + + auto recvPacket = copyToReadPacket(packet); + + // Peek & read first value + { + int peekValue = 0; + QCOMPARE(recvPacket->peekPrimitive(&peekValue), (int)sizeof(peekValue)); + QCOMPARE(peekValue, value1); + int readValue = 0; + QCOMPARE(recvPacket->readPrimitive(&readValue), (int)sizeof(readValue)); + QCOMPARE(readValue, value1); + } + + // Peek & read second value + { + char peekValue = 0; + QCOMPARE(recvPacket->peekPrimitive(&peekValue), (int)sizeof(peekValue)); + QCOMPARE(peekValue, value2); + + char readValue = 0; + QCOMPARE(recvPacket->readPrimitive(&readValue), (int)sizeof(readValue)); + QCOMPARE(readValue, value2); + } + + // Peek & read third value + { + bool peekValue = 0; + QCOMPARE(recvPacket->peekPrimitive(&peekValue), (int)sizeof(peekValue)); + QCOMPARE(peekValue, value3); + + bool readValue = 0; + QCOMPARE(recvPacket->readPrimitive(&readValue), (int)sizeof(readValue)); + QCOMPARE(readValue, value3); + } + + // Peek & read fourth value + { + qint64 peekValue = 0; + QCOMPARE(recvPacket->peekPrimitive(&peekValue), (int)sizeof(peekValue)); + QCOMPARE(peekValue, value4); + + qint64 readValue = 0; + QCOMPARE(recvPacket->readPrimitive(&readValue), (int)sizeof(readValue)); + QCOMPARE(readValue, value4); + } + + // We should be at the end of the packet, with no more to peek or read + int noValue; + QCOMPARE(recvPacket->peekPrimitive(&noValue), 0); + QCOMPARE(recvPacket->readPrimitive(&noValue), 0); +} diff --git a/tests/networking/src/PacketTests.h b/tests/networking/src/PacketTests.h index 498fddf39a..44ae193523 100644 --- a/tests/networking/src/PacketTests.h +++ b/tests/networking/src/PacketTests.h @@ -19,7 +19,23 @@ class PacketTests : public QObject { Q_OBJECT private slots: + // Test the base state of Packet + void emptyPacketTest(); + + // Test Packet writes + void writeTest(); + + // Test Packet reads void readTest(); + + // Test Packet writing past capacity + void writePastCapacityTest(); + + // Test primitive reads and writes + void primitiveTest(); + + // Test set/get packet type + void packetTypeTest(); }; #endif // hifi_PacketTests_h From 6502359f0435fa4d8b2f78523831f79b3651758a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 15 Jul 2015 16:29:15 -0700 Subject: [PATCH 05/10] Update NodeList's PacketReceiver to be a pointer --- libraries/networking/src/LimitedNodeList.cpp | 6 +++--- libraries/networking/src/LimitedNodeList.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 072286b9ab..c0ef16e61e 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -50,7 +50,7 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short _localSockAddr(), _publicSockAddr(), _stunSockAddr(STUN_SERVER_HOSTNAME, STUN_SERVER_PORT), - _packetReceiver(this), + _packetReceiver(new PacketReceiver(this)), _numCollectedPackets(0), _numCollectedBytes(0), _packetStatTimer(), @@ -99,12 +99,12 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short // TODO: Create a new thread, and move PacketReceiver to it - connect(&_nodeSocket, &QUdpSocket::readyRead, &_packetReceiver, &PacketReceiver::processDatagrams); + connect(&_nodeSocket, &QUdpSocket::readyRead, _packetReceiver, &PacketReceiver::processDatagrams); _packetStatTimer.start(); // make sure we handle STUN response packets - _packetReceiver.registerListener(PacketType::StunResponse, this, "processSTUNResponse"); + _packetReceiver->registerListener(PacketType::StunResponse, this, "processSTUNResponse"); } void LimitedNodeList::setSessionUUID(const QUuid& sessionUUID) { diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index a2cbac7348..7f0dd1eae9 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -117,7 +117,7 @@ public: bool packetSourceAndHashMatch(const NLPacket& packet, SharedNodePointer& matchingNode); - PacketReceiver& getPacketReceiver() { return _packetReceiver; } + PacketReceiver& getPacketReceiver() { return *_packetReceiver; } qint64 sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode); qint64 sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr, @@ -276,7 +276,7 @@ protected: HifiSockAddr _publicSockAddr; HifiSockAddr _stunSockAddr; - PacketReceiver _packetReceiver; + PacketReceiver* _packetReceiver; // XXX can BandwidthRecorder be used for this? int _numCollectedPackets; From 1d1962d5f5a449e88dfab1274ecf42761bc48e5f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 16 Jul 2015 12:10:28 -0700 Subject: [PATCH 06/10] Fix avatar data processing --- libraries/avatars/src/AvatarHashMap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 2ad997c306..83706ee9f4 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -68,12 +68,12 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer packet, Sha } // have the matching (or new) avatar parse the data from the packet - int bytesRead = avatar->parseDataFromBuffer(QByteArray::fromRawData(packet->getPayload(), packet->pos())); + int bytesRead = avatar->parseDataFromBuffer(QByteArray::fromRawData(packet->getPayload(), packet->getPayloadSize())); packet->seek(packet->pos() + bytesRead); } else { // create a dummy AvatarData class to throw this data on the ground AvatarData dummyData; - int bytesRead = dummyData.parseDataFromBuffer(QByteArray::fromRawData(packet->getPayload(), packet->pos())); + int bytesRead = dummyData.parseDataFromBuffer(QByteArray::fromRawData(packet->getPayload(), packet->getPayloadSize())); packet->seek(packet->pos() + bytesRead); } } From b4121eb464adf6a154535fb2120e3d77c5d512fe Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 16 Jul 2015 13:14:17 -0700 Subject: [PATCH 07/10] Remove unnecessary move --- interface/src/Application.cpp | 2 +- libraries/entities/src/EntityTree.cpp | 2 +- libraries/networking/src/LimitedNodeList.cpp | 4 ++-- libraries/networking/src/NLPacketList.cpp | 2 +- libraries/networking/src/udt/PacketList.cpp | 4 ++-- libraries/networking/src/udt/PacketList.h | 2 +- libraries/octree/src/JurisdictionMap.cpp | 4 ++-- libraries/octree/src/OctreeEditPacketSender.cpp | 3 +-- libraries/shared/src/GLMHelpers.cpp | 2 +- 9 files changed, 12 insertions(+), 13 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f61f725c4e..b03df3a1cc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1797,7 +1797,7 @@ void Application::sendPingPackets() { return false; } }, [nodeList](const SharedNodePointer& node) { - nodeList->sendPacket(std::move(nodeList->constructPingPacket()), *node); + nodeList->sendPacket(nodeList->constructPingPacket(), *node); }); } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d5f2026978..ba2691aa3b 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -826,7 +826,7 @@ std::unique_ptr EntityTree::encodeEntitiesDeletedSince(OCTREE_PACKET_S deletesPacket->seek(numberOfIDsPos); deletesPacket->writePrimitive(numberOfIDs); - return std::move(deletesPacket); + return deletesPacket; } diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index badfbef60a..4a15602f95 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -290,7 +290,7 @@ qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& des packetList.closeCurrentPacket(); while (!packetList._packets.empty()) { - bytesSent += sendPacket(std::move(packetList.takeFront()), destinationNode); + bytesSent += sendPacket(packetList.takeFront(), destinationNode); } return bytesSent; @@ -304,7 +304,7 @@ qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockA packetList.closeCurrentPacket(); while (!packetList._packets.empty()) { - bytesSent += sendPacket(std::move(packetList.takeFront()), sockAddr, connectionSecret); + bytesSent += sendPacket(packetList.takeFront(), sockAddr, connectionSecret); } return bytesSent; diff --git a/libraries/networking/src/NLPacketList.cpp b/libraries/networking/src/NLPacketList.cpp index 85b413eda9..7ac9fe11c3 100644 --- a/libraries/networking/src/NLPacketList.cpp +++ b/libraries/networking/src/NLPacketList.cpp @@ -17,6 +17,6 @@ NLPacketList::NLPacketList(PacketType::Value packetType) : PacketList(packetType } std::unique_ptr NLPacketList::createPacket() { - return std::move(NLPacket::create(getType())); + return NLPacket::create(getType()); } diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index 4036e872fd..9e3921e325 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -31,7 +31,7 @@ void PacketList::endSegment() { std::unique_ptr PacketList::createPacket() { // use the static create method to create a new packet - return std::move(Packet::create(getType())); + return Packet::create(getType()); } std::unique_ptr PacketList::createPacketWithExtendedHeader() { @@ -46,7 +46,7 @@ std::unique_ptr PacketList::createPacketWithExtendedHeader() { } } - return std::move(packet); + return packet; } qint64 PacketList::writeData(const char* data, qint64 maxSize) { diff --git a/libraries/networking/src/udt/PacketList.h b/libraries/networking/src/udt/PacketList.h index f4b542155a..0a1bdd080a 100644 --- a/libraries/networking/src/udt/PacketList.h +++ b/libraries/networking/src/udt/PacketList.h @@ -80,7 +80,7 @@ template std::unique_ptr PacketList::takeFront() { auto packet = std::move(_packets.front()); _packets.pop_front(); - return std::move(std::unique_ptr(dynamic_cast(packet.release()))); + return std::unique_ptr(dynamic_cast(packet.release())); } #endif // hifi_PacketList_h \ No newline at end of file diff --git a/libraries/octree/src/JurisdictionMap.cpp b/libraries/octree/src/JurisdictionMap.cpp index 64e8a7bca5..255652a3cc 100644 --- a/libraries/octree/src/JurisdictionMap.cpp +++ b/libraries/octree/src/JurisdictionMap.cpp @@ -260,7 +260,7 @@ std::unique_ptr JurisdictionMap::packEmptyJurisdictionIntoMessage(Node // No root or end node details to pack! packet->writePrimitive(bytes); - return std::move(packet); // includes header! + return packet; // includes header! } std::unique_ptr JurisdictionMap::packIntoPacket() { @@ -295,7 +295,7 @@ std::unique_ptr JurisdictionMap::packIntoPacket() { packet->writePrimitive(bytes); } - return std::move(packet); + return packet; } int JurisdictionMap::unpackFromPacket(NLPacket& packet) { diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 4df172008f..30e1630e36 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -121,8 +121,7 @@ void OctreeEditPacketSender::processPreServerExistsPackets() { // First send out all the single message packets... _pendingPacketsLock.lock(); while (!_preServerSingleMessagePackets.empty()) { - std::unique_ptr packet = std::move(_preServerSingleMessagePackets.front()); - queuePacketToNodes(std::move(packet)); + queuePacketToNodes(std::move(_preServerSingleMessagePackets.front())); _preServerSingleMessagePackets.pop_front(); } diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index 53b3b90560..d5b2917369 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -327,7 +327,7 @@ glm::vec2 toGlm(const QPointF & pt) { glm::vec3 toGlm(const xColor & color) { static const float MAX_COLOR = 255.0f; - return std::move(glm::vec3(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR)); + return glm::vec3(color.red, color.green, color.blue) / MAX_COLOR; } glm::vec4 toGlm(const QColor & color) { From 00fbff112f102925fa23db2c9194407b56628e1a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 16 Jul 2015 14:03:11 -0700 Subject: [PATCH 08/10] Process avatar data --- libraries/avatars/src/AvatarHashMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 3243ff3f9a..0dbc1a5e46 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -22,7 +22,7 @@ AvatarHashMap::AvatarHashMap() { connect(DependencyManager::get().data(), &NodeList::uuidChanged, this, &AvatarHashMap::sessionUUIDChanged); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); - packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket"); + packetReceiver.registerListener(PacketType::AvatarData, this, "processAvatarDataPacket"); packetReceiver.registerListener(PacketType::KillAvatar, this, "processKillAvatar"); packetReceiver.registerListener(PacketType::AvatarIdentity, this, "processAvatarIdentityPacket"); packetReceiver.registerListener(PacketType::AvatarBillboard, this, "processAvatarBillboardPacket"); From f8f47f99c659bb8dd48daac6aab32c0f8f02fd49 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 16 Jul 2015 14:03:36 -0700 Subject: [PATCH 09/10] Temporarily disable body lean in avatar --- libraries/avatars/src/AvatarData.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 5d439b4aec..dc6f507c0d 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -166,10 +166,10 @@ QByteArray AvatarData::toByteArray() { destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalYaw()); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalRoll()); - // Body lean - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist); + // // Body lean + // destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward); + // destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways); + // destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist); // Lookat Position memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition)); From b561014d775003bbf94efa8c4212214e941fdf22 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 16 Jul 2015 14:11:36 -0700 Subject: [PATCH 10/10] Add head-lean reading back into AvatarData --- libraries/avatars/src/AvatarData.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index dc6f507c0d..c5e4946b9c 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -166,10 +166,10 @@ QByteArray AvatarData::toByteArray() { destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalYaw()); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalRoll()); - // // Body lean - // destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward); - // destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways); - // destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist); + // Body lean + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist); // Lookat Position memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition)); @@ -371,6 +371,22 @@ int AvatarData::parseDataFromBuffer(const QByteArray& buffer) { _headData->setBaseRoll(headRoll); } // 6 bytes + { // Head lean (relative to pelvis) + float leanForward, leanSideways, torsoTwist; + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanForward); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanSideways); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &torsoTwist); + if (glm::isnan(leanForward) || glm::isnan(leanSideways)) { + if (shouldLogError(now)) { + qCDebug(avatars) << "Discard nan AvatarData::leanForward,leanSideways,torsoTwise; displayName = '" << _displayName << "'"; + } + return maxAvailableSize; + } + _headData->_leanForward = leanForward; + _headData->_leanSideways = leanSideways; + _headData->_torsoTwist = torsoTwist; + } // 6 bytes + { // Lookat Position glm::vec3 lookAt; memcpy(&lookAt, sourceBuffer, sizeof(lookAt));