Showing the changes to interface/src/VoxelSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -110,6 +110,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 109 unmodified lines | ||
| 110 | 110 | |
| 111 | 111 | _culledOnce = false; |
| 112 | 112 | _inhideOutOfView = false; |
| 113 | + _treeIsBusy = false; | |
| 113 | 114 | } |
| 114 | 115 | |
| 115 | 116 | void VoxelSystem::voxelDeleted(VoxelNode* node) { |
| @@ -595,9 +596,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 479 unmodified lines | ||
| 595 | 596 | "readBitstreamToTree()"); |
| 596 | 597 | // ask the VoxelTree to read the bitstream into the tree |
| 597 | 598 | ReadBitstreamToTreeParams args(WANT_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID()); |
| 598 | − pthread_mutex_lock(&_treeLock); | |
| 599 | + lockTree(); | |
| 599 | 600 | _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args); |
| 600 | − pthread_mutex_unlock(&_treeLock); | |
| 601 | + unlockTree(); | |
| 601 | 602 | } |
| 602 | 603 | break; |
| 603 | 604 | case PACKET_TYPE_VOXEL_DATA_MONOCHROME: { |
| @@ -605,9 +606,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 1 unmodified line | ||
| 605 | 606 | "readBitstreamToTree()"); |
| 606 | 607 | // ask the VoxelTree to read the MONOCHROME bitstream into the tree |
| 607 | 608 | ReadBitstreamToTreeParams args(NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID()); |
| 608 | − pthread_mutex_lock(&_treeLock); | |
| 609 | + lockTree(); | |
| 609 | 610 | _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args); |
| 610 | − pthread_mutex_unlock(&_treeLock); | |
| 611 | + unlockTree(); | |
| 611 | 612 | } |
| 612 | 613 | break; |
| 613 | 614 | case PACKET_TYPE_Z_COMMAND: |
| @@ -1002,7 +1003,9 @@ int VoxelSystem::updateNodeInArrays(VoxelNode* node, bool reuseIndex, bool force · 388 unmodified lines | ||
| 1002 | 1003 | // not render these Voxels. We need to think about ways to keep the entire scene intact but maybe lower quality |
| 1003 | 1004 | // possibly shifting down to lower LOD or something. This debug message is to help identify, if/when/how this |
| 1004 | 1005 | // state actually occurs. |
| 1005 | − qDebug("OHHHH NOOOOOO!!!! updateNodeInArrays() BAILING (_voxelsInWriteArrays >= _maxVoxels)\n"); | |
| 1006 | + if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) { | |
| 1007 | + qDebug("OHHHH NOOOOOO!!!! updateNodeInArrays() BAILING (_voxelsInWriteArrays >= _maxVoxels)\n"); | |
| 1008 | + } | |
| 1006 | 1009 | return 0; |
| 1007 | 1010 | } |
| 1008 | 1011 | |
| @@ -1405,9 +1408,9 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { · 396 unmodified lines | ||
| 1405 | 1408 | int VoxelSystem::_nodeCount = 0; |
| 1406 | 1409 | |
| 1407 | 1410 | void VoxelSystem::killLocalVoxels() { |
| 1408 | − pthread_mutex_lock(&_treeLock); | |
| 1411 | + lockTree(); | |
| 1409 | 1412 | _tree->eraseAllVoxels(); |
| 1410 | − pthread_mutex_unlock(&_treeLock); | |
| 1413 | + unlockTree(); | |
| 1411 | 1414 | clearFreeBufferIndexes(); |
| 1412 | 1415 | _voxelsInReadArrays = 0; // do we need to do this? |
| 1413 | 1416 | setupNewVoxelsForDrawing(); |
| @@ -1426,9 +1429,9 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(VoxelNode* node, void* extra · 12 unmodified lines | ||
| 1426 | 1429 | |
| 1427 | 1430 | void VoxelSystem::clearAllNodesBufferIndex() { |
| 1428 | 1431 | _nodeCount = 0; |
| 1429 | − pthread_mutex_lock(&_treeLock); | |
| 1432 | + lockTree(); | |
| 1430 | 1433 | _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation); |
| 1431 | − pthread_mutex_unlock(&_treeLock); | |
| 1434 | + unlockTree(); | |
| 1432 | 1435 | if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) { |
| 1433 | 1436 | qDebug("clearing buffer index of %d nodes\n", _nodeCount); |
| 1434 | 1437 | } |
| @@ -1916,9 +1919,9 @@ void VoxelSystem::hideOutOfView(bool forceFullFrustum) { · 481 unmodified lines | ||
| 1916 | 1919 | return; |
| 1917 | 1920 | } |
| 1918 | 1921 | |
| 1919 | − pthread_mutex_lock(&_treeLock); | |
| 1922 | + lockTree(); | |
| 1920 | 1923 | _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); |
| 1921 | − pthread_mutex_unlock(&_treeLock); | |
| 1924 | + unlockTree(); | |
| 1922 | 1925 | _lastCulledViewFrustum = args.thisViewFrustum; // save last stable |
| 1923 | 1926 | _culledOnce = true; |
| 1924 | 1927 | |
| @@ -2107,10 +2110,10 @@ bool VoxelSystem::hideOutOfViewOperation(VoxelNode* node, void* extraData) { · 182 unmodified lines | ||
| 2107 | 2110 | |
| 2108 | 2111 | bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, |
| 2109 | 2112 | VoxelDetail& detail, float& distance, BoxFace& face) { |
| 2110 | − pthread_mutex_lock(&_treeLock); | |
| 2113 | + lockTree(); | |
| 2111 | 2114 | VoxelNode* node; |
| 2112 | 2115 | if (!_tree->findRayIntersection(origin, direction, node, distance, face)) { |
| 2113 | − pthread_mutex_unlock(&_treeLock); | |
| 2116 | + unlockTree(); | |
| 2114 | 2117 | return false; |
| 2115 | 2118 | } |
| 2116 | 2119 | detail.x = node->getCorner().x; |
| @@ -2120,21 +2123,21 @@ bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& · 3 unmodified lines | ||
| 2120 | 2123 | detail.red = node->getColor()[0]; |
| 2121 | 2124 | detail.green = node->getColor()[1]; |
| 2122 | 2125 | detail.blue = node->getColor()[2]; |
| 2123 | − pthread_mutex_unlock(&_treeLock); | |
| 2126 | + unlockTree(); | |
| 2124 | 2127 | return true; |
| 2125 | 2128 | } |
| 2126 | 2129 | |
| 2127 | 2130 | bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) { |
| 2128 | − pthread_mutex_lock(&_treeLock); | |
| 2131 | + lockTree(); | |
| 2129 | 2132 | bool result = _tree->findSpherePenetration(center, radius, penetration); |
| 2130 | − pthread_mutex_unlock(&_treeLock); | |
| 2133 | + unlockTree(); | |
| 2131 | 2134 | return result; |
| 2132 | 2135 | } |
| 2133 | 2136 | |
| 2134 | 2137 | bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { |
| 2135 | − pthread_mutex_lock(&_treeLock); | |
| 2138 | + lockTree(); | |
| 2136 | 2139 | bool result = _tree->findCapsulePenetration(start, end, radius, penetration); |
| 2137 | − pthread_mutex_unlock(&_treeLock); | |
| 2140 | + unlockTree(); | |
| 2138 | 2141 | return result; |
| 2139 | 2142 | } |
| 2140 | 2143 | |
| @@ -2308,9 +2311,9 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 167 unmodified lines | ||
| 2308 | 2311 | |
| 2309 | 2312 | |
| 2310 | 2313 | void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) { |
| 2311 | − pthread_mutex_lock(&_treeLock); | |
| 2314 | + lockTree(); | |
| 2312 | 2315 | _tree->deleteVoxelAt(x, y, z, s); |
| 2313 | − pthread_mutex_unlock(&_treeLock); | |
| 2316 | + unlockTree(); | |
| 2314 | 2317 | |
| 2315 | 2318 | // redraw! |
| 2316 | 2319 | setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in? |
| @@ -2325,9 +2328,9 @@ void VoxelSystem::createVoxel(float x, float y, float z, float s, · 8 unmodified lines | ||
| 2325 | 2328 | unsigned char red, unsigned char green, unsigned char blue, bool destructive) { |
| 2326 | 2329 | |
| 2327 | 2330 | //qDebug("VoxelSystem::createVoxel(%f,%f,%f,%f)\n",x,y,z,s); |
| 2328 | − pthread_mutex_lock(&_treeLock); | |
| 2331 | + lockTree(); | |
| 2329 | 2332 | _tree->createVoxel(x, y, z, s, red, green, blue, destructive); |
| 2330 | − pthread_mutex_unlock(&_treeLock); | |
| 2333 | + unlockTree(); | |
| 2331 | 2334 | |
| 2332 | 2335 | setupNewVoxelsForDrawing(); |
| 2333 | 2336 | }; |
| @@ -2650,9 +2653,9 @@ void VoxelSystem::nodeKilled(Node* node) { · 316 unmodified lines | ||
| 2650 | 2653 | if (_voxelServerCount > 0) { |
| 2651 | 2654 | // Kill any voxels from the local tree that match this nodeID |
| 2652 | 2655 | // commenting out for removal of 16 bit node IDs |
| 2653 | − pthread_mutex_lock(&_treeLock); | |
| 2656 | + lockTree(); | |
| 2654 | 2657 | _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeUUID); |
| 2655 | − pthread_mutex_unlock(&_treeLock); | |
| 2658 | + unlockTree(); | |
| 2656 | 2659 | _tree->setDirtyBit(); |
| 2657 | 2660 | setupNewVoxelsForDrawing(); |
| 2658 | 2661 | } else { |
| @@ -2720,5 +2723,15 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 61 unmodified lines | ||
| 2720 | 2723 | return (_initialMemoryUsageGPU - currentFreeMemory); |
| 2721 | 2724 | } |
| 2722 | 2725 | |
| 2726 | +void VoxelSystem::lockTree() { | |
| 2727 | + pthread_mutex_lock(&_treeLock); | |
| 2728 | + _treeIsBusy = true; | |
| 2729 | +} | |
| 2730 | + | |
| 2731 | +void VoxelSystem::unlockTree() { | |
| 2732 | + _treeIsBusy = false; | |
| 2733 | + pthread_mutex_unlock(&_treeLock); | |
| 2734 | +} | |
| 2735 | + | |
| 2723 | 2736 | |
| 2724 | 2737 | |