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 | _culledOnce = false; | 100 | _culledOnce = false; |
| 101 | _inhideOutOfView = false; | 101 | _inhideOutOfView = false; |
| 102 | _treeIsBusy = false; | ||
| 103 | |||
| 104 | } | 102 | } |
| 105 | 103 | ||
| 106 | void VoxelSystem::elementDeleted(OctreeElement* element) { | 104 | void VoxelSystem::elementDeleted(OctreeElement* element) { |
| @@ -594,9 +592,10 @@ int VoxelSystem::parseData(const QByteArray& packet) { · 487 unmodified lines | |||
| 594 | } | 592 | } |
| 595 | 593 | ||
| 596 | if (sectionLength) { | 594 | if (sectionLength) { |
| 595 | PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData() section"); | ||
| 597 | // ask the VoxelTree to read the bitstream into the tree | 596 | // ask the VoxelTree to read the bitstream into the tree |
| 598 | ReadBitstreamToTreeParams args(packetIsColored ? WANT_COLOR : NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID()); | 597 | ReadBitstreamToTreeParams args(packetIsColored ? WANT_COLOR : NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID()); |
| 599 | lockTree(); | 598 | _tree->lockForWrite(); |
| 600 | VoxelPacketData packetData(packetIsCompressed); | 599 | VoxelPacketData packetData(packetIsCompressed); |
| 601 | packetData.loadFinalizedContent(dataAt, sectionLength); | 600 | packetData.loadFinalizedContent(dataAt, sectionLength); |
| 602 | if (Application::getInstance()->getLogger()->extraDebugging()) { | 601 | if (Application::getInstance()->getLogger()->extraDebugging()) { |
| @@ -608,7 +607,7 @@ int VoxelSystem::parseData(const QByteArray& packet) { · 5 unmodified lines | |||
| 608 | packetData.getUncompressedSize()); | 607 | packetData.getUncompressedSize()); |
| 609 | } | 608 | } |
| 610 | _tree->readBitstreamToTree(packetData.getUncompressedData(), packetData.getUncompressedSize(), args); | 609 | _tree->readBitstreamToTree(packetData.getUncompressedData(), packetData.getUncompressedSize(), args); |
| 611 | unlockTree(); | 610 | _tree->unlock(); |
| 612 | 611 | ||
| 613 | dataBytes -= sectionLength; | 612 | dataBytes -= sectionLength; |
| 614 | dataAt += sectionLength; | 613 | dataAt += sectionLength; |
| @@ -1395,9 +1394,11 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { · 780 unmodified lines | |||
| 1395 | int VoxelSystem::_nodeCount = 0; | 1394 | int VoxelSystem::_nodeCount = 0; |
| 1396 | 1395 | ||
| 1397 | void VoxelSystem::killLocalVoxels() { | 1396 | void VoxelSystem::killLocalVoxels() { |
| 1398 | lockTree(); | 1397 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 1398 | "VoxelSystem::killLocalVoxels()"); | ||
| 1399 | _tree->lockForWrite(); | ||
| 1399 | _tree->eraseAllOctreeElements(); | 1400 | _tree->eraseAllOctreeElements(); |
| 1400 | unlockTree(); | 1401 | _tree->unlock(); |
| 1401 | clearFreeBufferIndexes(); | 1402 | clearFreeBufferIndexes(); |
| 1402 | _voxelsInReadArrays = 0; // do we need to do this? | 1403 | _voxelsInReadArrays = 0; // do we need to do this? |
| 1403 | setupNewVoxelsForDrawing(); | 1404 | setupNewVoxelsForDrawing(); |
| @@ -1416,10 +1417,12 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(OctreeElement* element, void · 12 unmodified lines | |||
| 1416 | } | 1417 | } |
| 1417 | 1418 | ||
| 1418 | void VoxelSystem::clearAllNodesBufferIndex() { | 1419 | void VoxelSystem::clearAllNodesBufferIndex() { |
| 1420 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | ||
| 1421 | "VoxelSystem::clearAllNodesBufferIndex()"); | ||
| 1419 | _nodeCount = 0; | 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 | _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation); | 1424 | _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation); |
| 1422 | unlockTree(); | 1425 | _tree->unlock(); |
| 1423 | if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) { | 1426 | if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) { |
| 1424 | qDebug("clearing buffer index of %d nodes", _nodeCount); | 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 | void VoxelSystem::trueColorize() { | 1486 | void VoxelSystem::trueColorize() { |
| 1484 | PerformanceWarning warn(true, "trueColorize()",true); | 1487 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 1488 | "trueColorize()",true); | ||
| 1485 | _nodeCount = 0; | 1489 | _nodeCount = 0; |
| 1486 | _tree->recurseTreeWithOperation(trueColorizeOperation); | 1490 | _tree->recurseTreeWithOperation(trueColorizeOperation); |
| 1487 | qDebug("setting true color for %d nodes", _nodeCount); | 1491 | qDebug("setting true color for %d nodes", _nodeCount); |
| @@ -1951,9 +1955,13 @@ void VoxelSystem::hideOutOfView(bool forceFullFrustum) { · 463 unmodified lines | |||
| 1951 | return; | 1955 | return; |
| 1952 | } | 1956 | } |
| 1953 | 1957 | ||
| 1954 | lockTree(); | 1958 | { |
| 1955 | _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); | 1959 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 1956 | unlockTree(); | 1960 | "VoxelSystem::... recurseTreeWithOperation(hideOutOfViewOperation)"); |
| 1961 | _tree->lockForRead(); | ||
| 1962 | _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args); | ||
| 1963 | _tree->unlock(); | ||
| 1964 | } | ||
| 1957 | _lastCulledViewFrustum = args.thisViewFrustum; // save last stable | 1965 | _lastCulledViewFrustum = args.thisViewFrustum; // save last stable |
| 1958 | _culledOnce = true; | 1966 | _culledOnce = true; |
| 1959 | 1967 | ||
| @@ -2150,35 +2158,47 @@ bool VoxelSystem::hideOutOfViewOperation(OctreeElement* element, void* extraData · 190 unmodified lines | |||
| 2150 | 2158 | ||
| 2151 | bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, | 2159 | bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, |
| 2152 | VoxelDetail& detail, float& distance, BoxFace& face) { | 2160 | VoxelDetail& detail, float& distance, BoxFace& face) { |
| 2153 | lockTree(); | 2161 | |
| 2154 | OctreeElement* element; | 2162 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 2155 | if (!_tree->findRayIntersection(origin, direction, element, distance, face)) { | 2163 | "VoxelSystem::findRayIntersection()"); |
| 2156 | unlockTree(); | 2164 | bool result = false; // assume no intersection |
| 2157 | return false; | 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; | 2180 | return result; |
| 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; | ||
| 2169 | } | 2181 | } |
| 2170 | 2182 | ||
| 2171 | bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) { | 2183 | bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) { |
| 2172 | lockTree(); | 2184 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 2173 | bool result = _tree->findSpherePenetration(center, radius, penetration); | 2185 | "VoxelSystem::findSpherePenetration()"); |
| 2174 | unlockTree(); | 2186 | bool result = false; // assume no penetration |
| 2187 | if (_tree->tryLockForRead()) { | ||
| 2188 | result = _tree->findSpherePenetration(center, radius, penetration); | ||
| 2189 | _tree->unlock(); | ||
| 2190 | } | ||
| 2175 | return result; | 2191 | return result; |
| 2176 | } | 2192 | } |
| 2177 | 2193 | ||
| 2178 | bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { | 2194 | bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { |
| 2179 | lockTree(); | 2195 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 2180 | bool result = _tree->findCapsulePenetration(start, end, radius, penetration); | 2196 | "VoxelSystem::findCapsulePenetration()"); |
| 2181 | unlockTree(); | 2197 | bool result = false; // assume no penetration |
| 2198 | if (_tree->tryLockForRead()) { | ||
| 2199 | result = _tree->findCapsulePenetration(start, end, radius, penetration); | ||
| 2200 | _tree->unlock(); | ||
| 2201 | } | ||
| 2182 | return result; | 2202 | return result; |
| 2183 | } | 2203 | } |
| 2184 | 2204 | ||
| @@ -2354,13 +2374,14 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 169 unmodified lines | |||
| 2354 | 2374 | ||
| 2355 | 2375 | ||
| 2356 | void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) { | 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 | _tree->deleteVoxelAt(x, y, z, s); | 2380 | _tree->deleteVoxelAt(x, y, z, s); |
| 2359 | unlockTree(); | 2381 | _tree->unlock(); |
| 2360 | 2382 | ||
| 2361 | // redraw! | 2383 | // redraw! |
| 2362 | setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in? | 2384 | setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in? |
| 2363 | |||
| 2364 | }; | 2385 | }; |
| 2365 | 2386 | ||
| 2366 | VoxelTreeElement* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const { | 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 | void VoxelSystem::createVoxel(float x, float y, float z, float s, | 2391 | void VoxelSystem::createVoxel(float x, float y, float z, float s, |
| 2371 | unsigned char red, unsigned char green, unsigned char blue, bool destructive) { | 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); | 2394 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| 2374 | lockTree(); | 2395 | "VoxelSystem::createVoxel()"); |
| 2396 | |||
| 2397 | _tree->lockForWrite(); | ||
| 2375 | _tree->createVoxel(x, y, z, s, red, green, blue, destructive); | 2398 | _tree->createVoxel(x, y, z, s, red, green, blue, destructive); |
| 2376 | unlockTree(); | 2399 | _tree->unlock(); |
| 2377 | 2400 | ||
| 2378 | setupNewVoxelsForDrawing(); | 2401 | setupNewVoxelsForDrawing(); |
| 2379 | }; | 2402 | }; |
| @@ -2744,37 +2767,3 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 364 unmodified lines | |||
| 2744 | return (_initialMemoryUsageGPU - currentFreeMemory); | 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 | |||