@@ -434,7 +434,7 @@ define([
434
434
this . allTilesLoaded = new Event ( ) ;
435
435
436
436
/**
437
- * The event fired to indicate that a tile's content was unloaded from the cache .
437
+ * The event fired to indicate that a tile's content was unloaded.
438
438
* <p>
439
439
* The unloaded {@link Cesium3DTile} is passed to the event listener.
440
440
* </p>
@@ -924,11 +924,6 @@ define([
924
924
// If there is a parentTile, add the root of the currently loading tileset
925
925
// to parentTile's children, and increment its numberOfChildrenWithoutContent
926
926
if ( defined ( parentTile ) ) {
927
- if ( parentTile . children . length > 0 ) {
928
- // Unload the old subtree if it exists
929
- unloadExpiredSubtree ( parentTile ) ;
930
- }
931
-
932
927
parentTile . children . push ( rootTile ) ;
933
928
++ parentTile . numberOfChildrenWithoutContent ;
934
929
@@ -1015,13 +1010,6 @@ define([
1015
1010
}
1016
1011
}
1017
1012
1018
- function recheckRefinement ( tile ) {
1019
- var ancestor = getAncestorWithContent ( tile ) ;
1020
- if ( defined ( ancestor ) && ( ancestor . refine === Cesium3DTileRefine . REPLACE ) ) {
1021
- prepareRefiningTiles ( [ ancestor ] ) ;
1022
- }
1023
- }
1024
-
1025
1013
var scratchPositionNormal = new Cartesian3 ( ) ;
1026
1014
var scratchCartographic = new Cartographic ( ) ;
1027
1015
var scratchMatrix = new Matrix4 ( ) ;
@@ -1161,71 +1149,23 @@ define([
1161
1149
1162
1150
///////////////////////////////////////////////////////////////////////////
1163
1151
1164
- var scratchJulianDate = new JulianDate ( ) ;
1165
-
1166
- function updateExpireDate ( tile ) {
1167
- if ( defined ( tile . expireDuration ) ) {
1168
- var expireDurationDate = JulianDate . now ( scratchJulianDate ) ;
1169
- JulianDate . addSeconds ( expireDurationDate , tile . expireDuration , expireDurationDate ) ;
1170
-
1171
- if ( defined ( tile . expireDate ) ) {
1172
- if ( JulianDate . lessThan ( expireDurationDate , tile . expireDate ) ) {
1173
- JulianDate . clone ( expireDurationDate , tile . expireDate ) ;
1174
- }
1175
- } else {
1176
- tile . expireDate = JulianDate . clone ( expireDurationDate ) ;
1177
- }
1178
- }
1179
- }
1180
-
1181
- function unloadExpiredSubtree ( tile ) {
1152
+ function unloadSubtree ( tileset , tile ) {
1153
+ var stats = tileset . _statistics ;
1182
1154
var stack = [ ] ;
1183
1155
stack . push ( tile ) ;
1184
1156
while ( stack . length > 0 ) {
1185
1157
tile = stack . pop ( ) ;
1158
+ unloadTile ( tileset , tile , false ) ;
1186
1159
var children = tile . children ;
1187
1160
var length = children . length ;
1188
1161
for ( var i = 0 ; i < length ; ++ i ) {
1189
1162
var child = children [ i ] ;
1190
- child . destroy ( ) ;
1163
+ -- stats . numberTotal ;
1191
1164
stack . push ( child ) ;
1192
1165
}
1193
1166
}
1194
- tile . children = [ ] ;
1195
- tile . unloadContent ( ) ;
1196
- }
1197
-
1198
- function unloadExpiredLeafTile ( tile ) {
1199
- tile . destroy ( ) ;
1200
- var parent = tile . parent ;
1201
- if ( defined ( parent ) ) {
1202
- var index = parent . children . indexOf ( tile ) ;
1203
- parent . children . splice ( index , 1 ) ;
1204
- recheckRefinement ( parent ) ;
1205
- }
1206
- }
1207
-
1208
- function unloadExpiredTile ( tile ) {
1209
- if ( tile . children . length === 0 ) {
1210
- unloadExpiredLeafTile ( tile ) ;
1211
- return ;
1212
- }
1213
1167
1214
- if ( tile . hasContent ) {
1215
- // When the tile is expired and the request fails, there is no longer any content to show.
1216
- // Unload the tile's old content and replace it with Empty3DTileContent.
1217
- tile . unloadContentAndMakeEmpty ( ) ;
1218
- // Now that the tile is empty recheck its parent's refinement
1219
- recheckRefinement ( tile . parent ) ;
1220
- } else if ( tile . hasTilesetContent ) {
1221
- // When the tile is the root of an external tileset, unload the entire subtree
1222
- unloadExpiredSubtree ( tile ) ;
1223
- // Also destroy this tile
1224
- unloadExpiredLeafTile ( tile ) ;
1225
- }
1226
- }
1227
- function isVisible ( visibilityPlaneMask ) {
1228
- return visibilityPlaneMask !== CullingVolume . MASK_OUTSIDE ;
1168
+ tile . children = [ ] ;
1229
1169
}
1230
1170
1231
1171
function requestContent ( tileset , tile , outOfCore ) {
@@ -1236,7 +1176,7 @@ define([
1236
1176
return ;
1237
1177
}
1238
1178
1239
- var expired = ( tile . content . state === Cesium3DTileContentState . EXPIRED ) ;
1179
+ var expired = tile . isContentExpired ( ) ;
1240
1180
1241
1181
tile . requestContent ( ) ;
1242
1182
@@ -1247,25 +1187,28 @@ define([
1247
1187
if ( tile . content . state === Cesium3DTileContentState . LOADING ) {
1248
1188
++ stats . numberOfPendingRequests ;
1249
1189
1190
+ if ( expired && tile . hasTilesetContent ) {
1191
+ unloadSubtree ( tileset , tile ) ;
1192
+ }
1193
+
1250
1194
var removeFunction = removeFromProcessingQueue ( tileset , tile ) ;
1251
- when ( tile . content . contentReadyToProcessPromise ) . then ( function ( ) {
1252
- // Content is loaded and ready to process
1253
- addToProcessingQueue ( tileset , tile ) ;
1254
- updateExpireDate ( tile ) ;
1255
- } ) . otherwise ( removeFunction ) ;
1256
-
1257
- when ( tile . content . readyPromise ) . then ( removeFunction ) . otherwise ( function ( ) {
1258
- // The request failed
1195
+ tile . content . contentReadyToProcessPromise . then ( addToProcessingQueue ( tileset , tile ) ) ;
1196
+ tile . content . readyPromise . then ( removeFunction ) . otherwise ( function ( ) {
1259
1197
removeFunction ( ) ;
1260
1198
if ( expired ) {
1261
- unloadExpiredTile ( tile ) ;
1199
+ // Failed to request new content for the expired tile, so unload it and make it empty
1200
+ unloadTile ( tileset , tile , true ) ;
1262
1201
}
1263
1202
} ) ;
1264
1203
} else {
1265
1204
++ stats . numberOfAttemptedRequests ;
1266
1205
}
1267
1206
}
1268
1207
1208
+ function isVisible ( visibilityPlaneMask ) {
1209
+ return visibilityPlaneMask !== CullingVolume . MASK_OUTSIDE ;
1210
+ }
1211
+
1269
1212
function selectTile ( tileset , tile , fullyVisible , frameState ) {
1270
1213
// There may also be a tight box around just the tile's contents, e.g., for a city, we may be
1271
1214
// zoomed into a neighborhood and can cull the skyscrapers in the root node.
@@ -1386,6 +1329,10 @@ define([
1386
1329
t . replaced = false ;
1387
1330
++ stats . visited ;
1388
1331
1332
+ if ( t . isContentExpired ( ) ) {
1333
+ requestContent ( tileset , t , outOfCore ) ;
1334
+ }
1335
+
1389
1336
var visibilityPlaneMask = t . visibilityPlaneMask ;
1390
1337
var fullyVisible = ( visibilityPlaneMask === CullingVolume . MASK_INSIDE ) ;
1391
1338
@@ -1395,18 +1342,6 @@ define([
1395
1342
var sse = getScreenSpaceError ( tileset , t . geometricError , t , frameState ) ;
1396
1343
// PERFORMANCE_IDEA: refine also based on (1) occlusion/VMSSE and/or (2) center of viewport
1397
1344
1398
- // If the tile is expired, request new content
1399
- if ( defined ( t . expireDate ) ) {
1400
- var now = JulianDate . now ( scratchJulianDate ) ;
1401
- if ( JulianDate . lessThan ( now , t . expireDate ) ) {
1402
- // Request new content
1403
- if ( t . contentReady && ( t . hasContent || t . hasTilesetContent ) ) {
1404
- t . content . state = Cesium3DTileContentState . EXPIRED ;
1405
- requestContent ( tileset , t , outOfCore ) ;
1406
- }
1407
- }
1408
- }
1409
-
1410
1345
var children = t . children ;
1411
1346
var childrenLength = children . length ;
1412
1347
var child ;
@@ -1698,10 +1633,12 @@ define([
1698
1633
///////////////////////////////////////////////////////////////////////////
1699
1634
1700
1635
function addToProcessingQueue ( tileset , tile ) {
1701
- tileset . _processingQueue . push ( tile ) ;
1636
+ return function ( ) {
1637
+ tileset . _processingQueue . push ( tile ) ;
1702
1638
1703
- -- tileset . _statistics . numberOfPendingRequests ;
1704
- ++ tileset . _statistics . numberProcessing ;
1639
+ -- tileset . _statistics . numberOfPendingRequests ;
1640
+ ++ tileset . _statistics . numberProcessing ;
1641
+ } ;
1705
1642
}
1706
1643
1707
1644
function removeFromProcessingQueue ( tileset , tile ) {
@@ -1878,14 +1815,29 @@ define([
1878
1815
}
1879
1816
}
1880
1817
1818
+ function unloadTile ( tileset , tile , makeEmpty ) {
1819
+ if ( tile . hasContent ) {
1820
+ var stats = tileset . _statistics ;
1821
+ var replacementList = tileset . _replacementList ;
1822
+ var tileUnload = tileset . tileUnload ;
1823
+
1824
+ tileUnload . raiseEvent ( tile ) ;
1825
+ replacementList . remove ( tile . replacementNode ) ;
1826
+ decrementPointAndFeatureLoadCounts ( tileset , tile . content ) ;
1827
+ -- stats . numberContentReady ;
1828
+ }
1829
+
1830
+ if ( tile . hasContent || ( tile . hasTilesetContent && makeEmpty ) ) {
1831
+ tile . unloadContent ( makeEmpty ) ;
1832
+ }
1833
+ }
1834
+
1881
1835
function unloadTiles ( tileset , frameState ) {
1882
1836
var trimTiles = tileset . _trimTiles ;
1883
1837
tileset . _trimTiles = false ;
1884
1838
1885
- var stats = tileset . _statistics ;
1886
1839
var maximumNumberOfLoadedTiles = tileset . _maximumNumberOfLoadedTiles + 1 ; // + 1 to account for sentinel
1887
1840
var replacementList = tileset . _replacementList ;
1888
- var tileUnload = tileset . tileUnload ;
1889
1841
1890
1842
// Traverse the list only to the sentinel since tiles/nodes to the
1891
1843
// right of the sentinel were used this frame.
@@ -1895,16 +1847,8 @@ define([
1895
1847
var node = replacementList . head ;
1896
1848
while ( ( node !== sentinel ) && ( ( replacementList . length > maximumNumberOfLoadedTiles ) || trimTiles ) ) {
1897
1849
var tile = node . item ;
1898
-
1899
- decrementPointAndFeatureLoadCounts ( tileset , tile . content ) ;
1900
- tileUnload . raiseEvent ( tile ) ;
1901
- tile . unloadContent ( ) ;
1902
-
1903
- var currentNode = node ;
1904
1850
node = node . next ;
1905
- replacementList . remove ( currentNode ) ;
1906
-
1907
- -- stats . numberContentReady ;
1851
+ unloadTile ( tileset , tile , false ) ;
1908
1852
}
1909
1853
}
1910
1854
0 commit comments