History

Merge branch 'master' of https://github.com/worklist/hifi

Andrzej Kapolka committed 13 years ago

Commit 0cff1272 parents 785e55e 507e42424 files · +389 −128Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+80−14
@@ -139,22 +139,22 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 138 unmodified lines
139139 double start = usecTimestampNow();
140140 double sinceLastTime = (start - _setupNewVoxelsForDrawingLastFinished) / 1000.0;
141141
142− if (sinceLastTime <= std::max(_setupNewVoxelsForDrawingLastElapsed,SIXTY_FPS_IN_MILLISECONDS)) {
142+ if (sinceLastTime <= std::max(_setupNewVoxelsForDrawingLastElapsed, SIXTY_FPS_IN_MILLISECONDS)) {
143143 return; // bail early, it hasn't been long enough since the last time we ran
144144 }
145145
146146 double sinceLastViewCulling = (start - _lastViewCulling) / 1000.0;
147−
148147 // If the view frustum has changed, since last time, then remove nodes that are out of view
149− if ((sinceLastViewCulling >= VIEW_CULLING_RATE_IN_MILLISECONDS) && hasViewChanged()) {
148+ if ((sinceLastViewCulling >= std::max(_lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)) && hasViewChanged()) {
150149 _lastViewCulling = start;
151150 removeOutOfView();
151+ double endViewCulling = usecTimestampNow();
152+ _lastViewCullingElapsed = (endViewCulling - start) / 1000.0;
152153 }
153154
154155 if (_tree->isDirty()) {
155156 PerformanceWarning warn(_renderWarningsOn, "calling... newTreeToArrays()");
156157 _callsToTreesToArrays++;
157−
158158 if (_alwaysRenderFullVBO) {
159159 _voxelsInWriteArrays = 0; // reset our VBO
160160 }
@@ -171,7 +171,7 @@ void VoxelSystem::setupNewVoxelsForDrawing() { · 10 unmodified lines
171171 copyWrittenDataToReadArrays();
172172
173173 double end = usecTimestampNow();
174− double elapsedmsec = (end - start)/1000.0;
174+ double elapsedmsec = (end - start) / 1000.0;
175175 _setupNewVoxelsForDrawingLastFinished = end;
176176 _setupNewVoxelsForDrawingLastElapsed = elapsedmsec;
177177 }
@@ -220,6 +220,11 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { · 42 unmodified lines
220220 }
221221
222222 int VoxelSystem::newway__updateNodeInArray(VoxelNode* node) {
223+ // If we've run out of room, then just bail...
224+ if (_voxelsInWriteArrays >= MAX_VOXELS_PER_SYSTEM) {
225+ return 0;
226+ }
227+
223228 if (node->getShouldRender()) {
224229 glm::vec3 startVertex = node->getCorner();
225230 float voxelScale = node->getScale();
@@ -294,7 +299,7 @@ void VoxelSystem::init() { · 68 unmodified lines
294299 _callsToTreesToArrays = 0;
295300 _setupNewVoxelsForDrawingLastFinished = 0;
296301 _setupNewVoxelsForDrawingLastElapsed = 0;
297− _lastViewCulling = 0;
302+ _lastViewCullingElapsed = _lastViewCulling = 0;
298303
299304 // When we change voxels representations in the arrays, we'll update this
300305 _voxelsDirty = false;
@@ -583,17 +588,71 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { · 282 unmodified lines
583588 setupNewVoxelsForDrawing();
584589 }
585590
591+// combines the removeOutOfView args into a single class
592+class removeOutOfViewArgs {
593+public:
594+ VoxelSystem* thisVoxelSystem;
595+ VoxelNodeBag dontRecurseBag;
596+ unsigned long nodesScanned;
597+ unsigned long nodesRemoved;
598+ unsigned long nodesInside;
599+ unsigned long nodesIntersect;
600+ unsigned long nodesOutside;
601+
602+ removeOutOfViewArgs(VoxelSystem* voxelSystem) :
603+ thisVoxelSystem(voxelSystem),
604+ dontRecurseBag(),
605+ nodesScanned(0),
606+ nodesRemoved(0),
607+ nodesInside(0),
608+ nodesIntersect(0),
609+ nodesOutside(0)
610+ { }
611+};
612+
586613 // "Remove" voxels from the tree that are not in view. We don't actually delete them,
587614 // we remove them from the tree and place them into a holding area for later deletion
588615 bool VoxelSystem::removeOutOfViewOperation(VoxelNode* node, void* extraData) {
589− VoxelSystem* thisVoxelSystem = (VoxelSystem*) extraData;
590− _nodeCount++;
616+ removeOutOfViewArgs* args = (removeOutOfViewArgs*)extraData;
617+
618+ // If our node was previously added to the don't recurse bag, then return false to
619+ // stop the further recursion. This means that the whole node and it's children are
620+ // known to be in view, so don't recurse them
621+ if (args->dontRecurseBag.contains(node)) {
622+ args->dontRecurseBag.remove(node);
623+ return false; // stop recursion
624+ }
625+
626+ VoxelSystem* thisVoxelSystem = args->thisVoxelSystem;
627+ args->nodesScanned++;
591628 // Need to operate on our child nodes, so we can remove them
592629 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
593630 VoxelNode* childNode = node->getChildAtIndex(i);
594− if (childNode && !childNode->isInView(*thisVoxelSystem->_viewFrustum)) {
595− node->removeChildAtIndex(i);
596− thisVoxelSystem->_removedVoxels.insert(childNode);
631+ if (childNode) {
632+ ViewFrustum::location inFrustum = childNode->inFrustum(*thisVoxelSystem->_viewFrustum);
633+ switch (inFrustum) {
634+ case ViewFrustum::OUTSIDE: {
635+ args->nodesOutside++;
636+ args->nodesRemoved++;
637+ node->removeChildAtIndex(i);
638+ thisVoxelSystem->_removedVoxels.insert(childNode);
639+ // by removing the child, it will not get recursed!
640+ } break;
641+ case ViewFrustum::INSIDE: {
642+ // if the child node is fully INSIDE the view, then there's no need to recurse it
643+ // because we know all it's children will also be in the view, so we want to
644+ // tell the caller to NOT recurse this child
645+ args->nodesInside++;
646+ args->dontRecurseBag.insert(childNode);
647+ } break;
648+ case ViewFrustum::INTERSECT: {
649+ // if the child node INTERSECTs the view, then we don't want to remove it because
650+ // it is at least partially in view. But we DO want to recurse the children because
651+ // some of them may not be in view... nothing specifically to do, just keep iterating
652+ // the children
653+ args->nodesIntersect++;
654+ } break;
655+ }
597656 }
598657 }
599658 return true; // keep going!
@@ -609,9 +668,16 @@ bool VoxelSystem::hasViewChanged() { · 9 unmodified lines
609668 }
610669
611670 void VoxelSystem::removeOutOfView() {
612− PerformanceWarning warn(_renderWarningsOn, "removeOutOfView()"); // would like to include removedCount, _nodeCount, _removedVoxels.count()
613− _nodeCount = 0;
614− _tree->recurseTreeWithOperation(removeOutOfViewOperation,(void*)this);
671+ PerformanceWarning warn(_renderWarningsOn, "removeOutOfView()");
672+ removeOutOfViewArgs args(this);
673+ _tree->recurseTreeWithOperation(removeOutOfViewOperation,(void*)&args);
674+
675+ if (_renderWarningsOn) {
676+ printLog("removeOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld bag.count()=%d \n",
677+ args.nodesScanned, args.nodesRemoved, args.nodesInside,
678+ args.nodesIntersect, args.nodesOutside, args.dontRecurseBag.count()
679+ );
680+ }
615681 }
616682
617683 bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelDetail& detail, float& distance) {