From 87b9e85584032742f07f320f36ba3c09dd249a58 Mon Sep 17 00:00:00 2001 From: Romain BOULLARD Date: Sun, 30 Aug 2026 15:40:22 +0200 Subject: [PATCH] IsLoaded for asset library --- Bigfoot/Sources/Engine/Asset/AssetLibrary.cpp | 7 ++++ .../Include/Engine/Asset/AssetLibrary.hpp | 9 +++++ Bigfoot/Tests/Engine/Asset/AssetLibrary.cpp | 39 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/Bigfoot/Sources/Engine/Asset/AssetLibrary.cpp b/Bigfoot/Sources/Engine/Asset/AssetLibrary.cpp index 382c952..72ea5b0 100644 --- a/Bigfoot/Sources/Engine/Asset/AssetLibrary.cpp +++ b/Bigfoot/Sources/Engine/Asset/AssetLibrary.cpp @@ -62,6 +62,13 @@ AssetContainerBase* AssetLibrary::GetAssetContainer(const UUID& p_uuid) /****************************************************************************************/ +bool AssetLibrary::IsLoaded(const UUID& p_uuid) const +{ + return GetAssetContainer(p_uuid) != nullptr; +} + +/****************************************************************************************/ + void SetActiveAssetLibrary(AssetLibrary* p_assetLibrary) { g_activeAssetLibrary = p_assetLibrary; diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp index 5a4652d..59877c6 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp @@ -81,6 +81,15 @@ class AssetLibrary [[nodiscard]] AssetContainerBase* GetAssetContainer(const UUID& p_uuid); + /** + * Check if an Asset is already loaded in the library + * + * \param p_uuid The asset to check + * \return True if already loaded, false otherwise + */ + [[nodiscard]] + bool IsLoaded(const UUID& p_uuid) const; + AssetLibrary& operator=(const AssetLibrary& p_library) = default; AssetLibrary& operator=(AssetLibrary&& p_library) = delete; diff --git a/Bigfoot/Tests/Engine/Asset/AssetLibrary.cpp b/Bigfoot/Tests/Engine/Asset/AssetLibrary.cpp index 3bdbcfa..2e96b09 100644 --- a/Bigfoot/Tests/Engine/Asset/AssetLibrary.cpp +++ b/Bigfoot/Tests/Engine/Asset/AssetLibrary.cpp @@ -99,6 +99,45 @@ TEST_F(AssetLibraryFixture, GetAssetContainer_ShouldReturnNullptrIfNoContainerHa /****************************************************************************************/ +TEST_F(AssetLibraryFixture, IsLoaded_ShouldReturnTrueIfTheAssetIsLoaded) +{ + std::ignore = m_library.Insert(&m_containerA); + std::ignore = m_library.Insert(&m_containerB); + + const UUID uuid = m_containerB.Insert()->GetAsset()->GetHeader().uuid; + + EXPECT_TRUE(m_library.IsLoaded(uuid)); +} + +/****************************************************************************************/ + +TEST_F(AssetLibraryFixture, IsLoaded_ShouldReturnFalseIfTheAssetIsNotLoaded) +{ + std::ignore = m_library.Insert(&m_containerA); + std::ignore = m_library.Insert(&m_containerB); + + const UUID uuid; + + EXPECT_FALSE(m_library.IsLoaded(uuid)); +} + +/****************************************************************************************/ + +TEST_F(AssetLibraryFixture, IsLoaded_ShouldReturnFalseIfTheAssetWasRemovedFromItsContainer) +{ + std::ignore = m_library.Insert(&m_containerA); + std::ignore = m_library.Insert(&m_containerB); + + const UUID uuid = m_containerB.Insert()->GetAsset()->GetHeader().uuid; + ASSERT_TRUE(m_library.IsLoaded(uuid)); + + m_containerB.Remove(uuid); + + EXPECT_FALSE(m_library.IsLoaded(uuid)); +} + +/****************************************************************************************/ + TEST_F(AssetLibraryFixture, SetActiveAssetLibrary_ShouldSetTheActiveAssetLibraryToTheGivenLibrary) { SetActiveAssetLibrary(&m_library);