mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 17:56:43 +02:00
remove NetworkPacket and replace with NodePacketPair
This commit is contained in:
parent
30840422ad
commit
6c6143f21e
9 changed files with 59 additions and 151 deletions
|
@ -15,7 +15,6 @@
|
||||||
#define hifi_OctreeSendThread_h
|
#define hifi_OctreeSendThread_h
|
||||||
|
|
||||||
#include <GenericThread.h>
|
#include <GenericThread.h>
|
||||||
#include <NetworkPacket.h>
|
|
||||||
#include <OctreeElementBag.h>
|
#include <OctreeElementBag.h>
|
||||||
|
|
||||||
#include "OctreeQueryNode.h"
|
#include "OctreeQueryNode.h"
|
||||||
|
@ -28,7 +27,7 @@ class OctreeSendThread : public GenericThread {
|
||||||
public:
|
public:
|
||||||
OctreeSendThread(OctreeServer* myServer, const SharedNodePointer& node);
|
OctreeSendThread(OctreeServer* myServer, const SharedNodePointer& node);
|
||||||
virtual ~OctreeSendThread();
|
virtual ~OctreeSendThread();
|
||||||
|
|
||||||
void setIsShuttingDown();
|
void setIsShuttingDown();
|
||||||
|
|
||||||
static quint64 _totalBytes;
|
static quint64 _totalBytes;
|
||||||
|
@ -51,7 +50,7 @@ private:
|
||||||
int packetDistributor(OctreeQueryNode* nodeData, bool viewFrustumChanged);
|
int packetDistributor(OctreeQueryNode* nodeData, bool viewFrustumChanged);
|
||||||
|
|
||||||
OctreePacketData _packetData;
|
OctreePacketData _packetData;
|
||||||
|
|
||||||
int _nodeMissingCount;
|
int _nodeMissingCount;
|
||||||
bool _isShuttingDown;
|
bool _isShuttingDown;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
#include <EntityEditPacketSender.h>
|
#include <EntityEditPacketSender.h>
|
||||||
#include <EntityTreeRenderer.h>
|
#include <EntityTreeRenderer.h>
|
||||||
#include <GeometryCache.h>
|
#include <GeometryCache.h>
|
||||||
#include <NetworkPacket.h>
|
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
#include <OctreeQuery.h>
|
#include <OctreeQuery.h>
|
||||||
#include <OffscreenUi.h>
|
#include <OffscreenUi.h>
|
||||||
|
@ -122,7 +121,7 @@ static const QString INFO_HELP_PATH = "html/interface-welcome.html";
|
||||||
static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html";
|
static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html";
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
static const UINT UWM_IDENTIFY_INSTANCES =
|
static const UINT UWM_IDENTIFY_INSTANCES =
|
||||||
RegisterWindowMessage("UWM_IDENTIFY_INSTANCES_{8AB82783-B74A-4258-955B-8188C22AA0D6}_" + qgetenv("USERNAME"));
|
RegisterWindowMessage("UWM_IDENTIFY_INSTANCES_{8AB82783-B74A-4258-955B-8188C22AA0D6}_" + qgetenv("USERNAME"));
|
||||||
static const UINT UWM_SHOW_APPLICATION =
|
static const UINT UWM_SHOW_APPLICATION =
|
||||||
RegisterWindowMessage("UWM_SHOW_APPLICATION_{71123FD6-3DA8-4DC1-9C27-8A12A6250CBA}_" + qgetenv("USERNAME"));
|
RegisterWindowMessage("UWM_SHOW_APPLICATION_{71123FD6-3DA8-4DC1-9C27-8A12A6250CBA}_" + qgetenv("USERNAME"));
|
||||||
|
@ -199,11 +198,11 @@ public:
|
||||||
bool isThrottleRendering() const;
|
bool isThrottleRendering() const;
|
||||||
|
|
||||||
Camera* getCamera() { return &_myCamera; }
|
Camera* getCamera() { return &_myCamera; }
|
||||||
// Represents the current view frustum of the avatar.
|
// Represents the current view frustum of the avatar.
|
||||||
ViewFrustum* getViewFrustum();
|
ViewFrustum* getViewFrustum();
|
||||||
const ViewFrustum* getViewFrustum() const;
|
const ViewFrustum* getViewFrustum() const;
|
||||||
// Represents the view frustum of the current rendering pass,
|
// Represents the view frustum of the current rendering pass,
|
||||||
// which might be different from the viewFrustum, i.e. shadowmap
|
// which might be different from the viewFrustum, i.e. shadowmap
|
||||||
// passes, mirror window passes, etc
|
// passes, mirror window passes, etc
|
||||||
ViewFrustum* getDisplayViewFrustum();
|
ViewFrustum* getDisplayViewFrustum();
|
||||||
const ViewFrustum* getDisplayViewFrustum() const;
|
const ViewFrustum* getDisplayViewFrustum() const;
|
||||||
|
@ -215,7 +214,7 @@ public:
|
||||||
OctreeQuery& getOctreeQuery() { return _octreeQuery; }
|
OctreeQuery& getOctreeQuery() { return _octreeQuery; }
|
||||||
EntityTree* getEntityClipboard() { return &_entityClipboard; }
|
EntityTree* getEntityClipboard() { return &_entityClipboard; }
|
||||||
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; }
|
||||||
|
|
||||||
bool isMousePressed() const { return _mousePressed; }
|
bool isMousePressed() const { return _mousePressed; }
|
||||||
bool isMouseHidden() const { return !_cursorVisible; }
|
bool isMouseHidden() const { return !_cursorVisible; }
|
||||||
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
|
||||||
|
@ -237,7 +236,7 @@ public:
|
||||||
int getTrueMouseDragStartedX() const { return getTrueMouseDragStarted().x; }
|
int getTrueMouseDragStartedX() const { return getTrueMouseDragStarted().x; }
|
||||||
int getTrueMouseDragStartedY() const { return getTrueMouseDragStarted().y; }
|
int getTrueMouseDragStartedY() const { return getTrueMouseDragStarted().y; }
|
||||||
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; }
|
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; }
|
||||||
|
|
||||||
FaceTracker* getActiveFaceTracker();
|
FaceTracker* getActiveFaceTracker();
|
||||||
FaceTracker* getSelectedFaceTracker();
|
FaceTracker* getSelectedFaceTracker();
|
||||||
|
|
||||||
|
@ -254,7 +253,7 @@ public:
|
||||||
|
|
||||||
virtual const Transform& getViewTransform() const { return _viewTransform; }
|
virtual const Transform& getViewTransform() const { return _viewTransform; }
|
||||||
void setViewTransform(const Transform& view);
|
void setViewTransform(const Transform& view);
|
||||||
|
|
||||||
float getFieldOfView() { return _fieldOfView.get(); }
|
float getFieldOfView() { return _fieldOfView.get(); }
|
||||||
void setFieldOfView(float fov) { _fieldOfView.set(fov); }
|
void setFieldOfView(float fov) { _fieldOfView.set(fov); }
|
||||||
|
|
||||||
|
@ -319,7 +318,7 @@ public:
|
||||||
|
|
||||||
QStringList getRunningScripts() { return _scriptEnginesHash.keys(); }
|
QStringList getRunningScripts() { return _scriptEnginesHash.keys(); }
|
||||||
ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; }
|
ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; }
|
||||||
|
|
||||||
bool isLookingAtMyAvatar(Avatar* avatar);
|
bool isLookingAtMyAvatar(Avatar* avatar);
|
||||||
|
|
||||||
float getRenderResolutionScale() const;
|
float getRenderResolutionScale() const;
|
||||||
|
@ -344,17 +343,17 @@ public:
|
||||||
RunningScriptsWidget* getRunningScriptsWidget() { return _runningScriptsWidget; }
|
RunningScriptsWidget* getRunningScriptsWidget() { return _runningScriptsWidget; }
|
||||||
|
|
||||||
Bookmarks* getBookmarks() const { return _bookmarks; }
|
Bookmarks* getBookmarks() const { return _bookmarks; }
|
||||||
|
|
||||||
QString getScriptsLocation();
|
QString getScriptsLocation();
|
||||||
void setScriptsLocation(const QString& scriptsLocation);
|
void setScriptsLocation(const QString& scriptsLocation);
|
||||||
|
|
||||||
void initializeAcceptedFiles();
|
void initializeAcceptedFiles();
|
||||||
bool canAcceptURL(const QString& url);
|
bool canAcceptURL(const QString& url);
|
||||||
bool acceptURL(const QString& url);
|
bool acceptURL(const QString& url);
|
||||||
|
|
||||||
void setMaxOctreePacketsPerSecond(int maxOctreePPS);
|
void setMaxOctreePacketsPerSecond(int maxOctreePPS);
|
||||||
int getMaxOctreePacketsPerSecond();
|
int getMaxOctreePacketsPerSecond();
|
||||||
|
|
||||||
render::ScenePointer getMain3DScene() { return _main3DScene; }
|
render::ScenePointer getMain3DScene() { return _main3DScene; }
|
||||||
render::EnginePointer getRenderEngine() { return _renderEngine; }
|
render::EnginePointer getRenderEngine() { return _renderEngine; }
|
||||||
|
|
||||||
|
@ -373,7 +372,7 @@ signals:
|
||||||
|
|
||||||
/// Fired when the import window is closed
|
/// Fired when the import window is closed
|
||||||
void importDone();
|
void importDone();
|
||||||
|
|
||||||
void scriptLocationChanged(const QString& newPath);
|
void scriptLocationChanged(const QString& newPath);
|
||||||
|
|
||||||
void svoImportRequested(const QString& url);
|
void svoImportRequested(const QString& url);
|
||||||
|
@ -384,7 +383,7 @@ signals:
|
||||||
void headURLChanged(const QString& newValue, const QString& modelName);
|
void headURLChanged(const QString& newValue, const QString& modelName);
|
||||||
void bodyURLChanged(const QString& newValue, const QString& modelName);
|
void bodyURLChanged(const QString& newValue, const QString& modelName);
|
||||||
void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
|
void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
|
||||||
|
|
||||||
void beforeAboutToQuit();
|
void beforeAboutToQuit();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -408,7 +407,7 @@ public slots:
|
||||||
bool askToSetAvatarUrl(const QString& url);
|
bool askToSetAvatarUrl(const QString& url);
|
||||||
bool askToLoadScript(const QString& scriptFilenameOrURL);
|
bool askToLoadScript(const QString& scriptFilenameOrURL);
|
||||||
|
|
||||||
ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true,
|
ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true,
|
||||||
bool loadScriptFromEditor = false, bool activateMainWindow = false, bool reload = false);
|
bool loadScriptFromEditor = false, bool activateMainWindow = false, bool reload = false);
|
||||||
void reloadScript(const QString& scriptName, bool isUserLoaded = true);
|
void reloadScript(const QString& scriptName, bool isUserLoaded = true);
|
||||||
void scriptFinished(const QString& scriptName);
|
void scriptFinished(const QString& scriptName);
|
||||||
|
@ -424,11 +423,11 @@ public slots:
|
||||||
void friendsWindowClosed();
|
void friendsWindowClosed();
|
||||||
|
|
||||||
void packageModel();
|
void packageModel();
|
||||||
|
|
||||||
void openUrl(const QUrl& url);
|
void openUrl(const QUrl& url);
|
||||||
|
|
||||||
void updateMyAvatarTransform();
|
void updateMyAvatarTransform();
|
||||||
|
|
||||||
void domainSettingsReceived(const QJsonObject& domainSettingsObject);
|
void domainSettingsReceived(const QJsonObject& domainSettingsObject);
|
||||||
|
|
||||||
void setVSyncEnabled();
|
void setVSyncEnabled();
|
||||||
|
@ -439,14 +438,14 @@ public slots:
|
||||||
|
|
||||||
void aboutApp();
|
void aboutApp();
|
||||||
void showEditEntitiesHelp();
|
void showEditEntitiesHelp();
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
void notifyPacketVersionMismatch();
|
void notifyPacketVersionMismatch();
|
||||||
|
|
||||||
void domainConnectionDenied(const QString& reason);
|
void domainConnectionDenied(const QString& reason);
|
||||||
|
|
||||||
void cameraMenuChanged();
|
void cameraMenuChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -454,7 +453,7 @@ private slots:
|
||||||
void checkFPS();
|
void checkFPS();
|
||||||
void idle();
|
void idle();
|
||||||
void aboutToQuit();
|
void aboutToQuit();
|
||||||
|
|
||||||
void handleScriptEngineLoaded(const QString& scriptFilename);
|
void handleScriptEngineLoaded(const QString& scriptFilename);
|
||||||
void handleScriptLoadError(const QString& scriptFilename);
|
void handleScriptLoadError(const QString& scriptFilename);
|
||||||
|
|
||||||
|
@ -464,7 +463,7 @@ private slots:
|
||||||
void setFullscreen(bool fullscreen);
|
void setFullscreen(bool fullscreen);
|
||||||
void setEnable3DTVMode(bool enable3DTVMode);
|
void setEnable3DTVMode(bool enable3DTVMode);
|
||||||
void setEnableVRMode(bool enableVRMode);
|
void setEnableVRMode(bool enableVRMode);
|
||||||
|
|
||||||
void rotationModeChanged();
|
void rotationModeChanged();
|
||||||
|
|
||||||
glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint);
|
glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint);
|
||||||
|
@ -474,9 +473,9 @@ private slots:
|
||||||
void shrinkMirrorView();
|
void shrinkMirrorView();
|
||||||
|
|
||||||
void manageRunningScriptsWidgetVisibility(bool shown);
|
void manageRunningScriptsWidgetVisibility(bool shown);
|
||||||
|
|
||||||
void runTests();
|
void runTests();
|
||||||
|
|
||||||
void audioMuteToggled();
|
void audioMuteToggled();
|
||||||
void faceTrackerMuteToggled();
|
void faceTrackerMuteToggled();
|
||||||
|
|
||||||
|
@ -491,7 +490,7 @@ private:
|
||||||
|
|
||||||
void initDisplay();
|
void initDisplay();
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void cleanupBeforeQuit();
|
void cleanupBeforeQuit();
|
||||||
|
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
|
@ -528,7 +527,7 @@ private:
|
||||||
|
|
||||||
ToolWindow* _toolWindow;
|
ToolWindow* _toolWindow;
|
||||||
WebWindowClass* _friendsWindow;
|
WebWindowClass* _friendsWindow;
|
||||||
|
|
||||||
DatagramProcessor* _datagramProcessor;
|
DatagramProcessor* _datagramProcessor;
|
||||||
|
|
||||||
QUndoStack _undoStack;
|
QUndoStack _undoStack;
|
||||||
|
@ -569,7 +568,7 @@ private:
|
||||||
Camera _myCamera; // My view onto the world
|
Camera _myCamera; // My view onto the world
|
||||||
Camera _mirrorCamera; // Cammera for mirror view
|
Camera _mirrorCamera; // Cammera for mirror view
|
||||||
QRect _mirrorViewRect;
|
QRect _mirrorViewRect;
|
||||||
|
|
||||||
Setting::Handle<bool> _firstRun;
|
Setting::Handle<bool> _firstRun;
|
||||||
Setting::Handle<QString> _previousScriptLocation;
|
Setting::Handle<QString> _previousScriptLocation;
|
||||||
Setting::Handle<QString> _scriptsLocationHandle;
|
Setting::Handle<QString> _scriptsLocationHandle;
|
||||||
|
@ -648,23 +647,23 @@ private:
|
||||||
quint64 _lastSendDownstreamAudioStats;
|
quint64 _lastSendDownstreamAudioStats;
|
||||||
|
|
||||||
bool _isVSyncOn;
|
bool _isVSyncOn;
|
||||||
|
|
||||||
bool _aboutToQuit;
|
bool _aboutToQuit;
|
||||||
|
|
||||||
Bookmarks* _bookmarks;
|
Bookmarks* _bookmarks;
|
||||||
|
|
||||||
bool _notifiedPacketVersionMismatchThisDomain;
|
bool _notifiedPacketVersionMismatchThisDomain;
|
||||||
|
|
||||||
QThread _settingsThread;
|
QThread _settingsThread;
|
||||||
QTimer _settingsTimer;
|
QTimer _settingsTimer;
|
||||||
|
|
||||||
GLCanvas* _glWidget = new GLCanvas(); // our GLCanvas has a couple extra features
|
GLCanvas* _glWidget = new GLCanvas(); // our GLCanvas has a couple extra features
|
||||||
|
|
||||||
void checkSkeleton();
|
void checkSkeleton();
|
||||||
|
|
||||||
QWidget* _fullscreenMenuWidget = new QWidget();
|
QWidget* _fullscreenMenuWidget = new QWidget();
|
||||||
int _menuBarHeight;
|
int _menuBarHeight;
|
||||||
|
|
||||||
QHash<QString, AcceptURLMethod> _acceptedExtensions;
|
QHash<QString, AcceptURLMethod> _acceptedExtensions;
|
||||||
|
|
||||||
QList<QString> _domainConnectionRefusals;
|
QList<QString> _domainConnectionRefusals;
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
//
|
|
||||||
// NetworkPacket.cpp
|
|
||||||
// libraries/networking/src
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 8/9/13.
|
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
|
||||||
#include <QtDebug>
|
|
||||||
|
|
||||||
#include "SharedUtil.h"
|
|
||||||
#include "NetworkLogging.h"
|
|
||||||
|
|
||||||
#include "NetworkPacket.h"
|
|
||||||
|
|
||||||
NetworkPacket::NetworkPacket(const NetworkPacket& other) :
|
|
||||||
_node(other._node),
|
|
||||||
_nlPacket(other._nlPacket) {
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkPacket::NetworkPacket(const SharedNodePointer& node, const NLPacket& packet) {
|
|
||||||
if (packet.getSizeWithHeader() && packet.getSizeWithHeader() <= MAX_PACKET_SIZE) {
|
|
||||||
_node = node;
|
|
||||||
_nlPacket = packet;
|
|
||||||
} else {
|
|
||||||
qCDebug(networking, ">>> NetworkPacket::copyContents() unexpected length = %d", packet.size());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// copy assignment
|
|
||||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) {
|
|
||||||
_node = other._node;
|
|
||||||
_nlPacket = NLPacket::createCopy(other._nlPacket);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAS_MOVE_SEMANTICS
|
|
||||||
// move, same as copy, but other packet won't be used further
|
|
||||||
NetworkPacket::NetworkPacket(NetworkPacket&& other) :
|
|
||||||
_node(std::move(other._node)),
|
|
||||||
_nlPacket(std::move(other._nlPacket)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// move assignment
|
|
||||||
NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) {
|
|
||||||
_node = std::move(other._node);
|
|
||||||
_nlPacket = std::move(other._nlPacket);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,42 +0,0 @@
|
||||||
//
|
|
||||||
// NetworkPacket.h
|
|
||||||
// libraries/networking/src
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 8/9/13.
|
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// A really simple class that stores a network packet between being received and being processed
|
|
||||||
//
|
|
||||||
// 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_NetworkPacket_h
|
|
||||||
#define hifi_NetworkPacket_h
|
|
||||||
|
|
||||||
#include "NodeList.h"
|
|
||||||
|
|
||||||
/// Storage of not-yet processed inbound, or not yet sent outbound generic UDP network packet
|
|
||||||
class NetworkPacket {
|
|
||||||
public:
|
|
||||||
NetworkPacket();
|
|
||||||
NetworkPacket(const NetworkPacket& packet); // copy constructor
|
|
||||||
NetworkPacket& operator= (const NetworkPacket& other); // copy assignment
|
|
||||||
|
|
||||||
#ifdef HAS_MOVE_SEMANTICS
|
|
||||||
NetworkPacket(NetworkPacket&& other); // move?? // same as copy, but other packet won't be used further
|
|
||||||
NetworkPacket& operator= (NetworkPacket&& other); // move assignment
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NetworkPacket(const SharedNodePointer& node, const NLPacket& nlPacket);
|
|
||||||
|
|
||||||
const SharedNodePointer& getNode() const { return _node; }
|
|
||||||
const NLPacket& getPacket() const { return _nlPacket; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
SharedNodePointer _node;
|
|
||||||
NLPacket _nlPacket;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // hifi_NetworkPacket_h
|
|
|
@ -37,6 +37,8 @@ const quint64 DOMAIN_SERVER_CHECK_IN_MSECS = 1 * 1000;
|
||||||
|
|
||||||
const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5;
|
const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5;
|
||||||
|
|
||||||
|
using std::pair<SharedNodePointer, std::unique_ptr<NLPacket>> NodePacketPair;
|
||||||
|
|
||||||
class Application;
|
class Application;
|
||||||
class Assignment;
|
class Assignment;
|
||||||
|
|
||||||
|
|
|
@ -48,11 +48,13 @@ PacketSender::~PacketSender() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNode, const NLPacket& packet) {
|
void PacketSender::queuePacketForSending(const SharedNodePointer& destinationNode, std::unique_ptr<NLPacket> packet) {
|
||||||
NetworkPacket networkPacket(destinationNode, packet);
|
NodePacketPair networkPacket(destinationNode, packet);
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
_packets.push_back(networkPacket);
|
_packets.push_back(networkPacket);
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
_totalPacketsQueued++;
|
_totalPacketsQueued++;
|
||||||
_totalBytesQueued += packet.getSizeWithHeader();
|
_totalBytesQueued += packet.getSizeWithHeader();
|
||||||
|
|
||||||
|
@ -118,7 +120,7 @@ bool PacketSender::threadedProcess() {
|
||||||
|
|
||||||
// if threaded and we haven't slept? We want to wait for our consumer to signal us with new packets
|
// if threaded and we haven't slept? We want to wait for our consumer to signal us with new packets
|
||||||
if (!hasSlept) {
|
if (!hasSlept) {
|
||||||
// wait till we have packets
|
// wait till we have packets
|
||||||
_waitingOnPacketsMutex.lock();
|
_waitingOnPacketsMutex.lock();
|
||||||
_hasPackets.wait(&_waitingOnPacketsMutex);
|
_hasPackets.wait(&_waitingOnPacketsMutex);
|
||||||
_waitingOnPacketsMutex.unlock();
|
_waitingOnPacketsMutex.unlock();
|
||||||
|
@ -264,21 +266,24 @@ bool PacketSender::nonThreadedProcess() {
|
||||||
// Now that we know how many packets to send this call to process, just send them.
|
// Now that we know how many packets to send this call to process, just send them.
|
||||||
while ((packetsSentThisCall < packetsToSendThisCall) && (packetsLeft > 0)) {
|
while ((packetsSentThisCall < packetsToSendThisCall) && (packetsLeft > 0)) {
|
||||||
lock();
|
lock();
|
||||||
NetworkPacket& packet = _packets.front();
|
|
||||||
NetworkPacket temporary = packet; // make a copy
|
NodePacketPair& packetPair = _packets.pop_front();
|
||||||
_packets.erase(_packets.begin());
|
|
||||||
packetsLeft = _packets.size();
|
packetsLeft = _packets.size();
|
||||||
|
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
// send the packet through the NodeList...
|
// send the packet through the NodeList...
|
||||||
DependencyManager::get<NodeList>()->sendUnreliablePacket(temporary.getPacket(), temporary.getNode());
|
DependencyManager::get<NodeList>()->sendUnreliablePacket(packetPair->second(), packetPair->first());
|
||||||
|
|
||||||
packetsSentThisCall++;
|
packetsSentThisCall++;
|
||||||
_packetsOverCheckInterval++;
|
_packetsOverCheckInterval++;
|
||||||
_totalPacketsSent++;
|
_totalPacketsSent++;
|
||||||
_totalBytesSent += temporary.getPacket().getSizeWithHeader();
|
|
||||||
|
int packetSize = packetPair->second().getSizeWithHeader();
|
||||||
emit packetSent(temporary.getPacket().getSizeWithHeader());
|
|
||||||
|
_totalBytesSent += packetSize;
|
||||||
|
emit packetSent(packetSize);
|
||||||
|
|
||||||
_lastSendTime = now;
|
_lastSendTime = now;
|
||||||
}
|
}
|
||||||
return isStillRunning();
|
return isStillRunning();
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
|
|
||||||
#include "GenericThread.h"
|
#include "GenericThread.h"
|
||||||
#include "NetworkPacket.h"
|
|
||||||
#include "NodeList.h"
|
#include "NodeList.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
|
@ -39,7 +38,7 @@ public:
|
||||||
~PacketSender();
|
~PacketSender();
|
||||||
|
|
||||||
/// Add packet to outbound queue.
|
/// Add packet to outbound queue.
|
||||||
void queuePacketForSending(const SharedNodePointer& destinationNode, const NLPacket& packet);
|
void queuePacketForSending(const SharedNodePointer& destinationNode, std::unique_ptr<NLPacket> packet);
|
||||||
|
|
||||||
void setPacketsPerSecond(int packetsPerSecond);
|
void setPacketsPerSecond(int packetsPerSecond);
|
||||||
int getPacketsPerSecond() const { return _packetsPerSecond; }
|
int getPacketsPerSecond() const { return _packetsPerSecond; }
|
||||||
|
@ -100,7 +99,7 @@ protected:
|
||||||
SimpleMovingAverage _averageProcessCallTime;
|
SimpleMovingAverage _averageProcessCallTime;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<NetworkPacket> _packets;
|
std::list<NodePacketPair> _packets;
|
||||||
quint64 _lastSendTime;
|
quint64 _lastSendTime;
|
||||||
|
|
||||||
bool threadedProcess();
|
bool threadedProcess();
|
||||||
|
|
|
@ -21,12 +21,14 @@ void ReceivedPacketProcessor::queueReceivedPacket(const SharedNodePointer& sendi
|
||||||
// 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.
|
||||||
sendingNode->setLastHeardMicrostamp(usecTimestampNow());
|
sendingNode->setLastHeardMicrostamp(usecTimestampNow());
|
||||||
|
|
||||||
NetworkPacket networkPacket(sendingNode, packet);
|
// TODO: fix the NodePacketPair once we've figured out receive API
|
||||||
|
NodePacketPair networkPacket(sendingNode, NLPacket::create(PacketType::OctreeStats));
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
_packets.push_back(networkPacket);
|
_packets.push_back(networkPacket);
|
||||||
_nodePacketCounts[sendingNode->getUUID()]++;
|
_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.
|
||||||
_hasPackets.wakeAll();
|
_hasPackets.wakeAll();
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,8 @@ bool ReceivedPacketProcessor::process() {
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
foreach(auto& packet, currentPackets) {
|
foreach(auto& packet, currentPackets) {
|
||||||
processPacket(packet.getNode(), packet.getByteArray());
|
// TODO: Replace QByteArray() once NLPacket is coming through on receive side
|
||||||
|
processPacket(packet->first(), QByteArray());
|
||||||
midProcess();
|
midProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,8 @@
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
|
|
||||||
#include "GenericThread.h"
|
#include "GenericThread.h"
|
||||||
#include "NetworkPacket.h"
|
|
||||||
|
|
||||||
/// Generalized threaded processor for handling received inbound packets.
|
/// Generalized threaded processor for handling received inbound packets.
|
||||||
class ReceivedPacketProcessor : public GenericThread {
|
class ReceivedPacketProcessor : public GenericThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -74,8 +73,7 @@ protected:
|
||||||
virtual void postProcess() { }
|
virtual void postProcess() { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
std::list<NodePacketPair> _packets;
|
||||||
QVector<NetworkPacket> _packets;
|
|
||||||
QHash<QUuid, int> _nodePacketCounts;
|
QHash<QUuid, int> _nodePacketCounts;
|
||||||
|
|
||||||
QWaitCondition _hasPackets;
|
QWaitCondition _hasPackets;
|
||||||
|
|
Loading…
Reference in a new issue