Showing the changes to interface/src/VoxelSystem.cpp (1 of 184 files). Show all
Unified · Split
| @@ -5,16 +5,11 @@ · 4 unmodified lines | ||
| 5 | 5 | // Copyright (c) 2012 High Fidelity, Inc. All rights reserved. |
| 6 | 6 | // |
| 7 | 7 | |
| 8 | −#ifdef _WIN32 | |
| 9 | −#define _timeval_ | |
| 10 | −#define _USE_MATH_DEFINES | |
| 11 | −#endif | |
| 12 | 8 | |
| 13 | 9 | #include <cstring> |
| 14 | 10 | #include <cmath> |
| 15 | 11 | #include <iostream> // to load voxels from file |
| 16 | 12 | #include <fstream> // to load voxels from file |
| 17 | −#include <pthread.h> | |
| 18 | 13 | |
| 19 | 14 | #include <OctalCode.h> |
| 20 | 15 | #include <PacketHeaders.h> |
| @@ -73,9 +68,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) · 52 unmodified lines | ||
| 73 | 68 | _tree = new VoxelTree(); |
| 74 | 69 | |
| 75 | 70 | _tree->getRoot()->setVoxelSystem(this); |
| 76 | − pthread_mutex_init(&_bufferWriteLock, NULL); | |
| 77 | − pthread_mutex_init(&_treeLock, NULL); | |
| 78 | − pthread_mutex_init(&_freeIndexLock, NULL); | |
| 79 | 71 | |
| 80 | 72 | VoxelTreeElement::addDeleteHook(this); |
| 81 | 73 | VoxelTreeElement::addUpdateHook(this); |
| @@ -187,10 +179,10 @@ glBufferIndex VoxelSystem::getNextBufferIndex() { · 105 unmodified lines | ||
| 187 | 179 | glBufferIndex output = GLBUFFER_INDEX_UNKNOWN; |
| 188 | 180 | // if there's a free index, use it... |
| 189 | 181 | if (_freeIndexes.size() > 0) { |
| 190 | − pthread_mutex_lock(&_freeIndexLock); | |
| 182 | + _freeIndexLock.lock(); | |
| 191 | 183 | output = _freeIndexes.back(); |
| 192 | 184 | _freeIndexes.pop_back(); |
| 193 | − pthread_mutex_unlock(&_freeIndexLock); | |
| 185 | + _freeIndexLock.unlock(); | |
| 194 | 186 | } else { |
| 195 | 187 | output = _voxelsInWriteArrays; |
| 196 | 188 | _voxelsInWriteArrays++; |
| @@ -211,7 +203,7 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 14 unmodified lines | ||
| 211 | 203 | |
| 212 | 204 | // make sure the index isn't already in the free list..., this is a debugging measure only done if you've enabled audits |
| 213 | 205 | 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++) { | |
| 215 | 207 | if (_freeIndexes[i] == index) { |
| 216 | 208 | printf("freeBufferIndex(glBufferIndex index)... index=%ld already in free list!", index); |
| 217 | 209 | inList = true; |
| @@ -221,9 +213,9 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { · 3 unmodified lines | ||
| 221 | 213 | } |
| 222 | 214 | if (!inList) { |
| 223 | 215 | // make the index available for next node that needs to be drawn |
| 224 | − pthread_mutex_lock(&_freeIndexLock); | |
| 216 | + _freeIndexLock.lock(); | |
| 225 | 217 | _freeIndexes.push_back(index); |
| 226 | − pthread_mutex_unlock(&_freeIndexLock); | |
| 218 | + _freeIndexLock.unlock(); | |
| 227 | 219 | |
| 228 | 220 | // make the VBO slot "invisible" in case this slot is not used |
| 229 | 221 | const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX); |
| @@ -242,14 +234,14 @@ void VoxelSystem::clearFreeBufferIndexes() { · 12 unmodified lines | ||
| 242 | 234 | |
| 243 | 235 | // clear out freeIndexes |
| 244 | 236 | { |
| 245 | − PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : pthread_mutex_lock(&_freeIndexLock)"); | |
| 246 | − pthread_mutex_lock(&_freeIndexLock); | |
| 237 | + PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexLock.lock()"); | |
| 238 | + _freeIndexLock.lock(); | |
| 247 | 239 | } |
| 248 | 240 | { |
| 249 | 241 | PerformanceWarning warn(showWarnings,"clearFreeBufferIndexes() : _freeIndexes.clear()"); |
| 250 | 242 | _freeIndexes.clear(); |
| 251 | 243 | } |
| 252 | − pthread_mutex_unlock(&_freeIndexLock); | |
| 244 | + _freeIndexLock.unlock(); | |
| 253 | 245 | } |
| 254 | 246 | |
| 255 | 247 | VoxelSystem::~VoxelSystem() { |
| @@ -258,9 +250,6 @@ VoxelSystem::~VoxelSystem() { · 2 unmodified lines | ||
| 258 | 250 | |
| 259 | 251 | cleanupVoxelMemory(); |
| 260 | 252 | delete _tree; |
| 261 | − pthread_mutex_destroy(&_bufferWriteLock); | |
| 262 | − pthread_mutex_destroy(&_treeLock); | |
| 263 | − pthread_mutex_destroy(&_freeIndexLock); | |
| 264 | 253 | } |
| 265 | 254 | |
| 266 | 255 | void VoxelSystem::setMaxVoxels(int maxVoxels) { |
| @@ -344,7 +333,7 @@ void VoxelSystem::setVoxelsAsPoints(bool voxelsAsPoints) { · 77 unmodified lines | ||
| 344 | 333 | |
| 345 | 334 | void VoxelSystem::cleanupVoxelMemory() { |
| 346 | 335 | if (_initialized) { |
| 347 | − pthread_mutex_lock(&_bufferWriteLock); | |
| 336 | + _bufferWriteLock.lock(); | |
| 348 | 337 | _initialized = false; // no longer initialized |
| 349 | 338 | if (_useVoxelShader) { |
| 350 | 339 | // these are used when in VoxelShader mode. |
| @@ -382,7 +371,7 @@ void VoxelSystem::cleanupVoxelMemory() { · 31 unmodified lines | ||
| 382 | 371 | delete[] _writeVoxelDirtyArray; |
| 383 | 372 | delete[] _readVoxelDirtyArray; |
| 384 | 373 | _writeVoxelDirtyArray = _readVoxelDirtyArray = NULL; |
| 385 | − pthread_mutex_unlock(&_bufferWriteLock); | |
| 374 | + _bufferWriteLock.unlock(); | |
| 386 | 375 | } |
| 387 | 376 | } |
| 388 | 377 | |
| @@ -391,7 +380,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 2 unmodified lines | ||
| 391 | 380 | |
| 392 | 381 | // populate the indicesArray |
| 393 | 382 | // 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++) { | |
| 395 | 384 | // fill the indices array |
| 396 | 385 | int voxelIndexOffset = n * INDICES_PER_FACE; |
| 397 | 386 | GLuint* currentIndicesPos = indicesArray + voxelIndexOffset; |
| @@ -415,7 +404,7 @@ void VoxelSystem::setupFaceIndices(GLuint& faceVBOID, GLubyte faceIdentityIndice · 17 unmodified lines | ||
| 415 | 404 | } |
| 416 | 405 | |
| 417 | 406 | void VoxelSystem::initVoxelMemory() { |
| 418 | − pthread_mutex_lock(&_bufferWriteLock); | |
| 407 | + _bufferWriteLock.lock(); | |
| 419 | 408 | |
| 420 | 409 | _memoryUsageRAM = 0; |
| 421 | 410 | _memoryUsageVBO = 0; // our VBO allocations as we know them |
| @@ -430,7 +419,7 @@ void VoxelSystem::initVoxelMemory() { · 8 unmodified lines | ||
| 430 | 419 | |
| 431 | 420 | // populate the indicesArray |
| 432 | 421 | // 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++) { | |
| 434 | 423 | indicesArray[n] = n; |
| 435 | 424 | } |
| 436 | 425 | |
| @@ -530,7 +519,7 @@ void VoxelSystem::initVoxelMemory() { · 93 unmodified lines | ||
| 530 | 519 | |
| 531 | 520 | _initialized = true; |
| 532 | 521 | |
| 533 | − pthread_mutex_unlock(&_bufferWriteLock); | |
| 522 | + _bufferWriteLock.unlock(); | |
| 534 | 523 | } |
| 535 | 524 | |
| 536 | 525 | void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const { |
| @@ -684,7 +673,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 147 unmodified lines | ||
| 684 | 673 | } |
| 685 | 674 | |
| 686 | 675 | // 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(); | |
| 688 | 677 | |
| 689 | 678 | if (_voxelsUpdated) { |
| 690 | 679 | _voxelsDirty=true; |
| @@ -693,7 +682,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 2 unmodified lines | ||
| 693 | 682 | // copy the newly written data to the arrays designated for reading, only does something if _voxelsDirty && _voxelsUpdated |
| 694 | 683 | copyWrittenDataToReadArrays(didWriteFullVBO); |
| 695 | 684 | |
| 696 | − pthread_mutex_unlock(&_bufferWriteLock); | |
| 685 | + _bufferWriteLock.unlock(); | |
| 697 | 686 | |
| 698 | 687 | uint64_t end = usecTimestampNow(); |
| 699 | 688 | int elapsedmsec = (end - start) / 1000; |
| @@ -724,8 +713,8 @@ void VoxelSystem::setupNewVoxelsForDrawingSingleNode(bool allowBailEarly) { · 24 unmodified lines | ||
| 724 | 713 | // lock on the buffer write lock so we can't modify the data when the GPU is reading it |
| 725 | 714 | { |
| 726 | 715 | 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(); | |
| 729 | 718 | } |
| 730 | 719 | |
| 731 | 720 | _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 | ||
| 736 | 725 | // after... |
| 737 | 726 | _voxelsUpdated = 0; |
| 738 | 727 | |
| 739 | − pthread_mutex_unlock(&_bufferWriteLock); | |
| 728 | + _bufferWriteLock.unlock(); | |
| 740 | 729 | |
| 741 | 730 | uint64_t end = usecTimestampNow(); |
| 742 | 731 | int elapsedmsec = (end - start) / 1000; |
| @@ -1603,13 +1592,13 @@ void VoxelSystem::falseColorizeBySource() { · 860 unmodified lines | ||
| 1603 | 1592 | }; |
| 1604 | 1593 | |
| 1605 | 1594 | // create a bunch of colors we'll use during colorization |
| 1606 | − | |
| 1595 | + | |
| 1607 | 1596 | foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { |
| 1608 | 1597 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { |
| 1609 | 1598 | uint16_t nodeID = VoxelTreeElement::getSourceNodeUUIDKey(node->getUUID()); |
| 1610 | 1599 | int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS; |
| 1611 | 1600 | args.colors[nodeID] = groupColors[groupColor]; |
| 1612 | − | |
| 1601 | + | |
| 1613 | 1602 | if (groupColors[groupColor].red > 0) { |
| 1614 | 1603 | groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR; |
| 1615 | 1604 | } |
| @@ -1619,7 +1608,7 @@ void VoxelSystem::falseColorizeBySource() { · 3 unmodified lines | ||
| 1619 | 1608 | if (groupColors[groupColor].blue > 0) { |
| 1620 | 1609 | groupColors[groupColor].blue = ((groupColors[groupColor].blue - MIN_COLOR)/2) + MIN_COLOR; |
| 1621 | 1610 | } |
| 1622 | − | |
| 1611 | + | |
| 1623 | 1612 | voxelServerCount++; |
| 1624 | 1613 | } |
| 1625 | 1614 | } |
| @@ -2397,12 +2386,6 @@ void VoxelSystem::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, · 771 unmodified lines | ||
| 2397 | 2386 | setupNewVoxelsForDrawing(); |
| 2398 | 2387 | }; |
| 2399 | 2388 | |
| 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 | − | |
| 2406 | 2389 | void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) { |
| 2407 | 2390 | _tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot); |
| 2408 | 2391 | destination->setupNewVoxelsForDrawing(); |
| @@ -2765,13 +2748,13 @@ unsigned long VoxelSystem::getVoxelMemoryUsageGPU() { · 356 unmodified lines | ||
| 2765 | 2748 | } |
| 2766 | 2749 | |
| 2767 | 2750 | void VoxelSystem::lockTree() { |
| 2768 | − pthread_mutex_lock(&_treeLock); | |
| 2751 | + _treeLock.lock(); | |
| 2769 | 2752 | _treeIsBusy = true; |
| 2770 | 2753 | } |
| 2771 | 2754 | |
| 2772 | 2755 | void VoxelSystem::unlockTree() { |
| 2773 | 2756 | _treeIsBusy = false; |
| 2774 | − pthread_mutex_unlock(&_treeLock); | |
| 2757 | + _treeLock.unlock(); | |
| 2775 | 2758 | } |
| 2776 | 2759 | |
| 2777 | 2760 | |