diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp index 7682833..6eb65e6 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp @@ -121,6 +121,7 @@ class AssetContainerBase { using SlotMap = StableSlotMap; using SlotMapKey = SlotMap::SlotMapKey; + public: virtual ~AssetContainerBase() = default; @@ -262,6 +263,7 @@ class AssetContainer: public AssetContainerBase { using SlotMap = StableSlotMap; using SlotMapKey = SlotMap::SlotMapKey; + public: AssetContainer() = default; diff --git a/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp b/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp index 626c067..c341c75 100644 --- a/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp +++ b/Bigfoot/Sources/Utils/Include/Utils/Containers/SlotMap.hpp @@ -10,18 +10,9 @@ #include #include -#include +#include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include namespace Bigfoot { @@ -150,7 +141,8 @@ class DenseSlotMap const std::size_t indexToRecyclingKey = m_freeListHead; m_freeListHead = m_keys[indexToRecyclingKey].GetIndex(); - m_keys[indexToRecyclingKey] = SlotMapKey {m_keys[indexToRecyclingKey].GetVersion(), static_cast(indexToInsertedData)}; + m_keys[indexToRecyclingKey] = SlotMapKey {m_keys[indexToRecyclingKey].GetVersion(), + static_cast(indexToInsertedData)}; m_dataToKey.emplace_back(indexToRecyclingKey); return SlotMapKey {m_keys[indexToRecyclingKey].GetVersion(), @@ -305,7 +297,8 @@ class DenseSlotMap void RecycleKey(const SlotMapKey p_key) { - const typename SlotMapKey::VersionType nextVersion = static_cast(p_key.GetVersion() + 1); + const typename SlotMapKey::VersionType nextVersion = static_cast(p_key.GetVersion() + + 1); if (nextVersion == SlotMapKey::INVALID_VERSION) { @@ -345,7 +338,6 @@ class StableSlotMap alignas(T) std::byte m_bytes[sizeof(T)]; }; - struct Page { Page() = default; @@ -395,8 +387,9 @@ class StableSlotMap { private: using PagesVector = eastl::vector>; - using PageIterator = - std::conditional_t, typename PagesVector::const_iterator, typename PagesVector::iterator>; + using PageIterator = std::conditional_t, + typename PagesVector::const_iterator, + typename PagesVector::iterator>; using MapType = std::conditional_t, const StableSlotMap, StableSlotMap>; using PageType = std::conditional_t, const Page, Page>; @@ -585,12 +578,12 @@ class StableSlotMap std::size_t Size() const { return eastl::accumulate(m_pages.begin(), - m_pages.end(), - 0, - [](const std::size_t p_value, const eastl::unique_ptr& p_page) - { - return p_value + p_page->Size(); - }); + m_pages.end(), + 0, + [](const std::size_t p_value, const eastl::unique_ptr& p_page) + { + return p_value + p_page->Size(); + }); } [[nodiscard]] diff --git a/Bigfoot/Tests/Utils/Containers/SlotMap.cpp b/Bigfoot/Tests/Utils/Containers/SlotMap.cpp index e7e2263..b0b81be 100644 --- a/Bigfoot/Tests/Utils/Containers/SlotMap.cpp +++ b/Bigfoot/Tests/Utils/Containers/SlotMap.cpp @@ -14,7 +14,7 @@ namespace Bigfoot class SlotMapKeyFixture: public ::testing::Test { protected: - using SlotMapKey = SlotMapKey<>; + using SlotMapKey = SlotMapKey<>; }; /****************************************************************************************/ @@ -155,7 +155,8 @@ class SlotMapNameGenerator } }; -using SlotMapTypes = ::testing::Types>, StableSlotMap>>; +using SlotMapTypes = ::testing::Types>, + StableSlotMap>>; TYPED_TEST_SUITE(SlotMapFixture, SlotMapTypes, SlotMapNameGenerator); /****************************************************************************************/ @@ -1114,51 +1115,51 @@ TYPED_TEST(SlotMapFixture, ConstReverseIterator) /****************************************************************************************/ - class StableSlotMapFixture: public ::testing::Test - { - protected: - StableSlotMap m_slotMap; +class StableSlotMapFixture: public ::testing::Test +{ + protected: + StableSlotMap m_slotMap; - using SlotMapKey = StableSlotMap::SlotMapKey; - }; + using SlotMapKey = StableSlotMap::SlotMapKey; +}; - /****************************************************************************************/ +/****************************************************************************************/ - TEST_F(StableSlotMapFixture, PointersAreStable) - { - const SlotMapKey key = m_slotMap.Insert(42); - const std::uint32_t* const pointer = m_slotMap.Get(key); +TEST_F(StableSlotMapFixture, PointersAreStable) +{ + const SlotMapKey key = m_slotMap.Insert(42); + const std::uint32_t* const pointer = m_slotMap.Get(key); - // Inserting enough elements to span multiple pages (PAGE_SIZE is 64) must not move already - // -inserted data: unlike DenseSlotMap's contiguous eastl::vector, growth only appends new - // Page objects (each individually heap-allocated), it never reallocates existing ones. - constexpr std::uint32_t elementCount = 200; - eastl::array keys; - for (std::uint32_t value = 0; value < elementCount; ++value) - { - keys[value] = m_slotMap.Insert(value); - } + // Inserting enough elements to span multiple pages (PAGE_SIZE is 64) must not move already + // -inserted data: unlike DenseSlotMap's contiguous eastl::vector, growth only appends new + // Page objects (each individually heap-allocated), it never reallocates existing ones. + constexpr std::uint32_t elementCount = 200; + eastl::array keys; + for (std::uint32_t value = 0; value < elementCount; ++value) + { + keys[value] = m_slotMap.Insert(value); + } - EXPECT_EQ(m_slotMap.Get(key), pointer); - EXPECT_EQ(*pointer, 42); + EXPECT_EQ(m_slotMap.Get(key), pointer); + EXPECT_EQ(*pointer, 42); - // Removing unrelated elements, including ones sharing the same page as key, must not move it - // either: Remove() only destroys that slot in place, it never compacts the page's array. - for (std::uint32_t value = 0; value < elementCount; value += 2) - { - m_slotMap.Remove(keys[value]); - } + // Removing unrelated elements, including ones sharing the same page as key, must not move it + // either: Remove() only destroys that slot in place, it never compacts the page's array. + for (std::uint32_t value = 0; value < elementCount; value += 2) + { + m_slotMap.Remove(keys[value]); + } - EXPECT_EQ(m_slotMap.Get(key), pointer); - EXPECT_EQ(*pointer, 42); + EXPECT_EQ(m_slotMap.Get(key), pointer); + EXPECT_EQ(*pointer, 42); - // Re-inserting into the freed slots must not move it either - for (std::uint32_t value = 0; value < elementCount / 2; ++value) - { - std::ignore = m_slotMap.Insert(value); - } + // Re-inserting into the freed slots must not move it either + for (std::uint32_t value = 0; value < elementCount / 2; ++value) + { + std::ignore = m_slotMap.Insert(value); + } - EXPECT_EQ(m_slotMap.Get(key), pointer); - EXPECT_EQ(*pointer, 42); - } + EXPECT_EQ(m_slotMap.Get(key), pointer); + EXPECT_EQ(*pointer, 42); +} } // namespace Bigfoot