History

Merge branch 'master' of git://github.com/highfidelity/hifi into 19644

Ryan Huffman committed 12 years ago

Commit 173be2c2 parents f249020 c46453c70 files · +3532 −612Browse files

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

Unified · Split

interface/src/Application.cpp+54−40
@@ -2125,19 +2125,19 @@ void Application::updateMyAvatar(float deltaTime) { · 2124 unmodified lines
21252125 const quint64 TOO_LONG_SINCE_LAST_NACK = 1 * USECS_PER_SECOND;
21262126 if (sinceLastNack > TOO_LONG_SINCE_LAST_NACK) {
21272127 _lastNackTime = now;
2128− sendNack();
2128+ sendNackPackets();
21292129 }
21302130 }
21312131 }
21322132
2133−void Application::sendNack() {
2133+int Application::sendNackPackets() {
21342134
21352135 if (Menu::getInstance()->isOptionChecked(MenuOption::DisableNackPackets)) {
2136− return;
2136+ return 0;
21372137 }
21382138
2139+ int packetsSent = 0;
21392140 char packet[MAX_PACKET_SIZE];
2140− NodeList* nodeList = NodeList::getInstance();
21412141
21422142 // iterates thru all nodes in NodeList
21432143 foreach(const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
@@ -2148,14 +2148,14 @@ void Application::sendNack() { · 4 unmodified lines
21482148 || node->getType() == NodeType::ModelServer)
21492149 ) {
21502150
2151+ QUuid nodeUUID = node->getUUID();
2152+
21512153 // if there are octree packets from this node that are waiting to be processed,
21522154 // don't send a NACK since the missing packets may be among those waiting packets.
2153− if (_octreeProcessor.hasPacketsToProcessFrom(node)) {
2155+ if (_octreeProcessor.hasPacketsToProcessFrom(nodeUUID)) {
21542156 continue;
21552157 }
2156−
2157− QUuid nodeUUID = node->getUUID();
2158−
2158+
21592159 _octreeSceneStatsLock.lockForRead();
21602160
21612161 // retreive octree scene stats of this node
@@ -2165,40 +2165,48 @@ void Application::sendNack() { · 3 unmodified lines
21652165 }
21662166 OctreeSceneStats& stats = _octreeServerSceneStats[nodeUUID];
21672167
2168− // check if there are any sequence numbers that need to be nacked
2169− int numSequenceNumbersAvailable = stats.getNumSequenceNumbersToNack();
2170− if (numSequenceNumbersAvailable == 0) {
2171− _octreeSceneStatsLock.unlock();
2172− continue;
2173− }
2168+ // make copy of missing sequence numbers from stats
2169+ const QSet<OCTREE_PACKET_SEQUENCE> missingSequenceNumbers = stats.getMissingSequenceNumbers();
21742170
2175− char* dataAt = packet;
2176− int bytesRemaining = MAX_PACKET_SIZE;
2177−
2178− // pack header
2179− int numBytesPacketHeader = populatePacketHeader(packet, PacketTypeOctreeDataNack);
2180− dataAt += numBytesPacketHeader;
2181− bytesRemaining -= numBytesPacketHeader;
2182− int numSequenceNumbersRoomFor = (bytesRemaining - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE);
2183−
2184− // calculate and pack the number of sequence numbers
2185− uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor);
2186− uint16_t* numSequenceNumbersAt = (uint16_t*)dataAt;
2187− *numSequenceNumbersAt = numSequenceNumbers;
2188− dataAt += sizeof(uint16_t);
2189−
2190− // pack sequence numbers
2191− for (int i = 0; i < numSequenceNumbers; i++) {
2192− OCTREE_PACKET_SEQUENCE* sequenceNumberAt = (OCTREE_PACKET_SEQUENCE*)dataAt;
2193− *sequenceNumberAt = stats.getNextSequenceNumberToNack();
2194− dataAt += sizeof(OCTREE_PACKET_SEQUENCE);
2195− }
2196−
21972171 _octreeSceneStatsLock.unlock();
21982172
2199− nodeList->writeUnverifiedDatagram(packet, dataAt - packet, node);
2173+ // construct nack packet(s) for this node
2174+ int numSequenceNumbersAvailable = missingSequenceNumbers.size();
2175+ QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin();
2176+ while (numSequenceNumbersAvailable > 0) {
2177+
2178+ char* dataAt = packet;
2179+ int bytesRemaining = MAX_PACKET_SIZE;
2180+
2181+ // pack header
2182+ int numBytesPacketHeader = populatePacketHeader(packet, PacketTypeOctreeDataNack);
2183+ dataAt += numBytesPacketHeader;
2184+ bytesRemaining -= numBytesPacketHeader;
2185+
2186+ // calculate and pack the number of sequence numbers
2187+ int numSequenceNumbersRoomFor = (bytesRemaining - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE);
2188+ uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor);
2189+ uint16_t* numSequenceNumbersAt = (uint16_t*)dataAt;
2190+ *numSequenceNumbersAt = numSequenceNumbers;
2191+ dataAt += sizeof(uint16_t);
2192+
2193+ // pack sequence numbers
2194+ for (int i = 0; i < numSequenceNumbers; i++) {
2195+ OCTREE_PACKET_SEQUENCE* sequenceNumberAt = (OCTREE_PACKET_SEQUENCE*)dataAt;
2196+ *sequenceNumberAt = *missingSequenceNumbersIterator;
2197+ dataAt += sizeof(OCTREE_PACKET_SEQUENCE);
2198+
2199+ missingSequenceNumbersIterator++;
2200+ }
2201+ numSequenceNumbersAvailable -= numSequenceNumbers;
2202+
2203+ // send it
2204+ NodeList::getInstance()->writeUnverifiedDatagram(packet, dataAt - packet, node);
2205+ packetsSent++;
2206+ }
22002207 }
22012208 }
2209+ return packetsSent;
22022210 }
22032211
22042212 void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) {
@@ -3183,7 +3191,7 @@ void Application::updateWindowTitle(){ · 978 unmodified lines
31833191 float creditBalance = accountManager.getAccountInfo().getBalance() / SATOSHIS_PER_CREDIT;
31843192
31853193 QString creditBalanceString;
3186− creditBalanceString.sprintf("%.8f", creditBalance);
3194+ creditBalanceString.sprintf("%.8f", floor(creditBalance + 0.5));
31873195
31883196 title += " - ₵" + creditBalanceString;
31893197 }
@@ -3272,10 +3280,16 @@ void Application::nodeAdded(SharedNodePointer node) { · 82 unmodified lines
32723280
32733281 void Application::nodeKilled(SharedNodePointer node) {
32743282
3275− // this is here because connecting NodeList::nodeKilled to OctreePacketProcessor::nodeKilled doesn't work:
3276− // OctreePacketProcessor::nodeKilled is not called when NodeList::nodeKilled is emitted for some reason.
3283+ // These are here because connecting NodeList::nodeKilled to OctreePacketProcessor::nodeKilled doesn't work:
3284+ // OctreePacketProcessor::nodeKilled is not being called when NodeList::nodeKilled is emitted.
3285+ // This may have to do with GenericThread::threadRoutine() blocking the QThread event loop
3286+
32773287 _octreeProcessor.nodeKilled(node);
32783288
3289+ _voxelEditSender.nodeKilled(node);
3290+ _particleEditSender.nodeKilled(node);
3291+ _modelEditSender.nodeKilled(node);
3292+
32793293 if (node->getType() == NodeType::VoxelServer) {
32803294 QUuid nodeUUID = node->getUUID();
32813295 // see if this is the first we've heard of this node...

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