From 75fe53263c22e4a28cca57d697a6ea4ccea059b5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 1 Aug 2013 12:40:40 -0700 Subject: [PATCH] first cut at jurisdiction maps, not working yet --- libraries/voxels/src/JurisdictionMap.cpp | 64 ++++++++++++++++++++++++ libraries/voxels/src/JurisdictionMap.h | 40 +++++++++++++++ libraries/voxels/src/VoxelTree.cpp | 25 +++++---- libraries/voxels/src/VoxelTree.h | 18 ++++--- 4 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 libraries/voxels/src/JurisdictionMap.cpp create mode 100644 libraries/voxels/src/JurisdictionMap.h diff --git a/libraries/voxels/src/JurisdictionMap.cpp b/libraries/voxels/src/JurisdictionMap.cpp new file mode 100644 index 0000000000..1a2b57965b --- /dev/null +++ b/libraries/voxels/src/JurisdictionMap.cpp @@ -0,0 +1,64 @@ +// +// JurisdictionMap.cpp +// hifi +// +// Created by Brad Hefta-Gaub on 8/1/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#include + +#include "JurisdictionMap.h" +#include "VoxelNode.h" + +JurisdictionMap::~JurisdictionMap() { + clear(); +} + +void JurisdictionMap::clear() { + delete[] _rootOctalCode; + _rootOctalCode = NULL; + + for (int i = 0; i < _endNodes.size(); i++) { + delete[] _endNodes[i]; + } + _endNodes.clear(); +} + +JurisdictionMap::JurisdictionMap() { + unsigned char* rootCode = new unsigned char[1]; + *rootCode = 0; + + std::vector emptyEndNodes; + init(rootCode, emptyEndNodes); +} + +JurisdictionMap::JurisdictionMap(const char* filename) { + clear(); // clean up our own memory + readFromFile(filename); +} + + +JurisdictionMap::JurisdictionMap(unsigned char* rootOctalCode, const std::vector& endNodes) { + init(rootOctalCode, endNodes); +} + +void JurisdictionMap::init(unsigned char* rootOctalCode, const std::vector& endNodes) { + clear(); // clean up our own memory + _rootOctalCode = rootOctalCode; + _endNodes = endNodes; +} + +bool JurisdictionMap::isMyJurisdiction(VoxelNode* node, int childIndex) const { + return true; +} + + +bool JurisdictionMap::readFromFile(const char* filename) { + QSettings settings(QString(filename), QSettings::IniFormat); + QString rootCode = settings->value("root","").toString(); + qDebug("rootCode=%s\n",rootCode); +} + +bool JurisdictionMap::writeToFile(const char* filename) { +} diff --git a/libraries/voxels/src/JurisdictionMap.h b/libraries/voxels/src/JurisdictionMap.h new file mode 100644 index 0000000000..9c9ed9ec0a --- /dev/null +++ b/libraries/voxels/src/JurisdictionMap.h @@ -0,0 +1,40 @@ +// +// JurisdictionMap.h +// hifi +// +// Created by Brad Hefta-Gaub on 8/1/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__JurisdictionMap__ +#define __hifi__JurisdictionMap__ + +#include + +class VoxelNode; // forward declaration + +class JurisdictionMap { +public: + JurisdictionMap(); + JurisdictionMap(const char* filename); + JurisdictionMap(unsigned char* rootOctalCode, const std::vector& endNodes); + ~JurisdictionMap(); + + + bool isMyJurisdiction(VoxelNode* node, int childIndex) const; + +private: + void clear(); + void init(unsigned char* rootOctalCode, const std::vector& endNodes); + + bool writeToFile(const char* filename); + bool readFromFile(const char* filename); + + + unsigned char* _rootOctalCode; + std::vector _endNodes; +}; + +#endif /* defined(__hifi__JurisdictionMap__) */ + + diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 14244ec1e4..0b8812f850 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -306,13 +306,7 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, childIndex++; } - // Here's where we need to handle the idea of multiple voxel servers. If we have multiple voxel - // servers, then we don't want to "honor" exists bits for portions of the tree that the server in - // question is responsible for. Maybe we can handle this in the server and not "remove" bits for - // portions of the server that the server is not responsible for.... or maybe we need to let the client - // manage this concept. - const bool singleVoxelServer = false; - if (singleVoxelServer && args.includeExistsBits) { + if (args.includeExistsBits) { for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { // now also check the childrenInTreeMask, if the mask is missing the bit, then it means we need to delete this child // subtree/node, because it shouldn't actually exist in the tree. @@ -1203,9 +1197,18 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { VoxelNode* childNode = node->getChildAtIndex(i); - // if the caller wants to include childExistsBits, then include them even if not in view - if (params.includeExistsBits && childNode) { - childrenExistInTreeBits += (1 << (7 - i)); + // if the caller wants to include childExistsBits, then include them even if not in view, if however, + // we're in a portion of the tree that's not our responsibility, then we assume the child nodes exist + // even if they don't in our local tree + bool notMyJurisdictionBro = false; + if (params.jurisdictionMap) { + notMyJurisdictionBro = !params.jurisdictionMap->isMyJurisdiction(node, i); + } + if (params.includeExistsBits) { + // If the child is known to exist, OR, it's not my jurisdiction, then we mark the bit as existing + if (childNode || notMyJurisdictionBro) { + childrenExistInTreeBits += (1 << (7 - i)); + } } if (params.wantOcclusionCulling) { @@ -1886,4 +1889,4 @@ void VoxelTree::computeBlockColor(int id, int data, int& red, int& green, int& b create = 0; break; } -} +} \ No newline at end of file diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 4d3a906874..f27543caa8 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -13,6 +13,7 @@ #include #include "CoverageMap.h" +#include "JurisdictionMap.h" #include "ViewFrustum.h" #include "VoxelNode.h" #include "VoxelNodeBag.h" @@ -36,9 +37,10 @@ const int NO_BOUNDARY_ADJUST = 0; const int LOW_RES_MOVING_ADJUST = 1; const uint64_t IGNORE_LAST_SENT = 0; -#define IGNORE_SCENE_STATS NULL -#define IGNORE_VIEW_FRUSTUM NULL -#define IGNORE_COVERAGE_MAP NULL +#define IGNORE_SCENE_STATS NULL +#define IGNORE_VIEW_FRUSTUM NULL +#define IGNORE_COVERAGE_MAP NULL +#define IGNORE_JURISDICTION_MAP NULL class EncodeBitstreamParams { public: @@ -56,6 +58,7 @@ public: bool forceSendScene; VoxelSceneStats* stats; CoverageMap* map; + JurisdictionMap* jurisdictionMap; EncodeBitstreamParams( int maxEncodeLevel = INT_MAX, @@ -70,7 +73,8 @@ public: int boundaryLevelAdjust = NO_BOUNDARY_ADJUST, uint64_t lastViewFrustumSent = IGNORE_LAST_SENT, bool forceSendScene = true, - VoxelSceneStats* stats = IGNORE_SCENE_STATS) : + VoxelSceneStats* stats = IGNORE_SCENE_STATS, + JurisdictionMap* jurisdictionMap = IGNORE_JURISDICTION_MAP) : maxEncodeLevel (maxEncodeLevel), maxLevelReached (0), viewFrustum (viewFrustum), @@ -84,7 +88,8 @@ public: lastViewFrustumSent (lastViewFrustumSent), forceSendScene (forceSendScene), stats (stats), - map (map) + map (map), + jurisdictionMap (jurisdictionMap) {} }; @@ -186,7 +191,8 @@ public: void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime, RecurseVoxelTreeOperation operation, const glm::vec3& point, void* extraData); - + + private: void deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraData); void readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraData);