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),
#endif
_stopNetworkReceiveThread(false),
_voxelProcessor(this),
_voxelEditSender(this),
_voxelProcessor(),
_voxelEditSender(),
_packetCount(0),
_packetsPerSecond(0),
_bytesPerSecond(0),

View file

@ -13,15 +13,12 @@
#include "Application.h"
#include "VoxelEditPacketSender.h"
VoxelEditPacketSender::VoxelEditPacketSender(Application* app) :
_app(app)
{
}
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 (!_app->_renderVoxels->isChecked()) {
if (!app->_renderVoxels->isChecked()) {
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
_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) {
@ -51,6 +48,8 @@ void VoxelEditPacketSender::actuallySendMessage(uint16_t nodeID, unsigned char*
}
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
// 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
@ -63,7 +62,7 @@ void VoxelEditPacketSender::queueVoxelEditMessage(PACKET_TYPE type, unsigned cha
// we need to get the jurisdiction for this
// here we need to get the "pending packet" for this server
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) {
EditPacketBuffer& packetBuffer = _pendingEditPackets[nodeID];
packetBuffer._nodeID = nodeID;

View file

@ -14,8 +14,6 @@
#include <PacketSender.h>
#include <SharedUtil.h> // for VoxelDetail
class Application;
/// Used for construction of edit voxel packets
class EditPacketBuffer {
public:
@ -29,8 +27,6 @@ public:
/// Threaded processor for queueing and sending of outbound edit voxel packets.
class VoxelEditPacketSender : public PacketSender {
public:
VoxelEditPacketSender(Application* app);
/// Send voxel edit message immediately
void sendVoxelEditMessage(PACKET_TYPE type, VoxelDetail& detail);
@ -46,7 +42,6 @@ private:
void initializePacket(EditPacketBuffer& packetBuffer, PACKET_TYPE type);
void flushQueue(EditPacketBuffer& packetBuffer); // flushes specific queued packet
Application* _app;
std::map<uint16_t,EditPacketBuffer> _pendingEditPackets;
};
#endif // __shared__VoxelEditPacketSender__

View file

@ -13,18 +13,16 @@
#include "Application.h"
#include "VoxelPacketProcessor.h"
VoxelPacketProcessor::VoxelPacketProcessor(Application* app) :
_app(app) {
}
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;
// 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) {
_app->_voxels.killLocalVoxels();
_app->_wantToKillLocalVoxels = false;
if (app->_wantToKillLocalVoxels) {
app->_voxels.killLocalVoxels();
app->_wantToKillLocalVoxels = false;
}
// 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
if (packetData[0] == PACKET_TYPE_VOXEL_STATS) {
int statsMessageLength = _app->parseVoxelStats(packetData, messageLength, senderAddress);
int statsMessageLength = app->parseVoxelStats(packetData, messageLength, senderAddress);
if (messageLength > statsMessageLength) {
packetData += statsMessageLength;
messageLength -= statsMessageLength;
@ -44,16 +42,16 @@ void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char*
}
} // fall through to piggyback message
if (_app->_renderVoxels->isChecked()) {
if (app->_renderVoxels->isChecked()) {
Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) {
voxelServer->lock();
if (packetData[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
_app->_environment.parseData(&senderAddress, packetData, messageLength);
app->_environment.parseData(&senderAddress, packetData, messageLength);
} else {
_app->_voxels.setDataSourceID(voxelServer->getNodeID());
_app->_voxels.parseData(packetData, messageLength);
_app->_voxels.setDataSourceID(UNKNOWN_NODE_ID);
app->_voxels.setDataSourceID(voxelServer->getNodeID());
app->_voxels.parseData(packetData, messageLength);
app->_voxels.setDataSourceID(UNKNOWN_NODE_ID);
}
voxelServer->unlock();
}

View file

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