@@ -6,20 +6,15 @@ import { UNLOADED, LOADING, PARSING, LOADED, FAILED } from './constants.js';
66
77const PLUGIN_REGISTERED = Symbol ( 'PLUGIN_REGISTERED' ) ;
88
9- /**
10- * Function for provided to sort all tiles for prioritizing loading/unloading.
11- *
12- * @param {Tile } a
13- * @param {Tile } b
14- * @returns number
15- */
9+ // priority queue sort function that takes two tiles to compare. Returning 1 means
10+ // "tile a" is loaded first.
1611const priorityCallback = ( a , b ) => {
1712
18- if ( a . __depth !== b . __depth ) {
13+ if ( a . __depthFromRenderedParent !== b . __depthFromRenderedParent ) {
1914
20- // TODO: is it best to sort this by "depth from rendered parent"?
21- // load shallower tiles first
22- return a . __depth > b . __depth ? - 1 : 1 ;
15+ // load shallower tiles first using "depth from rendered parent" to help
16+ // even out depth disparities caused by non-content parent tiles
17+ return a . __depthFromRenderedParent > b . __depthFromRenderedParent ? - 1 : 1 ;
2318
2419 } else if ( a . __inFrustum !== b . __inFrustum ) {
2520
@@ -48,7 +43,8 @@ const priorityCallback = ( a, b ) => {
4843
4944} ;
5045
51- // lru cache unload callback that takes two tiles to compare
46+ // lru cache unload callback that takes two tiles to compare. Returning 1 means "tile a"
47+ // is unloaded first.
5248const lruPriorityCallback = ( a , b ) => {
5349
5450 if ( a . __depthFromRenderedParent !== b . __depthFromRenderedParent ) {
@@ -370,8 +366,9 @@ export class TilesRendererBase {
370366
371367 } else {
372368
369+ // increment the "depth from parent" when we encounter a new tile with content
373370 tile . __depth = parentTile . __depth + 1 ;
374- tile . __depthFromRenderedParent = parentTile . __depthFromRenderedParent + ( parentTile . __contentEmpty ? 0 : 1 ) ;
371+ tile . __depthFromRenderedParent = parentTile . __depthFromRenderedParent + ( tile . __contentEmpty ? 0 : 1 ) ;
375372
376373 tile . refine = tile . refine || parentTile . refine ;
377374
0 commit comments