mirror of
https://github.com/overte-org/overte.git
synced 2025-07-10 18:58:37 +02:00
moved SentPacketHistory to libraries/networking/src
This commit is contained in:
parent
0f7ce694c0
commit
69c2a2d12b
2 changed files with 79 additions and 0 deletions
44
libraries/networking/src/SentPacketHistory.cpp
Normal file
44
libraries/networking/src/SentPacketHistory.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
//
|
||||||
|
// SentPacketHistory.cpp
|
||||||
|
// assignement-client/src/octree
|
||||||
|
//
|
||||||
|
// Created by Yixin Wang on 6/5/2014
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "SentPacketHistory.h"
|
||||||
|
|
||||||
|
SentPacketHistory::SentPacketHistory(int size)
|
||||||
|
: _sentPackets(size),
|
||||||
|
_newestPacketAt(0),
|
||||||
|
_numExistingPackets(0),
|
||||||
|
_newestSequenceNumber(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SentPacketHistory::packetSent(OCTREE_PACKET_SEQUENCE sequenceNumber, const QByteArray& packet) {
|
||||||
|
_newestSequenceNumber = sequenceNumber;
|
||||||
|
|
||||||
|
// increment _newestPacketAt cyclically, insert new packet there.
|
||||||
|
// this will overwrite the oldest packet in the buffer
|
||||||
|
_newestPacketAt = (_newestPacketAt == _sentPackets.size() - 1) ? 0 : _newestPacketAt + 1;
|
||||||
|
_sentPackets[_newestPacketAt] = packet;
|
||||||
|
if (_numExistingPackets < _sentPackets.size()) {
|
||||||
|
_numExistingPackets++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const QByteArray* SentPacketHistory::getPacket(OCTREE_PACKET_SEQUENCE sequenceNumber) const {
|
||||||
|
OCTREE_PACKET_SEQUENCE seqDiff = _newestSequenceNumber - sequenceNumber;
|
||||||
|
if (!(seqDiff >= 0 && seqDiff < _numExistingPackets)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
int packetAt = _newestPacketAt - seqDiff;
|
||||||
|
if (packetAt < 0) {
|
||||||
|
packetAt += _sentPackets.size();
|
||||||
|
}
|
||||||
|
return &_sentPackets.at(packetAt);
|
||||||
|
}
|
35
libraries/networking/src/SentPacketHistory.h
Normal file
35
libraries/networking/src/SentPacketHistory.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
//
|
||||||
|
// SentPacketHistory.h
|
||||||
|
// assignement-client/src/octree
|
||||||
|
//
|
||||||
|
// Created by Yixin Wang on 6/5/2014
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_SentPacketHistory_h
|
||||||
|
#define hifi_SentPacketHistory_h
|
||||||
|
|
||||||
|
#include <qbytearray.h>
|
||||||
|
#include <qvector.h>
|
||||||
|
|
||||||
|
#include "OctreePacketData.h"
|
||||||
|
|
||||||
|
class SentPacketHistory {
|
||||||
|
|
||||||
|
public:
|
||||||
|
SentPacketHistory(int size);
|
||||||
|
|
||||||
|
void packetSent(OCTREE_PACKET_SEQUENCE sequenceNumber, const QByteArray& packet);
|
||||||
|
const QByteArray* getPacket(OCTREE_PACKET_SEQUENCE sequenceNumber) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVector<QByteArray> _sentPackets; // circular buffer
|
||||||
|
int _newestPacketAt;
|
||||||
|
int _numExistingPackets;
|
||||||
|
|
||||||
|
OCTREE_PACKET_SEQUENCE _newestSequenceNumber;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue