History

repairs to node hash iterations in Application

Stephen Birarda committed 12 years ago

Commit 455cbac1 parent 0e9e8a01 file · +40 −47Browse files

Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t