diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 913f22be18..f4f9d6fb69 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -97,9 +97,6 @@ void Agent::run() { // setup an Avatar for the script to use AvatarData scriptedAvatar; - // match the scripted avatar's UUID to the DataServerScriptingInterface UUID - scriptedAvatar.setUUID(_scriptEngine.getDataServerScriptingInterface().getUUID()); - // give this AvatarData object to the script engine _scriptEngine.setAvatarData(&scriptedAvatar, "Avatar"); diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index d05ea7a7c0..6af6ed478d 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -71,7 +71,6 @@ foreach(EXTERNAL_SOURCE_SUBDIR ${EXTERNAL_SOURCE_SUBDIRS}) set(INTERFACE_SRCS ${INTERFACE_SRCS} ${SUBDIR_SRCS}) endforeach(EXTERNAL_SOURCE_SUBDIR) - find_package(Qt5Core REQUIRED) find_package(Qt5Gui REQUIRED) find_package(Qt5Multimedia REQUIRED) @@ -81,7 +80,14 @@ find_package(Qt5Svg REQUIRED) find_package(Qt5WebKit REQUIRED) find_package(Qt5WebKitWidgets REQUIRED) find_package(Qt5Xml REQUIRED) -find_package(Qt5UiTools REQUIRED) + +# grab the ui files in resources/ui +file (GLOB_RECURSE QT_UI_FILES ui/*.ui) +# have qt5 wrap them and generate the appropriate header files +qt5_wrap_ui(QT_UI_HEADERS ${QT_UI_FILES}) + +# add them to the interface source files +set(INTERFACE_SRCS ${INTERFACE_SRCS} ${QT_UI_HEADERS}) if (APPLE) set(MACOSX_BUNDLE_BUNDLE_NAME Interface) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index de1bbb059c..9dc4dc5d8f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2438,17 +2438,14 @@ void Application::updateAvatar(float deltaTime) { // Get audio loudness data from audio input device _myAvatar.getHead().setAudioLoudness(_audio.getLastInputLoudness()); - NodeList* nodeList = NodeList::getInstance(); - // send head/hand data to the avatar mixer and voxel server unsigned char broadcastString[MAX_PACKET_SIZE]; unsigned char* endOfBroadcastStringWrite = broadcastString; endOfBroadcastStringWrite += populateTypeAndVersion(endOfBroadcastStringWrite, PACKET_TYPE_HEAD_DATA); - QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); - memcpy(endOfBroadcastStringWrite, ownerUUID.constData(), ownerUUID.size()); - endOfBroadcastStringWrite += ownerUUID.size(); + // pack the NodeList owner UUID + endOfBroadcastStringWrite += NodeList::getInstance()->packOwnerUUID(endOfBroadcastStringWrite); endOfBroadcastStringWrite += _myAvatar.getBroadcastData(endOfBroadcastStringWrite); @@ -3857,6 +3854,11 @@ void Application::setMenuShortcutsEnabled(bool enabled) { void Application::attachNewHeadToNode(Node* newNode) { if (newNode->getLinkedData() == NULL) { newNode->setLinkedData(new Avatar(newNode)); + + // new UUID requires mesh and skeleton request to data-server + DataServerClient::getValuesForKeysAndUUID(QStringList() << DataServerKey::FaceMeshURL << DataServerKey::SkeletonURL, + newNode->getUUID(), Application::getInstance()->getProfile()); + } } diff --git a/interface/src/VoxelHideShowThread.h b/interface/src/VoxelHideShowThread.h index 22df6c299c..2925888022 100644 --- a/interface/src/VoxelHideShowThread.h +++ b/interface/src/VoxelHideShowThread.h @@ -15,7 +15,7 @@ #include "VoxelSystem.h" /// Generalized threaded processor for handling received inbound packets. -class VoxelHideShowThread : public virtual GenericThread { +class VoxelHideShowThread : public GenericThread { public: VoxelHideShowThread(VoxelSystem* theSystem); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 30de5b1e2a..7705a5d03e 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -345,20 +345,11 @@ int Avatar::parseData(unsigned char* sourceBuffer, int numBytes) { // change in position implies movement glm::vec3 oldPosition = _position; - // change in UUID requires mesh and skeleton request to data-server - - QUuid oldUuid = _uuid; - int bytesRead = AvatarData::parseData(sourceBuffer, numBytes); const float MOVE_DISTANCE_THRESHOLD = 0.001f; _moving = glm::distance(oldPosition, _position) > MOVE_DISTANCE_THRESHOLD; - if (oldUuid != _uuid && !_uuid.isNull()) { - DataServerClient::getValuesForKeysAndUUID(QStringList() << DataServerKey::FaceMeshURL << DataServerKey::SkeletonURL, - _uuid, Application::getInstance()->getProfile()); - } - return bytesRead; } diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index 89ce750d68..dfd06daa4a 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -48,8 +48,8 @@ QString Profile::getUserString() const { void Profile::setUUID(const QUuid& uuid) { _uuid = uuid; - // when the UUID is changed we need set it appropriately on our avatar instance - Application::getInstance()->getAvatar()->setUUID(_uuid); + // when the UUID is changed we need set it appropriately on the NodeList instance + NodeList::getInstance()->setOwnerUUID(uuid); } void Profile::setFaceModelURL(const QUrl& faceModelURL) { @@ -156,19 +156,15 @@ void Profile::processDataServerResponse(const QString& userString, const QString Application::getInstance()->getProfile()->setFaceModelURL(QUrl(valueList[i])); } else { // mesh URL for a UUID, find avatar in our list - - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { - if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { - Avatar* avatar = (Avatar *) node->getLinkedData(); - - if (avatar->getUUID() == QUuid(userString)) { - qDebug() << "Changing mesh to" << valueList[i] << "for avatar with UUID" - << uuidStringWithoutCurlyBraces(avatar->getUUID()); - - QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(), - "setURL", Q_ARG(QUrl, QUrl(valueList[i]))); - } - } + SharedNodePointer matchingNode = NodeList::getInstance()->nodeWithUUID(QUuid(userString)); + if (matchingNode && matchingNode->getType() == NODE_TYPE_AGENT) { + qDebug() << "Changing mesh to" << valueList[i] << "for avatar with UUID" + << uuidStringWithoutCurlyBraces(matchingNode->getUUID()); + + Avatar* avatar = (Avatar *) matchingNode->getLinkedData(); + + QMetaObject::invokeMethod(&avatar->getHead().getFaceModel(), + "setURL", Q_ARG(QUrl, QUrl(valueList[i]))); } } } else if (keyList[i] == DataServerKey::SkeletonURL) { @@ -177,18 +173,15 @@ void Profile::processDataServerResponse(const QString& userString, const QString Application::getInstance()->getProfile()->setSkeletonModelURL(QUrl(valueList[i])); } else { // skeleton URL for a UUID, find avatar in our list - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { - if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { - Avatar* avatar = (Avatar *) node->getLinkedData(); - - if (avatar->getUUID() == QUuid(userString)) { - qDebug() << "Changing skeleton to" << valueList[i] << "for avatar with UUID" - << uuidStringWithoutCurlyBraces(avatar->getUUID()); - - QMetaObject::invokeMethod(&avatar->getSkeletonModel(), "setURL", - Q_ARG(QUrl, QUrl(valueList[i]))); - } - } + SharedNodePointer matchingNode = NodeList::getInstance()->nodeWithUUID(QUuid(userString)); + if (matchingNode && matchingNode->getType() == NODE_TYPE_AGENT) { + qDebug() << "Changing skeleton to" << valueList[i] << "for avatar with UUID" + << uuidStringWithoutCurlyBraces(matchingNode->getUUID()); + + Avatar* avatar = (Avatar *) matchingNode->getLinkedData(); + + QMetaObject::invokeMethod(&avatar->getSkeletonModel(), + "setURL", Q_ARG(QUrl, QUrl(valueList[i]))); } } } else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position && diff --git a/interface/src/ui/LogDialog.cpp b/interface/src/ui/LogDialog.cpp index b532c0fe52..474b4f034e 100644 --- a/interface/src/ui/LogDialog.cpp +++ b/interface/src/ui/LogDialog.cpp @@ -97,7 +97,7 @@ void LogDialog::initControls() { } void LogDialog::showEvent(QShowEvent*) { - connect(_logger, SIGNAL(logReceived(QString)), this, SLOT(appendLogLine(QString))); + connect(_logger, SIGNAL(logReceived(QString)), this, SLOT(appendLogLine(QString)), Qt::QueuedConnection); showLogData(); } @@ -111,11 +111,9 @@ void LogDialog::resizeEvent(QResizeEvent*) { void LogDialog::appendLogLine(QString logLine) { if (isVisible()) { - _mutex.lock(); if (logLine.contains(_searchTerm, Qt::CaseInsensitive)) { _logTextBox->appendPlainText(logLine.simplified()); } - _mutex.unlock(); _logTextBox->ensureCursorVisible(); } } @@ -140,12 +138,10 @@ void LogDialog::handleSearchTextChanged(const QString searchText) { void LogDialog::showLogData() { _logTextBox->clear(); - _mutex.lock(); QStringList _logData = _logger->getLogData(); for (int i = 0; i < _logData.size(); ++i) { appendLogLine(_logData[i]); } - _mutex.unlock(); } KeywordHighlighter::KeywordHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent), keywordFormat() { diff --git a/interface/src/ui/LogDialog.h b/interface/src/ui/LogDialog.h index c8e7441d3c..17216db0c4 100644 --- a/interface/src/ui/LogDialog.h +++ b/interface/src/ui/LogDialog.h @@ -60,7 +60,6 @@ private: QCheckBox* _extraDebuggingBox; QPushButton* _revealLogButton; QPlainTextEdit* _logTextBox; - QMutex _mutex; QString _searchTerm; KeywordHighlighter* _highlighter; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp index 12c5cd83e0..deb671427f 100644 --- a/interface/src/ui/UpdateDialog.cpp +++ b/interface/src/ui/UpdateDialog.cpp @@ -6,48 +6,40 @@ // Copyright (c) 2013, 2014 High Fidelity, Inc. All rights reserved. // -#include -#include -#include #include -#include -#include -#include -#include #include "Application.h" -#include "SharedUtil.h" +#include "ui_updateDialog.h" + #include "UpdateDialog.h" + UpdateDialog::UpdateDialog(QWidget *parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL) : - QWidget(parent, Qt::Widget), + QDialog(parent), _latestVersion(latestVersion), - _downloadUrl(downloadURL) { - - QUiLoader updateDialogLoader; - QWidget* updateDialog; - QFile updateDialogUi("resources/ui/updateDialog.ui"); - updateDialogUi.open(QFile::ReadOnly); - updateDialog = updateDialogLoader.load(&updateDialogUi, this); + _downloadUrl(downloadURL) +{ + Ui::Dialog dialogUI; + dialogUI.setupUi(this); QString updateRequired = QString("You are currently running build %1, the latest build released is %2. \ Please download and install the most recent release to access the latest features and bug fixes.") .arg(Application::getInstance()->applicationVersion(), latestVersion); + setAttribute(Qt::WA_DeleteOnClose); - updateDialog->setAttribute(Qt::WA_DeleteOnClose); - - QPushButton* downloadButton = updateDialog->findChild("downloadButton"); - QPushButton* skipButton = updateDialog->findChild("skipButton"); - QPushButton* closeButton = updateDialog->findChild("closeButton"); - QLabel* updateContent = updateDialog->findChild("updateContent"); + QPushButton* downloadButton = findChild("downloadButton"); + QPushButton* skipButton = findChild("skipButton"); + QPushButton* closeButton = findChild("closeButton"); + QLabel* updateContent = findChild("updateContent"); updateContent->setText(updateRequired); connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip())); connect(closeButton, SIGNAL(released()), this, SLOT(close())); - updateDialog->show(); + + QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection); } void UpdateDialog::handleDownload() { diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h index 1c4f5de9d0..14f4e6f39c 100644 --- a/interface/src/ui/UpdateDialog.h +++ b/interface/src/ui/UpdateDialog.h @@ -11,7 +11,7 @@ #include -class UpdateDialog : public QWidget { +class UpdateDialog : public QDialog { Q_OBJECT public: diff --git a/interface/resources/ui/updateDialog.ui b/interface/ui/updateDialog.ui similarity index 100% rename from interface/resources/ui/updateDialog.ui rename to interface/ui/updateDialog.ui diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 35e6c37e96..1ae44bb57a 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -24,7 +24,6 @@ static const float fingerVectorRadix = 4; // bits of precision when converting f AvatarData::AvatarData(Node* owningNode) : NodeData(owningNode), - _uuid(), _handPosition(0,0,0), _bodyYaw(-90.0), _bodyPitch(0.0), @@ -69,11 +68,6 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { _handData = new HandData(this); } - // UUID - QByteArray uuidByteArray = _uuid.toRfc4122(); - memcpy(destinationBuffer, uuidByteArray.constData(), uuidByteArray.size()); - destinationBuffer += uuidByteArray.size(); - // Body world position memcpy(destinationBuffer, &_position, sizeof(float) * 3); destinationBuffer += sizeof(float) * 3; @@ -180,11 +174,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { // push past the node session UUID sourceBuffer += NUM_BYTES_RFC4122_UUID; - - // user UUID - _uuid = QUuid::fromRfc4122(QByteArray((char*) sourceBuffer, NUM_BYTES_RFC4122_UUID)); - sourceBuffer += NUM_BYTES_RFC4122_UUID; - + // Body world position memcpy(&_position, sourceBuffer, sizeof(float) * 3); sourceBuffer += sizeof(float) * 3; diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 0005d1eb11..ac0d198fc9 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -82,9 +82,6 @@ public: int getBroadcastData(unsigned char* destinationBuffer); int parseData(unsigned char* sourceBuffer, int numBytes); - QUuid& getUUID() { return _uuid; } - void setUUID(const QUuid& uuid) { _uuid = uuid; } - // Body Rotation float getBodyYaw() const { return _bodyYaw; } void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; } @@ -137,8 +134,6 @@ public: } protected: - QUuid _uuid; - glm::vec3 _position; glm::vec3 _handPosition; diff --git a/libraries/octree-server/src/OctreeSendThread.h b/libraries/octree-server/src/OctreeSendThread.h index a2de8fcb5d..c0936371f2 100644 --- a/libraries/octree-server/src/OctreeSendThread.h +++ b/libraries/octree-server/src/OctreeSendThread.h @@ -17,7 +17,7 @@ #include "OctreeServer.h" /// Threaded processor for sending voxel packets to a single client -class OctreeSendThread : public virtual GenericThread { +class OctreeSendThread : public GenericThread { public: OctreeSendThread(const QUuid& nodeUUID, OctreeServer* myServer); diff --git a/libraries/octree/src/JurisdictionListener.cpp b/libraries/octree/src/JurisdictionListener.cpp index d8919ac48e..6ed039f0bd 100644 --- a/libraries/octree/src/JurisdictionListener.cpp +++ b/libraries/octree/src/JurisdictionListener.cpp @@ -16,13 +16,13 @@ #include "JurisdictionListener.h" JurisdictionListener::JurisdictionListener(NODE_TYPE type, PacketSenderNotify* notify) : - PacketSender(notify, JurisdictionListener::DEFAULT_PACKETS_PER_SECOND) + _packetSender(notify, JurisdictionListener::DEFAULT_PACKETS_PER_SECOND) { _nodeType = type; ReceivedPacketProcessor::_dontSleep = true; // we handle sleeping so this class doesn't need to -// connect(nodeList, &NodeList::nodeKilled, this, &JurisdictionListener::nodeKilled); -// qDebug("JurisdictionListener::JurisdictionListener(NODE_TYPE type=%c)\n", type); + connect(NodeList::getInstance(), &NodeList::nodeKilled, this, &JurisdictionListener::nodeKilled); + //qDebug("JurisdictionListener::JurisdictionListener(NODE_TYPE type=%c)", type); } void JurisdictionListener::nodeKilled(SharedNodePointer node) { @@ -32,7 +32,7 @@ void JurisdictionListener::nodeKilled(SharedNodePointer node) { } bool JurisdictionListener::queueJurisdictionRequest() { - //qDebug() << "JurisdictionListener::queueJurisdictionRequest()\n"; + //qDebug() << "JurisdictionListener::queueJurisdictionRequest()"; static unsigned char buffer[MAX_PACKET_SIZE]; unsigned char* bufferOut = &buffer[0]; @@ -45,15 +45,15 @@ bool JurisdictionListener::queueJurisdictionRequest() { if (nodeList->getNodeActiveSocketOrPing(node.data()) && node->getType() == getNodeType()) { const HifiSockAddr* nodeAddress = node->getActiveSocket(); - PacketSender::queuePacketForSending(*nodeAddress, bufferOut, sizeOut); + _packetSender.queuePacketForSending(*nodeAddress, bufferOut, sizeOut); nodeCount++; } } if (nodeCount > 0){ - setPacketsPerSecond(nodeCount); + _packetSender.setPacketsPerSecond(nodeCount); } else { - setPacketsPerSecond(NO_SERVER_CHECK_RATE); + _packetSender.setPacketsPerSecond(NO_SERVER_CHECK_RATE); } // keep going if still running @@ -61,6 +61,7 @@ bool JurisdictionListener::queueJurisdictionRequest() { } void JurisdictionListener::processPacket(const HifiSockAddr& senderAddress, unsigned char* packetData, ssize_t packetLength) { + //qDebug() << "JurisdictionListener::processPacket()"; if (packetData[0] == PACKET_TYPE_JURISDICTION) { SharedNodePointer node = NodeList::getInstance()->nodeWithAddress(senderAddress); if (node) { @@ -73,12 +74,17 @@ void JurisdictionListener::processPacket(const HifiSockAddr& senderAddress, unsi } bool JurisdictionListener::process() { + //qDebug() << "JurisdictionListener::process()"; bool continueProcessing = isStillRunning(); // If we're still running, and we don't have any requests waiting to be sent, then queue our jurisdiction requests - if (continueProcessing && !hasPacketsToSend()) { + if (continueProcessing && !_packetSender.hasPacketsToSend()) { queueJurisdictionRequest(); - continueProcessing = PacketSender::process(); + } + + if (continueProcessing) { + //qDebug() << "JurisdictionListener::process() calling _packetSender.process()"; + continueProcessing = _packetSender.process(); } if (continueProcessing) { // NOTE: This will sleep if there are no pending packets to process diff --git a/libraries/octree/src/JurisdictionListener.h b/libraries/octree/src/JurisdictionListener.h index 393ca80420..c112f43b52 100644 --- a/libraries/octree/src/JurisdictionListener.h +++ b/libraries/octree/src/JurisdictionListener.h @@ -22,7 +22,7 @@ /// the PACKET_TYPE_JURISDICTION packets it receives in order to maintain an accurate state of all jurisidictions /// within the domain. As with other ReceivedPacketProcessor classes the user is responsible for reading inbound packets /// and adding them to the processing queue by calling queueReceivedPacket() -class JurisdictionListener : public PacketSender, public ReceivedPacketProcessor { +class JurisdictionListener : public ReceivedPacketProcessor { public: static const int DEFAULT_PACKETS_PER_SECOND = 1; static const int NO_SERVER_CHECK_RATE = 60; // if no servers yet detected, keep checking at 60fps @@ -55,5 +55,7 @@ private: NODE_TYPE _nodeType; bool queueJurisdictionRequest(); + + PacketSender _packetSender; }; #endif // __shared__JurisdictionListener__ diff --git a/libraries/octree/src/JurisdictionMap.cpp b/libraries/octree/src/JurisdictionMap.cpp index 53cc955553..bf64e19959 100644 --- a/libraries/octree/src/JurisdictionMap.cpp +++ b/libraries/octree/src/JurisdictionMap.cpp @@ -331,16 +331,20 @@ int JurisdictionMap::unpackFromMessage(unsigned char* sourceBuffer, int availabl // increment to push past the packet header int numBytesPacketHeader = numBytesForPacketHeader(sourceBuffer); sourceBuffer += numBytesPacketHeader; + int remainingBytes = availableBytes - numBytesPacketHeader; // read the root jurisdiction int bytes = 0; memcpy(&bytes, sourceBuffer, sizeof(bytes)); sourceBuffer += sizeof(bytes); + remainingBytes -= sizeof(bytes); - if (bytes > 0) { + if (bytes > 0 && bytes <= remainingBytes) { _rootOctalCode = new unsigned char[bytes]; memcpy(_rootOctalCode, sourceBuffer, bytes); sourceBuffer += bytes; + remainingBytes -= bytes; + // if and only if there's a root jurisdiction, also include the end nodes int endNodeCount = 0; memcpy(&endNodeCount, sourceBuffer, sizeof(endNodeCount)); @@ -349,13 +353,18 @@ int JurisdictionMap::unpackFromMessage(unsigned char* sourceBuffer, int availabl int bytes = 0; memcpy(&bytes, sourceBuffer, sizeof(bytes)); sourceBuffer += sizeof(bytes); - unsigned char* endNodeCode = new unsigned char[bytes]; - memcpy(endNodeCode, sourceBuffer, bytes); - sourceBuffer += bytes; + remainingBytes -= sizeof(bytes); - // if the endNodeCode was 0 length then don't add it - if (bytes > 0) { - _endNodes.push_back(endNodeCode); + if (bytes <= remainingBytes) { + unsigned char* endNodeCode = new unsigned char[bytes]; + memcpy(endNodeCode, sourceBuffer, bytes); + sourceBuffer += bytes; + remainingBytes -= bytes; + + // if the endNodeCode was 0 length then don't add it + if (bytes > 0) { + _endNodes.push_back(endNodeCode); + } } } } diff --git a/libraries/octree/src/JurisdictionSender.cpp b/libraries/octree/src/JurisdictionSender.cpp index ab31f9356b..521dbdb7e4 100644 --- a/libraries/octree/src/JurisdictionSender.cpp +++ b/libraries/octree/src/JurisdictionSender.cpp @@ -17,9 +17,9 @@ JurisdictionSender::JurisdictionSender(JurisdictionMap* map, NODE_TYPE type, PacketSenderNotify* notify) : - PacketSender(notify, JurisdictionSender::DEFAULT_PACKETS_PER_SECOND), ReceivedPacketProcessor(), - _jurisdictionMap(map) + _jurisdictionMap(map), + _packetSender(notify, JurisdictionSender::DEFAULT_PACKETS_PER_SECOND) { _nodeType = type; } @@ -66,16 +66,16 @@ bool JurisdictionSender::process() { if (node->getActiveSocket() != NULL) { const HifiSockAddr* nodeAddress = node->getActiveSocket(); - queuePacketForSending(*nodeAddress, bufferOut, sizeOut); + _packetSender.queuePacketForSending(*nodeAddress, bufferOut, sizeOut); nodeCount++; } } unlockRequestingNodes(); // set our packets per second to be the number of nodes - setPacketsPerSecond(nodeCount); + _packetSender.setPacketsPerSecond(nodeCount); - continueProcessing = PacketSender::process(); + continueProcessing = _packetSender.process(); } return continueProcessing; } diff --git a/libraries/octree/src/JurisdictionSender.h b/libraries/octree/src/JurisdictionSender.h index 441bb5ee1e..287a5dbf61 100644 --- a/libraries/octree/src/JurisdictionSender.h +++ b/libraries/octree/src/JurisdictionSender.h @@ -21,7 +21,7 @@ /// Will process PACKET_TYPE_JURISDICTION_REQUEST packets and send out PACKET_TYPE_JURISDICTION packets /// to requesting parties. As with other ReceivedPacketProcessor classes the user is responsible for reading inbound packets /// and adding them to the processing queue by calling queueReceivedPacket() -class JurisdictionSender : public PacketSender, public ReceivedPacketProcessor { +class JurisdictionSender : public ReceivedPacketProcessor { Q_OBJECT public: static const int DEFAULT_PACKETS_PER_SECOND = 1; @@ -51,5 +51,7 @@ private: JurisdictionMap* _jurisdictionMap; std::queue _nodesRequestingJurisdictions; NODE_TYPE _nodeType; + + PacketSender _packetSender; }; #endif // __shared__JurisdictionSender__ diff --git a/libraries/octree/src/OctreeScriptingInterface.cpp b/libraries/octree/src/OctreeScriptingInterface.cpp index d72f2e7443..7355b8e2de 100644 --- a/libraries/octree/src/OctreeScriptingInterface.cpp +++ b/libraries/octree/src/OctreeScriptingInterface.cpp @@ -46,7 +46,7 @@ void OctreeScriptingInterface::init() { } else { _managedJurisdictionListener = true; _jurisdictionListener = new JurisdictionListener(getServerNodeType()); - //printf("OctreeScriptingInterface::init() _managedJurisdictionListener=true, creating _jurisdictionListener=%p\n", _jurisdictionListener); + //qDebug("OctreeScriptingInterface::init() _managedJurisdictionListener=true, creating _jurisdictionListener=%p", _jurisdictionListener); _jurisdictionListener->initialize(true); } @@ -55,7 +55,7 @@ void OctreeScriptingInterface::init() { } else { _managedPacketSender = true; _packetSender = createPacketSender(); - //printf("OctreeScriptingInterface::init() _managedPacketSender=true, creating _packetSender=%p\n", _packetSender); + //qDebug("OctreeScriptingInterface::init() _managedPacketSender=true, creating _packetSender=%p", _packetSender); _packetSender->setServerJurisdictions(_jurisdictionListener->getJurisdictions()); } } diff --git a/libraries/particles/src/Particle.h b/libraries/particles/src/Particle.h index 160eee9db2..9c93423c08 100644 --- a/libraries/particles/src/Particle.h +++ b/libraries/particles/src/Particle.h @@ -136,6 +136,9 @@ public: ParticleID(uint32_t id, uint32_t creatorTokenID, bool isKnownID) : id(id), creatorTokenID(creatorTokenID), isKnownID(isKnownID) { }; + ParticleID(uint32_t id) : + id(id), creatorTokenID(UNKNOWN_TOKEN), isKnownID(true) { }; + uint32_t id; uint32_t creatorTokenID; bool isKnownID; diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 61417aa735..ff65bc4298 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -16,7 +16,6 @@ #include "Particle.h" #include "ParticleCollisionSystem.h" -#include "ParticleEditHandle.h" #include "ParticleEditPacketSender.h" #include "ParticleTree.h" @@ -117,19 +116,23 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA) float massB = (particleB->getInHand()) ? MAX_MASS : particleB->getMass(); float totalMass = massA + massB; + // handle A particle particleA->setVelocity(particleA->getVelocity() - axialVelocity * (2.0f * massB / totalMass)); + ParticleProperties propertiesA; + ParticleID particleAid(particleA->getID()); + propertiesA.copyFromParticle(*particleA); + propertiesA.setVelocity(particleA->getVelocity() * (float)TREE_SCALE); + _packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleAid, propertiesA); - ParticleEditHandle particleEditHandle(_packetSender, _particles, particleA->getID()); - particleEditHandle.updateParticle(particleA->getPosition(), particleA->getRadius(), particleA->getXColor(), - particleA->getVelocity(), particleA->getGravity(), particleA->getDamping(), particleA->getLifetime(), - particleA->getInHand(), particleA->getScript()); - + // handle B particle particleB->setVelocity(particleB->getVelocity() + axialVelocity * (2.0f * massA / totalMass)); + ParticleProperties propertiesB; + ParticleID particleBid(particleB->getID()); + propertiesB.copyFromParticle(*particleB); + propertiesB.setVelocity(particleB->getVelocity() * (float)TREE_SCALE); + _packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleBid, propertiesB); - ParticleEditHandle penetratedparticleEditHandle(_packetSender, _particles, particleB->getID()); - penetratedparticleEditHandle.updateParticle(particleB->getPosition(), particleB->getRadius(), - particleB->getXColor(), particleB->getVelocity(), particleB->getGravity(), particleB->getDamping(), - particleB->getLifetime(), particleB->getInHand(), particleB->getScript()); + _packetSender->releaseQueuedMessages(); penetration /= (float)(TREE_SCALE); updateCollisionSound(particleA, penetration, COLLISION_FREQUENCY); @@ -256,10 +259,17 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, float elast particle->getID(), velocity.x, velocity.y, velocity.z, debug::valueOf(particle->getInHand())); } - ParticleEditHandle particleEditHandle(_packetSender, _particles, particle->getID()); - particleEditHandle.updateParticle(position, particle->getRadius(), particle->getXColor(), velocity, - particle->getGravity(), particle->getDamping(), particle->getLifetime(), - particle->getInHand(), particle->getScript()); + // send off the result to the particle server + ParticleProperties properties; + ParticleID particleID(particle->getID()); + properties.copyFromParticle(*particle); + properties.setPosition(position * (float)TREE_SCALE); + properties.setVelocity(velocity * (float)TREE_SCALE); + _packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties); + + // change the local particle too... + particle->setPosition(position); + particle->setVelocity(velocity); } diff --git a/libraries/particles/src/ParticleEditHandle.cpp b/libraries/particles/src/ParticleEditHandle.cpp deleted file mode 100644 index 30ff71951d..0000000000 --- a/libraries/particles/src/ParticleEditHandle.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// -// ParticleEditHandle.cpp -// hifi -// -// Created by Brad Hefta-Gaub on 12/4/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// -// - -#include "Particle.h" -#include "ParticleEditHandle.h" -#include "ParticleEditPacketSender.h" -#include "ParticleTree.h" - -std::map ParticleEditHandle::_allHandles; - -ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id) { - if (id == NEW_PARTICLE) { - _creatorTokenID = Particle::getNextCreatorTokenID(); - _id = NEW_PARTICLE; - _isKnownID = false; - _allHandles[_creatorTokenID] = this; - } else { - _creatorTokenID = UNKNOWN_TOKEN; - _id = id; - _isKnownID = true; - // don't add to _allHandles because we already know it... - } - _packetSender = packetSender; - _localTree = localTree; - -} - -ParticleEditHandle::~ParticleEditHandle() { - // remove us from our _allHandles map - if (_creatorTokenID != UNKNOWN_TOKEN) { - _allHandles.erase(_allHandles.find(_creatorTokenID)); - } -} - -void ParticleEditHandle::createParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, - glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript) { - - // setup a ParticleDetail struct with the data -/**** - uint64_t now = usecTimestampNow(); - ParticleDetail addParticleDetail = { NEW_PARTICLE, now, - position, radius, {color.red, color.green, color.blue }, - velocity, gravity, damping, lifetime, inHand, updateScript, _creatorTokenID }; - - // queue the packet - _packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, 1, &addParticleDetail); - - // release them - _packetSender->releaseQueuedMessages(); - - // if we have a local tree, also update it... - if (_localTree) { - // we can't really do this here, because if we create a particle locally, we'll get a ghost particle - // because we can't really handle updating/deleting it locally - } -****/ - -} - -bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, - glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript) { - - if (!isKnownID()) { - return false; // not allowed until we know the id - } - - // setup a ParticleDetail struct with the data -/**** - uint64_t now = usecTimestampNow(); - ParticleDetail newParticleDetail = { _id, now, - position, radius, {color.red, color.green, color.blue }, - velocity, gravity, damping, lifetime, inHand, updateScript, _creatorTokenID }; - - // queue the packet - _packetSender->queueParticleEditMessages(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, 1, &newParticleDetail); - - // release them - _packetSender->releaseQueuedMessages(); - - // if we have a local tree, also update it... - if (_localTree) { - rgbColor rcolor = {color.red, color.green, color.blue }; - Particle tempParticle(position, radius, rcolor, velocity, gravity, damping, lifetime, inHand, updateScript, _id); - _localTree->storeParticle(tempParticle); - } -***/ - - return true; -} - -void ParticleEditHandle::handleAddResponse(unsigned char* packetData , int packetLength) { - unsigned char* dataAt = packetData; - int numBytesPacketHeader = numBytesForPacketHeader(packetData); - dataAt += numBytesPacketHeader; - - uint32_t creatorTokenID; - memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID)); - dataAt += sizeof(creatorTokenID); - - uint32_t particleID; - memcpy(&particleID, dataAt, sizeof(particleID)); - dataAt += sizeof(particleID); - - // find this particle in the _allHandles map - if (_allHandles.find(creatorTokenID) != _allHandles.end()) { - ParticleEditHandle* theHandle = _allHandles[creatorTokenID]; - theHandle->_id = particleID; - theHandle->_isKnownID = true; - } -} diff --git a/libraries/particles/src/ParticleEditHandle.h b/libraries/particles/src/ParticleEditHandle.h deleted file mode 100644 index 5343b29343..0000000000 --- a/libraries/particles/src/ParticleEditHandle.h +++ /dev/null @@ -1,53 +0,0 @@ -// -// ParticleEditHandle.h -// hifi -// -// Created by Brad Hefta-Gaub on 12/4/13. -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// -// - -#ifndef __hifi__ParticleEditHandle__ -#define __hifi__ParticleEditHandle__ - -#include -#include - -#include -#include - -#include -#include - -#include "Particle.h" - -class ParticleEditPacketSender; -class ParticleTree; - -class ParticleEditHandle { -public: - ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id = NEW_PARTICLE); - ~ParticleEditHandle(); - - uint32_t getCreatorTokenID() const { return _creatorTokenID; } - uint32_t getID() const { return _id; } - - bool isKnownID() const { return _isKnownID; } - - void createParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, - glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript); - - bool updateParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, - glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript); - - static void handleAddResponse(unsigned char* packetData , int packetLength); -private: - uint32_t _creatorTokenID; - uint32_t _id; - bool _isKnownID; - static std::map _allHandles; - ParticleEditPacketSender* _packetSender; - ParticleTree* _localTree; -}; - -#endif /* defined(__hifi__ParticleEditHandle__) */ \ No newline at end of file diff --git a/libraries/particles/src/ParticleEditPacketSender.cpp b/libraries/particles/src/ParticleEditPacketSender.cpp index f745adc05b..3206a0d200 100644 --- a/libraries/particles/src/ParticleEditPacketSender.cpp +++ b/libraries/particles/src/ParticleEditPacketSender.cpp @@ -42,7 +42,8 @@ void ParticleEditPacketSender::adjustEditPacketForClockSkew(unsigned char* codeC } -void ParticleEditPacketSender::queueParticleEditMessage(PACKET_TYPE type, ParticleID particleID, const ParticleProperties& properties) { +void ParticleEditPacketSender::queueParticleEditMessage(PACKET_TYPE type, ParticleID particleID, + const ParticleProperties& properties) { if (!_shouldSend) { return; // bail early } diff --git a/libraries/particles/src/ParticleEditPacketSender.h b/libraries/particles/src/ParticleEditPacketSender.h index c45a3ef8c4..f142931222 100644 --- a/libraries/particles/src/ParticleEditPacketSender.h +++ b/libraries/particles/src/ParticleEditPacketSender.h @@ -21,11 +21,13 @@ public: ~ParticleEditPacketSender() { } /// Send particle add message immediately + /// NOTE: ParticleProperties assumes that all distances are in meter units void sendEditParticleMessage(PACKET_TYPE type, ParticleID particleID, const ParticleProperties& properties); /// Queues an array of several voxel edit messages. Will potentially send a pending multi-command packet. Determines /// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in /// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known. + /// NOTE: ParticleProperties assumes that all distances are in meter units void queueParticleEditMessage(PACKET_TYPE type, ParticleID particleID, const ParticleProperties& properties); // My server type is the particle server diff --git a/libraries/particles/src/ParticlesScriptingInterface.h b/libraries/particles/src/ParticlesScriptingInterface.h index edd2ac43dc..d61f8289f4 100644 --- a/libraries/particles/src/ParticlesScriptingInterface.h +++ b/libraries/particles/src/ParticlesScriptingInterface.h @@ -11,7 +11,6 @@ #include -#include #include #include "ParticleEditPacketSender.h" diff --git a/libraries/script-engine/src/DataServerScriptingInterface.cpp b/libraries/script-engine/src/DataServerScriptingInterface.cpp index 236f46e54c..6effd7ebdc 100644 --- a/libraries/script-engine/src/DataServerScriptingInterface.cpp +++ b/libraries/script-engine/src/DataServerScriptingInterface.cpp @@ -7,15 +7,15 @@ // #include +#include #include "DataServerScriptingInterface.h" -DataServerScriptingInterface::DataServerScriptingInterface() : - _uuid(QUuid::createUuid()) +DataServerScriptingInterface::DataServerScriptingInterface() { } void DataServerScriptingInterface::setValueForKey(const QString& key, const QString& value) { - DataServerClient::putValueForKeyAndUUID(key, value, _uuid); + DataServerClient::putValueForKeyAndUUID(key, value, NodeList::getInstance()->getOwnerUUID()); } \ No newline at end of file diff --git a/libraries/script-engine/src/DataServerScriptingInterface.h b/libraries/script-engine/src/DataServerScriptingInterface.h index 8bd3eea565..b46c0bda7a 100644 --- a/libraries/script-engine/src/DataServerScriptingInterface.h +++ b/libraries/script-engine/src/DataServerScriptingInterface.h @@ -18,13 +18,8 @@ class DataServerScriptingInterface : public QObject { public: DataServerScriptingInterface(); - void refreshUUID() { _uuid = QUuid::createUuid(); } - const QUuid& getUUID() const { return _uuid; } - public slots: void setValueForKey(const QString& key, const QString& value); -private: - QUuid _uuid; }; #endif /* defined(__hifi__DataServerScriptingInterface__) */ diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index e6a74af9b3..a1c1f602fb 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -41,6 +41,7 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, const QString& fileNameString, AbstractMenuInterface* menu, AbstractControllerScriptingInterface* controllerScriptingInterface) : + _dataServerScriptingInterface(), _avatarData(NULL) { _scriptContents = scriptContents; @@ -159,10 +160,6 @@ void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { _engine.globalObject().setProperty(name, value); } -void ScriptEngine::preEvaluateReset() { - _dataServerScriptingInterface.refreshUUID(); -} - void ScriptEngine::evaluate() { if (!_isInitialized) { init(); @@ -248,9 +245,7 @@ void ScriptEngine::run() { numAvatarHeaderBytes = populateTypeAndVersion(avatarPacket, PACKET_TYPE_HEAD_DATA); // pack the owner UUID for this script - QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); - memcpy(avatarPacket + numAvatarHeaderBytes, ownerUUID.constData(), ownerUUID.size()); - numAvatarHeaderBytes += ownerUUID.size(); + numAvatarHeaderBytes += NodeList::getInstance()->packOwnerUUID(avatarPacket); } int numAvatarPacketBytes = _avatarData->getBroadcastData(avatarPacket + numAvatarHeaderBytes) + numAvatarHeaderBytes; diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index ab0129bc6f..b36e2425fe 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -74,7 +74,6 @@ signals: void finished(const QString& fileNameString); protected: - void preEvaluateReset(); QString _scriptContents; bool _isFinished; diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index f33137a092..f37f2b48dc 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -642,6 +642,12 @@ void NodeList::sendAssignment(Assignment& assignment) { assignmentServerSocket->getPort()); } +int NodeList::packOwnerUUID(unsigned char* packetData) { + QByteArray rfcUUID = _ownerUUID.toRfc4122(); + memcpy(packetData, rfcUUID.constData(), rfcUUID.size()); + return rfcUUID.size(); +} + int NodeList::fillPingPacket(unsigned char* buffer) { int numHeaderBytes = populateTypeAndVersion(buffer, PACKET_TYPE_PING); uint64_t currentTime = usecTimestampNow(); diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index b5e27564b1..9ac6c5970c 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -96,6 +96,8 @@ public: void setAssignmentServerSocket(const HifiSockAddr& serverSocket) { _assignmentServerSocket = serverSocket; } void sendAssignment(Assignment& assignment); + + int packOwnerUUID(unsigned char* packetData); int fillPingPacket(unsigned char* buffer); int fillPingReplyPacket(unsigned char* pingBuffer, unsigned char* replyBuffer); diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index f595dfcafc..c512eac74d 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -20,7 +20,7 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) { return 2; case PACKET_TYPE_HEAD_DATA: - return 15; + return 16; case PACKET_TYPE_OCTREE_STATS: return 2; diff --git a/libraries/shared/src/PacketSender.h b/libraries/shared/src/PacketSender.h index 9005a2b254..7a2c6e6d2a 100644 --- a/libraries/shared/src/PacketSender.h +++ b/libraries/shared/src/PacketSender.h @@ -23,7 +23,7 @@ public: /// Generalized threaded processor for queueing and sending of outbound packets. -class PacketSender : public virtual GenericThread { +class PacketSender : public GenericThread { public: static const uint64_t USECS_PER_SECOND; diff --git a/libraries/shared/src/ReceivedPacketProcessor.h b/libraries/shared/src/ReceivedPacketProcessor.h index 621204025e..567434a49e 100644 --- a/libraries/shared/src/ReceivedPacketProcessor.h +++ b/libraries/shared/src/ReceivedPacketProcessor.h @@ -15,7 +15,7 @@ #include "NetworkPacket.h" /// Generalized threaded processor for handling received inbound packets. -class ReceivedPacketProcessor : public virtual GenericThread { +class ReceivedPacketProcessor : public GenericThread { public: ReceivedPacketProcessor(); diff --git a/libraries/voxels/src/VoxelsScriptingInterface.h b/libraries/voxels/src/VoxelsScriptingInterface.h index 6bbe21d601..a1f52fc1c3 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.h +++ b/libraries/voxels/src/VoxelsScriptingInterface.h @@ -11,7 +11,6 @@ #include -#include #include #include "VoxelConstants.h"