more networking API changes in octree classes

This commit is contained in:
Stephen Birarda 2015-07-07 12:31:22 -07:00
parent fca23cc69b
commit 01b1c46237
5 changed files with 68 additions and 65 deletions

View file

@ -365,7 +365,7 @@ bool OctreeQueryNode::hasNextNackedPacket() const {
return !_nackedSequenceNumbers.isEmpty();
}
NLPacket* OctreeQueryNode::getNextNackedPacket() {
const NLPacket* OctreeQueryNode::getNextNackedPacket() {
if (!_nackedSequenceNumbers.isEmpty()) {
// could return null if packet is not in the history
return _sentPacketHistory.getPacket(_nackedSequenceNumbers.dequeue());

View file

@ -111,7 +111,7 @@ public:
void parseNackPacket(const QByteArray& packet);
bool hasNextNackedPacket() const;
NLPacket* getNextNackedPacket();
const NLPacket* getNextNackedPacket();
private slots:
void sendThreadFinished();

View file

@ -243,22 +243,24 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
if (nodeData->isPacketWaiting() && !nodeData->isShuttingDown()) {
// just send the octree packet
OctreeServer::didCallWriteDatagram(this);
DependencyManager::get<NodeList>()->writeDatagram((char*)nodeData->getPacket(), nodeData->getPacketLength(), _node);
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), _node);
packetSent = true;
int thisWastedBytes = MAX_PACKET_SIZE - nodeData->getPacketLength();
_totalWastedBytes += thisWastedBytes;
_totalBytes += nodeData->getPacketLength();
_totalPackets++;
if (debug) {
const unsigned char* messageData = nodeData->getPacket();
int numBytesPacketHeader = numBytesForPacketHeader(reinterpret_cast<const char*>(messageData));
const unsigned char* dataAt = messageData + numBytesPacketHeader;
dataAt += sizeof(OCTREE_PACKET_FLAGS);
OCTREE_PACKET_SEQUENCE sequence = (*(OCTREE_PACKET_SEQUENCE*)dataAt);
dataAt += sizeof(OCTREE_PACKET_SEQUENCE);
OCTREE_PACKET_SENT_TIME timestamp = (*(OCTREE_PACKET_SENT_TIME*)dataAt);
dataAt += sizeof(OCTREE_PACKET_SENT_TIME);
NLPacket& sentPacket = nodeData->getPacket();
sentPacket->seek(sizeof(OCTREE_PACKET_FLAGS));
OCTREE_PACKET_SEQUENCE sequence;
sentPacket->read(&sequence, sizeof(sequence));
OCTREE_PACKET_SENT_TIME timestamp;
sentPacket->read(&timestamp, sizeof(timestamp));
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
@ -267,10 +269,11 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
}
}
}
// remember to track our stats
if (packetSent) {
nodeData->stats.packetSent(nodeData->getPacketLength());
trueBytesSent += nodeData->getPacketLength();
nodeData->stats.packetSent(nodeData->getPacket()->getSizeUsed());
trueBytesSent += nodeData->getPacket()->getSizeUsed();
truePacketsSent++;
packetsSent++;
nodeData->octreePacketSent();
@ -582,20 +585,20 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
// Re-send packets that were nacked by the client
while (nodeData->hasNextNackedPacket() && packetsSentThisInterval < maxPacketsPerInterval) {
const QByteArray* packet = nodeData->getNextNackedPacket();
const NLPacket* packet = nodeData->getNextNackedPacket();
if (packet) {
DependencyManager::get<NodeList>()->writeDatagram(*packet, _node);
DependencyManager::get<NodeList>()->sendUnreliablePacket(*packet, _node);
truePacketsSent++;
packetsSentThisInterval++;
_totalBytes += packet->size();
_totalBytes += packet->getSizeWithHeader();
_totalPackets++;
_totalWastedBytes += MAX_PACKET_SIZE - packet->size();
_totalWastedBytes += MAX_PACKET_SIZE - packet->getSizeWithHeader();
}
}
quint64 end = usecTimestampNow();
int elapsedmsec = (end - start)/USECS_PER_MSEC;
int elapsedmsec = (end - start) / USECS_PER_MSEC;
OctreeServer::trackLoopTime(elapsedmsec);
// TODO: add these to stats page

View file

@ -23,7 +23,7 @@ public:
SentPacketHistory(int size = MAX_REASONABLE_SEQUENCE_GAP);
void packetSent(uint16_t sequenceNumber, const NLPacket& packet);
const QByteArray* getPacket(uint16_t sequenceNumber) const;
const NLPacket* getPacket(uint16_t sequenceNumber) const;
private:
RingBufferHistory<NLPacket*> _sentPackets; // circular buffer