overte/libraries/octree/src/JurisdictionMap.h
matsukaze 46d45a2d43 Job #19700 BUG: Crash in NodeBounds::draw() fixed.
QMap and QReadWriteLock are orthogonal. Combined them into a wrapper
class called NodeToJurisdictionMap, replacing typedef. This allows us to
avoid changing method signatures wherever NodeToJurisdictionMap is used.
The lock is bound with the map and is available to all clients of the
NodeToJurisdictionMap. The lock allows multi-threaded access to the map.

Fixed compiler warning in NodeBounds.cpp regarding loss of precision
during conversion of double to GLfloat.
2014-06-02 05:55:58 -04:00

90 lines
3.1 KiB
C++

//
// JurisdictionMap.h
// libraries/octree/src
//
// Created by Brad Hefta-Gaub on 8/1/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_JurisdictionMap_h
#define hifi_JurisdictionMap_h
#include <map>
#include <stdint.h>
#include <vector>
#include <QtCore/QString>
#include <QtCore/QUuid>
#include <QReadWriteLock>
#include <Node.h>
class JurisdictionMap {
public:
enum Area {
ABOVE,
WITHIN,
BELOW
};
// standard constructors
JurisdictionMap(NodeType_t type = NodeType::VoxelServer); // default constructor
JurisdictionMap(const JurisdictionMap& other); // copy constructor
// standard assignment
JurisdictionMap& operator=(const JurisdictionMap& other); // copy assignment
#ifdef HAS_MOVE_SEMANTICS
// move constructor and assignment
JurisdictionMap(JurisdictionMap&& other); // move constructor
JurisdictionMap& operator= (JurisdictionMap&& other); // move assignment
#endif
// application constructors
JurisdictionMap(const char* filename);
JurisdictionMap(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes);
JurisdictionMap(const char* rootHextString, const char* endNodesHextString);
~JurisdictionMap();
Area isMyJurisdiction(const unsigned char* nodeOctalCode, int childIndex) const;
bool writeToFile(const char* filename);
bool readFromFile(const char* filename);
unsigned char* getRootOctalCode() const { return _rootOctalCode; }
unsigned char* getEndNodeOctalCode(int index) const { return _endNodes[index]; }
int getEndNodeCount() const { return _endNodes.size(); }
void copyContents(unsigned char* rootCodeIn, const std::vector<unsigned char*>& endNodesIn);
int unpackFromMessage(const unsigned char* sourceBuffer, int availableBytes);
int packIntoMessage(unsigned char* destinationBuffer, int availableBytes);
/// Available to pack an empty or unknown jurisdiction into a network packet, used when no JurisdictionMap is available
static int packEmptyJurisdictionIntoMessage(NodeType_t type, unsigned char* destinationBuffer, int availableBytes);
void displayDebugDetails() const;
NodeType_t getNodeType() const { return _nodeType; }
void setNodeType(NodeType_t type) { _nodeType = type; }
private:
void copyContents(const JurisdictionMap& other); // use assignment instead
void clear();
void init(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes);
unsigned char* _rootOctalCode;
std::vector<unsigned char*> _endNodes;
NodeType_t _nodeType;
};
/// Map between node IDs and their reported JurisdictionMap. Typically used by classes that need to know which nodes are
/// managing which jurisdictions.
class NodeToJurisdictionMap : public QMap<QUuid, JurisdictionMap>, public QReadWriteLock {};
typedef QMap<QUuid, JurisdictionMap>::iterator NodeToJurisdictionMapIterator;
#endif // hifi_JurisdictionMap_h