Parcourir la source

Add relative depth from parent

Garrett Johnson il y a 5 ans
Parent
commit
b6f85a17c5
2 fichiers modifiés avec 22 ajouts et 4 suppressions
  1. 7 4
      src/base/TilesRendererBase.js
  2. 15 0
      src/base/traverseFunctions.js

+ 7 - 4
src/base/TilesRendererBase.js

@@ -10,7 +10,7 @@ import { UNLOADED, LOADING, PARSING, LOADED, FAILED } from './constants.js';
 // TODO: Make sure active state works as expected
 
 // Function for sorting the evicted LRU items. We should evict the shallowest depth first.
-const priorityCallback = tile => 1 / tile.__depth;
+const priorityCallback = tile => 1 / ( tile.__depthFromRenderedParent + 1 );
 
 export class TilesRendererBase {
 
@@ -191,6 +191,7 @@ export class TilesRendererBase {
 
 		tile.__loadAbort = null;
 
+		tile.__depthFromRenderedParent = - 1;
 		if ( parentTile === null ) {
 
 			tile.__depth = 0;
@@ -311,10 +312,10 @@ export class TilesRendererBase {
 
 			}
 
+			t.__buffer = null;
 			t.__loadingState = UNLOADED;
 			t.__loadIndex ++;
 
-			// TODO: Removing from the queues here is slow?
 			parseQueue.remove( t );
 			downloadQueue.remove( t );
 
@@ -322,7 +323,6 @@ export class TilesRendererBase {
 
 		tile.__loadIndex ++;
 		const loadIndex = tile.__loadIndex;
-		const priority = 1 / ( tile.__depth + 1 );
 		const stats = this.stats;
 
 		const controller = new AbortController();
@@ -374,8 +374,9 @@ export class TilesRendererBase {
 				stats.parsing ++;
 				tile.__loadAbort = null;
 				tile.__loadingState = PARSING;
+				tile.__buffer = buffer;
 
-				return parseQueue.add( buffer, buffer => {
+				return parseQueue.add( tile, tile => {
 
 					// if it has been unloaded then the tile has been disposed
 					if ( tile.__loadIndex !== loadIndex ) {
@@ -386,6 +387,8 @@ export class TilesRendererBase {
 
 					const uri = tile.content.uri;
 					const extension = uri.split( /\./g ).pop();
+					const buffer = tile.__buffer;
+					tile.__buffer = null;
 
 					return this.parseTile( buffer, tile, extension );
 

+ 15 - 0
src/base/traverseFunctions.js

@@ -212,10 +212,16 @@ export function skipTraversal( tile, renderer ) {
 
 	}
 
+	const parent = tile.parent;
+	const parentDepthToParent = parent ? parent.__depthFromRenderedParent : - 1;
+	tile.__depthFromRenderedParent = parentDepthToParent;
+
 	// Request the tile contents or mark it as visible if we've found a leaf.
 	const lruCache = renderer.lruCache;
 	if ( tile.__isLeaf ) {
 
+		tile.__depthFromRenderedParent = parentDepthToParent + 1;
+
 		if ( tile.__loadingState === LOADED ) {
 
 			if ( tile.__inFrustum ) {
@@ -232,6 +238,7 @@ export function skipTraversal( tile, renderer ) {
 			renderer.requestTileContents( tile );
 
 		}
+
 		return;
 
 	}
@@ -256,6 +263,14 @@ export function skipTraversal( tile, renderer ) {
 
 	}
 
+	// Increment the relative depth of the node to the nearest rendered parent if it has content
+	// and is being rendered.
+	if ( meetsSSE && hasContent ) {
+
+		tile.__depthFromRenderedParent = parentDepthToParent + 1;
+
+	}
+
 	// If we've met the SSE requirements and we can load content then fire a fetch.
 	if ( meetsSSE && ! loadedContent && ! lruCache.isFull() && hasContent ) {