Showing the changes to interface/src/VoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -63,6 +63,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 62 unmodified lines | ||
| 63 | 63 | _abandonedVBOSlots = 0; |
| 64 | 64 | _falseColorizeBySource = false; |
| 65 | 65 | _dataSourceID = UNKNOWN_NODE_ID; |
| 66 | + _voxelServerCount = 0; | |
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | void VoxelSystem::nodeDeleted(VoxelNode* node) { |
| @@ -1538,6 +1539,7 @@ void VoxelSystem::nodeAdded(Node* node) { · 1469 unmodified lines | ||
| 1538 | 1539 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { |
| 1539 | 1540 | uint16_t nodeID = node->getNodeID(); |
| 1540 | 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 | 1547 | uint16_t killedNodeID = *(uint16_t*)extraData; |
| 1546 | 1548 | for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { |
| 1547 | 1549 | VoxelNode* childNode = node->getChildAtIndex(i); |
| 1548 | − if (childNode && childNode->getSourceID()== killedNodeID) { | |
| 1549 | − node->safeDeepDeleteChildAtIndex(i); | |
| 1550 | + if (childNode) { | |
| 1551 | + uint16_t childNodeID = childNodeID = childNode->getSourceID(); | |
| 1552 | + if (childNodeID == killedNodeID) { | |
| 1553 | + node->safeDeepDeleteChildAtIndex(i); | |
| 1554 | + } | |
| 1550 | 1555 | } |
| 1551 | 1556 | } |
| 1552 | 1557 | return true; |
| @@ -1554,12 +1559,19 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { · 1 unmodified line | ||
| 1554 | 1559 | |
| 1555 | 1560 | void VoxelSystem::nodeKilled(Node* node) { |
| 1556 | 1561 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { |
| 1562 | + _voxelServerCount--; | |
| 1557 | 1563 | uint16_t nodeID = node->getNodeID(); |
| 1558 | 1564 | printf("VoxelSystem... voxel server %u removed...\n", nodeID); |
| 1559 | 1565 | |
| 1560 | − // Kill any voxels from the local tree | |
| 1561 | − _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeID); | |
| 1562 | − _tree->setDirtyBit(); | |
| 1566 | + if (_voxelServerCount > 0) { | |
| 1567 | + // Kill any voxels from the local tree that match this nodeID | |
| 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 | 1575 | setupNewVoxelsForDrawing(); |
| 1564 | 1576 | } |
| 1565 | 1577 | } |