mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 08:33:12 +02:00
make JurisdictionMap handle copy/move/assigment so that it will work in std::vector<> and std::map<>, switch application to have map of JurisdictionMap objects instead of just root codes
This commit is contained in:
parent
7d2c69f530
commit
60dedee739
7 changed files with 120 additions and 16 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -471,7 +471,7 @@ private:
|
|||
VoxelSceneStats _voxelSceneStats;
|
||||
int parseVoxelStats(unsigned char* messageData, ssize_t messageLength, sockaddr senderAddress);
|
||||
|
||||
std::map<uint16_t,VoxelPositionSize> _voxelServerJurisdictions;
|
||||
std::map<uint16_t,JurisdictionMap> _voxelServerJurisdictions;
|
||||
|
||||
std::vector<VoxelFade> _voxelFades;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<unsigned char*> 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<unsigned char*> 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<unsigned char*>& 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<unsigned char*>& 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<unsigned char*>& endNodes);
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public:
|
|||
char* getItemValue(int item);
|
||||
|
||||
unsigned char* getJurisdictionRoot() const { return _jurisdictionRoot; }
|
||||
|
||||
const std::vector<unsigned char*>& 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<unsigned char*> _jurisdictionEndNodes;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelSceneStats__) */
|
||||
|
|
Loading…
Reference in a new issue