History

Merge branch 'master' of https://github.com/worklist/hifi

Philip Rosedale committed 12 years ago

Commit 46bd6772 parents aa2ee25 84a5d75184 files · +30499 −2550Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+24−41
@@ -5,16 +5,11 @@ · 4 unmodified lines
55 // Copyright (c) 2012 High Fidelity, Inc. All rights reserved.
66 //
77
8−#ifdef _WIN32
9−#define _timeval_
10−#define _USE_MATH_DEFINES
11−#endif
128
139 #include <cstring>
1410 #include <cmath>
1511 #include <iostream> // to load voxels from file
1612 #include <fstream> // to load voxels from file
17−#include <pthread.h>
1813
1914 #include <OctalCode.h>
2015 #include <PacketHeaders.h>
@@ -73,9 +68,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 52 unmodified lines
7368 _tree = new VoxelTree();
7469
7570 _tree->getRoot()->setVoxelSystem(this);
76− pthread_mutex_init(&_bufferWriteLock, NULL);
77− pthread_mutex_init(&_treeLock, NULL);
78− pthread_mutex_init(&_freeIndexLock, NULL);
7971
8072 VoxelTreeElement::addDeleteHook(this);
8173 VoxelTreeElement::addUpdateHook(this);
@@ -187,10 +179,10 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 105 unmodified lines
187179 glBufferIndex output = GLBUFFER_INDEX_UNKNOWN;
188180 // if there's a free index, use it...
189181 if (_freeIndexes.size() > 0) {
190− pthread_mutex_lock(&_freeIndexLock);
182+ _freeIndexLock.lock();
191183 output = _freeIndexes.back();
192184 _freeIndexes.pop_back();
193− pthread_mutex_unlock(&_freeIndexLock);
185+ _freeIndexLock.unlock();
194186 } else {
195187 output = _voxelsInWriteArrays;
196188 _voxelsInWriteArrays++;
@@ -211,7 +203,7 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 14 unmodified lines
211203
212204 // make sure the index isn't already in the free list..., this is a debugging measure only done if you've enabled audits
213205 if (Menu::getInstance()->isOptionChecked(MenuOption::AutomaticallyAuditTree)) {
214− for (long i = 0; i < _freeIndexes.size(); i++) {
206+ for (unsigned long i = 0; i < _freeIndexes.size(); i++) {
215207 if (_freeIndexes[i] == index) {
216208 printf("freeBufferIndex(glBufferIndex index)... index=%ld already in free list!", index);
217209 inList = true;
@@ -221,9 +213,9 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 3 unmodified lines
221213 }
222214 if (!inList) {
223215 // make the index available for next node that needs to be drawn
224− pthread_mutex_lock(&_freeIndexLock);
216+ _freeIndexLock.lock();
225217 _freeIndexes.push_back(index);
226− pthread_mutex_unlock(&_freeIndexLock);
218+ _freeIndexLock.unlock();
227219
228220 // make the VBO slot "invisible" in case this slot is not used
229221 const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX);
@@ -242,14 +234,14 @@ void VoxelSystem::clearFreeBufferIndexes() { · 12 unmodified lines
242234
243235 // clear out freeIndexes
244236 {
245− PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : pthread_mutex_lock(&_freeIndexLock)");
246− pthread_mutex_lock(&_freeIndexLock);
237+ PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexLock.lock()");
238+ _freeIndexLock.lock();
247239 }
248240 {
249241 PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()");
250242 _freeIndexes.clear();
251243 }
252− pthread_mutex_unlock(&_freeIndexLock);
244+ _freeIndexLock.unlock();
253245 }
254246
255247 VoxelSystem::~VoxelSystem() {
@@ -258,9 +250,6 @@ VoxelSystem::~VoxelSystem() { · 2 unmodified lines
258250
259251 cleanupVoxelMemory();
260252 delete _tree;
261− pthread_mutex_destroy(&_bufferWriteLock);
262− pthread_mutex_destroy(&_treeLock);
263− pthread_mutex_destroy(&_freeIndexLock);
264253 }
265254
266255 void VoxelSystem::setMaxVoxels(int maxVoxels) {
@@ -344,7 +333,7 @@ void VoxelSystem::setVoxelsAsPoints(bool voxelsAsPoints) { · 77 unmodified lines
344333
345334 void VoxelSystem::cleanupVoxelMemory() {
346335 if (_initialized) {
347− pthread_mutex_lock(&_bufferWriteLock);
336+ _bufferWriteLock.lock();
348337 _initialized = false; // no longer initialized
349338 if (_useVoxelShader) {
350339 // these are used when in VoxelShader mode.
@@ -382,7 +371,7 @@ void VoxelSystem::cleanupVoxelMemory() { · 31 unmodified lines
382371 delete[] _writeVoxelDirtyArray;
383372 delete[] _readVoxelDirtyArray;
384373 _writeVoxelDirtyArray = _readVoxelDirtyArray = NULL;
385− pthread_mutex_unlock(&_bufferWriteLock);
374+ _bufferWriteLock.unlock();
386375 }
387376 }
388377
@@ -391,7 +380,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 2 unmodified lines
391380
392381 // populate the indicesArray
393382 // this will not change given new voxels, so we can set it all up now
394− for (int n = 0; n < _maxVoxels; n++) {
383+ for (unsigned long n = 0; n < _maxVoxels; n++) {
395384 // fill the indices array
396385 int voxelIndexOffset = n * INDICES_PER_FACE;
397386 GLuint* currentIndicesPos = indicesArray + voxelIndexOffset;
@@ -415,7 +404,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 17 unmodified lines
415404 }
416405
417406 void VoxelSystem::initVoxelMemory() {
418− pthread_mutex_lock(&_bufferWriteLock);
407+ _bufferWriteLock.lock();
419408
420409 _memoryUsageRAM = 0;
421410 _memoryUsageVBO = 0; // our VBO allocations as we know them
@@ -430,7 +419,7 @@ void VoxelSystem::initVoxelMemory() { · 8 unmodified lines
430419
431420 // populate the indicesArray
432421 // this will not change given new voxels, so we can set it all up now
433− for (int n = 0; n < _maxVoxels; n++) {
422+ for (unsigned long n = 0; n < _maxVoxels; n++) {
434423 indicesArray[n] = n;
435424 }
436425
@@ -530,7 +519,7 @@ void VoxelSystem::initVoxelMemory() { · 93 unmodified lines
530519
531520 _initialized = true;
532521
533− pthread_mutex_unlock(&_bufferWriteLock);
522+ _bufferWriteLock.unlock();
534523 }
535524
536525 void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const {
@@ -684,7 +673,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 147 unmodified lines
684673 }
685674
686675 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
687− pthread_mutex_lock(&_bufferWriteLock);
676+ _bufferWriteLock.lock();
688677
689678 if (_voxelsUpdated) {
690679 _voxelsDirty=true;
@@ -693,7 +682,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 2 unmodified lines
693682 // copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated
694683 copyWrittenDataToReadArrays(didWriteFullVBO);
695684
696− pthread_mutex_unlock(&_bufferWriteLock);
685+ _bufferWriteLock.unlock();
697686
698687 uint64_t end = usecTimestampNow();
699688 int elapsedmsec = (end - start) / 1000;
@@ -724,8 +713,8 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 24 unmodified lines
724713 // lock on the buffer write lock so we can't modify the data when the GPU is reading it
725714 {
726715 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
727− "setupNewVoxelsForDrawingSingleNode()... pthread_mutex_lock(&_bufferWriteLock);");
728− pthread_mutex_lock(&_bufferWriteLock);
716+ "setupNewVoxelsForDrawingSingleNode()... _bufferWriteLock.lock();" );
717+ _bufferWriteLock.lock();
729718 }
730719
731720 _voxelsDirty = true; // if we got this far, then we can assume some voxels are dirty
@@ -736,7 +725,7 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 4 unmodified lines
736725 // after...
737726 _voxelsUpdated = 0;
738727
739− pthread_mutex_unlock(&_bufferWriteLock);
728+ _bufferWriteLock.unlock();
740729
741730 uint64_t end = usecTimestampNow();
742731 int elapsedmsec = (end - start) / 1000;
@@ -1603,13 +1592,13 @@ void VoxelSystem::falseColorizeBySource() { · 860 unmodified lines
16031592 };
16041593
16051594 // create a bunch of colors we'll use during colorization
1606−
1595+
16071596 foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) {
16081597 if (node->getType() == NODE_TYPE_VOXEL_SERVER) {
16091598 uint16_t nodeID = VoxelTreeElement::getSourceNodeUUIDKey(node->getUUID());
16101599 int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS;
16111600 args.colors[nodeID] = groupColors[groupColor];
1612−
1601+
16131602 if (groupColors[groupColor].red > 0) {
16141603 groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR;
16151604 }
@@ -1619,7 +1608,7 @@ void VoxelSystem::falseColorizeBySource() { · 3 unmodified lines
16191608 if (groupColors[groupColor].blue > 0) {
16201609 groupColors[groupColor].blue = ((groupColors[groupColor].blue - MIN_COLOR)/2) + MIN_COLOR;
16211610 }
1622−
1611+
16231612 voxelServerCount++;
16241613 }
16251614 }
@@ -2397,12 +2386,6 @@ void VoxelSystem::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, · 771 unmodified lines
23972386 setupNewVoxelsForDrawing();
23982387 };
23992388
2400−void VoxelSystem::createSphere(float r,float xc, float yc, float zc, float s, bool solid,
2401− creationMode mode, bool destructive, bool debug) {
2402− _tree->createSphere(r, xc, yc, zc, s, solid, mode, destructive, debug);
2403− setupNewVoxelsForDrawing();
2404−};
2405−
24062389 void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) {
24072390 _tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot);
24082391 destination->setupNewVoxelsForDrawing();
@@ -2765,13 +2748,13 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 356 unmodified lines
27652748 }
27662749
27672750 void VoxelSystem::lockTree() {
2768− pthread_mutex_lock(&_treeLock);
2751+ _treeLock.lock();
27692752 _treeIsBusy = true;
27702753 }
27712754
27722755 void VoxelSystem::unlockTree() {
27732756 _treeIsBusy = false;
2774− pthread_mutex_unlock(&_treeLock);
2757+ _treeLock.unlock();
27752758 }
27762759
27772760