memory wastes and code cleaning PR comments

This commit is contained in:
atlante45 2013-09-04 15:12:24 -07:00
parent 1781abe937
commit 5da525fc3e
21 changed files with 47 additions and 225 deletions

View file

@ -42,8 +42,8 @@ public:
float getLastInputLoudness() const { return _lastInputLoudness; } float getLastInputLoudness() const { return _lastInputLoudness; }
void setLastAcceleration(glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; } void setLastAcceleration(const glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; }
void setLastVelocity(glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; } void setLastVelocity(const glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; }
void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; } void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; }
int getJitterBufferSamples() { return _jitterBufferSamples; } int getJitterBufferSamples() { return _jitterBufferSamples; }

View file

@ -416,7 +416,6 @@ Menu::Menu() :
Menu::~Menu() { Menu::~Menu() {
bandwidthDetailsClosed(); bandwidthDetailsClosed();
voxelStatsDetailsClosed(); voxelStatsDetailsClosed();
delete _voxelModeActionsGroup;
} }
void Menu::loadSettings(QSettings* settings) { void Menu::loadSettings(QSettings* settings) {

View file

@ -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; return startVertex + glm::vec3(identityVertex[0], identityVertex[1], identityVertex[2]) * voxelScale;
} }
bool VoxelSystem::_perlinModulateProgramInitialized = false;
ProgramObject VoxelSystem::_perlinModulateProgram; ProgramObject VoxelSystem::_perlinModulateProgram;
void VoxelSystem::init() { void VoxelSystem::init() {
@ -634,7 +633,7 @@ void VoxelSystem::init() {
// create our simple fragment shader if we're the first system to init // create our simple fragment shader if we're the first system to init
if (!_perlinModulateProgramInitialized) { if (!_perlinModulateProgram.isLinked()) {
switchToResourcesParentIfRequired(); switchToResourcesParentIfRequired();
_perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert"); _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert");
_perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag"); _perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag");
@ -643,8 +642,6 @@ void VoxelSystem::init() {
_perlinModulateProgram.bind(); _perlinModulateProgram.bind();
_perlinModulateProgram.setUniformValue("permutationNormalTexture", 0); _perlinModulateProgram.setUniformValue("permutationNormalTexture", 0);
_perlinModulateProgram.release(); _perlinModulateProgram.release();
_perlinModulateProgramInitialized = true;
} }
_initialized = true; _initialized = true;
} }

View file

@ -34,8 +34,8 @@ public:
VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM); VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM);
~VoxelSystem(); ~VoxelSystem();
void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }; void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }
int getDataSourceID() const { return _dataSourceID; }; int getDataSourceID() const { return _dataSourceID; }
int parseData(unsigned char* sourceBuffer, int numBytes); int parseData(unsigned char* sourceBuffer, int numBytes);
@ -45,8 +45,8 @@ public:
ViewFrustum* getViewFrustum() const {return _viewFrustum;} ViewFrustum* getViewFrustum() const {return _viewFrustum;}
void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;} void setViewFrustum(ViewFrustum* viewFrustum) {_viewFrustum = viewFrustum;}
unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}; unsigned long getVoxelsUpdated() const {return _voxelsUpdated;}
unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;}; unsigned long getVoxelsRendered() const {return _voxelsInReadArrays;}
void loadVoxelsFile(const char* fileName,bool wantColorRandomizer); void loadVoxelsFile(const char* fileName,bool wantColorRandomizer);
void writeToSVOFile(const char* filename, VoxelNode* node) const; void writeToSVOFile(const char* filename, VoxelNode* node) const;
@ -207,8 +207,7 @@ private:
void updatePartialVBOs(); // multiple segments, only dirty voxels void updatePartialVBOs(); // multiple segments, only dirty voxels
bool _voxelsDirty; bool _voxelsDirty;
static bool _perlinModulateProgramInitialized;
static ProgramObject _perlinModulateProgram; static ProgramObject _perlinModulateProgram;
int _hookID; int _hookID;

View file

@ -43,7 +43,6 @@ AvatarVoxelSystem::~AvatarVoxelSystem() {
} }
} }
bool AvatarVoxelSystem::_skinProgramInitialized = false;
ProgramObject AvatarVoxelSystem::_skinProgram; ProgramObject AvatarVoxelSystem::_skinProgram;
int AvatarVoxelSystem::_boneMatricesLocation; int AvatarVoxelSystem::_boneMatricesLocation;
int AvatarVoxelSystem::_boneIndicesLocation; 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); 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 // 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.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert");
_skinProgram.link(); _skinProgram.link();
_skinProgramInitialized = true;
} }
_boneMatricesLocation = _skinProgram.uniformLocation("boneMatrices"); _boneMatricesLocation = _skinProgram.uniformLocation("boneMatrices");

View file

@ -74,8 +74,7 @@ private:
GLuint _vboBoneWeightsID; GLuint _vboBoneWeightsID;
QNetworkReply* _voxelReply; QNetworkReply* _voxelReply;
static bool _skinProgramInitialized;
static ProgramObject _skinProgram; static ProgramObject _skinProgram;
static int _boneMatricesLocation; static int _boneMatricesLocation;
static int _boneIndicesLocation; static int _boneIndicesLocation;

View file

@ -54,9 +54,6 @@ Face::~Face() {
glDeleteTextures(1, &_depthTextureID); glDeleteTextures(1, &_depthTextureID);
} }
} }
glDeleteBuffers(1, &_vboID);
glDeleteBuffers(1, &_iboID);
} }
void Face::setFrameFromWebcam() { void Face::setFrameFromWebcam() {

View file

@ -46,7 +46,6 @@ const float IRIS_RADIUS = 0.007;
const float IRIS_PROTRUSION = 0.0145f; const float IRIS_PROTRUSION = 0.0145f;
const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png"; const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png";
bool Head::_irisProgramInitialized = false;
ProgramObject Head::_irisProgram; ProgramObject Head::_irisProgram;
GLuint Head::_irisTextureID; GLuint Head::_irisTextureID;
int Head::_eyePositionLocation; int Head::_eyePositionLocation;
@ -97,12 +96,8 @@ Head::Head(Avatar* owningAvatar) :
} }
} }
Head::~Head() {
glDeleteTextures(1, &_irisTextureID);
}
void Head::init() { void Head::init() {
if (!_irisProgramInitialized) { if (!_irisProgram.isLinked()) {
switchToResourcesParentIfRequired(); switchToResourcesParentIfRequired();
_irisProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert"); _irisProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert");
_irisProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag"); _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_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
_irisProgramInitialized = true;
} }
} }

View file

@ -38,7 +38,6 @@ class ProgramObject;
class Head : public HeadData { class Head : public HeadData {
public: public:
Head(Avatar* owningAvatar); Head(Avatar* owningAvatar);
~Head();
void init(); void init();
void reset(); void reset();
@ -73,7 +72,7 @@ public:
Face& getFace() { return _face; } Face& getFace() { return _face; }
const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected) 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; } glm::vec3 calculateAverageEyePosition() { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; }
float yawRate; float yawRate;
@ -131,8 +130,7 @@ private:
bool _cameraFollowsHead; bool _cameraFollowsHead;
float _cameraFollowHeadRate; float _cameraFollowHeadRate;
Face _face; Face _face;
static bool _irisProgramInitialized;
static ProgramObject _irisProgram; static ProgramObject _irisProgram;
static GLuint _irisTextureID; static GLuint _irisTextureID;
static int _eyePositionLocation; static int _eyePositionLocation;

View file

@ -30,7 +30,7 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) :
this->QDialog::setLayout(form); this->QDialog::setLayout(form);
// Setup labels // 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::Item item = (VoxelSceneStats::Item)(i);
VoxelSceneStats::ItemInfo& itemInfo = _model->getItemInfo(item); VoxelSceneStats::ItemInfo& itemInfo = _model->getItemInfo(item);
QLabel* label = _labels[item] = new QLabel(); QLabel* label = _labels[item] = new QLabel();
@ -54,7 +54,7 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) :
} }
VoxelStatsDialog::~VoxelStatsDialog() { VoxelStatsDialog::~VoxelStatsDialog() {
for (int i = 0; i <(int)VoxelSceneStats::ITEM_COUNT; ++i) { for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; ++i) {
delete _labels[i]; delete _labels[i];
} }
} }
@ -63,7 +63,7 @@ void VoxelStatsDialog::paintEvent(QPaintEvent* event) {
// Update labels // Update labels
char strBuf[256]; 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); VoxelSceneStats::Item item = (VoxelSceneStats::Item)(i);
QLabel* label = _labels[item]; QLabel* label = _labels[item];
snprintf(strBuf, sizeof(strBuf), "%s", _model->getItemValue(item)); snprintf(strBuf, sizeof(strBuf), "%s", _model->getItemValue(item));

View file

@ -73,13 +73,13 @@ public:
void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; } void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; }
float getBodyPitch() const { return _bodyPitch; } float getBodyPitch() const { return _bodyPitch; }
void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; } void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; }
float getBodyRoll() const {return _bodyRoll; } float getBodyRoll() const { return _bodyRoll; }
void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; }
// Hand State // Hand State
void setHandState(char s) { _handState = s; } void setHandState(char s) { _handState = s; }
char getHandState() const {return _handState; } char getHandState() const { return _handState; }
// getters for camera details // getters for camera details
const glm::vec3& getCameraPosition() const { return _cameraPosition; } const glm::vec3& getCameraPosition() const { return _cameraPosition; }

View file

@ -33,7 +33,7 @@ public:
NetworkPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength); NetworkPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength);
sockaddr& getAddress() { return _address; } sockaddr& getAddress() { return _address; }
ssize_t getLength() const { return _packetLength; } ssize_t getLength() const { return _packetLength; }
unsigned char* getData() { return &_packetData[0]; } unsigned char* getData() { return &_packetData[0]; }
const sockaddr& getAddress() const { return _address; } const sockaddr& getAddress() const { return _address; }

View file

@ -156,7 +156,6 @@ private:
class NodeListIterator : public std::iterator<std::input_iterator_tag, Node> { class NodeListIterator : public std::iterator<std::input_iterator_tag, Node> {
public: public:
NodeListIterator(const NodeList* nodeList, int nodeIndex); NodeListIterator(const NodeList* nodeList, int nodeIndex);
~NodeListIterator() {}
int getNodeIndex() { return _nodeIndex; } int getNodeIndex() { return _nodeIndex; }

View file

@ -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 <stdio.h>
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++;
}

View file

@ -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 <cstring> // 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__) */

View file

@ -16,7 +16,7 @@ class StDev {
void addValue(float v); void addValue(float v);
float getAverage(); float getAverage();
float getStDev(); float getStDev();
int getSamples() {return sampleCount;} int getSamples() const { return sampleCount; }
private: private:
float * data; float * data;
int sampleCount; int sampleCount;

View file

@ -109,7 +109,10 @@ TagList::TagList(std::stringstream &ss) :
} }
TagList::~TagList() { TagList::~TagList() {
_data.clear(); while (!_data.empty()) {
delete _data.back();
_data.pop_back();
}
} }
TagCompound::TagCompound(std::stringstream &ss) : TagCompound::TagCompound(std::stringstream &ss) :
@ -150,7 +153,10 @@ TagCompound::TagCompound(std::stringstream &ss) :
} }
TagCompound::~TagCompound() { TagCompound::~TagCompound() {
_data.clear(); while (!_data.empty()) {
delete _data.back();
_data.pop_back();
}
} }
TagIntArray::TagIntArray(std::stringstream &ss) : Tag(TAG_Int_Array, ss) { TagIntArray::TagIntArray(std::stringstream &ss) : Tag(TAG_Int_Array, ss) {

View file

@ -53,7 +53,7 @@ public:
float getEnclosingRadius() const; float getEnclosingRadius() const;
bool isColored() const { return (_trueColor[3]==1); } bool isColored() const { return _trueColor[3] == 1; }
bool isInView(const ViewFrustum& viewFrustum) const; bool isInView(const ViewFrustum& viewFrustum) const;
ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const; ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const;
float distanceToCamera(const ViewFrustum& viewFrustum) const; float distanceToCamera(const ViewFrustum& viewFrustum) const;
@ -70,8 +70,8 @@ public:
void printDebugDetails(const char* label) const; void printDebugDetails(const char* label) const;
bool isDirty() const { return _isDirty; } bool isDirty() const { return _isDirty; }
void clearDirtyBit() { _isDirty = false; } void clearDirtyBit() { _isDirty = false; }
bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); } bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); }
void markWithChangedTime() { _lastChanged = usecTimestampNow(); } void markWithChangedTime() { _lastChanged = usecTimestampNow(); }
uint64_t getLastChanged() const { return _lastChanged; } uint64_t getLastChanged() const { return _lastChanged; }
void handleSubtreeChanged(VoxelTree* myTree); void handleSubtreeChanged(VoxelTree* myTree);
@ -103,18 +103,18 @@ public:
const nodeColor& getColor() const { return _trueColor; }; const nodeColor& getColor() const { return _trueColor; };
#endif #endif
void setDensity(float density) { _density = density; } void setDensity(float density) { _density = density; }
float getDensity() const { return _density; } float getDensity() const { return _density; }
void setSourceID(uint16_t sourceID) { _sourceID = sourceID; } void setSourceID(uint16_t sourceID) { _sourceID = sourceID; }
uint16_t getSourceID() const { return _sourceID; } uint16_t getSourceID() const { return _sourceID; }
static void addDeleteHook(VoxelNodeDeleteHook* hook); static void addDeleteHook(VoxelNodeDeleteHook* hook);
static void removeDeleteHook(VoxelNodeDeleteHook* hook); static void removeDeleteHook(VoxelNodeDeleteHook* hook);
void recalculateSubTreeNodeCount(); void recalculateSubTreeNodeCount();
unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; } unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; }
unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; } unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; }
unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; } unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; }
private: private:
void calculateAABox(); void calculateAABox();

View file

@ -19,7 +19,7 @@ class BoundingBox {
public: public:
enum { BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT, VERTEX_COUNT }; 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) {} BoundingBox() : _set(false) {}
glm::vec2 corner; glm::vec2 corner;
glm::vec2 size; glm::vec2 size;
@ -73,16 +73,16 @@ public:
const glm::vec2& getVertex(int i) const { return _vertices[i]; } const glm::vec2& getVertex(int i) const { return _vertices[i]; }
void setVertex(int vertex, const glm::vec2& point); void setVertex(int vertex, const glm::vec2& point);
int getVertexCount() const { return _vertexCount; } int getVertexCount() const { return _vertexCount; }
void setVertexCount(int vertexCount) { _vertexCount = vertexCount; } float getDistance() const { return _distance; }
float getDistance() const { return _distance; } bool getAnyInView() const { return _anyInView; }
void setDistance(float distance) { _distance = distance; } bool getAllInView() const { return _allInView; }
bool getAnyInView() const { return _anyInView; } unsigned char getProjectionType() const { return _projectionType; }
void setAnyInView(bool anyInView) { _anyInView = anyInView; } void setVertexCount(int vertexCount) { _vertexCount = vertexCount; }
bool getAllInView() const { return _allInView; } void setDistance(float distance) { _distance = distance; }
void setAllInView(bool allInView) { _allInView = allInView; } void setAnyInView(bool anyInView) { _anyInView = anyInView; }
void setAllInView(bool allInView) { _allInView = allInView; }
void setProjectionType(unsigned char type) { _projectionType = type; } void setProjectionType(unsigned char type) { _projectionType = type; }
unsigned char getProjectionType() const { return _projectionType; }
bool pointInside(const glm::vec2& point, bool* matchesVertex = NULL) const; bool pointInside(const glm::vec2& point, bool* matchesVertex = NULL) const;

View file

@ -70,61 +70,6 @@ VoxelTree::~VoxelTree() {
pthread_mutex_destroy(&_deletePendingSetLock); 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. // Recurses voxel tree calling the RecurseVoxelTreeOperation function for each node.
// stops recursion if operation function returns false. // stops recursion if operation function returns false.
void VoxelTree::recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData) { void VoxelTree::recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData) {

View file

@ -10,7 +10,6 @@
#define __hifi__VoxelTree__ #define __hifi__VoxelTree__
#include <set> #include <set>
#include <PointerStack.h>
#include <SimpleMovingAverage.h> #include <SimpleMovingAverage.h>
#include "CoverageMap.h" #include "CoverageMap.h"
@ -189,12 +188,6 @@ public:
void recurseNodeWithOperation(VoxelNode* node, RecurseVoxelTreeOperation operation, void* extraData); void recurseNodeWithOperation(VoxelNode* node, RecurseVoxelTreeOperation operation, void* extraData);
void recurseNodeWithOperationDistanceSorted(VoxelNode* node, RecurseVoxelTreeOperation operation, void recurseNodeWithOperationDistanceSorted(VoxelNode* node, RecurseVoxelTreeOperation operation,
const glm::vec3& point, void* extraData); const glm::vec3& point, void* extraData);
void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime,
RecurseVoxelTreeOperation operation,
const glm::vec3& point, void* extraData);
signals: signals:
void importSize(float x, float y, float z); void importSize(float x, float y, float z);
void importProgress(int progress); void importProgress(int progress);