mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:48:44 +02:00
remove Application dependency from VoxelEditPacketSender class
This commit is contained in:
parent
82782b6ec5
commit
209c9f93ed
6 changed files with 61 additions and 22 deletions
|
@ -222,7 +222,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
#endif
|
#endif
|
||||||
_stopNetworkReceiveThread(false),
|
_stopNetworkReceiveThread(false),
|
||||||
_voxelProcessor(),
|
_voxelProcessor(),
|
||||||
_voxelEditSender(),
|
_voxelEditSender(this),
|
||||||
_packetCount(0),
|
_packetCount(0),
|
||||||
_packetsPerSecond(0),
|
_packetsPerSecond(0),
|
||||||
_bytesPerSecond(0),
|
_bytesPerSecond(0),
|
||||||
|
@ -329,6 +329,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_glWidget->setMouseTracking(true);
|
_glWidget->setMouseTracking(true);
|
||||||
|
|
||||||
// initialization continues in initializeGL when OpenGL context is ready
|
// initialization continues in initializeGL when OpenGL context is ready
|
||||||
|
|
||||||
|
// Tell our voxel edit sender about our known jurisdictions
|
||||||
|
_voxelEditSender.setVoxelServerJurisdictions(&_voxelServerJurisdictions);
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
@ -1437,6 +1440,7 @@ void Application::setRenderWarnings(bool renderWarnings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setRenderVoxels(bool voxelRender) {
|
void Application::setRenderVoxels(bool voxelRender) {
|
||||||
|
_voxelEditSender.setShouldSend(voxelRender);
|
||||||
if (!voxelRender) {
|
if (!voxelRender) {
|
||||||
doKillLocalVoxels();
|
doKillLocalVoxels();
|
||||||
}
|
}
|
||||||
|
@ -4156,5 +4160,6 @@ void Application::updateParticleSystem(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::packetSentNotification(ssize_t length) {
|
||||||
|
_bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length);
|
||||||
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ static const float NODE_KILLED_RED = 1.0f;
|
||||||
static const float NODE_KILLED_GREEN = 0.0f;
|
static const float NODE_KILLED_GREEN = 0.0f;
|
||||||
static const float NODE_KILLED_BLUE = 0.0f;
|
static const float NODE_KILLED_BLUE = 0.0f;
|
||||||
|
|
||||||
class Application : public QApplication, public NodeListHook {
|
class Application : public QApplication, public NodeListHook, public PacketSenderNotify {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class VoxelPacketProcessor;
|
friend class VoxelPacketProcessor;
|
||||||
|
@ -131,6 +131,7 @@ public:
|
||||||
|
|
||||||
virtual void nodeAdded(Node* node);
|
virtual void nodeAdded(Node* node);
|
||||||
virtual void nodeKilled(Node* node);
|
virtual void nodeKilled(Node* node);
|
||||||
|
virtual void packetSentNotification(ssize_t length);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data);
|
void sendAvatarFaceVideoMessage(int frameCount, const QByteArray& data);
|
||||||
|
|
|
@ -10,29 +10,30 @@
|
||||||
|
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include <OctalCode.h>
|
||||||
|
#include <PacketHeaders.h>
|
||||||
#include "VoxelEditPacketSender.h"
|
#include "VoxelEditPacketSender.h"
|
||||||
|
|
||||||
|
|
||||||
|
VoxelEditPacketSender::VoxelEditPacketSender(PacketSenderNotify* notify) :
|
||||||
|
PacketSender(notify),
|
||||||
|
_shouldSend(true),
|
||||||
|
_voxelServerJurisdictions(NULL) {
|
||||||
|
}
|
||||||
|
|
||||||
void VoxelEditPacketSender::sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail) {
|
void VoxelEditPacketSender::sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail) {
|
||||||
|
// allows app to disable sending if for example voxels have been disabled
|
||||||
Application* app = Application::getInstance();
|
if (!_shouldSend) {
|
||||||
|
|
||||||
// if the app has Voxels disabled, we don't do any of this...
|
|
||||||
if (!app->_renderVoxels->isChecked()) {
|
|
||||||
return; // bail early
|
return; // bail early
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* bufferOut;
|
unsigned char* bufferOut;
|
||||||
int sizeOut;
|
int sizeOut;
|
||||||
int totalBytesSent = 0;
|
|
||||||
|
|
||||||
if (createVoxelEditMessage(type, 0, 1, &detail, bufferOut, sizeOut)){
|
if (createVoxelEditMessage(type, 0, 1, &detail, bufferOut, sizeOut)){
|
||||||
actuallySendMessage(UNKNOWN_NODE_ID, bufferOut, sizeOut); // sends to all servers... not ideal!
|
actuallySendMessage(UNKNOWN_NODE_ID, bufferOut, sizeOut); // sends to all servers... not ideal!
|
||||||
delete[] bufferOut;
|
delete[] bufferOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell the application's bandwidth meters about what we've sent
|
|
||||||
app->_bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(totalBytesSent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelEditPacketSender::actuallySendMessage(uint16_t nodeID, unsigned char* bufferOut, ssize_t sizeOut) {
|
void VoxelEditPacketSender::actuallySendMessage(uint16_t nodeID, unsigned char* bufferOut, ssize_t sizeOut) {
|
||||||
|
@ -48,7 +49,10 @@ void VoxelEditPacketSender::actuallySendMessage(uint16_t nodeID, unsigned char*
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelEditPacketSender::queueVoxelEditMessage(PACKET_TYPE type, unsigned char* codeColorBuffer, ssize_t length) {
|
void VoxelEditPacketSender::queueVoxelEditMessage(PACKET_TYPE type, unsigned char* codeColorBuffer, ssize_t length) {
|
||||||
Application* app = Application::getInstance();
|
|
||||||
|
if (!_shouldSend) {
|
||||||
|
return; // bail early
|
||||||
|
}
|
||||||
|
|
||||||
// We want to filter out edit messages for voxel servers based on the server's Jurisdiction
|
// We want to filter out edit messages for voxel servers based on the server's Jurisdiction
|
||||||
// But we can't really do that with a packed message, since each edit message could be destined
|
// But we can't really do that with a packed message, since each edit message could be destined
|
||||||
|
@ -58,12 +62,16 @@ void VoxelEditPacketSender::queueVoxelEditMessage(PACKET_TYPE type, unsigned cha
|
||||||
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
|
||||||
// only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER
|
// only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER
|
||||||
if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) {
|
if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) {
|
||||||
|
|
||||||
// we need to get the jurisdiction for this
|
|
||||||
// here we need to get the "pending packet" for this server
|
|
||||||
uint16_t nodeID = node->getNodeID();
|
uint16_t nodeID = node->getNodeID();
|
||||||
const JurisdictionMap& map = app->_voxelServerJurisdictions[nodeID];
|
bool isMyJurisdiction = true;
|
||||||
if (map.isMyJurisdiction(codeColorBuffer, CHECK_NODE_ONLY) == JurisdictionMap::WITHIN) {
|
|
||||||
|
if (_voxelServerJurisdictions) {
|
||||||
|
// we need to get the jurisdiction for this
|
||||||
|
// here we need to get the "pending packet" for this server
|
||||||
|
const JurisdictionMap& map = (*_voxelServerJurisdictions)[nodeID];
|
||||||
|
isMyJurisdiction = (map.isMyJurisdiction(codeColorBuffer, CHECK_NODE_ONLY) == JurisdictionMap::WITHIN);
|
||||||
|
}
|
||||||
|
if (isMyJurisdiction) {
|
||||||
EditPacketBuffer& packetBuffer = _pendingEditPackets[nodeID];
|
EditPacketBuffer& packetBuffer = _pendingEditPackets[nodeID];
|
||||||
packetBuffer._nodeID = nodeID;
|
packetBuffer._nodeID = nodeID;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <PacketSender.h>
|
#include <PacketSender.h>
|
||||||
#include <SharedUtil.h> // for VoxelDetail
|
#include <SharedUtil.h> // for VoxelDetail
|
||||||
|
#include <JurisdictionMap.h>
|
||||||
|
|
||||||
/// Used for construction of edit voxel packets
|
/// Used for construction of edit voxel packets
|
||||||
class EditPacketBuffer {
|
class EditPacketBuffer {
|
||||||
|
@ -27,6 +28,8 @@ public:
|
||||||
/// Threaded processor for queueing and sending of outbound edit voxel packets.
|
/// Threaded processor for queueing and sending of outbound edit voxel packets.
|
||||||
class VoxelEditPacketSender : public PacketSender {
|
class VoxelEditPacketSender : public PacketSender {
|
||||||
public:
|
public:
|
||||||
|
VoxelEditPacketSender(PacketSenderNotify* notify = NULL);
|
||||||
|
|
||||||
/// Send voxel edit message immediately
|
/// Send voxel edit message immediately
|
||||||
void sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail);
|
void sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail);
|
||||||
|
|
||||||
|
@ -37,11 +40,21 @@ public:
|
||||||
/// flushes all queued packets for all nodes
|
/// flushes all queued packets for all nodes
|
||||||
void flushQueue();
|
void flushQueue();
|
||||||
|
|
||||||
|
bool getShouldSend() const { return _shouldSend; }
|
||||||
|
void setShouldSend(bool shouldSend) { _shouldSend = shouldSend; }
|
||||||
|
|
||||||
|
void setVoxelServerJurisdictions(std::map<uint16_t, JurisdictionMap>* voxelServerJurisdictions) {
|
||||||
|
_voxelServerJurisdictions = voxelServerJurisdictions;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool _shouldSend;
|
||||||
void actuallySendMessage(uint16_t nodeID, unsigned char* bufferOut, ssize_t sizeOut);
|
void actuallySendMessage(uint16_t nodeID, unsigned char* bufferOut, ssize_t sizeOut);
|
||||||
void initializePacket(EditPacketBuffer& packetBuffer, PACKET_TYPE type);
|
void initializePacket(EditPacketBuffer& packetBuffer, PACKET_TYPE type);
|
||||||
void flushQueue(EditPacketBuffer& packetBuffer); // flushes specific queued packet
|
void flushQueue(EditPacketBuffer& packetBuffer); // flushes specific queued packet
|
||||||
|
|
||||||
std::map<uint16_t,EditPacketBuffer> _pendingEditPackets;
|
std::map<uint16_t,EditPacketBuffer> _pendingEditPackets;
|
||||||
|
|
||||||
|
std::map<uint16_t, JurisdictionMap>* _voxelServerJurisdictions;
|
||||||
};
|
};
|
||||||
#endif // __shared__VoxelEditPacketSender__
|
#endif // __shared__VoxelEditPacketSender__
|
||||||
|
|
|
@ -16,7 +16,7 @@ const uint64_t SEND_INTERVAL_USECS = 1000 * 5; // no more than 200pps... should
|
||||||
#include "PacketSender.h"
|
#include "PacketSender.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
||||||
PacketSender::PacketSender() {
|
PacketSender::PacketSender(PacketSenderNotify* notify) : _notify(notify) {
|
||||||
_lastSendTime = usecTimestampNow();
|
_lastSendTime = usecTimestampNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,9 @@ bool PacketSender::process() {
|
||||||
UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket();
|
UDPSocket* nodeSocket = NodeList::getInstance()->getNodeSocket();
|
||||||
|
|
||||||
nodeSocket->send(&packet.getAddress(), packet.getData(), packet.getLength());
|
nodeSocket->send(&packet.getAddress(), packet.getData(), packet.getLength());
|
||||||
|
if (_notify) {
|
||||||
|
_notify->packetSentNotification(packet.getLength());
|
||||||
|
}
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
_packets.erase(_packets.begin());
|
_packets.erase(_packets.begin());
|
||||||
|
|
|
@ -14,11 +14,18 @@
|
||||||
#include "GenericThread.h"
|
#include "GenericThread.h"
|
||||||
#include "NetworkPacket.h"
|
#include "NetworkPacket.h"
|
||||||
|
|
||||||
|
/// Notification Hook for packets being sent by a PacketSender
|
||||||
|
class PacketSenderNotify {
|
||||||
|
public:
|
||||||
|
virtual void packetSentNotification(ssize_t length) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Generalized threaded processor for queueing and sending of outbound packets.
|
/// Generalized threaded processor for queueing and sending of outbound packets.
|
||||||
class PacketSender : public GenericThread {
|
class PacketSender : public GenericThread {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PacketSender();
|
PacketSender(PacketSenderNotify* notify = NULL);
|
||||||
|
|
||||||
/// Add packet to outbound queue.
|
/// Add packet to outbound queue.
|
||||||
/// \param sockaddr& address the destination address
|
/// \param sockaddr& address the destination address
|
||||||
|
@ -33,6 +40,8 @@ private:
|
||||||
std::vector<NetworkPacket> _packets;
|
std::vector<NetworkPacket> _packets;
|
||||||
uint64_t _lastSendTime;
|
uint64_t _lastSendTime;
|
||||||
|
|
||||||
|
PacketSenderNotify* _notify;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __shared__PacketSender__
|
#endif // __shared__PacketSender__
|
||||||
|
|
Loading…
Reference in a new issue