Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -2405,75 +2405,73 @@ int Application::sendNackPackets() { · 2404 unmodified lines | ||
| 2405 | 2405 | char packet[MAX_PACKET_SIZE]; |
| 2406 | 2406 | |
| 2407 | 2407 | // iterates thru all nodes in NodeList |
| 2408 | − NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); | |
| 2408 | + NodeList* nodeList = NodeList::getInstance(); | |
| 2409 | 2409 | |
| 2410 | − for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { | |
| 2411 | − SharedNodePointer node = it->second; | |
| 2410 | + nodeList->eachNode([&](const SharedNodePointer& node){ | |
| 2412 | 2411 | |
| 2413 | − if (node->getActiveSocket() && | |
| 2414 | − ( node->getType() == NodeType::VoxelServer | |
| 2415 | − || node->getType() == NodeType::EntityServer) | |
| 2416 | − ) { | |
| 2417 | − | |
| 2412 | + if (node->getActiveSocket() | |
| 2413 | + && (node->getType() == NodeType::VoxelServer || node->getType() == NodeType::EntityServer)) { | |
| 2414 | + | |
| 2418 | 2415 | QUuid nodeUUID = node->getUUID(); |
| 2419 | − | |
| 2416 | + | |
| 2420 | 2417 | // if there are octree packets from this node that are waiting to be processed, |
| 2421 | 2418 | // don't send a NACK since the missing packets may be among those waiting packets. |
| 2422 | 2419 | if (_octreeProcessor.hasPacketsToProcessFrom(nodeUUID)) { |
| 2423 | − continue; | |
| 2420 | + return; | |
| 2424 | 2421 | } |
| 2425 | 2422 | |
| 2426 | 2423 | _octreeSceneStatsLock.lockForRead(); |
| 2427 | − | |
| 2424 | + | |
| 2428 | 2425 | // retreive octree scene stats of this node |
| 2429 | 2426 | if (_octreeServerSceneStats.find(nodeUUID) == _octreeServerSceneStats.end()) { |
| 2430 | 2427 | _octreeSceneStatsLock.unlock(); |
| 2431 | − continue; | |
| 2428 | + return; | |
| 2432 | 2429 | } |
| 2433 | − | |
| 2430 | + | |
| 2434 | 2431 | // get sequence number stats of node, prune its missing set, and make a copy of the missing set |
| 2435 | 2432 | SequenceNumberStats& sequenceNumberStats = _octreeServerSceneStats[nodeUUID].getIncomingOctreeSequenceNumberStats(); |
| 2436 | 2433 | sequenceNumberStats.pruneMissingSet(); |
| 2437 | 2434 | const QSet<OCTREE_PACKET_SEQUENCE> missingSequenceNumbers = sequenceNumberStats.getMissingSet(); |
| 2438 | − | |
| 2435 | + | |
| 2439 | 2436 | _octreeSceneStatsLock.unlock(); |
| 2440 | − | |
| 2437 | + | |
| 2441 | 2438 | // construct nack packet(s) for this node |
| 2442 | 2439 | int numSequenceNumbersAvailable = missingSequenceNumbers.size(); |
| 2443 | 2440 | QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin(); |
| 2444 | 2441 | while (numSequenceNumbersAvailable > 0) { |
| 2445 | − | |
| 2442 | + | |
| 2446 | 2443 | char* dataAt = packet; |
| 2447 | 2444 | int bytesRemaining = MAX_PACKET_SIZE; |
| 2448 | − | |
| 2445 | + | |
| 2449 | 2446 | // pack header |
| 2450 | 2447 | int numBytesPacketHeader = populatePacketHeader(packet, PacketTypeOctreeDataNack); |
| 2451 | 2448 | dataAt += numBytesPacketHeader; |
| 2452 | 2449 | bytesRemaining -= numBytesPacketHeader; |
| 2453 | − | |
| 2450 | + | |
| 2454 | 2451 | // calculate and pack the number of sequence numbers |
| 2455 | 2452 | int numSequenceNumbersRoomFor = (bytesRemaining - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE); |
| 2456 | 2453 | uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor); |
| 2457 | 2454 | uint16_t* numSequenceNumbersAt = (uint16_t*)dataAt; |
| 2458 | 2455 | *numSequenceNumbersAt = numSequenceNumbers; |
| 2459 | 2456 | dataAt += sizeof(uint16_t); |
| 2460 | − | |
| 2457 | + | |
| 2461 | 2458 | // pack sequence numbers |
| 2462 | 2459 | for (int i = 0; i < numSequenceNumbers; i++) { |
| 2463 | 2460 | OCTREE_PACKET_SEQUENCE* sequenceNumberAt = (OCTREE_PACKET_SEQUENCE*)dataAt; |
| 2464 | 2461 | *sequenceNumberAt = *missingSequenceNumbersIterator; |
| 2465 | 2462 | dataAt += sizeof(OCTREE_PACKET_SEQUENCE); |
| 2466 | − | |
| 2463 | + | |
| 2467 | 2464 | missingSequenceNumbersIterator++; |
| 2468 | 2465 | } |
| 2469 | 2466 | numSequenceNumbersAvailable -= numSequenceNumbers; |
| 2470 | − | |
| 2467 | + | |
| 2471 | 2468 | // send it |
| 2472 | − NodeList::getInstance()->writeUnverifiedDatagram(packet, dataAt - packet, node); | |
| 2469 | + nodeList->writeUnverifiedDatagram(packet, dataAt - packet, node); | |
| 2473 | 2470 | packetsSent++; |
| 2474 | 2471 | } |
| 2475 | 2472 | } |
| 2476 | − } | |
| 2473 | + }); | |
| 2474 | + | |
| 2477 | 2475 | return packetsSent; |
| 2478 | 2476 | } |
| 2479 | 2477 | |
| @@ -2507,12 +2505,8 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 27 unmodified lines | ||
| 2507 | 2505 | int unknownJurisdictionServers = 0; |
| 2508 | 2506 | |
| 2509 | 2507 | NodeList* nodeList = NodeList::getInstance(); |
| 2510 | − NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); | |
| 2511 | 2508 | |
| 2512 | − for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { | |
| 2513 | − | |
| 2514 | − SharedNodePointer node = it->second; | |
| 2515 | − | |
| 2509 | + nodeList->eachNode([&](const SharedNodePointer& node) { | |
| 2516 | 2510 | // only send to the NodeTypes that are serverType |
| 2517 | 2511 | if (node->getActiveSocket() && node->getType() == serverType) { |
| 2518 | 2512 | totalServers++; |
| @@ -2543,7 +2537,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 24 unmodified lines | ||
| 2543 | 2537 | } |
| 2544 | 2538 | } |
| 2545 | 2539 | } |
| 2546 | − } | |
| 2540 | + }); | |
| 2547 | 2541 | |
| 2548 | 2542 | if (wantExtraDebugging) { |
| 2549 | 2543 | qDebug("Servers: total %d, in view %d, unknown jurisdiction %d", |
| @@ -2570,18 +2564,17 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 20 unmodified lines | ||
| 2570 | 2564 | qDebug("perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer); |
| 2571 | 2565 | } |
| 2572 | 2566 | |
| 2573 | − for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { | |
| 2574 | − SharedNodePointer node = it->second; | |
| 2567 | + nodeList->eachNode([&](const SharedNodePointer& node){ | |
| 2575 | 2568 | // only send to the NodeTypes that are serverType |
| 2576 | 2569 | if (node->getActiveSocket() && node->getType() == serverType) { |
| 2577 | − | |
| 2578 | − | |
| 2570 | + | |
| 2571 | + | |
| 2579 | 2572 | // get the server bounds for this server |
| 2580 | 2573 | QUuid nodeUUID = node->getUUID(); |
| 2581 | − | |
| 2574 | + | |
| 2582 | 2575 | bool inView = false; |
| 2583 | 2576 | bool unknownView = false; |
| 2584 | − | |
| 2577 | + | |
| 2585 | 2578 | // if we haven't heard from this voxel server, go ahead and send it a query, so we |
| 2586 | 2579 | // can get the jurisdiction... |
| 2587 | 2580 | if (jurisdictions.find(nodeUUID) == jurisdictions.end()) { |
| @@ -2591,15 +2584,15 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 3 unmodified lines | ||
| 2591 | 2584 | } |
| 2592 | 2585 | } else { |
| 2593 | 2586 | const JurisdictionMap& map = (jurisdictions)[nodeUUID]; |
| 2594 | − | |
| 2587 | + | |
| 2595 | 2588 | unsigned char* rootCode = map.getRootOctalCode(); |
| 2596 | − | |
| 2589 | + | |
| 2597 | 2590 | if (rootCode) { |
| 2598 | 2591 | VoxelPositionSize rootDetails; |
| 2599 | 2592 | voxelDetailsForCode(rootCode, rootDetails); |
| 2600 | 2593 | AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); |
| 2601 | 2594 | serverBounds.scale(TREE_SCALE); |
| 2602 | − | |
| 2595 | + | |
| 2603 | 2596 | ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds); |
| 2604 | 2597 | if (serverFrustumLocation != ViewFrustum::OUTSIDE) { |
| 2605 | 2598 | inView = true; |
| @@ -2612,15 +2605,15 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 6 unmodified lines | ||
| 2612 | 2605 | } |
| 2613 | 2606 | } |
| 2614 | 2607 | } |
| 2615 | − | |
| 2608 | + | |
| 2616 | 2609 | if (inView) { |
| 2617 | 2610 | _octreeQuery.setMaxOctreePacketsPerSecond(perServerPPS); |
| 2618 | 2611 | } else if (unknownView) { |
| 2619 | 2612 | if (wantExtraDebugging) { |
| 2620 | 2613 | qDebug() << "no known jurisdiction for node " << *node << ", give it budget of " |
| 2621 | − << perUnknownServer << " to send us jurisdiction."; | |
| 2614 | + << perUnknownServer << " to send us jurisdiction."; | |
| 2622 | 2615 | } |
| 2623 | − | |
| 2616 | + | |
| 2624 | 2617 | // set the query's position/orientation to be degenerate in a manner that will get the scene quickly |
| 2625 | 2618 | // If there's only one server, then don't do this, and just let the normal voxel query pass through |
| 2626 | 2619 | // as expected... this way, we will actually get a valid scene if there is one to be seen |
| @@ -2644,22 +2637,22 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 17 unmodified lines | ||
| 2644 | 2637 | } |
| 2645 | 2638 | // set up the packet for sending... |
| 2646 | 2639 | unsigned char* endOfQueryPacket = queryPacket; |
| 2647 | − | |
| 2640 | + | |
| 2648 | 2641 | // insert packet type/version and node UUID |
| 2649 | 2642 | endOfQueryPacket += populatePacketHeader(reinterpret_cast<char*>(endOfQueryPacket), packetType); |
| 2650 | − | |
| 2643 | + | |
| 2651 | 2644 | // encode the query data... |
| 2652 | 2645 | endOfQueryPacket += _octreeQuery.getBroadcastData(endOfQueryPacket); |
| 2653 | − | |
| 2646 | + | |
| 2654 | 2647 | int packetLength = endOfQueryPacket - queryPacket; |
| 2655 | − | |
| 2648 | + | |
| 2656 | 2649 | // make sure we still have an active socket |
| 2657 | 2650 | nodeList->writeUnverifiedDatagram(reinterpret_cast<const char*>(queryPacket), packetLength, node); |
| 2658 | − | |
| 2651 | + | |
| 2659 | 2652 | // Feed number of bytes to corresponding channel of the bandwidth meter |
| 2660 | 2653 | _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength); |
| 2661 | 2654 | } |
| 2662 | − } | |
| 2655 | + }); | |
| 2663 | 2656 | } |
| 2664 | 2657 | |
| 2665 | 2658 | ///////////////////////////////////////////////////////////////////////////////////// |