Showing the changes to interface/src/VoxelSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -99,8 +99,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 98 unmodified lines | ||
| 99 | 99 | |
| 100 | 100 | _culledOnce = false; |
| 101 | 101 | _inhideOutOfView = false; |
| 102 | − _treeIsBusy = false; | |
| 103 | − | |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | 104 | void VoxelSystem::elementDeleted(OctreeElement* element) { |
| @@ -594,9 +592,10 @@ int VoxelSystem::parseData(const QByteArray& packet) { · 487 unmodified lines | ||
| 594 | 592 | } |
| 595 | 593 | |
| 596 | 594 | if (sectionLength) { |
| 595 | + PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData() section"); | |
| 597 | 596 | // ask the VoxelTree to read the bitstream into the tree |
| 598 | 597 | ReadBitstreamToTreeParams args(packetIsColored ? WANT_COLOR : NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID()); |
| 599 | − lockTree(); | |
| 598 | + _tree->lockForWrite(); | |
| 600 | 599 | VoxelPacketData packetData(packetIsCompressed); |
| 601 | 600 | packetData.loadFinalizedContent(dataAt, sectionLength); |
| 602 | 601 | if (Application::getInstance()->getLogger()->extraDebugging()) { |
| @@ -608,7 +607,7 @@ int VoxelSystem::parseData(const QByteArray& packet) { · 5 unmodified lines | ||
| 608 | 607 | packetData.getUncompressedSize()); |
| 609 | 608 | } |
| 610 | 609 | _tree->readBitstreamToTree(packetData.getUncompressedData(), packetData.getUncompressedSize(), args); |
| 611 | − unlockTree(); | |
| 610 | + _tree->unlock(); | |
| 612 | 611 | |
| 613 | 612 | dataBytes -= sectionLength; |
| 614 | 613 | dataAt += sectionLength; |
| @@ -1395,9 +1394,11 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { · 780 unmodified lines | ||
| 1395 | 1394 | int VoxelSystem::_nodeCount = 0; |
| 1396 | 1395 | |
| 1397 | 1396 | void VoxelSystem::killLocalVoxels() { |
| 1398 | − lockTree(); | |
| 1397 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 1398 | + "VoxelSystem::killLocalVoxels()"); | |
| 1399 | + _tree->lockForWrite(); | |
| 1399 | 1400 | _tree->eraseAllOctreeElements(); |
| 1400 | − unlockTree(); | |
| 1401 | + _tree->unlock(); | |
| 1401 | 1402 | clearFreeBufferIndexes(); |
| 1402 | 1403 | _voxelsInReadArrays = 0; // do we need to do this? |
| 1403 | 1404 | setupNewVoxelsForDrawing(); |
| @@ -1416,10 +1417,12 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(OctreeElement* element, void · 12 unmodified lines | ||
| 1416 | 1417 | } |
| 1417 | 1418 | |
| 1418 | 1419 | void VoxelSystem::clearAllNodesBufferIndex() { |
| 1420 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 1421 | + "VoxelSystem::clearAllNodesBufferIndex()"); | |
| 1419 | 1422 | _nodeCount = 0; |
| 1420 | − lockTree(); | |
| 1423 | + _tree->lockForRead(); // we won't change the tree so it's ok to treat this as a read | |
| 1421 | 1424 | _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation); |
| 1422 | − unlockTree(); | |
| 1425 | + _tree->unlock(); | |
| 1423 | 1426 | if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) { |
| 1424 | 1427 | qDebug("clearing buffer index of %d nodes", _nodeCount); |
| 1425 | 1428 | } |
| @@ -1481,7 +1484,8 @@ bool VoxelSystem::trueColorizeOperation(OctreeElement* element, void* extraData) · 55 unmodified lines | ||
| 1481 | 1484 | } |
| 1482 | 1485 | |
| 1483 | 1486 | void VoxelSystem::trueColorize() { |
| 1484 | − PerformanceWarning warn(true, "trueColorize()",true); | |
| 1487 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 1488 | + "trueColorize()",true); | |
| 1485 | 1489 | _nodeCount = 0; |
| 1486 | 1490 | _tree->recurseTreeWithOperation(trueColorizeOperation); |
| 1487 | 1491 | qDebug("setting true color for %d nodes", _nodeCount); |
| @@ -1951,9 +1955,13 @@ void VoxelSystem::hideOutOfView(bool forceFullFrustum) { · 463 unmodified lines | ||
| 1951 | 1955 | return; |
| 1952 | 1956 | } |
| 1953 | 1957 | |
| 1954 | − lockTree(); | |
| 1955 | − _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); | |
| 1956 | − unlockTree(); | |
| 1958 | + { | |
| 1959 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 1960 | + "VoxelSystem::... recurseTreeWithOperation(hideOutOfViewOperation)"); | |
| 1961 | + _tree->lockForRead(); | |
| 1962 | + _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); | |
| 1963 | + _tree->unlock(); | |
| 1964 | + } | |
| 1957 | 1965 | _lastCulledViewFrustum = args.thisViewFrustum; // save last stable |
| 1958 | 1966 | _culledOnce = true; |
| 1959 | 1967 | |
| @@ -2150,35 +2158,47 @@ bool VoxelSystem::hideOutOfViewOperation(OctreeElement* element, void* extraData · 190 unmodified lines | ||
| 2150 | 2158 | |
| 2151 | 2159 | bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, |
| 2152 | 2160 | VoxelDetail& detail, float& distance, BoxFace& face) { |
| 2153 | − lockTree(); | |
| 2154 | − OctreeElement* element; | |
| 2155 | − if (!_tree->findRayIntersection(origin, direction, element, distance, face)) { | |
| 2156 | − unlockTree(); | |
| 2157 | − return false; | |
| 2161 | + | |
| 2162 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 2163 | + "VoxelSystem::findRayIntersection()"); | |
| 2164 | + bool result = false; // assume no intersection | |
| 2165 | + if (_tree->tryLockForRead()) { | |
| 2166 | + OctreeElement* element; | |
| 2167 | + result = _tree->findRayIntersection(origin, direction, element, distance, face); | |
| 2168 | + if (result) { | |
| 2169 | + VoxelTreeElement* voxel = (VoxelTreeElement*)element; | |
| 2170 | + detail.x = voxel->getCorner().x; | |
| 2171 | + detail.y = voxel->getCorner().y; | |
| 2172 | + detail.z = voxel->getCorner().z; | |
| 2173 | + detail.s = voxel->getScale(); | |
| 2174 | + detail.red = voxel->getColor()[0]; | |
| 2175 | + detail.green = voxel->getColor()[1]; | |
| 2176 | + detail.blue = voxel->getColor()[2]; | |
| 2177 | + } | |
| 2178 | + _tree->unlock(); | |
| 2158 | 2179 | } |
| 2159 | − VoxelTreeElement* voxel = (VoxelTreeElement*)element; | |
| 2160 | − detail.x = voxel->getCorner().x; | |
| 2161 | − detail.y = voxel->getCorner().y; | |
| 2162 | − detail.z = voxel->getCorner().z; | |
| 2163 | − detail.s = voxel->getScale(); | |
| 2164 | − detail.red = voxel->getColor()[0]; | |
| 2165 | − detail.green = voxel->getColor()[1]; | |
| 2166 | − detail.blue = voxel->getColor()[2]; | |
| 2167 | − unlockTree(); | |
| 2168 | − return true; | |
| 2180 | + return result; | |
| 2169 | 2181 | } |
| 2170 | 2182 | |
| 2171 | 2183 | bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) { |
| 2172 | − lockTree(); | |
| 2173 | − bool result = _tree->findSpherePenetration(center, radius, penetration); | |
| 2174 | − unlockTree(); | |
| 2184 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 2185 | + "VoxelSystem::findSpherePenetration()"); | |
| 2186 | + bool result = false; // assume no penetration | |
| 2187 | + if (_tree->tryLockForRead()) { | |
| 2188 | + result = _tree->findSpherePenetration(center, radius, penetration); | |
| 2189 | + _tree->unlock(); | |
| 2190 | + } | |
| 2175 | 2191 | return result; |
| 2176 | 2192 | } |
| 2177 | 2193 | |
| 2178 | 2194 | bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { |
| 2179 | − lockTree(); | |
| 2180 | − bool result = _tree->findCapsulePenetration(start, end, radius, penetration); | |
| 2181 | − unlockTree(); | |
| 2195 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 2196 | + "VoxelSystem::findCapsulePenetration()"); | |
| 2197 | + bool result = false; // assume no penetration | |
| 2198 | + if (_tree->tryLockForRead()) { | |
| 2199 | + result = _tree->findCapsulePenetration(start, end, radius, penetration); | |
| 2200 | + _tree->unlock(); | |
| 2201 | + } | |
| 2182 | 2202 | return result; |
| 2183 | 2203 | } |
| 2184 | 2204 | |
| @@ -2354,13 +2374,14 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 169 unmodified lines | ||
| 2354 | 2374 | |
| 2355 | 2375 | |
| 2356 | 2376 | void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) { |
| 2357 | − lockTree(); | |
| 2377 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 2378 | + "VoxelSystem::deleteVoxelAt()"); | |
| 2379 | + _tree->lockForWrite(); | |
| 2358 | 2380 | _tree->deleteVoxelAt(x, y, z, s); |
| 2359 | − unlockTree(); | |
| 2381 | + _tree->unlock(); | |
| 2360 | 2382 | |
| 2361 | 2383 | // redraw! |
| 2362 | 2384 | setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in? |
| 2363 | − | |
| 2364 | 2385 | }; |
| 2365 | 2386 | |
| 2366 | 2387 | VoxelTreeElement* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const { |
| @@ -2370,10 +2391,12 @@ VoxelTreeElement* VoxelSystem::getVoxelAt(float x, float y, float z, float s) co · 3 unmodified lines | ||
| 2370 | 2391 | void VoxelSystem::createVoxel(float x, float y, float z, float s, |
| 2371 | 2392 | unsigned char red, unsigned char green, unsigned char blue, bool destructive) { |
| 2372 | 2393 | |
| 2373 | − //qDebug("VoxelSystem::createVoxel(%f,%f,%f,%f)\n",x,y,z,s); | |
| 2374 | − lockTree(); | |
| 2394 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 2395 | + "VoxelSystem::createVoxel()"); | |
| 2396 | + | |
| 2397 | + _tree->lockForWrite(); | |
| 2375 | 2398 | _tree->createVoxel(x, y, z, s, red, green, blue, destructive); |
| 2376 | − unlockTree(); | |
| 2399 | + _tree->unlock(); | |
| 2377 | 2400 | |
| 2378 | 2401 | setupNewVoxelsForDrawing(); |
| 2379 | 2402 | }; |
| @@ -2744,37 +2767,3 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 364 unmodified lines | ||
| 2744 | 2767 | return (_initialMemoryUsageGPU - currentFreeMemory); |
| 2745 | 2768 | } |
| 2746 | 2769 | |
| 2747 | −void VoxelSystem::lockTree() { | |
| 2748 | − _treeLock.lock(); | |
| 2749 | − _treeIsBusy = true; | |
| 2750 | −} | |
| 2751 | − | |
| 2752 | −void VoxelSystem::unlockTree() { | |
| 2753 | − _treeIsBusy = false; | |
| 2754 | − _treeLock.unlock(); | |
| 2755 | −} | |
| 2756 | − | |
| 2757 | − | |
| 2758 | −void VoxelSystem::localVoxelCacheLoaded() { | |
| 2759 | − qDebug() << "localVoxelCacheLoaded()"; | |
| 2760 | − | |
| 2761 | − // Make sure that the application has properly set up the view frustum for our loaded state | |
| 2762 | − Application::getInstance()->initAvatarAndViewFrustum(); | |
| 2763 | − | |
| 2764 | − _tree->setDirtyBit(); // make sure the tree thinks it's dirty | |
| 2765 | − _setupNewVoxelsForDrawingLastFinished = 0; // don't allow the setupNewVoxelsForDrawing() shortcuts | |
| 2766 | − _writeRenderFullVBO = true; // this will disable individual node updates, was reset by killLocalVoxels() | |
| 2767 | − setupNewVoxelsForDrawing(); | |
| 2768 | − _inhideOutOfView = false; // reenable hideOutOfView behavior | |
| 2769 | −} | |
| 2770 | − | |
| 2771 | −void VoxelSystem::beginLoadingLocalVoxelCache() { | |
| 2772 | − qDebug() << "beginLoadingLocalVoxelCache()"; | |
| 2773 | − _writeRenderFullVBO = true; // this will disable individual node updates | |
| 2774 | − _inhideOutOfView = true; // this will disable hidOutOfView which we want to do until local cache is loaded | |
| 2775 | − killLocalVoxels(); | |
| 2776 | − qDebug() << "DONE beginLoadingLocalVoxelCache()"; | |
| 2777 | −} | |
| 2778 | − | |
| 2779 | − | |
| 2780 | − | |