remove old PacketHeader methods

This commit is contained in:
Stephen Birarda 2015-07-16 16:04:12 -07:00
parent 648f9868f0
commit 61653bd88d
6 changed files with 12 additions and 59 deletions

View file

@ -22,9 +22,9 @@ EntityEditPacketSender::EntityEditPacketSender() {
packetReceiver.registerListener(PacketType::EntityEditNack, this, "processEntityEditNackPacket");
}
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet) {
void EntityEditPacketSender::processEntityEditNackPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
if (_shouldNack) {
processNackPacket(QByteArray::fromRawData(packet->getData(), packet->getDataSize()));
processNackPacket(*packet, sendingNode);
}
}

View file

@ -37,7 +37,7 @@ public:
virtual void adjustEditPacketForClockSkew(PacketType::Value type, QByteArray& buffer, int clockSkew);
public slots:
void processEntityEditNackPacket(QSharedPointer<NLPacket> packet);
void processEntityEditNackPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
void toggleNackPackets() { _shouldNack = !_shouldNack; }
private:

View file

@ -155,32 +155,6 @@ int numSequenceNumberBytesForType(PacketType::Value packetType) {
return (SEQUENCE_NUMBERED_PACKETS.contains(packetType) ? sizeof(PacketSequenceNumber) : 0);
}
QUuid uuidFromPacketHeader(const QByteArray& packet) {
return QUuid::fromRfc4122(packet.mid(numBytesArithmeticCodingFromBuffer(packet.data()) + sizeof(PacketVersion),
NUM_BYTES_RFC4122_UUID));
}
int hashOffsetForPacketType(PacketType::Value packetType) {
return numBytesForArithmeticCodedPacketType(packetType) + NUM_STATIC_HEADER_BYTES;
}
int sequenceNumberOffsetForPacketType(PacketType::Value packetType) {
return numBytesForPacketHeaderGivenPacketType(packetType) - sizeof(PacketSequenceNumber);
}
PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType::Value packetType) {
if (packetType == PacketType::Unknown) {
packetType = packetTypeForPacket(packet);
}
PacketSequenceNumber result = DEFAULT_SEQUENCE_NUMBER;
if (SEQUENCE_NUMBERED_PACKETS.contains(packetType)) {
memcpy(&result, packet.data() + sequenceNumberOffsetForPacketType(packetType), sizeof(PacketSequenceNumber));
}
return result;
}
PacketType::Value packetTypeForPacket(const QByteArray& packet) {
return (PacketType::Value) arithmeticCodingValueFromBuffer(packet.data());

View file

@ -112,16 +112,6 @@ int numBytesForArithmeticCodedPacketType(PacketType::Value packetType);
int numBytesForPacketHeaderGivenPacketType(PacketType::Value packetType);
int packArithmeticallyCodedValue(int value, char* destination);
QUuid uuidFromPacketHeader(const QByteArray& packet);
int hashOffsetForPacketType(PacketType::Value packetType);
int sequenceNumberOffsetForPacketType(PacketType::Value packetType);
// NOTE: The following four methods accept a PacketType::Value which defaults to PacketType::Unknown.
// If the caller has already looked at the packet type and can provide it then the methods below won't have to look it up.
PacketSequenceNumber sequenceNumberFromHeader(const QByteArray& packet, PacketType::Value packetType = PacketType::Unknown);
int arithmeticCodingValueFromBuffer(const char* checkValue);
int numBytesArithmeticCodingFromBuffer(const char* checkValue);

View file

@ -339,35 +339,24 @@ bool OctreeEditPacketSender::process() {
return PacketSender::process();
}
void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) {
void OctreeEditPacketSender::processNackPacket(NLPacket& packet, SharedNodePointer sendingNode) {
// parse sending node from packet, retrieve packet history for that node
QUuid sendingNodeUUID = uuidFromPacketHeader(packet);
// if packet history doesn't exist for the sender node (somehow), bail
if (_sentPacketHistories.count(sendingNodeUUID) == 0) {
if (_sentPacketHistories.count(sendingNode->getUUID()) == 0) {
return;
}
const SentPacketHistory& sentPacketHistory = _sentPacketHistories[sendingNodeUUID];
// TODO: these NAK packets no longer send the number of sequence numbers - just read out sequence numbers in blocks
int numBytesPacketHeader = numBytesForPacketHeader(packet);
const unsigned char* dataAt = reinterpret_cast<const unsigned char*>(packet.data()) + numBytesPacketHeader;
// read number of sequence numbers
uint16_t numSequenceNumbers = (*(uint16_t*)dataAt);
dataAt += sizeof(uint16_t);
const SentPacketHistory& sentPacketHistory = _sentPacketHistories[sendingNode->getSourceID()];
// read sequence numbers and queue packets for resend
for (int i = 0; i < numSequenceNumbers; i++) {
unsigned short int sequenceNumber = (*(unsigned short int*)dataAt);
dataAt += sizeof(unsigned short int);
while (packet.bytesLeftToRead() > 0) {
unsigned short int sequenceNumber;
packet.readPrimitive(&sequenceNumber);
// retrieve packet from history
const NLPacket* packet = sentPacketHistory.getPacket(sequenceNumber);
if (packet) {
const SharedNodePointer& node = DependencyManager::get<NodeList>()->nodeWithUUID(sendingNodeUUID);
queuePacketForSending(node, NLPacket::createCopy(*packet));
queuePacketForSending(sendingNode, NLPacket::createCopy(*packet));
}
}
}

View file

@ -83,7 +83,7 @@ public:
virtual char getMyNodeType() const = 0;
virtual void adjustEditPacketForClockSkew(PacketType::Value type, QByteArray& buffer, int clockSkew) { }
void processNackPacket(const QByteArray& packet);
void processNackPacket(NLPacket& packet, SharedNodePointer sendingNode);
public slots:
void nodeKilled(SharedNodePointer node);