Merge pull request #836 from ZappoMan/master

Fixed voxel server "down" case for last voxel server
This commit is contained in:
Stephen Birarda 2013-08-08 14:33:33 -07:00
commit 80cf39e437
2 changed files with 19 additions and 5 deletions

View file

@ -63,6 +63,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) :
_abandonedVBOSlots = 0;
_falseColorizeBySource = false;
_dataSourceID = UNKNOWN_NODE_ID;
_voxelServerCount = 0;
}
void VoxelSystem::nodeDeleted(VoxelNode* node) {
@ -1538,6 +1539,7 @@ void VoxelSystem::nodeAdded(Node* node) {
if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
uint16_t nodeID = node->getNodeID();
printf("VoxelSystem... voxel server %u added...\n", nodeID);
_voxelServerCount++;
}
}
@ -1545,8 +1547,11 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) {
uint16_t killedNodeID = *(uint16_t*)extraData;
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
VoxelNode* childNode = node->getChildAtIndex(i);
if (childNode && childNode->getSourceID()== killedNodeID) {
node->safeDeepDeleteChildAtIndex(i);
if (childNode) {
uint16_t childNodeID = childNode->getSourceID();
if (childNodeID == killedNodeID) {
node->safeDeepDeleteChildAtIndex(i);
}
}
}
return true;
@ -1554,12 +1559,19 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) {
void VoxelSystem::nodeKilled(Node* node) {
if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
_voxelServerCount--;
uint16_t nodeID = node->getNodeID();
printf("VoxelSystem... voxel server %u removed...\n", nodeID);
// Kill any voxels from the local tree
_tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID);
_tree->setDirtyBit();
if (_voxelServerCount > 0) {
// Kill any voxels from the local tree that match this nodeID
_tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID);
_tree->setDirtyBit();
} else {
// Last server, take the easy way and kill all the local voxels!
_tree->eraseAllVoxels();
_voxelsInWriteArrays = _voxelsInReadArrays = 0; // better way to do this??
}
setupNewVoxelsForDrawing();
}
}

View file

@ -206,6 +206,8 @@ private:
bool _falseColorizeBySource;
int _dataSourceID;
int _voxelServerCount;
};
#endif