mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
move payload adjustments to Packet
This commit is contained in:
parent
df47f1dd0b
commit
862c788aec
6 changed files with 21 additions and 23 deletions
|
@ -24,7 +24,7 @@ OctreeQueryNode::OctreeQueryNode() :
|
|||
_viewSent(false),
|
||||
_octreePacket(),
|
||||
_octreePacketWaiting(false),
|
||||
_lastOctreePayload(new char[MAX_PACKET_SIZE]),
|
||||
_lastOctreePayload(new char[udt::MAX_PACKET_SIZE]),
|
||||
_lastOctreePacketLength(0),
|
||||
_duplicatePacketCount(0),
|
||||
_firstSuppressedPacket(usecTimestampNow()),
|
||||
|
|
|
@ -219,7 +219,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
|
|||
packetSent = true;
|
||||
|
||||
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
|
||||
thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
|
||||
thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader;
|
||||
_totalWastedBytes += thisWastedBytes;
|
||||
_totalBytes += nodeData->getPacket().getDataSize();
|
||||
_totalPackets++;
|
||||
|
@ -251,7 +251,7 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
|
|||
packetSent = true;
|
||||
|
||||
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
|
||||
int thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
|
||||
int thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader;
|
||||
_totalWastedBytes += thisWastedBytes;
|
||||
_totalBytes += packetSizeWithHeader;
|
||||
_totalPackets++;
|
||||
|
@ -598,7 +598,7 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
|
|||
|
||||
_totalBytes += packet->getDataSize();
|
||||
_totalPackets++;
|
||||
_totalWastedBytes += MAX_PACKET_SIZE - packet->getDataSize();
|
||||
_totalWastedBytes += udt::MAX_PACKET_SIZE - packet->getDataSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -207,16 +207,6 @@ void NLPacket::readVersion() {
|
|||
_version = NLPacket::versionInHeader(*this);
|
||||
}
|
||||
|
||||
void NLPacket::adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize) {
|
||||
qint64 headerSize = localHeaderSize(_type);
|
||||
_payloadStart += headerSize;
|
||||
_payloadCapacity -= headerSize;
|
||||
|
||||
if (shouldDecreasePayloadSize) {
|
||||
_payloadSize -= headerSize;
|
||||
}
|
||||
}
|
||||
|
||||
void NLPacket::readSourceID() {
|
||||
if (!NON_SOURCED_PACKETS.contains(_type)) {
|
||||
_sourceID = sourceIDInHeader(*this);
|
||||
|
|
|
@ -65,8 +65,6 @@ protected:
|
|||
NLPacket& operator=(const NLPacket& other);
|
||||
NLPacket& operator=(NLPacket&& other);
|
||||
|
||||
void adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize = false);
|
||||
|
||||
// Header writers
|
||||
void writePacketTypeAndVersion();
|
||||
|
||||
|
|
|
@ -62,8 +62,7 @@ Packet::Packet(qint64 size, bool isReliable, bool isPartOfMessage) :
|
|||
_isReliable(isReliable),
|
||||
_isPartOfMessage(isPartOfMessage)
|
||||
{
|
||||
_payloadCapacity = size;
|
||||
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
|
||||
adjustPayloadStartAndCapacity();
|
||||
|
||||
// set the UDT header to default values
|
||||
writeSequenceNumber(0);
|
||||
|
@ -75,10 +74,8 @@ Packet::Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& send
|
|||
readIsReliable();
|
||||
readIsPartOfMessage();
|
||||
readSequenceNumber();
|
||||
|
||||
_payloadCapacity = _packetSize - localHeaderSize();
|
||||
_payloadSize = _payloadCapacity;
|
||||
_payloadStart = _packet.get() + (_packetSize - _payloadCapacity);
|
||||
|
||||
adjustPayloadStartAndCapacity(_payloadSize > 0);
|
||||
}
|
||||
|
||||
Packet::Packet(const Packet& other) :
|
||||
|
@ -117,6 +114,16 @@ Packet& Packet::operator=(Packet&& other) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
void Packet::adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize) {
|
||||
qint64 headerSize = localHeaderSize();
|
||||
_payloadStart += headerSize;
|
||||
_payloadCapacity -= headerSize;
|
||||
|
||||
if (shouldDecreasePayloadSize) {
|
||||
_payloadSize -= headerSize;
|
||||
}
|
||||
}
|
||||
|
||||
static const uint32_t CONTROL_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 1);
|
||||
static const uint32_t RELIABILITY_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 2);
|
||||
static const uint32_t MESSAGE_BIT_MASK = 1 << (sizeof(Packet::SequenceNumberAndBitField) - 3);
|
||||
|
|
|
@ -56,9 +56,12 @@ protected:
|
|||
Packet(qint64 size, bool isReliable = false, bool isPartOfMessage = false);
|
||||
Packet(std::unique_ptr<char> data, qint64 size, const HifiSockAddr& senderSockAddr);
|
||||
Packet(const Packet& other);
|
||||
Packet& operator=(const Packet& other);
|
||||
Packet(Packet&& other);
|
||||
|
||||
Packet& operator=(const Packet& other);
|
||||
Packet& operator=(Packet&& other);
|
||||
|
||||
virtual void adjustPayloadStartAndCapacity(bool shouldDecreasePayloadSize = false);
|
||||
|
||||
// Header readers - these read data to member variables after pulling packet off wire
|
||||
void readIsPartOfMessage();
|
||||
|
|
Loading…
Reference in a new issue