Skip to content

Commit

Permalink
Keep query tiles loaded until we're done with them.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Sep 16, 2024
1 parent 51a5322 commit ca62417
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cesium3DTilesSelection/src/Tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ Tileset::updateView(const std::vector<ViewState>& frustums, float deltaTime) {
TilesetHeightRequest::processHeightRequests(
*this->_pTilesetContentManager,
this->_options,
this->_loadedTiles,
this->_heightRequests,
this->_heightQueryLoadQueue);

Expand Down
19 changes: 16 additions & 3 deletions Cesium3DTilesSelection/src/TilesetHeightQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ void TilesetHeightQuery::intersectVisibleTile(

void TilesetHeightQuery::findCandidateTiles(
Tile* pTile,
Tile::LoadedLinkedList& loadedTiles,
std::vector<std::string>& warnings) {
// Make sure this tile is not unloaded until we're done with it.
loadedTiles.insertAtTail(*pTile);

// If tile failed to load, this means we can't complete the intersection
if (pTile->getState() == TileLoadState::Failed) {
Expand Down Expand Up @@ -169,14 +172,15 @@ void TilesetHeightQuery::findCandidateTiles(
continue;

// Child is a candidate, traverse it and its children
findCandidateTiles(&child, warnings);
findCandidateTiles(&child, loadedTiles, warnings);
}
}
}

/*static*/ void TilesetHeightRequest::processHeightRequests(
TilesetContentManager& contentManager,
const TilesetOptions& options,
Tile::LoadedLinkedList& loadedTiles,
std::list<TilesetHeightRequest>& heightRequests,
std::vector<Tile*>& heightQueryLoadQueue) {
if (heightRequests.empty())
Expand All @@ -190,6 +194,7 @@ void TilesetHeightQuery::findCandidateTiles(
if (!request.tryCompleteHeightRequest(
contentManager,
options,
loadedTiles,
tilesNeedingLoading)) {
++it;
} else {
Expand All @@ -207,14 +212,18 @@ void TilesetHeightQuery::findCandidateTiles(
bool TilesetHeightRequest::tryCompleteHeightRequest(
TilesetContentManager& contentManager,
const TilesetOptions& options,
Tile::LoadedLinkedList& loadedTiles,
std::set<Tile*>& tilesNeedingLoading) {
bool tileStillNeedsLoading = false;
std::vector<std::string> warnings;
for (TilesetHeightQuery& query : this->queries) {
if (query.candidateTiles.empty() && query.additiveCandidateTiles.empty()) {
// Find the initial set of tiles whose bounding volume is intersected by
// the query ray.
query.findCandidateTiles(contentManager.getRootTile(), warnings);
query.findCandidateTiles(
contentManager.getRootTile(),
loadedTiles,
warnings);
} else {
// Refine the current set of candidate tiles, in case further tiles from
// implicit tiling, external tilesets, etc. having been loaded since last
Expand All @@ -227,8 +236,12 @@ bool TilesetHeightRequest::tryCompleteHeightRequest(
TileLoadState loadState = pCandidate->getState();
if (!pCandidate->getChildren().empty() &&
loadState >= TileLoadState::ContentLoaded) {
query.findCandidateTiles(pCandidate, warnings);
query.findCandidateTiles(pCandidate, loadedTiles, warnings);
} else {
// Make sure this tile stays loaded.
loadedTiles.insertAtTail(*pCandidate);

// Check again next frame to see if this tile has children.
query.candidateTiles.emplace_back(pCandidate);
}
}
Expand Down
18 changes: 16 additions & 2 deletions Cesium3DTilesSelection/src/TilesetHeightQuery.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <Cesium3DTilesSelection/Tile.h>
#include <CesiumAsync/Future.h>
#include <CesiumAsync/Promise.h>
#include <CesiumGeometry/Ray.h>
Expand All @@ -13,7 +14,6 @@

namespace Cesium3DTilesSelection {

class Tile;
class TilesetContentManager;
struct TilesetOptions;
struct SampleHeightResult;
Expand Down Expand Up @@ -90,10 +90,16 @@ class TilesetHeightQuery {
* {@link TilesetHeightQuery::additiveCandidateTiles}.
*
* @param pTile The tile at which to start traversal.
* @param loadedTiles The linked list of loaded tiles, used to ensure that
* tiles loaded for height queries stay loaded long enough to complete the
* query and no longer.
* @param outWarnings On return, any warnings that occurred during candidate
* search.
*/
void findCandidateTiles(Tile* pTile, std::vector<std::string>& outWarnings);
void findCandidateTiles(
Tile* pTile,
Tile::LoadedLinkedList& loadedTiles,
std::vector<std::string>& outWarnings);
};

/**
Expand All @@ -117,6 +123,9 @@ struct TilesetHeightRequest {
*
* @param contentManager The content manager.
* @param options Options associated with the tileset.
* @param loadedTiles The linked list of loaded tiles, used to ensure that
* tiles loaded for height queries stay loaded long enough to complete the
* query and no longer.
* @param heightRequests The list of all height requests. Completed requests
* will be removed from this list.
* @param heightQueryLoadQueue Tiles that still need to be loaded before all
Expand All @@ -125,6 +134,7 @@ struct TilesetHeightRequest {
static void processHeightRequests(
TilesetContentManager& contentManager,
const TilesetOptions& options,
Tile::LoadedLinkedList& loadedTiles,
std::list<TilesetHeightRequest>& heightRequests,
std::vector<Tile*>& heightQueryLoadQueue);

Expand All @@ -134,12 +144,16 @@ struct TilesetHeightRequest {
*
* @param contentManager The content manager.
* @param options Options associated with the tileset.
* @param loadedTiles The linked list of loaded tiles, used to ensure that
* tiles loaded for height queries stay loaded long enough to complete the
* query and no longer.
* @param tilesNeedingLoading Tiles that needs to be loaded before this height
* request can complete.
*/
bool tryCompleteHeightRequest(
TilesetContentManager& contentManager,
const TilesetOptions& options,
Tile::LoadedLinkedList& loadedTiles,
std::set<Tile*>& tilesNeedingLoading);
};

Expand Down

0 comments on commit ca62417

Please sign in to comment.