History

fix stutter on rotating

ZappoMan committed 13 years ago

Commit 9bd27e21 parent c18de723 files · +65 −34Browse files

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

Unified · Split

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