From 5da525fc3ecb7916e373005aaa502deb9ff9f125 Mon Sep 17 00:00:00 2001 From: atlante45 Date: Wed, 4 Sep 2013 15:12:24 -0700 Subject: [PATCH] memory wastes and code cleaning PR comments --- interface/src/Audio.h | 4 +- interface/src/Menu.cpp | 1 - interface/src/VoxelSystem.cpp | 5 +- interface/src/VoxelSystem.h | 11 ++-- interface/src/avatar/AvatarVoxelSystem.cpp | 4 +- interface/src/avatar/AvatarVoxelSystem.h | 3 +- interface/src/avatar/Face.cpp | 3 - interface/src/avatar/Head.cpp | 9 +-- interface/src/avatar/Head.h | 6 +- interface/src/ui/VoxelStatsDialog.cpp | 6 +- libraries/avatars/src/AvatarData.h | 4 +- libraries/shared/src/NetworkPacket.h | 2 +- libraries/shared/src/NodeList.h | 1 - libraries/shared/src/PointerStack.cpp | 42 -------------- libraries/shared/src/PointerStack.h | 59 -------------------- libraries/shared/src/StdDev.h | 2 +- libraries/voxels/src/Tags.cpp | 10 +++- libraries/voxels/src/VoxelNode.h | 18 +++--- libraries/voxels/src/VoxelProjectedPolygon.h | 20 +++---- libraries/voxels/src/VoxelTree.cpp | 55 ------------------ libraries/voxels/src/VoxelTree.h | 7 --- 21 files changed, 47 insertions(+), 225 deletions(-) delete mode 100644 libraries/shared/src/PointerStack.cpp delete mode 100644 libraries/shared/src/PointerStack.h diff --git a/interface/src/Audio.h b/interface/src/Audio.h index c9fc8402e7..bf99fd3f42 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -42,8 +42,8 @@ public: float getLastInputLoudness() const { return _lastInputLoudness; } - void setLastAcceleration(glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; } - void setLastVelocity(glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; } + void setLastAcceleration(const glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; } + void setLastVelocity(const glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; } void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; } int getJitterBufferSamples() { return _jitterBufferSamples; } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 1fcc5a6274..65afc605b0 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -416,7 +416,6 @@ Menu::Menu() : Menu::~Menu() { bandwidthDetailsClosed(); voxelStatsDetailsClosed(); - delete _voxelModeActionsGroup; } void Menu::loadSettings(QSettings* settings) { diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 5229873164..d12d97a5da 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -545,7 +545,6 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo return startVertex + glm::vec3(identityVertex[0], identityVertex[1], identityVertex[2]) * voxelScale; } -bool VoxelSystem::_perlinModulateProgramInitialized = false; ProgramObject VoxelSystem::_perlinModulateProgram; void VoxelSystem::init() { @@ -634,7 +633,7 @@ void VoxelSystem::init() { // create our simple fragment shader if we're the first system to init - if (!_perlinModulateProgramInitialized) { + if (!_perlinModulateProgram.isLinked()) { switchToResourcesParentIfRequired(); _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert"); _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag"); @@ -643,8 +642,6 @@ void VoxelSystem::init() { _perlinModulateProgram.bind(); _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0); _perlinModulateProgram.release(); - - _perlinModulateProgramInitialized = true; } _initialized = true; } diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 35931d3191..fa4266d30a 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -34,8 +34,8 @@ public: VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM); ~VoxelSystem(); - void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }; - int getDataSourceID() const { return _dataSourceID; }; + void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; } + int getDataSourceID() const { return _dataSourceID; } int parseData(unsigned char* sourceBuffer, int numBytes); @@ -45,8 +45,8 @@ public: ViewFrustum* getViewFrustum() const {return _viewFrustum;} void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;} - unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}; - unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;}; + unsigned long getVoxelsUpdated() const {return _voxelsUpdated;} + unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;} void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void writeToSVOFile(const char* filename, VoxelNode* node) const; @@ -207,8 +207,7 @@ private: void updatePartialVBOs(); // multiple segments, only dirty voxels bool _voxelsDirty; - - static bool _perlinModulateProgramInitialized; + static ProgramObject _perlinModulateProgram; int _hookID; diff --git a/interface/src/avatar/AvatarVoxelSystem.cpp b/interface/src/avatar/AvatarVoxelSystem.cpp index 2b33c05807..15ece16ecd 100644 --- a/interface/src/avatar/AvatarVoxelSystem.cpp +++ b/interface/src/avatar/AvatarVoxelSystem.cpp @@ -43,7 +43,6 @@ AvatarVoxelSystem::~AvatarVoxelSystem() { } } -bool AvatarVoxelSystem::_skinProgramInitialized = false; ProgramObject AvatarVoxelSystem::_skinProgram; int AvatarVoxelSystem::_boneMatricesLocation; int AvatarVoxelSystem::_boneIndicesLocation; @@ -75,10 +74,9 @@ void AvatarVoxelSystem::init() { glBufferData(GL_ARRAY_BUFFER, BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW); // load our skin program if this is the first avatar system to initialize - if (!_skinProgramInitialized) { + if (!_skinProgram.isLinked()) { _skinProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert"); _skinProgram.link(); - _skinProgramInitialized = true; } _boneMatricesLocation = _skinProgram.uniformLocation("boneMatrices"); diff --git a/interface/src/avatar/AvatarVoxelSystem.h b/interface/src/avatar/AvatarVoxelSystem.h index bf95b774c3..43c76fb5c2 100644 --- a/interface/src/avatar/AvatarVoxelSystem.h +++ b/interface/src/avatar/AvatarVoxelSystem.h @@ -74,8 +74,7 @@ private: GLuint _vboBoneWeightsID; QNetworkReply* _voxelReply; - - static bool _skinProgramInitialized; + static ProgramObject _skinProgram; static int _boneMatricesLocation; static int _boneIndicesLocation; diff --git a/interface/src/avatar/Face.cpp b/interface/src/avatar/Face.cpp index cc9b90ad4a..6e8db503fa 100644 --- a/interface/src/avatar/Face.cpp +++ b/interface/src/avatar/Face.cpp @@ -54,9 +54,6 @@ Face::~Face() { glDeleteTextures(1, &_depthTextureID); } } - - glDeleteBuffers(1, &_vboID); - glDeleteBuffers(1, &_iboID); } void Face::setFrameFromWebcam() { diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 20c4c6c816..5e04a2b1e7 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -46,7 +46,6 @@ const float IRIS_RADIUS = 0.007; const float IRIS_PROTRUSION = 0.0145f; const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png"; -bool Head::_irisProgramInitialized = false; ProgramObject Head::_irisProgram; GLuint Head::_irisTextureID; int Head::_eyePositionLocation; @@ -97,12 +96,8 @@ Head::Head(Avatar* owningAvatar) : } } -Head::~Head() { - glDeleteTextures(1, &_irisTextureID); -} - void Head::init() { - if (!_irisProgramInitialized) { + if (!_irisProgram.isLinked()) { switchToResourcesParentIfRequired(); _irisProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert"); _irisProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag"); @@ -120,8 +115,6 @@ void Head::init() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glBindTexture(GL_TEXTURE_2D, 0); - - _irisProgramInitialized = true; } } diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 0952de0252..41886ad2f5 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -38,7 +38,6 @@ class ProgramObject; class Head : public HeadData { public: Head(Avatar* owningAvatar); - ~Head(); void init(); void reset(); @@ -73,7 +72,7 @@ public: Face& getFace() { return _face; } const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected) - float getAverageLoudness() {return _averageLoudness;} + float getAverageLoudness() const { return _averageLoudness; } glm::vec3 calculateAverageEyePosition() { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; } float yawRate; @@ -131,8 +130,7 @@ private: bool _cameraFollowsHead; float _cameraFollowHeadRate; Face _face; - - static bool _irisProgramInitialized; + static ProgramObject _irisProgram; static GLuint _irisTextureID; static int _eyePositionLocation; diff --git a/interface/src/ui/VoxelStatsDialog.cpp b/interface/src/ui/VoxelStatsDialog.cpp index 5892c2c70e..2fa9ff8cd3 100644 --- a/interface/src/ui/VoxelStatsDialog.cpp +++ b/interface/src/ui/VoxelStatsDialog.cpp @@ -30,7 +30,7 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) : this->QDialog::setLayout(form); // Setup labels - for (int i = 0; i < (int)VoxelSceneStats::ITEM_COUNT; i++) { + for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; i++) { VoxelSceneStats::Item item = (VoxelSceneStats::Item)(i); VoxelSceneStats::ItemInfo& itemInfo = _model->getItemInfo(item); QLabel* label = _labels[item] = new QLabel(); @@ -54,7 +54,7 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) : } VoxelStatsDialog::~VoxelStatsDialog() { - for (int i = 0; i <(int)VoxelSceneStats::ITEM_COUNT; ++i) { + for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; ++i) { delete _labels[i]; } } @@ -63,7 +63,7 @@ void VoxelStatsDialog::paintEvent(QPaintEvent* event) { // Update labels char strBuf[256]; - for (int i = 0; i < (int)VoxelSceneStats::ITEM_COUNT; i++) { + for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; i++) { VoxelSceneStats::Item item = (VoxelSceneStats::Item)(i); QLabel* label = _labels[item]; snprintf(strBuf, sizeof(strBuf), "%s", _model->getItemValue(item)); diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 2179cb3c4d..4f5e503cf4 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -73,13 +73,13 @@ public: void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; } float getBodyPitch() const { return _bodyPitch; } void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; } - float getBodyRoll() const {return _bodyRoll; } + float getBodyRoll() const { return _bodyRoll; } void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } // Hand State void setHandState(char s) { _handState = s; } - char getHandState() const {return _handState; } + char getHandState() const { return _handState; } // getters for camera details const glm::vec3& getCameraPosition() const { return _cameraPosition; } diff --git a/libraries/shared/src/NetworkPacket.h b/libraries/shared/src/NetworkPacket.h index 8017f7057e..9c7c61e10f 100644 --- a/libraries/shared/src/NetworkPacket.h +++ b/libraries/shared/src/NetworkPacket.h @@ -33,7 +33,7 @@ public: NetworkPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength); sockaddr& getAddress() { return _address; } - ssize_t getLength() const { return _packetLength; } + ssize_t getLength() const { return _packetLength; } unsigned char* getData() { return &_packetData[0]; } const sockaddr& getAddress() const { return _address; } diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index b76eab9da0..9e9f72767d 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -156,7 +156,6 @@ private: class NodeListIterator : public std::iterator { public: NodeListIterator(const NodeList* nodeList, int nodeIndex); - ~NodeListIterator() {} int getNodeIndex() { return _nodeIndex; } diff --git a/libraries/shared/src/PointerStack.cpp b/libraries/shared/src/PointerStack.cpp deleted file mode 100644 index 2098312298..0000000000 --- a/libraries/shared/src/PointerStack.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// PointerStack.cpp -// hifi -// -// Created by Brad Hefta-Gaub on 5/11/2013 -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// - -#include "PointerStack.h" -#include - -PointerStack::~PointerStack() { - deleteAll(); -} - -void PointerStack::deleteAll() { - if (_elements) { - delete[] _elements; - } - _elements = NULL; - _elementsInUse = 0; - _sizeOfElementsArray = 0; -} - -const int GROW_BY = 100; - -void PointerStack::growAndPush(void* element) { - //printf("PointerStack::growAndPush() _sizeOfElementsArray=%d",_sizeOfElementsArray); - void** oldElements = _elements; - _elements = new void* [_sizeOfElementsArray + GROW_BY]; - _sizeOfElementsArray += GROW_BY; - - // If we had an old stack... - if (oldElements) { - // copy old elements into the new stack - memcpy(_elements, oldElements, _elementsInUse * sizeof(void*)); - delete[] oldElements; - } - _elements[_elementsInUse] = element; - _elementsInUse++; -} - diff --git a/libraries/shared/src/PointerStack.h b/libraries/shared/src/PointerStack.h deleted file mode 100644 index 1626db3a3b..0000000000 --- a/libraries/shared/src/PointerStack.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// PointerStack.h -// hifi -// -// Created by Brad Hefta-Gaub on 4/25/2013 -// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -// -// - -#ifndef __hifi__PointerStack__ -#define __hifi__PointerStack__ - -#include // for NULL - -class PointerStack { - -public: - PointerStack() : - _elements(NULL), - _elementsInUse(0), - _sizeOfElementsArray(0) {} - - ~PointerStack(); - - void push(void* element) { - if (_sizeOfElementsArray < _elementsInUse + 1) { - return growAndPush(element); - } - _elements[_elementsInUse] = element; - _elementsInUse++; - } - - void* pop() { - if (_elementsInUse) { - // get the last element - void* element = _elements[_elementsInUse - 1]; - // reduce the count - _elementsInUse--; - return element; - } - return NULL; - } - - - void* top() const { return (_elementsInUse) ? _elements[_elementsInUse - 1] : NULL; } - bool isEmpty() const { return (_elementsInUse == 0); } - bool empty() const { return (_elementsInUse == 0); } - int count() const { return _elementsInUse; } - int size() const { return _elementsInUse; } - -private: - void growAndPush(void* element); - void deleteAll(); - void** _elements; - int _elementsInUse; - int _sizeOfElementsArray; -}; - -#endif /* defined(__hifi__PointerStack__) */ diff --git a/libraries/shared/src/StdDev.h b/libraries/shared/src/StdDev.h index 74937f6f9a..eea0cff3bb 100644 --- a/libraries/shared/src/StdDev.h +++ b/libraries/shared/src/StdDev.h @@ -16,7 +16,7 @@ class StDev { void addValue(float v); float getAverage(); float getStDev(); - int getSamples() {return sampleCount;} + int getSamples() const { return sampleCount; } private: float * data; int sampleCount; diff --git a/libraries/voxels/src/Tags.cpp b/libraries/voxels/src/Tags.cpp index ef0a2a1faf..4d1fb322cd 100644 --- a/libraries/voxels/src/Tags.cpp +++ b/libraries/voxels/src/Tags.cpp @@ -109,7 +109,10 @@ TagList::TagList(std::stringstream &ss) : } TagList::~TagList() { - _data.clear(); + while (!_data.empty()) { + delete _data.back(); + _data.pop_back(); + } } TagCompound::TagCompound(std::stringstream &ss) : @@ -150,7 +153,10 @@ TagCompound::TagCompound(std::stringstream &ss) : } TagCompound::~TagCompound() { - _data.clear(); + while (!_data.empty()) { + delete _data.back(); + _data.pop_back(); + } } TagIntArray::TagIntArray(std::stringstream &ss) : Tag(TAG_Int_Array, ss) { diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index c98b26744c..b7f31e3b61 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -53,7 +53,7 @@ public: float getEnclosingRadius() const; - bool isColored() const { return (_trueColor[3]==1); } + bool isColored() const { return _trueColor[3] == 1; } bool isInView(const ViewFrustum& viewFrustum) const; ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const; float distanceToCamera(const ViewFrustum& viewFrustum) const; @@ -70,8 +70,8 @@ public: void printDebugDetails(const char* label) const; bool isDirty() const { return _isDirty; } void clearDirtyBit() { _isDirty = false; } - bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } - void markWithChangedTime() { _lastChanged = usecTimestampNow(); } + bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } + void markWithChangedTime() { _lastChanged = usecTimestampNow(); } uint64_t getLastChanged() const { return _lastChanged; } void handleSubtreeChanged(VoxelTree* myTree); @@ -103,18 +103,18 @@ public: const nodeColor& getColor() const { return _trueColor; }; #endif - void setDensity(float density) { _density = density; } - float getDensity() const { return _density; } - void setSourceID(uint16_t sourceID) { _sourceID = sourceID; } - uint16_t getSourceID() const { return _sourceID; } + void setDensity(float density) { _density = density; } + float getDensity() const { return _density; } + void setSourceID(uint16_t sourceID) { _sourceID = sourceID; } + uint16_t getSourceID() const { return _sourceID; } static void addDeleteHook(VoxelNodeDeleteHook* hook); static void removeDeleteHook(VoxelNodeDeleteHook* hook); void recalculateSubTreeNodeCount(); - unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; } + unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; } unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; } - unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; } + unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; } private: void calculateAABox(); diff --git a/libraries/voxels/src/VoxelProjectedPolygon.h b/libraries/voxels/src/VoxelProjectedPolygon.h index 51daf28330..1d7ac9713c 100644 --- a/libraries/voxels/src/VoxelProjectedPolygon.h +++ b/libraries/voxels/src/VoxelProjectedPolygon.h @@ -19,7 +19,7 @@ class BoundingBox { public: enum { BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT, VERTEX_COUNT }; - BoundingBox(glm::vec2 corner, glm::vec2 size) : corner(corner), size(size), _set(true) {} + BoundingBox(const glm::vec2 corner, const glm::vec2 size) : corner(corner), size(size), _set(true) {} BoundingBox() : _set(false) {} glm::vec2 corner; glm::vec2 size; @@ -73,16 +73,16 @@ public: const glm::vec2& getVertex(int i) const { return _vertices[i]; } void setVertex(int vertex, const glm::vec2& point); - int getVertexCount() const { return _vertexCount; } - void setVertexCount(int vertexCount) { _vertexCount = vertexCount; } - float getDistance() const { return _distance; } - void setDistance(float distance) { _distance = distance; } - bool getAnyInView() const { return _anyInView; } - void setAnyInView(bool anyInView) { _anyInView = anyInView; } - bool getAllInView() const { return _allInView; } - void setAllInView(bool allInView) { _allInView = allInView; } + int getVertexCount() const { return _vertexCount; } + float getDistance() const { return _distance; } + bool getAnyInView() const { return _anyInView; } + bool getAllInView() const { return _allInView; } + unsigned char getProjectionType() const { return _projectionType; } + void setVertexCount(int vertexCount) { _vertexCount = vertexCount; } + void setDistance(float distance) { _distance = distance; } + void setAnyInView(bool anyInView) { _anyInView = anyInView; } + void setAllInView(bool allInView) { _allInView = allInView; } void setProjectionType(unsigned char type) { _projectionType = type; } - unsigned char getProjectionType() const { return _projectionType; } bool pointInside(const glm::vec2& point, bool* matchesVertex = NULL) const; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index b17200448b..d4927a293a 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -70,61 +70,6 @@ VoxelTree::~VoxelTree() { pthread_mutex_destroy(&_deletePendingSetLock); } - -void VoxelTree::recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime, - RecurseVoxelTreeOperation operation, - const glm::vec3& point, void* extraData) { - - long long start = usecTimestampNow(); - - // start case, stack empty, so start with root... - if (stackOfNodes->empty()) { - stackOfNodes->push(rootNode); - } - while (!stackOfNodes->empty()) { - VoxelNode* node = (VoxelNode*)stackOfNodes->top(); - stackOfNodes->pop(); - - if (operation(node, extraData)) { - - //sortChildren... CLOSEST to FURTHEST - // determine the distance sorted order of our children - VoxelNode* sortedChildren[NUMBER_OF_CHILDREN]; - float distancesToChildren[NUMBER_OF_CHILDREN]; - int indexOfChildren[NUMBER_OF_CHILDREN]; // not really needed - int currentCount = 0; - - for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { - VoxelNode* childNode = node->getChildAtIndex(i); - if (childNode) { - // chance to optimize, doesn't need to be actual distance!! Could be distance squared - float distanceSquared = childNode->distanceSquareToPoint(point); - currentCount = insertIntoSortedArrays((void*)childNode, distanceSquared, i, - (void**)&sortedChildren, (float*)&distancesToChildren, - (int*)&indexOfChildren, currentCount, NUMBER_OF_CHILDREN); - } - } - - //iterate sorted children FURTHEST to CLOSEST - for (int i = currentCount-1; i >= 0; i--) { - VoxelNode* child = sortedChildren[i]; - stackOfNodes->push(child); - } - } - - // at this point, we can check to see if we should bail for timing reasons - // because if we bail at this point, then reenter the while, we will basically - // be back to processing the stack from same place we left off, and all can proceed normally - long long now = usecTimestampNow(); - long elapsedTime = now - start; - - if (elapsedTime > allowedTime) { - return; // caller responsible for calling us again to finish the job! - } - } -} - - // Recurses voxel tree calling the RecurseVoxelTreeOperation function for each node. // stops recursion if operation function returns false. void VoxelTree::recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData) { diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 4425bb96b1..24fa723300 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -10,7 +10,6 @@ #define __hifi__VoxelTree__ #include -#include #include #include "CoverageMap.h" @@ -189,12 +188,6 @@ public: void recurseNodeWithOperation(VoxelNode* node, RecurseVoxelTreeOperation operation, void* extraData); void recurseNodeWithOperationDistanceSorted(VoxelNode* node, RecurseVoxelTreeOperation operation, const glm::vec3& point, void* extraData); - - - void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime, - RecurseVoxelTreeOperation operation, - const glm::vec3& point, void* extraData); - signals: void importSize(float x, float y, float z); void importProgress(int progress);