first cut at jurisdiction maps, not working yet

This commit is contained in:
ZappoMan 2013-08-01 12:40:40 -07:00
parent 93a8e1782d
commit 75fe53263c
4 changed files with 130 additions and 17 deletions

View file

@ -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 <QSettings>
#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<unsigned char*> 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<unsigned char*>& endNodes) {
init(rootOctalCode, endNodes);
}
void JurisdictionMap::init(unsigned char* rootOctalCode, const std::vector<unsigned char*>& 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) {
}

View file

@ -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 <vector>
class VoxelNode; // forward declaration
class JurisdictionMap {
public:
JurisdictionMap();
JurisdictionMap(const char* filename);
JurisdictionMap(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes);
~JurisdictionMap();
bool isMyJurisdiction(VoxelNode* node, int childIndex) const;
private:
void clear();
void init(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes);
bool writeToFile(const char* filename);
bool readFromFile(const char* filename);
unsigned char* _rootOctalCode;
std::vector<unsigned char*> _endNodes;
};
#endif /* defined(__hifi__JurisdictionMap__) */

View file

@ -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;
}
}
}

View file

@ -13,6 +13,7 @@
#include <SimpleMovingAverage.h>
#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);