Skip to content

Commit

Permalink
New Tile unload approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Feb 26, 2025
1 parent e60c349 commit caf4668
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 203 deletions.
12 changes: 12 additions & 0 deletions Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ class CESIUM3DTILESSELECTION_API Tile final {
*/
void decrementDoNotUnloadSubtreeCountOnParent(const char* reason) noexcept;

bool addViewGroupReference() const noexcept;
bool releaseViewGroupReference() const noexcept;

private:
void incrementDoNotUnloadSubtreeCount(const std::string& reason) noexcept;

Expand Down Expand Up @@ -587,6 +590,7 @@ class CESIUM3DTILESSELECTION_API Tile final {

// tile content
CesiumUtility::DoublyLinkedListPointers<Tile> _loadedTilesLinks;
CesiumUtility::DoublyLinkedListPointers<Tile> _unusedTilesLinks;
TileContent _content;
TilesetContentLoader* _pLoader;
TileLoadState _loadState;
Expand All @@ -599,6 +603,11 @@ class CESIUM3DTILESSELECTION_API Tile final {
// external tileset (if any) from being unloaded from the tree.
int32_t _doNotUnloadSubtreeCount = 0;

// The number of ViewGroups that currently reference this tile. While a tile
// is referenced by a view group, its content may not be unloaded, nor can the
// external tileset that contains this tile be unloaded.
mutable int32_t _viewGroupReferences = 0;

friend class TilesetContentManager;
friend class MockTilesetContentManagerTestFixture;

Expand All @@ -608,6 +617,9 @@ class CESIUM3DTILESSELECTION_API Tile final {
*/
typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_loadedTilesLinks>
LoadedLinkedList;

typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_unusedTilesLinks>
UnusedLinkedList;
};

} // namespace Cesium3DTilesSelection
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TileSelectionState final {
* @param frameNumber The previous frame number.
* @return The {@link TileSelectionState::Result}
*/
constexpr Result getResult(int32_t frameNumber) const noexcept {
constexpr Result getResult(int32_t /* frameNumber */) const noexcept {
// if (this->_frameNumber != frameNumber) {
// return Result::None;
// }
Expand Down
12 changes: 7 additions & 5 deletions Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <Cesium3DTilesSelection/TilesetExternals.h>
#include <Cesium3DTilesSelection/TilesetLoadFailureDetails.h>
#include <Cesium3DTilesSelection/TilesetOptions.h>
#include <Cesium3DTilesSelection/ViewGroup.h>
#include <Cesium3DTilesSelection/TilesetViewGroup.h>
#include <Cesium3DTilesSelection/ViewState.h>
#include <Cesium3DTilesSelection/ViewUpdateResult.h>
#include <CesiumAsync/AsyncSystem.h>
Expand All @@ -29,6 +29,7 @@ class TilesetMetadata;
class TilesetHeightQuery;
struct TilesetHeightRequest;
class TilesetSharedAssetSystem;
class TilesetViewGroup;

/**
* @brief A <a
Expand Down Expand Up @@ -218,7 +219,7 @@ class CESIUM3DTILESSELECTION_API Tileset final {
updateView(const std::vector<ViewState>& frustums, float deltaTime = 0.0f);

const ViewUpdateResult& updateView(
ViewGroup& viewGroup,
TilesetViewGroup& viewGroup,
const std::vector<ViewState>& frustums,
float deltaTime = 0.0f);

Expand Down Expand Up @@ -318,6 +319,8 @@ class CESIUM3DTILESSELECTION_API Tileset final {
CesiumAsync::Future<SampleHeightResult> sampleHeightMostDetailed(
const std::vector<CesiumGeospatial::Cartographic>& positions);

TilesetViewGroup createViewGroup();

Tileset(const Tileset& rhs) = delete;
Tileset& operator=(const Tileset& rhs) = delete;

Expand Down Expand Up @@ -380,7 +383,7 @@ class CESIUM3DTILESSELECTION_API Tileset final {
* passed on through the traversal.
*/
struct FrameState {
ViewGroup& viewGroup;
TilesetViewGroup& viewGroup;
const std::vector<ViewState>& frustums;
std::vector<double> fogDensities;
int32_t lastFrameNumber;
Expand Down Expand Up @@ -478,7 +481,6 @@ class CESIUM3DTILESSELECTION_API Tileset final {
void _processWorkerThreadLoadQueue();
void _processMainThreadLoadQueue();

void _clearChildrenRecursively(Tile* pTile) noexcept;
void _unloadCachedTiles(double timeBudget) noexcept;
void _markTileVisited(Tile& tile) noexcept;

Expand Down Expand Up @@ -565,7 +567,7 @@ class CESIUM3DTILESSELECTION_API Tileset final {

std::list<TilesetHeightRequest> _heightRequests;

ViewGroup _defaultViewGroup;
TilesetViewGroup _defaultViewGroup;

void addTileToLoadQueue(
Tile& tile,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pragma once

#include <Cesium3DTilesSelection/TileSelectionState.h>
#include <CesiumUtility/IntrusivePointer.h>

#include <unordered_map>

namespace Cesium3DTilesSelection {

class Tile;
class Tileset;
class TilesetContentManager;

/**
* @brief A group of views that select tiles from a particular {@link Tileset}
* together.
*
* Create an instance of this class by calling {@link Tileset::createViewGroup}.
*/
class CESIUM3DTILESSELECTION_API TilesetViewGroup final {
public:
TilesetViewGroup(const TilesetViewGroup& rhs) noexcept;
TilesetViewGroup(TilesetViewGroup&& rhs) noexcept;
~TilesetViewGroup() noexcept;

/**
* @brief Returns the previous {@link TileSelectionState} of this tile last
* time this view group was updated.
*
* This function is not supposed to be called by clients.
*
* @return The previous selection state
*/
TileSelectionState getPreviousSelectionState(const Tile& tile) const noexcept;

/**
* @brief Returns the current {@link TileSelectionState} of this tile during
* the current update of this view group.
*
* This function is not supposed to be called by clients.
*
* @return The current selection state
*/
TileSelectionState getCurrentSelectionState(const Tile& tile) const noexcept;

/**
* @brief Set the {@link TileSelectionState} of this tile.
*
* This function is not supposed to be called by clients.
*
* @param newState The new state
*/
void setCurrentSelectionState(
const Tile& tile,
const TileSelectionState& newState) noexcept;

void kick(const Tile& tile) noexcept;

/**
* @brief Finishes the current frame by making the current tile selection
* state the previous one and releasing references to tiles in the old previous
* one.
*/
void finishFrame();

private:
/**
* @brief Constructs a new instance.
*
* @param tileset The tileset that this view group views.
*/
TilesetViewGroup(const CesiumUtility::IntrusivePointer<TilesetContentManager>&
pTilesetContentManager);

CesiumUtility::IntrusivePointer<TilesetContentManager>
_pTilesetContentManager;
std::unordered_map<const Tile*, TileSelectionState> _previousSelectionStates;
std::unordered_map<const Tile*, TileSelectionState> _currentSelectionStates;

// So that the Tileset can create instances of this class.
friend class Tileset;
};

} // namespace Cesium3DTilesSelection
58 changes: 0 additions & 58 deletions Cesium3DTilesSelection/include/Cesium3DTilesSelection/ViewGroup.h

This file was deleted.

11 changes: 11 additions & 0 deletions Cesium3DTilesSelection/src/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,15 @@ void Tile::decrementDoNotUnloadSubtreeCount(
}
}

bool Tile::addViewGroupReference() const noexcept {
++this->_viewGroupReferences;
return this->_viewGroupReferences == 1;
}

bool Tile::releaseViewGroupReference() const noexcept {
CESIUM_ASSERT(this->_viewGroupReferences > 0);
--this->_viewGroupReferences;
return this->_viewGroupReferences == 0;
}

} // namespace Cesium3DTilesSelection
Loading

0 comments on commit caf4668

Please sign in to comment.