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
24052405 char packet[MAX_PACKET_SIZE];
24062406
24072407 // iterates thru all nodes in NodeList
2408− NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table();
2408+ NodeList* nodeList = NodeList::getInstance();
24092409
2410− for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
2411− SharedNodePointer node = it->second;
2410+ nodeList->eachNode([&](const SharedNodePointer& node){
24122411
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+
24182415 QUuid nodeUUID = node->getUUID();
2419−
2416+
24202417 // if there are octree packets from this node that are waiting to be processed,
24212418 // don't send a NACK since the missing packets may be among those waiting packets.
24222419 if (_octreeProcessor.hasPacketsToProcessFrom(nodeUUID)) {
2423− continue;
2420+ return;
24242421 }
24252422
24262423 _octreeSceneStatsLock.lockForRead();
2427−
2424+
24282425 // retreive octree scene stats of this node
24292426 if (_octreeServerSceneStats.find(nodeUUID) == _octreeServerSceneStats.end()) {
24302427 _octreeSceneStatsLock.unlock();
2431− continue;
2428+ return;
24322429 }
2433−
2430+
24342431 // get sequence number stats of node, prune its missing set, and make a copy of the missing set
24352432 SequenceNumberStats& sequenceNumberStats = _octreeServerSceneStats[nodeUUID].getIncomingOctreeSequenceNumberStats();
24362433 sequenceNumberStats.pruneMissingSet();
24372434 const QSet<OCTREE_PACKET_SEQUENCE> missingSequenceNumbers = sequenceNumberStats.getMissingSet();
2438−
2435+
24392436 _octreeSceneStatsLock.unlock();
2440−
2437+
24412438 // construct nack packet(s) for this node
24422439 int numSequenceNumbersAvailable = missingSequenceNumbers.size();
24432440 QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin();
24442441 while (numSequenceNumbersAvailable > 0) {
2445−
2442+
24462443 char* dataAt = packet;
24472444 int bytesRemaining = MAX_PACKET_SIZE;
2448−
2445+
24492446 // pack header
24502447 int numBytesPacketHeader = populatePacketHeader(packet, PacketTypeOctreeDataNack);
24512448 dataAt += numBytesPacketHeader;
24522449 bytesRemaining -= numBytesPacketHeader;
2453−
2450+
24542451 // calculate and pack the number of sequence numbers
24552452 int numSequenceNumbersRoomFor = (bytesRemaining - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE);
24562453 uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor);
24572454 uint16_t* numSequenceNumbersAt = (uint16_t*)dataAt;
24582455 *numSequenceNumbersAt = numSequenceNumbers;
24592456 dataAt += sizeof(uint16_t);
2460−
2457+
24612458 // pack sequence numbers
24622459 for (int i = 0; i < numSequenceNumbers; i++) {
24632460 OCTREE_PACKET_SEQUENCE* sequenceNumberAt = (OCTREE_PACKET_SEQUENCE*)dataAt;
24642461 *sequenceNumberAt = *missingSequenceNumbersIterator;
24652462 dataAt += sizeof(OCTREE_PACKET_SEQUENCE);
2466−
2463+
24672464 missingSequenceNumbersIterator++;
24682465 }
24692466 numSequenceNumbersAvailable -= numSequenceNumbers;
2470−
2467+
24712468 // send it
2472− NodeList::getInstance()->writeUnverifiedDatagram(packet, dataAt - packet, node);
2469+ nodeList->writeUnverifiedDatagram(packet, dataAt - packet, node);
24732470 packetsSent++;
24742471 }
24752472 }
2476− }
2473+ });
2474+
24772475 return packetsSent;
24782476 }
24792477
@@ -2507,12 +2505,8 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 27 unmodified lines
25072505 int unknownJurisdictionServers = 0;
25082506
25092507 NodeList* nodeList = NodeList::getInstance();
2510− NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table();
25112508
2512− for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
2513−
2514− SharedNodePointer node = it->second;
2515−
2509+ nodeList->eachNode([&](const SharedNodePointer& node) {
25162510 // only send to the NodeTypes that are serverType
25172511 if (node->getActiveSocket() && node->getType() == serverType) {
25182512 totalServers++;
@@ -2543,7 +2537,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 24 unmodified lines
25432537 }
25442538 }
25452539 }
2546− }
2540+ });
25472541
25482542 if (wantExtraDebugging) {
25492543 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
25702564 qDebug("perServerPPS: %d perUnknownServer: %d", perServerPPS, perUnknownServer);
25712565 }
25722566
2573− for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
2574− SharedNodePointer node = it->second;
2567+ nodeList->eachNode([&](const SharedNodePointer& node){
25752568 // only send to the NodeTypes that are serverType
25762569 if (node->getActiveSocket() && node->getType() == serverType) {
2577−
2578−
2570+
2571+
25792572 // get the server bounds for this server
25802573 QUuid nodeUUID = node->getUUID();
2581−
2574+
25822575 bool inView = false;
25832576 bool unknownView = false;
2584−
2577+
25852578 // if we haven't heard from this voxel server, go ahead and send it a query, so we
25862579 // can get the jurisdiction...
25872580 if (jurisdictions.find(nodeUUID) == jurisdictions.end()) {
@@ -2591,15 +2584,15 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 3 unmodified lines
25912584 }
25922585 } else {
25932586 const JurisdictionMap& map = (jurisdictions)[nodeUUID];
2594−
2587+
25952588 unsigned char* rootCode = map.getRootOctalCode();
2596−
2589+
25972590 if (rootCode) {
25982591 VoxelPositionSize rootDetails;
25992592 voxelDetailsForCode(rootCode, rootDetails);
26002593 AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
26012594 serverBounds.scale(TREE_SCALE);
2602−
2595+
26032596 ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds);
26042597 if (serverFrustumLocation != ViewFrustum::OUTSIDE) {
26052598 inView = true;
@@ -2612,15 +2605,15 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 6 unmodified lines
26122605 }
26132606 }
26142607 }
2615−
2608+
26162609 if (inView) {
26172610 _octreeQuery.setMaxOctreePacketsPerSecond(perServerPPS);
26182611 } else if (unknownView) {
26192612 if (wantExtraDebugging) {
26202613 qDebug() << "no known jurisdiction for node " << *node << ", give it budget of "
2621− << perUnknownServer << " to send us jurisdiction.";
2614+ << perUnknownServer << " to send us jurisdiction.";
26222615 }
2623−
2616+
26242617 // set the query's position/orientation to be degenerate in a manner that will get the scene quickly
26252618 // If there's only one server, then don't do this, and just let the normal voxel query pass through
26262619 // 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
26442637 }
26452638 // set up the packet for sending...
26462639 unsigned char* endOfQueryPacket = queryPacket;
2647−
2640+
26482641 // insert packet type/version and node UUID
26492642 endOfQueryPacket += populatePacketHeader(reinterpret_cast<char*>(endOfQueryPacket), packetType);
2650−
2643+
26512644 // encode the query data...
26522645 endOfQueryPacket += _octreeQuery.getBroadcastData(endOfQueryPacket);
2653−
2646+
26542647 int packetLength = endOfQueryPacket - queryPacket;
2655−
2648+
26562649 // make sure we still have an active socket
26572650 nodeList->writeUnverifiedDatagram(reinterpret_cast<const char*>(queryPacket), packetLength, node);
2658−
2651+
26592652 // Feed number of bytes to corresponding channel of the bandwidth meter
26602653 _bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(packetLength);
26612654 }
2662− }
2655+ });
26632656 }
26642657
26652658 /////////////////////////////////////////////////////////////////////////////////////

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