Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ class CESIUM3DTILESSELECTION_API TilesetViewGroup final
/** @inheritdoc */
const Tile* getNextTileToLoadInMainThread() override;

/**
* @brief Check if given credit is referenced in this view group's last frame.
*
* @param credit to test.
* @return True if the credit is referenced in this view group's last frame.
*/
bool isCreditReferenced(CesiumUtility::Credit credit) const noexcept;

/**
* @brief Check if given credit is referenced in raster overlays in this
* view group's last frame.
*
* @param credit to test.
* @return True if the credit is referenced in raster overlays in this
* view group's last frame.
*/
bool isCreditReferencedByRaster(CesiumUtility::Credit credit) const noexcept;

private:
double _weight = 1.0;
std::vector<TileLoadTask> _mainThreadLoadQueue;
Expand All @@ -235,6 +253,8 @@ class CESIUM3DTILESSELECTION_API TilesetViewGroup final
TraversalState _traversalState;
CesiumUtility::CreditReferencer _previousFrameCredits;
CesiumUtility::CreditReferencer _currentFrameCredits;
CesiumUtility::CreditReferencer _previousFrameRasterCredits;
CesiumUtility::CreditReferencer _currentFrameRasterCredits;
};

} // namespace Cesium3DTilesSelection
16 changes: 16 additions & 0 deletions Cesium3DTilesSelection/src/TilesetViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void TilesetViewGroup::finishFrame(
if (pRasterOverlayTile != nullptr) {
for (const Credit& credit : pRasterOverlayTile->getCredits()) {
this->_currentFrameCredits.addCreditReference(credit);
this->_currentFrameRasterCredits.addCreditReference(credit);
}
}
}
Expand All @@ -218,6 +219,11 @@ void TilesetViewGroup::finishFrame(

this->_previousFrameCredits.releaseAllReferences();
std::swap(this->_previousFrameCredits, this->_currentFrameCredits);

this->_previousFrameRasterCredits.releaseAllReferences();
std::swap(
this->_previousFrameRasterCredits,
this->_currentFrameRasterCredits);
}
}

Expand Down Expand Up @@ -259,4 +265,14 @@ const Tile* TilesetViewGroup::getNextTileToLoadInMainThread() {
return pResult;
}

bool TilesetViewGroup::isCreditReferenced(
CesiumUtility::Credit credit) const noexcept {
return this->_previousFrameCredits.isCreditReferenced(credit);
}

bool TilesetViewGroup::isCreditReferencedByRaster(
CesiumUtility::Credit credit) const noexcept {
return this->_previousFrameRasterCredits.isCreditReferenced(credit);
}

} // namespace Cesium3DTilesSelection
7 changes: 7 additions & 0 deletions CesiumUtility/include/CesiumUtility/CreditReferencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class CreditReferencer {
*/
void releaseAllReferences() noexcept;

/**
* @brief Tests if a credit is referenced by this referencer.
*
* @param credit to test if it is referenced.
*/
bool isCreditReferenced(Credit credit) const noexcept;

private:
std::shared_ptr<CreditSystem> _pCreditSystem;
std::vector<int32_t> _references;
Expand Down
11 changes: 11 additions & 0 deletions CesiumUtility/src/CreditReferencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,15 @@ void CreditReferencer::releaseAllReferences() noexcept {
this->_references.clear();
}

bool CreditReferencer::isCreditReferenced(Credit credit) const noexcept {
if (!this->_pCreditSystem)
return false;

if (this->_references.size() <= credit.id) {
return false;
}

return this->_references[credit.id] > 0;
}

} // namespace CesiumUtility
46 changes: 46 additions & 0 deletions CesiumUtility/test/TestCreditReferencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ TEST_CASE("CreditReferencer") {

referencer.addCreditReference(credit1);
referencer.releaseAllReferences();
REQUIRE(referencer.isCreditReferenced(credit1) == false);
}

SUBCASE("adds references to the underlying credit system") {
Expand Down Expand Up @@ -115,5 +116,50 @@ TEST_CASE("CreditReferencer") {
const CreditsSnapshot& snapshot2 = pCreditSystem->getSnapshot();
REQUIRE(snapshot2.currentCredits.size() == 0);
}

SUBCASE("and checks credit references") {
REQUIRE(pReferencer->isCreditReferenced(credit1) == true);
REQUIRE(pReferencer->isCreditReferenced(credit2) == true);
REQUIRE(pReferencer->isCreditReferenced(credit3) == false);
}

SUBCASE("and checks credit references after releasing them") {
pReferencer->releaseAllReferences();
REQUIRE(pReferencer->isCreditReferenced(credit1) == false);
REQUIRE(pReferencer->isCreditReferenced(credit2) == false);
REQUIRE(pReferencer->isCreditReferenced(credit3) == false);
}

SUBCASE("and checks credit references after duplicating via the copy "
"constructor") {
CreditReferencer referencerCopy(*pReferencer);
REQUIRE(referencerCopy.isCreditReferenced(credit1) == true);
REQUIRE(referencerCopy.isCreditReferenced(credit2) == true);
REQUIRE(referencerCopy.isCreditReferenced(credit3) == false);

pReferencer->releaseAllReferences();
REQUIRE(pReferencer->isCreditReferenced(credit1) == false);
REQUIRE(pReferencer->isCreditReferenced(credit2) == false);
REQUIRE(pReferencer->isCreditReferenced(credit3) == false);
REQUIRE(referencerCopy.isCreditReferenced(credit1) == true);
REQUIRE(referencerCopy.isCreditReferenced(credit2) == true);
REQUIRE(referencerCopy.isCreditReferenced(credit3) == false);
}

SUBCASE("and checks credit references after duplicating via the move "
"constructor") {
CreditReferencer referencerMove(std::move(*pReferencer));
REQUIRE(referencerMove.isCreditReferenced(credit1) == true);
REQUIRE(referencerMove.isCreditReferenced(credit2) == true);
REQUIRE(referencerMove.isCreditReferenced(credit3) == false);

pReferencer->releaseAllReferences();
REQUIRE(pReferencer->isCreditReferenced(credit1) == false);
REQUIRE(pReferencer->isCreditReferenced(credit2) == false);
REQUIRE(pReferencer->isCreditReferenced(credit3) == false);
REQUIRE(referencerMove.isCreditReferenced(credit1) == true);
REQUIRE(referencerMove.isCreditReferenced(credit2) == true);
REQUIRE(referencerMove.isCreditReferenced(credit3) == false);
}
}
}
Loading