History

fix delete local voxels in case of last voxel server going away

ZappoMan committed 13 years ago

Commit 48e35ec1 parent 8addfdc2 files · +19 −5Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+17−5
@@ -63,6 +63,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 62 unmodified lines
63 _abandonedVBOSlots = 0;63 _abandonedVBOSlots = 0;
64 _falseColorizeBySource = false;64 _falseColorizeBySource = false;
65 _dataSourceID = UNKNOWN_NODE_ID;65 _dataSourceID = UNKNOWN_NODE_ID;
66 _voxelServerCount = 0;
66}67}
67 68
68void VoxelSystem::nodeDeleted(VoxelNode* node) {69void VoxelSystem::nodeDeleted(VoxelNode* node) {
@@ -1538,6 +1539,7 @@ void VoxelSystem::nodeAdded(Node* node) { · 1469 unmodified lines
1538 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {1539 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
1539 uint16_t nodeID = node->getNodeID();1540 uint16_t nodeID = node->getNodeID();
1540 printf("VoxelSystem... voxel server %u added...\n", nodeID);1541 printf("VoxelSystem... voxel server %u added...\n", nodeID);
1542 _voxelServerCount++;
1541 }1543 }
1542}1544}
1543 1545
@@ -1545,8 +1547,11 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { · 1 unmodified line
1545 uint16_t killedNodeID = *(uint16_t*)extraData;1547 uint16_t killedNodeID = *(uint16_t*)extraData;
1546 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {1548 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
1547 VoxelNode* childNode = node->getChildAtIndex(i);1549 VoxelNode* childNode = node->getChildAtIndex(i);
1548 if (childNode && childNode->getSourceID()== killedNodeID) {1550 if (childNode) {
1549 node->safeDeepDeleteChildAtIndex(i);1551 uint16_t childNodeID = childNodeID = childNode->getSourceID();
1552 if (childNodeID == killedNodeID) {
1553 node->safeDeepDeleteChildAtIndex(i);
1554 }
1550 }1555 }
1551 }1556 }
1552 return true;1557 return true;
@@ -1554,12 +1559,19 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { · 1 unmodified line
1554 1559
1555void VoxelSystem::nodeKilled(Node* node) {1560void VoxelSystem::nodeKilled(Node* node) {
1556 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {1561 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
1562 _voxelServerCount--;
1557 uint16_t nodeID = node->getNodeID();1563 uint16_t nodeID = node->getNodeID();
1558 printf("VoxelSystem... voxel server %u removed...\n", nodeID);1564 printf("VoxelSystem... voxel server %u removed...\n", nodeID);
1559 1565
1560 // Kill any voxels from the local tree1566 if (_voxelServerCount > 0) {
1561 _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID);1567 // Kill any voxels from the local tree that match this nodeID
1562 _tree->setDirtyBit();1568 _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID);
1569 _tree->setDirtyBit();
1570 } else {
1571 // Last server, take the easy way and kill all the local voxels!
1572 _tree->eraseAllVoxels();
1573 _voxelsInWriteArrays = _voxelsInReadArrays = 0; // better way to do this??
1574 }
1563 setupNewVoxelsForDrawing();1575 setupNewVoxelsForDrawing();
1564 }1576 }
1565}1577}