From ed9118fd671f909bcc7265588d5b905f7f04a9d1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 23 Jan 2014 15:28:46 -0800 Subject: [PATCH] more NodeList QSet changes, closes #1660 --- interface/src/Application.cpp | 34 +++++++++----------- interface/src/Application.h | 4 +-- interface/src/Menu.cpp | 4 +-- interface/src/avatar/Profile.cpp | 2 +- libraries/script-engine/src/ScriptEngine.cpp | 2 +- libraries/shared/src/NodeList.cpp | 9 +++--- libraries/shared/src/NodeList.h | 5 +-- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index dadc4f1d3d..2b29f22aaa 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -292,7 +292,7 @@ Application::~Application() { _settings->sync(); // let the avatar mixer know we're out - NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); + NodeList::getInstance()->sendKillNode(QSet() << NODE_TYPE_AVATAR_MIXER); // ask the datagram processing thread to quit and wait until it is done _nodeThread->quit(); @@ -643,21 +643,20 @@ void Application::resetProfile(const QString& username) { } void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, - const char* nodeTypes, int numNodeTypes) { - Application* self = getInstance(); - for (int i = 0; i < numNodeTypes; ++i) { - + const QSet& destinationNodeTypes) { + foreach(NODE_TYPE type, destinationNodeTypes) { // Intercept data to voxel server when voxels are disabled - if (nodeTypes[i] == NODE_TYPE_VOXEL_SERVER && !Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { + if (type == NODE_TYPE_VOXEL_SERVER && !Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { continue; } - + // Perform the broadcast for one type - int nReceivingNodes = NodeList::getInstance()->broadcastToNodes(broadcastData, dataBytes, & nodeTypes[i], 1); - + int nReceivingNodes = NodeList::getInstance()->broadcastToNodes(broadcastData, dataBytes, + QSet() << type); + // Feed number of bytes to corresponding channel of the bandwidth meter, if any (done otherwise) BandwidthMeter::ChannelIndex channel; - switch (nodeTypes[i]) { + switch (type) { case NODE_TYPE_AGENT: case NODE_TYPE_AVATAR_MIXER: channel = BandwidthMeter::AVATARS; @@ -668,7 +667,7 @@ void Application::controlledBroadcastToNodes(unsigned char* broadcastData, size_ default: continue; } - self->_bandwidthMeter.outputStream(channel).updateValue(nReceivingNodes * dataBytes); + _bandwidthMeter.outputStream(channel).updateValue(nReceivingNodes * dataBytes); } } @@ -1323,15 +1322,13 @@ void Application::wheelEvent(QWheelEvent* event) { } void Application::sendPingPackets() { - - const char nodesToPing[] = {NODE_TYPE_VOXEL_SERVER, NODE_TYPE_PARTICLE_SERVER, - NODE_TYPE_AUDIO_MIXER, NODE_TYPE_AVATAR_MIXER, NODE_TYPE_METAVOXEL_SERVER}; - unsigned char pingPacket[MAX_PACKET_SIZE]; int length = NodeList::getInstance()->fillPingPacket(pingPacket); - getInstance()->controlledBroadcastToNodes(pingPacket, length, - nodesToPing, sizeof(nodesToPing)); + getInstance()->controlledBroadcastToNodes(pingPacket, length, QSet() + << NODE_TYPE_VOXEL_SERVER << NODE_TYPE_PARTICLE_SERVER + << NODE_TYPE_AUDIO_MIXER << NODE_TYPE_AVATAR_MIXER + << NODE_TYPE_METAVOXEL_SERVER); } // Every second, check the frame rates and other stuff @@ -2453,9 +2450,8 @@ void Application::updateAvatar(float deltaTime) { endOfBroadcastStringWrite += _myAvatar.getBroadcastData(endOfBroadcastStringWrite); - const char nodeTypesOfInterest[] = { NODE_TYPE_AVATAR_MIXER }; controlledBroadcastToNodes(broadcastString, endOfBroadcastStringWrite - broadcastString, - nodeTypesOfInterest, sizeof(nodeTypesOfInterest)); + QSet() << NODE_TYPE_AVATAR_MIXER); // Update _viewFrustum with latest camera and view frustum data... // NOTE: we get this from the view frustum, to make it simpler, since the diff --git a/interface/src/Application.h b/interface/src/Application.h index 803cb296a2..60ada75731 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -171,8 +171,8 @@ public: Profile* getProfile() { return &_profile; } void resetProfile(const QString& username); - static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, - const char* nodeTypes, int numNodeTypes); + void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, + const QSet& destinationNodeTypes); void setupWorldLight(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 740effcf1c..55f721afea 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -899,7 +899,7 @@ void Menu::goToDomain() { } // send a node kill request, indicating to other clients that they should play the "disappeared" effect - NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); + NodeList::getInstance()->sendKillNode(QSet() << NODE_TYPE_AVATAR_MIXER); // give our nodeList the new domain-server hostname NodeList::getInstance()->setDomainHostname(domainDialog.textValue()); @@ -941,7 +941,7 @@ void Menu::goToLocation() { if (newAvatarPos != avatarPos) { // send a node kill request, indicating to other clients that they should play the "disappeared" effect - NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); + NodeList::getInstance()->sendKillNode(QSet() << NODE_TYPE_AVATAR_MIXER); qDebug("Going To Location: %f, %f, %f...", x, y, z); myAvatar->setPosition(newAvatarPos); diff --git a/interface/src/avatar/Profile.cpp b/interface/src/avatar/Profile.cpp index fee5fbf6fc..dd2b547c47 100644 --- a/interface/src/avatar/Profile.cpp +++ b/interface/src/avatar/Profile.cpp @@ -198,7 +198,7 @@ void Profile::processDataServerResponse(const QString& userString, const QString if (coordinateItems.size() == 3 && orientationItems.size() == 3) { // send a node kill request, indicating to other clients that they should play the "disappeared" effect - NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); + NodeList::getInstance()->sendKillNode(QSet() << NODE_TYPE_AVATAR_MIXER); qDebug() << "Changing domain to" << valueList[i].toLocal8Bit().constData() << ", position to" << valueList[i + 1].toLocal8Bit().constData() << diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index a1c1f602fb..f77b428764 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -250,7 +250,7 @@ void ScriptEngine::run() { int numAvatarPacketBytes = _avatarData->getBroadcastData(avatarPacket + numAvatarHeaderBytes) + numAvatarHeaderBytes; - nodeList->broadcastToNodes(avatarPacket, numAvatarPacketBytes, &NODE_TYPE_AVATAR_MIXER, 1); + nodeList->broadcastToNodes(avatarPacket, numAvatarPacketBytes, QSet() << NODE_TYPE_AVATAR_MIXER); } if (willSendVisualDataCallBack) { diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index da35fa92ae..3107d4e620 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -460,7 +460,7 @@ NodeHash::iterator NodeList::killNodeAtHashIterator(NodeHash::iterator& nodeItem return _nodeHash.erase(nodeItemToKill); } -void NodeList::sendKillNode(const char* nodeTypes, int numNodeTypes) { +void NodeList::sendKillNode(const QSet& destinationNodeTypes) { unsigned char packet[MAX_PACKET_SIZE]; unsigned char* packetPosition = packet; @@ -470,7 +470,7 @@ void NodeList::sendKillNode(const char* nodeTypes, int numNodeTypes) { memcpy(packetPosition, rfcUUID.constData(), rfcUUID.size()); packetPosition += rfcUUID.size(); - broadcastToNodes(packet, packetPosition - packet, nodeTypes, numNodeTypes); + broadcastToNodes(packet, packetPosition - packet, destinationNodeTypes); } void NodeList::processKillNode(unsigned char* packetData, size_t dataBytes) { @@ -733,12 +733,13 @@ SharedNodePointer NodeList::addOrUpdateNode(const QUuid& uuid, char nodeType, } } -unsigned NodeList::broadcastToNodes(unsigned char* broadcastData, size_t dataBytes, const char* nodeTypes, int numNodeTypes) { +unsigned NodeList::broadcastToNodes(unsigned char* broadcastData, size_t dataBytes, + const QSet& destinationNodeTypes) { unsigned n = 0; foreach (const SharedNodePointer& node, getNodeHash()) { // only send to the NodeTypes we are asked to send to. - if (memchr(nodeTypes, node->getType(), numNodeTypes)) { + if (destinationNodeTypes.contains(node->getType())) { if (getNodeActiveSocketOrPing(node.data())) { // we know which socket is good for this node, send there _nodeSocket.writeDatagram((char*) broadcastData, dataBytes, diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index 2143ae87eb..13f9485069 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -90,6 +90,7 @@ public: void reset(); + const QSet& getNodeInterestSet() const { return _nodeTypesOfInterest; } void addNodeTypeToInterestSet(NODE_TYPE nodeTypeToAdd); void addSetOfNodeTypesToNodeInterestSet(const QSet& setOfNodeTypes); @@ -104,7 +105,7 @@ public: int fillPingReplyPacket(unsigned char* pingBuffer, unsigned char* replyBuffer); void pingPublicAndLocalSocketsForInactiveNode(Node* node); - void sendKillNode(const char* nodeTypes, int numNodeTypes); + void sendKillNode(const QSet& destinationNodeTypes); SharedNodePointer nodeWithAddress(const HifiSockAddr& senderSockAddr); SharedNodePointer nodeWithUUID(const QUuid& nodeUUID); @@ -116,7 +117,7 @@ public: int updateNodeWithData(Node *node, const HifiSockAddr& senderSockAddr, unsigned char *packetData, int dataBytes); - unsigned broadcastToNodes(unsigned char *broadcastData, size_t dataBytes, const char* nodeTypes, int numNodeTypes); + unsigned broadcastToNodes(unsigned char *broadcastData, size_t dataBytes, const QSet& destinationNodeTypes); SharedNodePointer soloNodeOfType(char nodeType); void loadData(QSettings* settings);