VoxelPacketProcessor -> OctreePacketProcessor

added nodes bookkeeping in ReceivedPacketProcessor; added check in
sendNack() to not send NACKs to nodes that have sent packets that are
waiting in the message queue.
This commit is contained in:
wangyix 2014-06-10 11:05:51 -07:00
parent ffda98fe0b
commit d84beee3e4
11 changed files with 56 additions and 41 deletions

View file

@ -158,7 +158,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_mousePressed(false), _mousePressed(false),
_audio(STARTUP_JITTER_SAMPLES), _audio(STARTUP_JITTER_SAMPLES),
_enableProcessVoxelsThread(true), _enableProcessVoxelsThread(true),
_voxelProcessor(), _octreeProcessor(),
_voxelHideShowThread(&_voxels), _voxelHideShowThread(&_voxels),
_packetsPerSecond(0), _packetsPerSecond(0),
_bytesPerSecond(0), _bytesPerSecond(0),
@ -418,7 +418,7 @@ Application::~Application() {
_audio.thread()->quit(); _audio.thread()->quit();
_audio.thread()->wait(); _audio.thread()->wait();
_voxelProcessor.terminate(); _octreeProcessor.terminate();
_voxelHideShowThread.terminate(); _voxelHideShowThread.terminate();
_voxelEditSender.terminate(); _voxelEditSender.terminate();
_particleEditSender.terminate(); _particleEditSender.terminate();
@ -517,7 +517,7 @@ void Application::initializeGL() {
qDebug( "init() complete."); qDebug( "init() complete.");
// create thread for parsing of voxel data independent of the main network and rendering threads // create thread for parsing of voxel data independent of the main network and rendering threads
_voxelProcessor.initialize(_enableProcessVoxelsThread); _octreeProcessor.initialize(_enableProcessVoxelsThread);
_voxelEditSender.initialize(_enableProcessVoxelsThread); _voxelEditSender.initialize(_enableProcessVoxelsThread);
_voxelHideShowThread.initialize(_enableProcessVoxelsThread); _voxelHideShowThread.initialize(_enableProcessVoxelsThread);
_particleEditSender.initialize(_enableProcessVoxelsThread); _particleEditSender.initialize(_enableProcessVoxelsThread);
@ -1884,7 +1884,7 @@ void Application::updateThreads(float deltaTime) {
// parse voxel packets // parse voxel packets
if (!_enableProcessVoxelsThread) { if (!_enableProcessVoxelsThread) {
_voxelProcessor.threadRoutine(); _octreeProcessor.threadRoutine();
_voxelHideShowThread.threadRoutine(); _voxelHideShowThread.threadRoutine();
_voxelEditSender.threadRoutine(); _voxelEditSender.threadRoutine();
_particleEditSender.threadRoutine(); _particleEditSender.threadRoutine();
@ -2125,6 +2125,12 @@ void Application::sendNack() {
|| node->getType() == NodeType::ModelServer) || node->getType() == NodeType::ModelServer)
) { ) {
// if there are octree packets from this node that are waiting to be processed,
// don't send a NACK since the missing packets may be among those waiting packets.
if (_octreeProcessor.hasPacketsToProcessFrom(node)) {
continue;
}
QUuid nodeUUID = node->getUUID(); QUuid nodeUUID = node->getUUID();
_octreeSceneStatsLock.lockForRead(); _octreeSceneStatsLock.lockForRead();

View file

@ -88,7 +88,7 @@
#include "voxels/VoxelFade.h" #include "voxels/VoxelFade.h"
#include "voxels/VoxelHideShowThread.h" #include "voxels/VoxelHideShowThread.h"
#include "voxels/VoxelImporter.h" #include "voxels/VoxelImporter.h"
#include "voxels/VoxelPacketProcessor.h" #include "voxels/OctreePacketProcessor.h"
#include "voxels/VoxelSystem.h" #include "voxels/VoxelSystem.h"
@ -129,7 +129,7 @@ static const float MIRROR_FIELD_OF_VIEW = 30.0f;
class Application : public QApplication { class Application : public QApplication {
Q_OBJECT Q_OBJECT
friend class VoxelPacketProcessor; friend class OctreePacketProcessor;
friend class VoxelEditPacketSender; friend class VoxelEditPacketSender;
friend class DatagramProcessor; friend class DatagramProcessor;
@ -192,7 +192,7 @@ public:
ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; } ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; }
VoxelSystem* getVoxels() { return &_voxels; } VoxelSystem* getVoxels() { return &_voxels; }
VoxelTree* getVoxelTree() { return _voxels.getTree(); } VoxelTree* getVoxelTree() { return _voxels.getTree(); }
const VoxelPacketProcessor& getVoxelPacketProcessor() const { return _voxelProcessor; } const OctreePacketProcessor& getOctreePacketProcessor() const { return _octreeProcessor; }
ParticleTreeRenderer* getParticles() { return &_particles; } ParticleTreeRenderer* getParticles() { return &_particles; }
MetavoxelSystem* getMetavoxels() { return &_metavoxels; } MetavoxelSystem* getMetavoxels() { return &_metavoxels; }
ModelTreeRenderer* getModels() { return &_models; } ModelTreeRenderer* getModels() { return &_models; }
@ -533,7 +533,7 @@ private:
Audio _audio; Audio _audio;
bool _enableProcessVoxelsThread; bool _enableProcessVoxelsThread;
VoxelPacketProcessor _voxelProcessor; OctreePacketProcessor _octreeProcessor;
VoxelHideShowThread _voxelHideShowThread; VoxelHideShowThread _voxelHideShowThread;
VoxelEditPacketSender _voxelEditSender; VoxelEditPacketSender _voxelEditSender;
ParticleEditPacketSender _particleEditSender; ParticleEditPacketSender _particleEditSender;

View file

@ -71,7 +71,7 @@ void DatagramProcessor::processDatagrams() {
case PacketTypeOctreeStats: case PacketTypeOctreeStats:
case PacketTypeEnvironmentData: { case PacketTypeEnvironmentData: {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::networkReceive()... _voxelProcessor.queueReceivedPacket()"); "Application::networkReceive()... _octreeProcessor.queueReceivedPacket()");
bool wantExtraDebugging = application->getLogger()->extraDebugging(); bool wantExtraDebugging = application->getLogger()->extraDebugging();
if (wantExtraDebugging && packetTypeForPacket(incomingPacket) == PacketTypeVoxelData) { if (wantExtraDebugging && packetTypeForPacket(incomingPacket) == PacketTypeVoxelData) {
@ -92,7 +92,7 @@ void DatagramProcessor::processDatagrams() {
if (matchedNode) { if (matchedNode) {
// add this packet to our list of voxel packets and process them on the voxel processing // add this packet to our list of voxel packets and process them on the voxel processing
application->_voxelProcessor.queueReceivedPacket(matchedNode, incomingPacket); application->_octreeProcessor.queueReceivedPacket(matchedNode, incomingPacket);
} }
break; break;

View file

@ -45,7 +45,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
QGLWidget* glWidget = application->getGLWidget(); QGLWidget* glWidget = application->getGLWidget();
MyAvatar* myAvatar = application->getAvatar(); MyAvatar* myAvatar = application->getAvatar();
Audio* audio = application->getAudio(); Audio* audio = application->getAudio();
const VoxelPacketProcessor& voxelPacketProcessor = application->getVoxelPacketProcessor(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor();
BandwidthMeter* bandwidthMeter = application->getBandwidthMeter(); BandwidthMeter* bandwidthMeter = application->getBandwidthMeter();
NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay(); NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay();
@ -200,7 +200,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) {
// let's set horizontal offset to give stats some margin to mirror // let's set horizontal offset to give stats some margin to mirror
int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2; int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2;
int voxelPacketsToProcess = voxelPacketProcessor.packetsToProcessCount(); int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount();
// Onscreen text about position, servers, etc // Onscreen text about position, servers, etc
Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess); Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess);
// Bandwidth meter // Bandwidth meter

View file

@ -1,5 +1,5 @@
// //
// VoxelPacketProcessor.cpp // OctreePacketProcessor.cpp
// interface/src/voxels // interface/src/voxels
// //
// Created by Brad Hefta-Gaub on 8/12/13. // Created by Brad Hefta-Gaub on 8/12/13.
@ -13,18 +13,18 @@
#include "Application.h" #include "Application.h"
#include "Menu.h" #include "Menu.h"
#include "VoxelPacketProcessor.h" #include "OctreePacketProcessor.h"
void VoxelPacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) { void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"VoxelPacketProcessor::processPacket()"); "OctreePacketProcessor::processPacket()");
QByteArray mutablePacket = packet; QByteArray mutablePacket = packet;
const int WAY_BEHIND = 300; const int WAY_BEHIND = 300;
if (packetsToProcessCount() > WAY_BEHIND && Application::getInstance()->getLogger()->extraDebugging()) { if (packetsToProcessCount() > WAY_BEHIND && Application::getInstance()->getLogger()->extraDebugging()) {
qDebug("VoxelPacketProcessor::processPacket() packets to process=%d", packetsToProcessCount()); qDebug("OctreePacketProcessor::processPacket() packets to process=%d", packetsToProcessCount());
} }
ssize_t messageLength = mutablePacket.size(); ssize_t messageLength = mutablePacket.size();

View file

@ -1,5 +1,5 @@
// //
// VoxelPacketProcessor.h // OctreePacketProcessor.h
// interface/src/voxels // interface/src/voxels
// //
// Created by Brad Hefta-Gaub on 8/12/13. // Created by Brad Hefta-Gaub on 8/12/13.
@ -9,16 +9,16 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_VoxelPacketProcessor_h #ifndef hifi_OctreePacketProcessor_h
#define hifi_VoxelPacketProcessor_h #define hifi_OctreePacketProcessor_h
#include <ReceivedPacketProcessor.h> #include <ReceivedPacketProcessor.h>
/// Handles processing of incoming voxel packets for the interface application. As with other ReceivedPacketProcessor classes /// Handles processing of incoming voxel packets for the interface application. As with other ReceivedPacketProcessor classes
/// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket() /// the user is responsible for reading inbound packets and adding them to the processing queue by calling queueReceivedPacket()
class VoxelPacketProcessor : public ReceivedPacketProcessor { class OctreePacketProcessor : public ReceivedPacketProcessor {
Q_OBJECT Q_OBJECT
protected: protected:
virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet); virtual void processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
}; };
#endif // hifi_VoxelPacketProcessor_h #endif // hifi_OctreePacketProcessor_h

View file

@ -17,9 +17,9 @@
#include "NetworkPacket.h" #include "NetworkPacket.h"
void NetworkPacket::copyContents(const SharedNodePointer& destinationNode, const QByteArray& packet) { void NetworkPacket::copyContents(const SharedNodePointer& sendingNode, const QByteArray& packet) {
if (packet.size() && packet.size() <= MAX_PACKET_SIZE) { if (packet.size() && packet.size() <= MAX_PACKET_SIZE) {
_destinationNode = destinationNode; _sendingNode = sendingNode;
_byteArray = packet; _byteArray = packet;
} else { } else {
qDebug(">>> NetworkPacket::copyContents() unexpected length = %d", packet.size()); qDebug(">>> NetworkPacket::copyContents() unexpected length = %d", packet.size());
@ -27,28 +27,28 @@ void NetworkPacket::copyContents(const SharedNodePointer& destinationNode, const
} }
NetworkPacket::NetworkPacket(const NetworkPacket& packet) { NetworkPacket::NetworkPacket(const NetworkPacket& packet) {
copyContents(packet.getDestinationNode(), packet.getByteArray()); copyContents(packet.getSendingNode(), packet.getByteArray());
} }
NetworkPacket::NetworkPacket(const SharedNodePointer& destinationNode, const QByteArray& packet) { NetworkPacket::NetworkPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
copyContents(destinationNode, packet); copyContents(sendingNode, packet);
}; };
// copy assignment // copy assignment
NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) { NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) {
copyContents(other.getDestinationNode(), other.getByteArray()); copyContents(other.getSendingNode(), other.getByteArray());
return *this; return *this;
} }
#ifdef HAS_MOVE_SEMANTICS #ifdef HAS_MOVE_SEMANTICS
// move, same as copy, but other packet won't be used further // move, same as copy, but other packet won't be used further
NetworkPacket::NetworkPacket(NetworkPacket && packet) { NetworkPacket::NetworkPacket(NetworkPacket && packet) {
copyContents(packet.getDestinationNode(), packet.getByteArray()); copyContents(packet.getSendingNode(), packet.getByteArray());
} }
// move assignment // move assignment
NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) { NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) {
copyContents(other.getDestinationNode(), other.getByteArray()); copyContents(other.getSendingNode(), other.getByteArray());
return *this; return *this;
} }
#endif #endif

View file

@ -34,15 +34,15 @@ public:
NetworkPacket& operator= (NetworkPacket&& other); // move assignment NetworkPacket& operator= (NetworkPacket&& other); // move assignment
#endif #endif
NetworkPacket(const SharedNodePointer& destinationNode, const QByteArray& byteArray); NetworkPacket(const SharedNodePointer& sendingNode, const QByteArray& byteArray);
const SharedNodePointer& getDestinationNode() const { return _destinationNode; } const SharedNodePointer& getSendingNode() const { return _sendingNode; }
const QByteArray& getByteArray() const { return _byteArray; } const QByteArray& getByteArray() const { return _byteArray; }
private: private:
void copyContents(const SharedNodePointer& destinationNode, const QByteArray& byteArray); void copyContents(const SharedNodePointer& sendingNode, const QByteArray& byteArray);
SharedNodePointer _destinationNode; SharedNodePointer _sendingNode;
QByteArray _byteArray; QByteArray _byteArray;
}; };

View file

@ -271,7 +271,7 @@ bool PacketSender::nonThreadedProcess() {
unlock(); unlock();
// send the packet through the NodeList... // send the packet through the NodeList...
NodeList::getInstance()->writeDatagram(temporary.getByteArray(), temporary.getDestinationNode()); NodeList::getInstance()->writeDatagram(temporary.getByteArray(), temporary.getSendingNode());
packetsSentThisCall++; packetsSentThisCall++;
_packetsOverCheckInterval++; _packetsOverCheckInterval++;
_totalPacketsSent++; _totalPacketsSent++;

View file

@ -17,13 +17,14 @@ void ReceivedPacketProcessor::terminating() {
_hasPackets.wakeAll(); _hasPackets.wakeAll();
} }
void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& destinationNode, const QByteArray& packet) { void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
// Make sure our Node and NodeList knows we've heard from this node. // Make sure our Node and NodeList knows we've heard from this node.
destinationNode->setLastHeardMicrostamp(usecTimestampNow()); sendingNode->setLastHeardMicrostamp(usecTimestampNow());
NetworkPacket networkPacket(destinationNode, packet); NetworkPacket networkPacket(sendingNode, packet);
lock(); lock();
_packets.push_back(networkPacket); _packets.push_back(networkPacket);
_nodePacketCounts[sendingNode->getUUID()]++;
unlock(); unlock();
// Make sure to wake our actual processing thread because we now have packets for it to process. // Make sure to wake our actual processing thread because we now have packets for it to process.
@ -42,8 +43,9 @@ bool ReceivedPacketProcessor::process() {
NetworkPacket& packet = _packets.front(); // get the oldest packet NetworkPacket& packet = _packets.front(); // get the oldest packet
NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
_packets.erase(_packets.begin()); // remove the oldest packet _packets.erase(_packets.begin()); // remove the oldest packet
_nodePacketCounts[temporary.getSendingNode()->getUUID()]--;
unlock(); // let others add to the packets unlock(); // let others add to the packets
processPacket(temporary.getDestinationNode(), temporary.getByteArray()); // process our temporary copy processPacket(temporary.getSendingNode(), temporary.getByteArray()); // process our temporary copy
} }
return isStillRunning(); // keep running till they terminate us return isStillRunning(); // keep running till they terminate us
} }

View file

@ -28,11 +28,16 @@ public:
/// \param packetData pointer to received data /// \param packetData pointer to received data
/// \param ssize_t packetLength size of received data /// \param ssize_t packetLength size of received data
/// \thread network receive thread /// \thread network receive thread
void queueReceivedPacket(const SharedNodePointer& destinationNode, const QByteArray& packet); void queueReceivedPacket(const SharedNodePointer& sendingNode, const QByteArray& packet);
/// Are there received packets waiting to be processed /// Are there received packets waiting to be processed
bool hasPacketsToProcess() const { return _packets.size() > 0; } bool hasPacketsToProcess() const { return _packets.size() > 0; }
/// Are there received packets waiting to be processed from a certain node
bool hasPacketsToProcessFrom(const SharedNodePointer& sendingNode) const {
return _nodePacketCounts[sendingNode->getUUID()] > 0;
}
/// How many received packets waiting are to be processed /// How many received packets waiting are to be processed
int packetsToProcessCount() const { return _packets.size(); } int packetsToProcessCount() const { return _packets.size(); }
@ -51,7 +56,9 @@ protected:
private: private:
std::vector<NetworkPacket> _packets; QVector<NetworkPacket> _packets;
QHash<QUuid, int> _nodePacketCounts;
QWaitCondition _hasPackets; QWaitCondition _hasPackets;
QMutex _waitingOnPacketsMutex; QMutex _waitingOnPacketsMutex;
}; };