Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary loop sending octree packets to a known node. #1353

Merged
merged 2 commits into from Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 29 additions & 11 deletions libraries/octree/src/OctreeEditPacketSender.cpp
Expand Up @@ -50,12 +50,10 @@ bool OctreeEditPacketSender::serversExist() const {
void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::unique_ptr<NLPacket> packet) {

bool wantDebug = false;
QMutexLocker lock(&_packetsQueueLock);
DependencyManager::get<NodeList>()->eachNode([&](const SharedNodePointer& node){

auto queueMessage = [&](const SharedNodePointer& node) {
// only send to the NodeTypes that are getMyNodeType()
if (node->getType() == getMyNodeType()
&& ((node->getUUID() == nodeUUID) || (nodeUUID.isNull()))
&& node->getActiveSocket()) {
if (node->getType() == getMyNodeType() && node->getActiveSocket()) {

// jump to the beginning of the payload
packet->seek(0);
Expand Down Expand Up @@ -88,23 +86,43 @@ void OctreeEditPacketSender::queuePacketToNode(const QUuid& nodeUUID, std::uniqu

queuePacketForSending(node, NLPacket::createCopy(*packet));
}
});
};

QSharedPointer<NodeList> nodeList = DependencyManager::get<NodeList>();
if (nodeUUID.isNull()) {
QMutexLocker lock(&_packetsQueueLock);
nodeList->eachNode(queueMessage);
} else {
SharedNodePointer node = nodeList->nodeWithUUID(nodeUUID);
if (node) {
QMutexLocker lock(&_packetsQueueLock);
queueMessage(node);
}
}
}

// This method is called when the edit packet layer has determined that it has a fully formed packet destined for
// a known nodeID.
void OctreeEditPacketSender::queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr<NLPacketList> packetList) {
DependencyManager::get<NodeList>()->eachNode([&](const SharedNodePointer& node) {
auto queueMessage = [&](const SharedNodePointer& node) {
// only send to the NodeTypes that are getMyNodeType()
if (node->getType() == getMyNodeType()
&& ((node->getUUID() == nodeUUID) || (nodeUUID.isNull()))
&& node->getActiveSocket()) {
if (node->getType() == getMyNodeType() && node->getActiveSocket()) {

// NOTE: unlike packets, the packet lists don't get rewritten sequence numbers.
// or do history for resend
queuePacketListForSending(node, std::move(packetList));
}
});
};

QSharedPointer<NodeList> nodeList = DependencyManager::get<NodeList>();
if (nodeUUID.isNull()) {
nodeList->eachNode(queueMessage);
} else {
SharedNodePointer node = nodeList->nodeWithUUID(nodeUUID);
if (node) {
queueMessage(node);
}
}
}

void OctreeEditPacketSender::processPreServerExistsPackets() {
Expand Down