History

fix stutter while spinning

Brad Hefta-Gaub committed 12 years ago

Commit a16b3a31 parent 01487423 files · +63 −83Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 3 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+62−73
@@ -99,8 +99,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 98 unmodified lines
9999
100100 _culledOnce = false;
101101 _inhideOutOfView = false;
102− _treeIsBusy = false;
103−
104102 }
105103
106104 void VoxelSystem::elementDeleted(OctreeElement* element) {
@@ -594,9 +592,10 @@ int VoxelSystem::parseData(const QByteArray& packet) { · 487 unmodified lines
594592 }
595593
596594 if (sectionLength) {
595+ PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData() section");
597596 // ask the VoxelTree to read the bitstream into the tree
598597 ReadBitstreamToTreeParams args(packetIsColored ? WANT_COLOR : NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID());
599− lockTree();
598+ _tree->lockForWrite();
600599 VoxelPacketData packetData(packetIsCompressed);
601600 packetData.loadFinalizedContent(dataAt, sectionLength);
602601 if (Application::getInstance()->getLogger()->extraDebugging()) {
@@ -608,7 +607,7 @@ int VoxelSystem::parseData(const QByteArray& packet) { · 5 unmodified lines
608607 packetData.getUncompressedSize());
609608 }
610609 _tree->readBitstreamToTree(packetData.getUncompressedData(), packetData.getUncompressedSize(), args);
611− unlockTree();
610+ _tree->unlock();
612611
613612 dataBytes -= sectionLength;
614613 dataAt += sectionLength;
@@ -1395,9 +1394,11 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { · 780 unmodified lines
13951394 int VoxelSystem::_nodeCount = 0;
13961395
13971396 void VoxelSystem::killLocalVoxels() {
1398− lockTree();
1397+ PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
1398+ "VoxelSystem::killLocalVoxels()");
1399+ _tree->lockForWrite();
13991400 _tree->eraseAllOctreeElements();
1400− unlockTree();
1401+ _tree->unlock();
14011402 clearFreeBufferIndexes();
14021403 _voxelsInReadArrays = 0; // do we need to do this?
14031404 setupNewVoxelsForDrawing();
@@ -1416,10 +1417,12 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(OctreeElement* element, void · 12 unmodified lines
14161417 }
14171418
14181419 void VoxelSystem::clearAllNodesBufferIndex() {
1420+ PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
1421+ "VoxelSystem::clearAllNodesBufferIndex()");
14191422 _nodeCount = 0;
1420− lockTree();
1423+ _tree->lockForRead(); // we won't change the tree so it's ok to treat this as a read
14211424 _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation);
1422− unlockTree();
1425+ _tree->unlock();
14231426 if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) {
14241427 qDebug("clearing buffer index of %d nodes", _nodeCount);
14251428 }
@@ -1481,7 +1484,8 @@ bool VoxelSystem::trueColorizeOperation(OctreeElement* element, void* extraData) · 55 unmodified lines
14811484 }
14821485
14831486 void VoxelSystem::trueColorize() {
1484− PerformanceWarning warn(true, "trueColorize()",true);
1487+ PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
1488+ "trueColorize()",true);
14851489 _nodeCount = 0;
14861490 _tree->recurseTreeWithOperation(trueColorizeOperation);
14871491 qDebug("setting true color for %d nodes", _nodeCount);
@@ -1951,9 +1955,13 @@ void VoxelSystem::hideOutOfView(bool forceFullFrustum) { · 463 unmodified lines
19511955 return;
19521956 }
19531957
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+ }
19571965 _lastCulledViewFrustum = args.thisViewFrustum; // save last stable
19581966 _culledOnce = true;
19591967
@@ -2150,35 +2158,47 @@ bool VoxelSystem::hideOutOfViewOperation(OctreeElement* element, void* extraData · 190 unmodified lines
21502158
21512159 bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
21522160 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();
21582179 }
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;
21692181 }
21702182
21712183 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+ }
21752191 return result;
21762192 }
21772193
21782194 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+ }
21822202 return result;
21832203 }
21842204
@@ -2354,13 +2374,14 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 169 unmodified lines
23542374
23552375
23562376 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();
23582380 _tree->deleteVoxelAt(x, y, z, s);
2359− unlockTree();
2381+ _tree->unlock();
23602382
23612383 // redraw!
23622384 setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in?
2363−
23642385 };
23652386
23662387 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
23702391 void VoxelSystem::createVoxel(float x, float y, float z, float s,
23712392 unsigned char red, unsigned char green, unsigned char blue, bool destructive) {
23722393
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();
23752398 _tree->createVoxel(x, y, z, s, red, green, blue, destructive);
2376− unlockTree();
2399+ _tree->unlock();
23772400
23782401 setupNewVoxelsForDrawing();
23792402 };
@@ -2744,37 +2767,3 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 364 unmodified lines
27442767 return (_initialMemoryUsageGPU - currentFreeMemory);
27452768 }
27462769
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−