From ded7328959b5f34dbe441108eb1db64a32c26ba6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 15:17:49 -0800 Subject: [PATCH] clean up application access to deleteVoxelAt()/createVoxel()/getVoxelAt() to access VoxelTree directly --- interface/src/Application.cpp | 16 +++++------ interface/src/VoxelSystem.cpp | 28 ------------------- interface/src/VoxelSystem.h | 5 ---- libraries/octree/src/Octree.cpp | 2 ++ libraries/voxels/src/VoxelTree.cpp | 9 ++---- .../voxels/src/VoxelsScriptingInterface.cpp | 6 ---- 6 files changed, 13 insertions(+), 53 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 28db3d8791..74d8afec54 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1288,7 +1288,7 @@ void Application::removeVoxel(glm::vec3 position, _voxelEditSender.sendVoxelEditMessage(PacketTypeVoxelErase, voxel); // delete it locally to see the effect immediately (and in case no voxel server is present) - _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); + _voxels.getTree()->deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); } @@ -1310,8 +1310,7 @@ void Application::makeVoxel(glm::vec3 position, _voxelEditSender.sendVoxelEditMessage(message, voxel); // create the voxel locally so it appears immediately - - _voxels.createVoxel(voxel.x, voxel.y, voxel.z, voxel.s, + _voxels.getTree()->createVoxel(voxel.x, voxel.y, voxel.z, voxel.s, voxel.red, voxel.green, voxel.blue, isDestructive); } @@ -1370,7 +1369,8 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { tr("Sparse Voxel Octree Files (*.svo)")); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); const char* fileName = fileNameAscii.data(); - VoxelTreeElement* selectedNode = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + + VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); if (selectedNode) { VoxelTree exportTree; _voxels.copySubTreeIntoNewTree(selectedNode, &exportTree, true); @@ -1415,7 +1415,7 @@ void Application::copyVoxels(const VoxelDetail& sourceVoxel) { } // then copy onto it if there is something to copy - VoxelTreeElement* selectedNode = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); if (selectedNode) { _voxels.copySubTreeIntoNewTree(selectedNode, &_sharedVoxelSystem, true); } @@ -1438,7 +1438,7 @@ void Application::pasteVoxelsToOctalCode(const unsigned char* octalCodeDestinati void Application::pasteVoxels(const VoxelDetail& sourceVoxel) { unsigned char* calculatedOctCode = NULL; - VoxelTreeElement* selectedNode = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the // voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a @@ -1458,7 +1458,7 @@ void Application::pasteVoxels(const VoxelDetail& sourceVoxel) { } void Application::nudgeVoxelsByVector(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec) { - VoxelTreeElement* nodeToNudge = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + VoxelTreeElement* nodeToNudge = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); if (nodeToNudge) { _voxels.getTree()->nudgeSubTree(nodeToNudge, nudgeVec, _voxelEditSender); } @@ -3206,7 +3206,7 @@ void Application::deleteVoxelAt(const VoxelDetail& voxel) { _voxelEditSender.sendVoxelEditMessage(PacketTypeVoxelErase, voxel); // delete it locally to see the effect immediately (and in case no voxel server is present) - _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); + _voxels.getTree()->deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); } } diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index f91e6eb1ff..8b43491a46 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -2302,34 +2302,6 @@ bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3 return result; } -void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "VoxelSystem::deleteVoxelAt()"); - _tree->lockForWrite(); - _tree->deleteVoxelAt(x, y, z, s); - _tree->unlock(); - - // redraw! - setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in? -}; - -VoxelTreeElement* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const { - return _tree->getVoxelAt(x, y, z, s); -}; - -void VoxelSystem::createVoxel(float x, float y, float z, float s, - unsigned char red, unsigned char green, unsigned char blue, bool destructive) { - - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "VoxelSystem::createVoxel()"); - - _tree->lockForWrite(); - _tree->createVoxel(x, y, z, s, red, green, blue, destructive); - _tree->unlock(); - - setupNewVoxelsForDrawing(); -}; - void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) { _tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot); destination->setupNewVoxelsForDrawing(); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 113c341ecc..7fa6746330 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -93,11 +93,6 @@ public: bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration); bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration); - void deleteVoxelAt(float x, float y, float z, float s); - VoxelTreeElement* getVoxelAt(float x, float y, float z, float s) const; - void createVoxel(float x, float y, float z, float s, - unsigned char red, unsigned char green, unsigned char blue, bool destructive = false); - void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destinationTree, bool rebaseToRoot); void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelTree* destinationTree, bool rebaseToRoot); void copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelTreeElement* destinationNode); diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 051d4f5ca2..e63424d92b 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -330,7 +330,9 @@ void Octree::readBitstreamToTree(const unsigned char * bitstream, unsigned long void Octree::deleteOctreeElementAt(float x, float y, float z, float s) { unsigned char* octalCode = pointToOctalCode(x,y,z,s); + lockForWrite(); deleteOctalCodeFromTree(octalCode); + unlock(); delete[] octalCode; // cleanup memory } diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 272668a19e..8ba3f34081 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -47,12 +47,9 @@ void VoxelTree::createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue, bool destructive) { unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue); - - //int length = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(voxelData)) + BYTES_PER_COLOR; - //printf("createVoxel()..."); - //outputBufferBits(voxelData,length); - - this->readCodeColorBufferToTree(voxelData, destructive); + lockForWrite(); + readCodeColorBufferToTree(voxelData, destructive); + unlock(); delete[] voxelData; } diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index db61460d69..be7c9664a0 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -47,9 +47,7 @@ void VoxelsScriptingInterface::setVoxelNonDestructive(float x, float y, float z, // handle the local tree also... if (_tree) { - _tree->lockForWrite(); _tree->createVoxel(addVoxelDetail.x, addVoxelDetail.y, addVoxelDetail.z, addVoxelDetail.s, red, green, blue, false); - _tree->unlock(); } } @@ -64,9 +62,7 @@ void VoxelsScriptingInterface::setVoxel(float x, float y, float z, float scale, // handle the local tree also... if (_tree) { - _tree->lockForWrite(); _tree->createVoxel(addVoxelDetail.x, addVoxelDetail.y, addVoxelDetail.z, addVoxelDetail.s, red, green, blue, true); - _tree->unlock(); } } @@ -80,9 +76,7 @@ void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale // handle the local tree also... if (_tree) { - _tree->lockForWrite(); _tree->deleteVoxelAt(deleteVoxelDetail.x, deleteVoxelDetail.y, deleteVoxelDetail.z, deleteVoxelDetail.s); - _tree->unlock(); } }