diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index dfe548afd4..8ee1fd2b24 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3826,15 +3826,16 @@ void Application::nodeKilled(Node* node) { uint16_t nodeID = node->getNodeID(); // see if this is the first we've heard of this node... if (_voxelServerJurisdictions.find(nodeID) != _voxelServerJurisdictions.end()) { - VoxelPositionSize jurisditionDetails; - jurisditionDetails = _voxelServerJurisdictions[nodeID]; + unsigned char* rootCode = _voxelServerJurisdictions[nodeID].getRootOctalCode(); + VoxelPositionSize rootDetails; + voxelDetailsForCode(rootCode, rootDetails); printf("voxel server going away...... v[%f, %f, %f, %f]\n", - jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s); + rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); // Add the jurisditionDetails object to the list of "fade outs" VoxelFade fade(VoxelFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE); - fade.voxelDetails = jurisditionDetails; + fade.voxelDetails = rootDetails; const float slightly_smaller = 0.99; fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; _voxelFades.push_back(fade); @@ -3855,23 +3856,24 @@ int Application::parseVoxelStats(unsigned char* messageData, ssize_t messageLeng if (voxelServer) { uint16_t nodeID = voxelServer->getNodeID(); - VoxelPositionSize jurisditionDetails; - voxelDetailsForCode(_voxelSceneStats.getJurisdictionRoot(), jurisditionDetails); + VoxelPositionSize rootDetails; + voxelDetailsForCode(_voxelSceneStats.getJurisdictionRoot(), rootDetails); // see if this is the first we've heard of this node... if (_voxelServerJurisdictions.find(nodeID) == _voxelServerJurisdictions.end()) { printf("stats from new voxel server... v[%f, %f, %f, %f]\n", - jurisditionDetails.x, jurisditionDetails.y, jurisditionDetails.z, jurisditionDetails.s); + rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); // Add the jurisditionDetails object to the list of "fade outs" VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE); - fade.voxelDetails = jurisditionDetails; + fade.voxelDetails = rootDetails; const float slightly_smaller = 0.99; fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; _voxelFades.push_back(fade); } // store jurisdiction details for later use - _voxelServerJurisdictions[nodeID] = jurisditionDetails; + _voxelServerJurisdictions[nodeID] = JurisdictionMap(_voxelSceneStats.getJurisdictionRoot(), + _voxelSceneStats.getJurisdictionEndNodes()); } return statsMessageLength; } diff --git a/interface/src/Application.h b/interface/src/Application.h index 89b8f9d28b..9ef808f603 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -471,7 +471,7 @@ private: VoxelSceneStats _voxelSceneStats; int parseVoxelStats(unsigned char* messageData, ssize_t messageLength, sockaddr senderAddress); - std::map _voxelServerJurisdictions; + std::map _voxelServerJurisdictions; std::vector _voxelFades; }; diff --git a/interface/src/VoxelEditPacketSender.cpp b/interface/src/VoxelEditPacketSender.cpp index 0e1a2b3343..64016bc592 100644 --- a/interface/src/VoxelEditPacketSender.cpp +++ b/interface/src/VoxelEditPacketSender.cpp @@ -44,9 +44,12 @@ void VoxelEditPacketSender::actuallySendMessage(unsigned char* bufferOut, ssize_ qDebug("VoxelEditPacketSender::actuallySendMessage() sizeOut=%lu\n", sizeOut); NodeList* nodeList = NodeList::getInstance(); for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { - // only send to the NodeTypes we are asked to send to. + // only send to the NodeTypes that are NODE_TYPE_VOXEL_SERVER if (node->getActiveSocket() != NULL && node->getType() == NODE_TYPE_VOXEL_SERVER) { - // we know which socket is good for this node, send there + + // 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... sockaddr* nodeAddress = node->getActiveSocket(); queuePacket(*nodeAddress, bufferOut, sizeOut); } @@ -54,6 +57,34 @@ void VoxelEditPacketSender::actuallySendMessage(unsigned char* bufferOut, ssize_ } void VoxelEditPacketSender::queueVoxelEditMessage(PACKET_TYPE type, unsigned char* codeColorBuffer, ssize_t length) { +/**** + // 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 + // for each voxel server + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { + // only send to the NodeTypes that are 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 + + // If we're switching type, then we send the last one and start over + if ((type != _currentType && _currentSize > 0) || (_currentSize + length >= MAX_PACKET_SIZE)) { + flushQueue(); + initializePacket(type); + } + + // If the buffer is empty and not correctly initialized for our type... + if (type != _currentType && _currentSize == 0) { + initializePacket(type); + } + + memcpy(&_currentBuffer[_currentSize], codeColorBuffer, length); + _currentSize += length; + } + } +****/ // If we're switching type, then we send the last one and start over if ((type != _currentType && _currentSize > 0) || (_currentSize + length >= MAX_PACKET_SIZE)) { flushQueue(); diff --git a/libraries/shared/src/OctalCode.h b/libraries/shared/src/OctalCode.h index 405b85164d..846b65203b 100644 --- a/libraries/shared/src/OctalCode.h +++ b/libraries/shared/src/OctalCode.h @@ -39,7 +39,7 @@ void copyFirstVertexForCode(unsigned char * octalCode, float* output); struct VoxelPositionSize { float x, y, z, s; }; -void voxelDetailsForCode(unsigned char * octalCode, VoxelPositionSize& voxelPositionSize); +void voxelDetailsForCode(unsigned char* octalCode, VoxelPositionSize& voxelPositionSize); typedef enum { ILLEGAL_CODE = -2, diff --git a/libraries/voxels/src/JurisdictionMap.cpp b/libraries/voxels/src/JurisdictionMap.cpp index b452c12d14..eec78fcda9 100644 --- a/libraries/voxels/src/JurisdictionMap.cpp +++ b/libraries/voxels/src/JurisdictionMap.cpp @@ -13,8 +13,64 @@ #include "JurisdictionMap.h" #include "VoxelNode.h" + +// standard assignment +// copy assignment +JurisdictionMap& JurisdictionMap::operator=(const JurisdictionMap& other) { + copyContents(other); + printf("JurisdictionMap& JurisdictionMap::operator=(JurisdictionMap const& other) COPY ASSIGNMENT %p from %p\n", this, &other); + return *this; +} + +// move assignment +JurisdictionMap& JurisdictionMap::operator=(JurisdictionMap&& other) { + init(other._rootOctalCode, other._endNodes); + other._rootOctalCode = NULL; + other._endNodes.clear(); + printf("JurisdictionMap& JurisdictionMap::operator=(JurisdictionMap&& other) MOVE ASSIGNMENT %p from %p\n", this, &other); + return *this; +} + +// Move constructor +JurisdictionMap::JurisdictionMap(JurisdictionMap&& other) : _rootOctalCode(NULL) { + init(other._rootOctalCode, other._endNodes); + other._rootOctalCode = NULL; + other._endNodes.clear(); + printf("JurisdictionMap::JurisdictionMap(JurisdictionMap&& other) MOVE CONSTRUCTOR %p from %p\n", this, &other); +} + +// Copy constructor +JurisdictionMap::JurisdictionMap(const JurisdictionMap& other) : _rootOctalCode(NULL) { + copyContents(other); + printf("JurisdictionMap::JurisdictionMap(const JurisdictionMap& other) COPY CONSTRUCTOR %p from %p\n", this, &other); +} + +void JurisdictionMap::copyContents(const JurisdictionMap& other) { + unsigned char* rootCode; + std::vector endNodes; + if (other._rootOctalCode) { + int bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(other._rootOctalCode)); + rootCode = new unsigned char[bytes]; + memcpy(rootCode, other._rootOctalCode, bytes); + } else { + rootCode = new unsigned char[1]; + *rootCode = 0; + } + + for (int i = 0; i < other._endNodes.size(); i++) { + if (other._endNodes[i]) { + int bytes = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(other._endNodes[i])); + unsigned char* endNodeCode = new unsigned char[bytes]; + memcpy(endNodeCode, other._endNodes[i], bytes); + endNodes.push_back(endNodeCode); + } + } + init(rootCode, endNodes); +} + JurisdictionMap::~JurisdictionMap() { clear(); + printf("JurisdictionMap::~JurisdictionMap() DESTRUCTOR %p\n",this); } void JurisdictionMap::clear() { @@ -37,16 +93,19 @@ JurisdictionMap::JurisdictionMap() : _rootOctalCode(NULL) { std::vector emptyEndNodes; init(rootCode, emptyEndNodes); + printf("JurisdictionMap::~JurisdictionMap() DEFAULT CONSTRUCTOR %p\n",this); } JurisdictionMap::JurisdictionMap(const char* filename) : _rootOctalCode(NULL) { clear(); // clean up our own memory readFromFile(filename); + printf("JurisdictionMap::~JurisdictionMap() INI FILE CONSTRUCTOR %p\n",this); } JurisdictionMap::JurisdictionMap(unsigned char* rootOctalCode, const std::vector& endNodes) : _rootOctalCode(NULL) { init(rootOctalCode, endNodes); + printf("JurisdictionMap::~JurisdictionMap() OCTCODE CONSTRUCTOR %p\n",this); } JurisdictionMap::JurisdictionMap(const char* rootHexCode, const char* endNodesHexCodes) { @@ -63,6 +122,7 @@ JurisdictionMap::JurisdictionMap(const char* rootHexCode, const char* endNodesHe //printOctalCode(endNodeOctcode); _endNodes.push_back(endNodeOctcode); } + printf("JurisdictionMap::~JurisdictionMap() HEX STRING CONSTRUCTOR %p\n",this); } diff --git a/libraries/voxels/src/JurisdictionMap.h b/libraries/voxels/src/JurisdictionMap.h index 6622292df6..d54f5147d0 100644 --- a/libraries/voxels/src/JurisdictionMap.h +++ b/libraries/voxels/src/JurisdictionMap.h @@ -20,7 +20,16 @@ public: BELOW }; - JurisdictionMap(); + // standard constructors + JurisdictionMap(); // default constructor + JurisdictionMap(const JurisdictionMap& other); // copy constructor + JurisdictionMap(JurisdictionMap&& other); // move constructor + + // standard assignment + JurisdictionMap& operator= (JurisdictionMap const &other); // copy assignment + JurisdictionMap& operator= (JurisdictionMap&& other); // move assignment + + // application constructors JurisdictionMap(const char* filename); JurisdictionMap(unsigned char* rootOctalCode, const std::vector& endNodes); JurisdictionMap(const char* rootHextString, const char* endNodesHextString); @@ -36,6 +45,7 @@ public: int getEndNodeCount() const { return _endNodes.size(); } private: + void copyContents(const JurisdictionMap& other); void clear(); void init(unsigned char* rootOctalCode, const std::vector& endNodes); diff --git a/libraries/voxels/src/VoxelSceneStats.h b/libraries/voxels/src/VoxelSceneStats.h index 910859ff3e..ba9fa559b1 100644 --- a/libraries/voxels/src/VoxelSceneStats.h +++ b/libraries/voxels/src/VoxelSceneStats.h @@ -81,7 +81,7 @@ public: char* getItemValue(int item); unsigned char* getJurisdictionRoot() const { return _jurisdictionRoot; } - + const std::vector& getJurisdictionEndNodes() const { return _jurisdictionEndNodes; } private: bool _isReadyToSend; @@ -171,7 +171,8 @@ private: static int const MAX_ITEM_VALUE_LENGTH = 128; char _itemValueBuffer[MAX_ITEM_VALUE_LENGTH]; - unsigned char* _jurisdictionRoot; + unsigned char* _jurisdictionRoot; + std::vector _jurisdictionEndNodes; }; #endif /* defined(__hifi__VoxelSceneStats__) */