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
6363 _abandonedVBOSlots = 0;
6464 _falseColorizeBySource = false;
6565 _dataSourceID = UNKNOWN_NODE_ID;
66+ _voxelServerCount = 0;
6667 }
6768
6869 void VoxelSystem::nodeDeleted(VoxelNode* node) {
@@ -1538,6 +1539,7 @@ void VoxelSystem::nodeAdded(Node* node) { · 1469 unmodified lines
15381539 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
15391540 uint16_t nodeID = node->getNodeID();
15401541 printf("VoxelSystem... voxel server %u added...\n", nodeID);
1542+ _voxelServerCount++;
15411543 }
15421544 }
15431545
@@ -1545,8 +1547,11 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { · 1 unmodified line
15451547 uint16_t killedNodeID = *(uint16_t*)extraData;
15461548 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
15471549 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+ }
15501555 }
15511556 }
15521557 return true;
@@ -1554,12 +1559,19 @@ bool VoxelSystem::killSourceVoxelsOperation(VoxelNode* node, void* extraData) { · 1 unmodified line
15541559
15551560 void VoxelSystem::nodeKilled(Node* node) {
15561561 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
1562+ _voxelServerCount--;
15571563 uint16_t nodeID = node->getNodeID();
15581564 printf("VoxelSystem... voxel server %u removed...\n", nodeID);
15591565
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+ }
15631575 setupNewVoxelsForDrawing();
15641576 }
15651577 }