History

some cleanup pre CR

ZappoMan committed 13 years ago

Commit b69c1a31 parent 68d58652 files · +0 −31Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+0−30
@@ -170,7 +170,6 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 169 unmodified lines
170 } else {170 } else {
171 _voxelsUpdated = 0;171 _voxelsUpdated = 0;
172 }172 }
173 //printLog("setupNewVoxelsForDrawing() AFTER treeToArray _voxelsUpdated=%ld _voxelsDirty=%s\n", _voxelsUpdated, (_voxelsDirty ? "yes" : "no"));
174 if (_voxelsUpdated) {173 if (_voxelsUpdated) {
175 _voxelsDirty=true;174 _voxelsDirty=true;
176 }175 }
@@ -200,10 +199,8 @@ void VoxelSystem::copyWrittenDataToReadArrays() { · 23 unmodified lines
200 199
201int VoxelSystem::newTreeToArrays(VoxelNode* node) {200int VoxelSystem::newTreeToArrays(VoxelNode* node) {
202 assert(_viewFrustum); // you must set up _viewFrustum before calling this201 assert(_viewFrustum); // you must set up _viewFrustum before calling this
203
204 int voxelsUpdated = 0;202 int voxelsUpdated = 0;
205 bool shouldRender = false; // assume we don't need to render it203 bool shouldRender = false; // assume we don't need to render it
206
207 // if it's colored, we might need to render it!204 // if it's colored, we might need to render it!
208 if (node->isColored()) {205 if (node->isColored()) {
209 float distanceToNode = node->distanceToCamera(*_viewFrustum);206 float distanceToNode = node->distanceToCamera(*_viewFrustum);
@@ -211,11 +208,8 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 1 unmodified line
211 float childBoundary = boundaryDistanceForRenderLevel(node->getLevel() + 1);208 float childBoundary = boundaryDistanceForRenderLevel(node->getLevel() + 1);
212 bool inBoundary = (distanceToNode <= boundary);209 bool inBoundary = (distanceToNode <= boundary);
213 bool inChildBoundary = (distanceToNode <= childBoundary);210 bool inChildBoundary = (distanceToNode <= childBoundary);
214
215 shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);211 shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);
216 }212 }
217
218
219 node->setShouldRender(shouldRender);213 node->setShouldRender(shouldRender);
220 // let children figure out their renderness214 // let children figure out their renderness
221 for (int i = 0; i < 8; i++) {215 for (int i = 0; i < 8; i++) {
@@ -223,7 +217,6 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 1 unmodified line
223 voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i));217 voxelsUpdated += newTreeToArrays(node->getChildAtIndex(i));
224 }218 }
225 }219 }
226
227 if (_alwaysRenderFullVBO) {220 if (_alwaysRenderFullVBO) {
228 voxelsUpdated += newway__updateNodeInArray(node);221 voxelsUpdated += newway__updateNodeInArray(node);
229 } else {222 } else {
@@ -438,7 +431,6 @@ void VoxelSystem::updateVBOs() { · 208 unmodified lines
438void VoxelSystem::render() {431void VoxelSystem::render() {
439 PerformanceWarning warn(_renderWarningsOn, "render()");432 PerformanceWarning warn(_renderWarningsOn, "render()");
440 glPushMatrix();433 glPushMatrix();
441 //cleanupRemovedVoxels();
442 updateVBOs();434 updateVBOs();
443 // tell OpenGL where to find vertex and color information435 // tell OpenGL where to find vertex and color information
444 glEnableClientState(GL_VERTEX_ARRAY);436 glEnableClientState(GL_VERTEX_ARRAY);
@@ -635,25 +627,3 @@ void VoxelSystem::removeOutOfView() { · 190 unmodified lines
635 _tree->recurseTreeWithOperation(removeOutOfViewOperation,(void*)this);627 _tree->recurseTreeWithOperation(removeOutOfViewOperation,(void*)this);
636 pthread_mutex_unlock(&_voxelCleanupLock);628 pthread_mutex_unlock(&_voxelCleanupLock);
637}629}
638
639// Deletes the VoxelNodes from the _removedVoxels bag, but also cleans up those items from the vertex arrays
640void VoxelSystem::cleanupRemovedVoxels() {
641 if (!pthread_mutex_trylock(&_voxelCleanupLock)) {
642 while (!_removedVoxels.isEmpty()){
643 VoxelNode* node = _removedVoxels.extract();
644 // If the voxel is in the vertex, and it was previously rendered, then set it's vertices to "hidden"
645 if (node->isKnownBufferIndex() && node->getShouldRender()) {
646 unsigned long nodeIndex = node->getBufferIndex();
647 _voxelDirtyArray[nodeIndex] = true;
648 for (int j = 0; j < VERTEX_POINTS_PER_VOXEL; j++ ) {
649 GLfloat* writeVerticesAt = _writeVerticesArray + (nodeIndex * VERTEX_POINTS_PER_VOXEL);
650 *(writeVerticesAt+j) = FLT_MAX;
651 }
652 _voxelsDirty = true; // yep
653 }
654 _unusedArraySpace++; // track this so we can blow away our arrays if they get too much
655 delete node; // actually delete the node
656 }
657 pthread_mutex_unlock(&_voxelCleanupLock);
658 }
659}