use PacketList for application nack packets

This commit is contained in:
Stephen Birarda 2015-07-07 15:31:58 -07:00
parent 22b3ce8759
commit 45b549398d
2 changed files with 15 additions and 26 deletions

View file

@ -2660,9 +2660,7 @@ int Application::sendNackPackets() {
return 0;
}
int packetsSent = 0;
auto nackPacket { NLPacket::create(PacketType::OctreeDataNack); }
PacketList nackPacketList = PacketList(PacketType::OctreeDataNack);
// iterates thru all nodes in NodeList
auto nodeList = DependencyManager::get<NodeList>();
@ -2696,34 +2694,23 @@ int Application::sendNackPackets() {
// construct nack packet(s) for this node
int numSequenceNumbersAvailable = missingSequenceNumbers.size();
QSet<OCTREE_PACKET_SEQUENCE>::const_iterator missingSequenceNumbersIterator = missingSequenceNumbers.constBegin();
while (numSequenceNumbersAvailable > 0) {
// reset the position we are writing at and the size we have used
nackPacket->seek(0);
nackPacket->setSizeUsed(0);
// calculate and pack the number of sequence numbers
int numSequenceNumbersRoomFor = (nackPacket->size() - sizeof(uint16_t)) / sizeof(OCTREE_PACKET_SEQUENCE);
uint16_t numSequenceNumbers = min(numSequenceNumbersAvailable, numSequenceNumbersRoomFor);
nackPacket->write(&numSequenceNumbers, sizeof(numSequenceNumbers));
// pack sequence numbers
for (int i = 0; i < numSequenceNumbers; i++) {
OCTREE_PACKET_SEQUENCE missingNumber = *missingSequenceNumbersIterator;
nackPacket->write(&missingNumber, sizeof(OCTREE_PACKET_SEQUENCE));
missingSequenceNumbersIterator++;
}
numSequenceNumbersAvailable -= numSequenceNumbers;
// send the packet
nodeList->sendUnreliablePacket(packet, node);
packetsSent++;
auto it = missingSequenceNumbers.constBegin();
while (it != missingSequenceNumbers.constEnd()) {
OCTREE_PACKET_SEQUENCE missingNumber = *it;
nackPacketList->write(&missingNumber, sizeof(OCTREE_PACKET_SEQUENCE));
++it;
}
}
});
int packetsSent = nackPacketList.getNumPackets();
if (packetsSent) {
// send the packet list
nodeList->sendPacketList(nackPacketList, node);
}
return packetsSent;
}

View file

@ -89,6 +89,8 @@ PacketVersion versionForPacketType(PacketType::Value packetType) {
return 2;
case OctreeStats:
return 1;
case OctreeDataNack:
return 1;
case StopNode:
return 1;
case EntityAdd: