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
110110
111111 _culledOnce = false;
112112 _inhideOutOfView = false;
113+ _treeIsBusy = false;
113114 }
114115
115116 void VoxelSystem::voxelDeleted(VoxelNode* node) {
@@ -595,9 +596,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 479 unmodified lines
595596 "readBitstreamToTree()");
596597 // ask the VoxelTree to read the bitstream into the tree
597598 ReadBitstreamToTreeParams args(WANT_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID());
598− pthread_mutex_lock(&_treeLock);
599+ lockTree();
599600 _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
600− pthread_mutex_unlock(&_treeLock);
601+ unlockTree();
601602 }
602603 break;
603604 case PACKET_TYPE_VOXEL_DATA_MONOCHROME: {
@@ -605,9 +606,9 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 1 unmodified line
605606 "readBitstreamToTree()");
606607 // ask the VoxelTree to read the MONOCHROME bitstream into the tree
607608 ReadBitstreamToTreeParams args(NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID());
608− pthread_mutex_lock(&_treeLock);
609+ lockTree();
609610 _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
610− pthread_mutex_unlock(&_treeLock);
611+ unlockTree();
611612 }
612613 break;
613614 case PACKET_TYPE_Z_COMMAND:
@@ -1002,7 +1003,9 @@ int VoxelSystem::updateNodeInArrays(VoxelNode* node, bool reuseIndex, bool force · 388 unmodified lines
10021003 // not render these Voxels. We need to think about ways to keep the entire scene intact but maybe lower quality
10031004 // possibly shifting down to lower LOD or something. This debug message is to help identify, if/when/how this
10041005 // 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+ }
10061009 return 0;
10071010 }
10081011
@@ -1405,9 +1408,9 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) { · 396 unmodified lines
14051408 int VoxelSystem::_nodeCount = 0;
14061409
14071410 void VoxelSystem::killLocalVoxels() {
1408− pthread_mutex_lock(&_treeLock);
1411+ lockTree();
14091412 _tree->eraseAllVoxels();
1410− pthread_mutex_unlock(&_treeLock);
1413+ unlockTree();
14111414 clearFreeBufferIndexes();
14121415 _voxelsInReadArrays = 0; // do we need to do this?
14131416 setupNewVoxelsForDrawing();
@@ -1426,9 +1429,9 @@ bool VoxelSystem::clearAllNodesBufferIndexOperation(VoxelNode* node, void* extra · 12 unmodified lines
14261429
14271430 void VoxelSystem::clearAllNodesBufferIndex() {
14281431 _nodeCount = 0;
1429− pthread_mutex_lock(&_treeLock);
1432+ lockTree();
14301433 _tree->recurseTreeWithOperation(clearAllNodesBufferIndexOperation);
1431− pthread_mutex_unlock(&_treeLock);
1434+ unlockTree();
14321435 if (Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings)) {
14331436 qDebug("clearing buffer index of %d nodes\n", _nodeCount);
14341437 }
@@ -1916,9 +1919,9 @@ void VoxelSystem::hideOutOfView(bool forceFullFrustum) { · 481 unmodified lines
19161919 return;
19171920 }
19181921
1919− pthread_mutex_lock(&_treeLock);
1922+ lockTree();
19201923 _tree->recurseTreeWithOperation(hideOutOfViewOperation,(void*)&args);
1921− pthread_mutex_unlock(&_treeLock);
1924+ unlockTree();
19221925 _lastCulledViewFrustum = args.thisViewFrustum; // save last stable
19231926 _culledOnce = true;
19241927
@@ -2107,10 +2110,10 @@ bool VoxelSystem::hideOutOfViewOperation(VoxelNode* node, void* extraData) { · 182 unmodified lines
21072110
21082111 bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
21092112 VoxelDetail& detail, float& distance, BoxFace& face) {
2110− pthread_mutex_lock(&_treeLock);
2113+ lockTree();
21112114 VoxelNode* node;
21122115 if (!_tree->findRayIntersection(origin, direction, node, distance, face)) {
2113− pthread_mutex_unlock(&_treeLock);
2116+ unlockTree();
21142117 return false;
21152118 }
21162119 detail.x = node->getCorner().x;
@@ -2120,21 +2123,21 @@ bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& · 3 unmodified lines
21202123 detail.red = node->getColor()[0];
21212124 detail.green = node->getColor()[1];
21222125 detail.blue = node->getColor()[2];
2123− pthread_mutex_unlock(&_treeLock);
2126+ unlockTree();
21242127 return true;
21252128 }
21262129
21272130 bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) {
2128− pthread_mutex_lock(&_treeLock);
2131+ lockTree();
21292132 bool result = _tree->findSpherePenetration(center, radius, penetration);
2130− pthread_mutex_unlock(&_treeLock);
2133+ unlockTree();
21312134 return result;
21322135 }
21332136
21342137 bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) {
2135− pthread_mutex_lock(&_treeLock);
2138+ lockTree();
21362139 bool result = _tree->findCapsulePenetration(start, end, radius, penetration);
2137− pthread_mutex_unlock(&_treeLock);
2140+ unlockTree();
21382141 return result;
21392142 }
21402143
@@ -2308,9 +2311,9 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { · 167 unmodified lines
23082311
23092312
23102313 void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) {
2311− pthread_mutex_lock(&_treeLock);
2314+ lockTree();
23122315 _tree->deleteVoxelAt(x, y, z, s);
2313− pthread_mutex_unlock(&_treeLock);
2316+ unlockTree();
23142317
23152318 // redraw!
23162319 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
23252328 unsigned char red, unsigned char green, unsigned char blue, bool destructive) {
23262329
23272330 //qDebug("VoxelSystem::createVoxel(%f,%f,%f,%f)\n",x,y,z,s);
2328− pthread_mutex_lock(&_treeLock);
2331+ lockTree();
23292332 _tree->createVoxel(x, y, z, s, red, green, blue, destructive);
2330− pthread_mutex_unlock(&_treeLock);
2333+ unlockTree();
23312334
23322335 setupNewVoxelsForDrawing();
23332336 };
@@ -2650,9 +2653,9 @@ void VoxelSystem::nodeKilled(Node* node) { · 316 unmodified lines
26502653 if (_voxelServerCount > 0) {
26512654 // Kill any voxels from the local tree that match this nodeID
26522655 // commenting out for removal of 16 bit node IDs
2653− pthread_mutex_lock(&_treeLock);
2656+ lockTree();
26542657 _tree->recurseTreeWithOperation(killSourceVoxelsOperation, &nodeUUID);
2655− pthread_mutex_unlock(&_treeLock);
2658+ unlockTree();
26562659 _tree->setDirtyBit();
26572660 setupNewVoxelsForDrawing();
26582661 } else {
@@ -2720,5 +2723,15 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 61 unmodified lines
27202723 return (_initialMemoryUsageGPU - currentFreeMemory);
27212724 }
27222725
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+
27232736
27242737