switched to using Application singleton

This commit is contained in:
ZappoMan 2013-08-15 13:10:41 -07:00
parent 04440d30d8
commit 82782b6ec5
5 changed files with 21 additions and 37 deletions

View file

@ -221,8 +221,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_audio(&_audioScope, STARTUP_JITTER_SAMPLES), _audio(&_audioScope, STARTUP_JITTER_SAMPLES),
#endif #endif
_stopNetworkReceiveThread(false), _stopNetworkReceiveThread(false),
_voxelProcessor(this), _voxelProcessor(),
_voxelEditSender(this), _voxelEditSender(),
_packetCount(0), _packetCount(0),
_packetsPerSecond(0), _packetsPerSecond(0),
_bytesPerSecond(0), _bytesPerSecond(0),

View file

@ -13,15 +13,12 @@
#include "Application.h" #include "Application.h"
#include "VoxelEditPacketSender.h" #include "VoxelEditPacketSender.h"
VoxelEditPacketSender::VoxelEditPacketSender(Application* app) :
_app(app)
{
}
void VoxelEditPacketSender::sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail) { void VoxelEditPacketSender::sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail) {
Application* app = Application::getInstance();
// if the app has Voxels disabled, we don't do any of this... // if the app has Voxels disabled, we don't do any of this...
if (!_app->_renderVoxels->isChecked()) { if (!app->_renderVoxels->isChecked()) {
return; // bail early return; // bail early
} }
@ -35,7 +32,7 @@ void VoxelEditPacketSender::sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail&
} }
// Tell the application's bandwidth meters about what we've sent // Tell the application's bandwidth meters about what we've sent
_app->_bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(totalBytesSent); 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) {
@ -51,6 +48,8 @@ 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();
// 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
// for a different voxel server... So we need to actually manage multiple queued packets... one // for a different voxel server... So we need to actually manage multiple queued packets... one
@ -63,7 +62,7 @@ void VoxelEditPacketSender::queueVoxelEditMessage(PACKET_TYPE type, unsigned cha
// we need to get the jurisdiction for this // we need to get the jurisdiction for this
// here we need to get the "pending packet" for this server // 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]; const JurisdictionMap& map = app->_voxelServerJurisdictions[nodeID];
if (map.isMyJurisdiction(codeColorBuffer, CHECK_NODE_ONLY) == JurisdictionMap::WITHIN) { if (map.isMyJurisdiction(codeColorBuffer, CHECK_NODE_ONLY) == JurisdictionMap::WITHIN) {
EditPacketBuffer& packetBuffer = _pendingEditPackets[nodeID]; EditPacketBuffer& packetBuffer = _pendingEditPackets[nodeID];
packetBuffer._nodeID = nodeID; packetBuffer._nodeID = nodeID;

View file

@ -14,8 +14,6 @@
#include <PacketSender.h> #include <PacketSender.h>
#include <SharedUtil.h> // for VoxelDetail #include <SharedUtil.h> // for VoxelDetail
class Application;
/// Used for construction of edit voxel packets /// Used for construction of edit voxel packets
class EditPacketBuffer { class EditPacketBuffer {
public: public:
@ -29,8 +27,6 @@ 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(Application* app);
/// Send voxel edit message immediately /// Send voxel edit message immediately
void sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail); void sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail);
@ -46,7 +42,6 @@ private:
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
Application* _app;
std::map<uint16_t,EditPacketBuffer> _pendingEditPackets; std::map<uint16_t,EditPacketBuffer> _pendingEditPackets;
}; };
#endif // __shared__VoxelEditPacketSender__ #endif // __shared__VoxelEditPacketSender__

View file

@ -13,18 +13,16 @@
#include "Application.h" #include "Application.h"
#include "VoxelPacketProcessor.h" #include "VoxelPacketProcessor.h"
VoxelPacketProcessor::VoxelPacketProcessor(Application* app) :
_app(app) {
}
void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) { void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength) {
PerformanceWarning warn(_app->_renderPipelineWarnings->isChecked(),"VoxelPacketProcessor::processPacket()"); Application* app = Application::getInstance();
PerformanceWarning warn(app->_renderPipelineWarnings->isChecked(),"VoxelPacketProcessor::processPacket()");
ssize_t messageLength = packetLength; ssize_t messageLength = packetLength;
// check to see if the UI thread asked us to kill the voxel tree. since we're the only thread allowed to do that // check to see if the UI thread asked us to kill the voxel tree. since we're the only thread allowed to do that
if (_app->_wantToKillLocalVoxels) { if (app->_wantToKillLocalVoxels) {
_app->_voxels.killLocalVoxels(); app->_voxels.killLocalVoxels();
_app->_wantToKillLocalVoxels = false; app->_wantToKillLocalVoxels = false;
} }
// note: PACKET_TYPE_VOXEL_STATS can have PACKET_TYPE_VOXEL_DATA or PACKET_TYPE_VOXEL_DATA_MONOCHROME // note: PACKET_TYPE_VOXEL_STATS can have PACKET_TYPE_VOXEL_DATA or PACKET_TYPE_VOXEL_DATA_MONOCHROME
@ -32,7 +30,7 @@ void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char*
// then process any remaining bytes as if it was another packet // then process any remaining bytes as if it was another packet
if (packetData[0] == PACKET_TYPE_VOXEL_STATS) { if (packetData[0] == PACKET_TYPE_VOXEL_STATS) {
int statsMessageLength = _app->parseVoxelStats(packetData, messageLength, senderAddress); int statsMessageLength = app->parseVoxelStats(packetData, messageLength, senderAddress);
if (messageLength > statsMessageLength) { if (messageLength > statsMessageLength) {
packetData += statsMessageLength; packetData += statsMessageLength;
messageLength -= statsMessageLength; messageLength -= statsMessageLength;
@ -44,16 +42,16 @@ void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char*
} }
} // fall through to piggyback message } // fall through to piggyback message
if (_app->_renderVoxels->isChecked()) { if (app->_renderVoxels->isChecked()) {
Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress); Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) {
voxelServer->lock(); voxelServer->lock();
if (packetData[0] == PACKET_TYPE_ENVIRONMENT_DATA) { if (packetData[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
_app->_environment.parseData(&senderAddress, packetData, messageLength); app->_environment.parseData(&senderAddress, packetData, messageLength);
} else { } else {
_app->_voxels.setDataSourceID(voxelServer->getNodeID()); app->_voxels.setDataSourceID(voxelServer->getNodeID());
_app->_voxels.parseData(packetData, messageLength); app->_voxels.parseData(packetData, messageLength);
_app->_voxels.setDataSourceID(UNKNOWN_NODE_ID); app->_voxels.setDataSourceID(UNKNOWN_NODE_ID);
} }
voxelServer->unlock(); voxelServer->unlock();
} }

View file

@ -13,17 +13,9 @@
#include <ReceivedPacketProcessor.h> #include <ReceivedPacketProcessor.h>
class Application;
/// Handles processing of incoming voxel packets for the interface application. /// Handles processing of incoming voxel packets for the interface application.
class VoxelPacketProcessor : public ReceivedPacketProcessor { class VoxelPacketProcessor : public ReceivedPacketProcessor {
public:
VoxelPacketProcessor(Application* app);
protected: protected:
virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength); virtual void processPacket(sockaddr& senderAddress, unsigned char* packetData, ssize_t packetLength);
private:
Application* _app;
}; };
#endif // __shared__VoxelPacketProcessor__ #endif // __shared__VoxelPacketProcessor__