Documentation
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 14m18s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 14m10s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 15m5s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 14m41s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 15m14s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 13m58s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 14m29s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m10s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 14m42s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 15m41s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 15m19s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m30s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 17m21s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 16m51s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 17m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 16m44s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 15m3s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 14m48s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 16m24s
Bigfoot / Clang Format Checks (push) Failing after 9s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 15m3s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 14m50s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 16m5s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 16m28s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 16m22s

This commit is contained in:
2026-08-22 19:17:25 +02:00
parent cbf4de6003
commit 407401bea2
6 changed files with 307 additions and 61 deletions
@@ -17,6 +17,9 @@
namespace Bigfoot
{
/**
* An indirection that allows References to immediately get the asset, without fetching the actual container
*/
class ContainerHandle
{
public:
@@ -17,22 +17,40 @@ namespace Bigfoot
template<class ASSET>
AssetTypeID GetAssetTypeID();
template<>
AssetTypeID GetAssetTypeID<AssetBase>() = delete;
template<class DERIVED, class ASSET>
class ReferenceBase
{
public:
/**
* Get the UUID of the reference
*
* \return The UUID of the reference
*/
[[nodiscard]]
const UUID& GetUUID() const
{
return m_uuid;
}
/**
* Get the asset
*
* \return The asset, nullptr if it is not loaded
*/
[[nodiscard]]
const ASSET* Get() const
{
return m_handle ? static_cast<const ASSET*>(m_handle->GetAsset()) : nullptr;
}
/**
* Get the asset
*
* \return The asset, nullptr if it is not loaded
*/
[[nodiscard]]
ASSET* Get()
{
@@ -96,6 +114,11 @@ class ReferenceBase
}
private:
/**
* Get the associated handle container for the asset
* Register the reference inside the handle
*
*/
void Acquire()
{
if (!m_uuid)
@@ -113,6 +136,10 @@ class ReferenceBase
}
}
/**
* Unregister the reference from the handle
*
*/
void Release()
{
if (m_handle)
@@ -122,10 +149,22 @@ class ReferenceBase
}
}
private:
/**
* The UUID
*/
UUID m_uuid = UUID::NULL_UUID;
/**
* Handle for the asset
*/
ContainerHandle* m_handle = nullptr;
};
/*
* Owning reference
* Keeps the asset alive
*/
template<class ASSET>
class HardReference: public ReferenceBase<HardReference<ASSET>, ASSET>
{
@@ -140,11 +179,21 @@ class HardReference: public ReferenceBase<HardReference<ASSET>, ASSET>
}
private:
/**
* Increment the hard ref count of the handle
*
* \param p_handle The handle for the asset
*/
static void IncrementCount(ContainerHandle& p_handle)
{
p_handle.IncrementHardRefCount();
}
/**
* Decrement the hard ref count of the handle
*
* \param p_handle The handle for the asset
*/
static void DecrementCount(ContainerHandle& p_handle)
{
p_handle.DecrementHardRefCount();
@@ -167,11 +216,21 @@ class SoftReference: public ReferenceBase<SoftReference<ASSET>, ASSET>
}
private:
/**
* Increment the soft ref count of the handle
*
* \param p_handle The handle for the asset
*/
static void IncrementCount(ContainerHandle& p_handle)
{
p_handle.IncrementSoftRefCount();
}
/**
* Decrement the hard ref count of the handle
*
* \param p_handle The handle for the asset
*/
static void DecrementCount(ContainerHandle& p_handle)
{
p_handle.DecrementSoftRefCount();
@@ -39,12 +39,23 @@ class SlotMapKey
static constexpr IndexType MAX_INDEX = std::numeric_limits<IndexType>::max();
static constexpr VersionType MAX_VERSION = std::numeric_limits<VersionType>::max();
/**
* Constructor
*
* \param p_version The version
* \param p_index The index
*/
constexpr SlotMapKey(const VersionType p_version, const IndexType p_index):
m_key((static_cast<std::uint64_t>(p_version) << INDEX_BIT_COUNT) |
(static_cast<std::uint64_t>(p_index) & INDEX_MASK))
{
}
/**
* Constructor
*
* Constructs an invalid key
*/
constexpr SlotMapKey():
SlotMapKey(INVALID_VERSION, 0)
{
@@ -55,18 +66,33 @@ class SlotMapKey
constexpr ~SlotMapKey() = default;
/**
* Check if the key is valid (Version different than INVALID_VERSION)
*
* \return True if valid, false otherwise
*/
[[nodiscard]]
constexpr bool Valid() const
{
return GetVersion() != INVALID_VERSION;
}
/**
* Get the version
*
* \return The version
*/
[[nodiscard]]
constexpr VersionType GetVersion() const
{
return static_cast<VersionType>(m_key >> INDEX_BIT_COUNT);
}
/**
* Get the index
*
* \return The index
*/
[[nodiscard]]
constexpr IndexType GetIndex() const
{
@@ -80,9 +106,17 @@ class SlotMapKey
constexpr bool operator==(const SlotMapKey& p_other) const = default;
private:
/**
* The key => (VERSION | INDEX)
*/
std::uint64_t m_key;
};
/**
* Storage is dense
* Pointer stability not guarantee
* Fast iteration
*/
template<class T, class SLOT_MAP_KEY_TYPE = SlotMapKey<>>
class DenseSlotMap
{
@@ -101,6 +135,12 @@ class DenseSlotMap
~DenseSlotMap() = default;
/**
* Check if the map has the key
*
* \param p_key The key to check
* \return True if it has the key, false otherwise
*/
[[nodiscard]]
bool Has(const SlotMapKey p_key) const
{
@@ -108,24 +148,46 @@ class DenseSlotMap
(p_key.GetIndex() < m_keys.size() && p_key.GetVersion() == m_keys[p_key.GetIndex()].GetVersion());
}
/**
* Get the size of the map
*
* \return The size of the map
*/
[[nodiscard]]
std::size_t Size() const
{
return m_data.size();
}
/**
* Get the capacity of the map
*
* \return The capacity of the map
*/
[[nodiscard]]
std::size_t Capacity() const
{
return m_data.capacity();
}
/**
* Check if the map is empty
*
* \return True if empty, false otherwise
*/
[[nodiscard]]
bool Empty() const
{
return m_data.empty();
}
/**
* Insert to the slotmap
*
* \tparam Templated arguments
* \param p_args The thing to insert, arguments will be forwarded
* \return A key to the inserted element
*/
template<class... ARGS>
[[nodiscard]]
SlotMapKey Insert(ARGS&&... p_args)
@@ -157,6 +219,11 @@ class DenseSlotMap
return SlotMapKey {1, static_cast<SlotMapKey::IndexType>(m_keys.size() - 1)};
}
/**
* Remove an element from the map
*
* \param p_key The element to remove
*/
void Remove(const SlotMapKey p_key)
{
if (!Has(p_key))
@@ -178,6 +245,12 @@ class DenseSlotMap
RecycleKey(p_key);
}
/**
* Reset the slotmap
* Everything will be cleared
* Old keys are not stale
*
*/
void Reset()
{
m_data.clear();
@@ -186,6 +259,12 @@ class DenseSlotMap
m_freeListHead = SlotMapKey::MAX_INDEX;
}
/**
* Clear the slotmap
* Data is lost
* Old keys are stale
*
*/
void Clear()
{
for (const std::size_t keyIndex: m_dataToKey)
@@ -197,12 +276,24 @@ class DenseSlotMap
m_dataToKey.clear();
}
/**
* Get the element at p_slotKey
*
* \param p_slotKey The key to get
* \return Pointer to the element, nullptr if p_slotKey is not in the map
*/
[[nodiscard]]
T* Get(const SlotMapKey p_slotKey)
{
return Has(p_slotKey) ? &m_data[GetDataIndex(p_slotKey)] : nullptr;
}
/**
* Get the element at p_slotKey
*
* \param p_slotKey The key to get
* \return Pointer to the element, nullptr if p_slotKey is not in the map
*/
[[nodiscard]]
const T* Get(const SlotMapKey p_slotKey) const
{
@@ -285,18 +376,34 @@ class DenseSlotMap
DenseSlotMap& operator=(DenseSlotMap&&) = default;
private:
/**
* Does the map have free slots (ie: indices that can be recyled)
*
* \return True if indices can be recycled, false otherwise
*/
[[nodiscard]]
bool HasFreeSlots() const
{
return m_freeListHead != SlotMapKey::MAX_INDEX;
}
/**
* The the index of the data in the contiguous array
*
* \param p_key The key of the element to get the index of
* \return The index of the element in the contiguous array
*/
[[nodiscard]]
std::size_t GetDataIndex(const SlotMapKey p_key) const
{
return m_keys[p_key.GetIndex()].GetIndex();
}
/**
* Recycle a key
*
* \param p_key The key to recycle
*/
void RecycleKey(const SlotMapKey p_key)
{
const typename SlotMapKey::VersionType nextVersion = static_cast<SlotMapKey::VersionType>(p_key.GetVersion() +
@@ -314,12 +421,17 @@ class DenseSlotMap
}
private:
/**
* The actual storage for our data
*/
eastl::vector<T> m_data;
/**
* The keys containing the indices to our data
*/
eastl::vector<SlotMapKey> m_keys;
/**
* Allows us to match m_data and m_keys.
* dataIndex = m_keys[m_dataToKey[dataIndex]].GetIndex()
*/
eastl::vector<std::size_t> m_dataToKey;
@@ -329,6 +441,11 @@ class DenseSlotMap
std::size_t m_freeListHead = SlotMapKey::MAX_INDEX;
};
/**
* Storage is not dense
* Pointer stability is guarantee
* Slower iteration, fast insert/remove/random access
*/
template<class T, class SLOT_MAP_KEY_TYPE = SlotMapKey<>>
class StableSlotMap
{
@@ -359,25 +476,48 @@ class StableSlotMap
Page& operator=(const Page& p_page) = delete;
Page& operator=(Page&& p_page) = delete;
/**
* Get the data at the specified offset
*
* \return Pointer to the data
*/
[[nodiscard]]
T* Get(const std::size_t p_offset)
{
ASSERT(UtilsAssertHandler, m_occupied[p_offset], "Requesting a dead data!");
return std::launder(reinterpret_cast<T*>(m_data[p_offset].m_bytes));
}
/**
* Get the data at the specified offset
*
* \return Pointer to the data
*/
[[nodiscard]]
const T* Get(const std::size_t p_offset) const
{
ASSERT(UtilsAssertHandler, m_occupied[p_offset], "Requesting a dead data!");
return std::launder(reinterpret_cast<const T*>(m_data[p_offset].m_bytes));
}
/**
* Get the size of the page
*
* \return The size of the page
*/
[[nodiscard]]
std::size_t Size() const
{
return m_occupied.count();
}
/**
* The data
*/
eastl::array<AlignedSlot, PAGE_SIZE> m_data;
/**
* Bitset representing which indices are alive or not
*/
eastl::bitset<PAGE_SIZE> m_occupied;
};
@@ -569,6 +709,12 @@ class StableSlotMap
~StableSlotMap() = default;
/**
* Check if the map has the key
*
* \param p_key The key to check
* \return True if it has the key, false otherwise
*/
[[nodiscard]]
bool Has(const SlotMapKey p_key) const
{
@@ -576,6 +722,11 @@ class StableSlotMap
(p_key.GetIndex() < m_keys.size() && p_key.GetVersion() == m_keys[p_key.GetIndex()].GetVersion());
}
/**
* Get the size of the map
*
* \return The size of the map
*/
[[nodiscard]]
std::size_t Size() const
{
@@ -588,18 +739,35 @@ class StableSlotMap
});
}
/**
* Get the capacity of the map
*
* \return The capacity of the map
*/
[[nodiscard]]
std::size_t Capacity() const
{
return m_pages.size() * PAGE_SIZE;
}
/**
* Check if the map is empty
*
* \return True if empty, false otherwise
*/
[[nodiscard]]
bool Empty() const
{
return Size() == 0;
}
/**
* Insert to the slotmap
*
* \tparam Templated arguments
* \param p_args The thing to insert, arguments will be forwarded
* \return A key to the inserted element
*/
template<class... ARGS>
[[nodiscard]]
SlotMapKey Insert(ARGS&&... p_args)
@@ -640,6 +808,11 @@ class StableSlotMap
return key;
}
/**
* Remove an element from the map
*
* \param p_key The element to remove
*/
void Remove(const SlotMapKey p_key)
{
if (!Has(p_key))
@@ -655,6 +828,12 @@ class StableSlotMap
RecycleKey(p_key);
}
/**
* Reset the slotmap
* Everything will be cleared
* Old keys are not stale
*
*/
void Reset()
{
for (eastl::unique_ptr<Page>& page: m_pages)
@@ -665,6 +844,12 @@ class StableSlotMap
m_freeListHead = SlotMapKey::MAX_INDEX;
}
/**
* Clear the slotmap
* Data is lost
* Old keys are stale
*
*/
void Clear()
{
std::size_t pageIndex = 0;
@@ -683,12 +868,24 @@ class StableSlotMap
}
}
/**
* Get the element at p_slotKey
*
* \param p_slotKey The key to get
* \return Pointer to the element, nullptr if p_slotKey is not in the map
*/
[[nodiscard]]
const T* Get(const SlotMapKey p_key) const
{
return Has(p_key) ? GetPageAt(GetPageIndex(p_key))->Get(GetDataOffset(p_key)) : nullptr;
}
/**
* Get the element at p_slotKey
*
* \param p_slotKey The key to get
* \return Pointer to the element, nullptr if p_slotKey is not in the map
*/
[[nodiscard]]
T* Get(const SlotMapKey p_key)
{
@@ -775,12 +972,22 @@ class StableSlotMap
StableSlotMap& operator=(StableSlotMap&& p_map) = default;
private:
/**
* Does the map have free slots (ie: indices that can be recyled)
*
* \return True if indices can be recycled, false otherwise
*/
[[nodiscard]]
bool HasFreeSlots() const
{
return m_freeListHead != SlotMapKey::MAX_INDEX;
}
/**
* Recycle a key
*
* \param p_key The key to recycle
*/
void RecycleKey(const SlotMapKey p_key)
{
const typename SlotMapKey::VersionType nextVersion = static_cast<SlotMapKey::VersionType>(p_key.GetVersion() +
@@ -797,24 +1004,48 @@ class StableSlotMap
m_freeListHead = p_key.GetIndex();
}
/**
* Given a key, get the index of its page
*
* \param p_key The key
* \return The index of the page
*/
[[nodiscard]]
static std::size_t GetPageIndex(const SlotMapKey p_key)
{
return p_key.GetIndex() / PAGE_SIZE;
}
/**
* Given a key, get the offset of the data inside its page
*
* \param p_key The key
* \return The offset the of data
*/
[[nodiscard]]
static std::size_t GetDataOffset(const SlotMapKey p_key)
{
return p_key.GetIndex() % PAGE_SIZE;
}
/**
* Get the page
*
* \param p_pageIndex The idnex to get
* \return The page
*/
[[nodiscard]]
const Page* GetPageAt(const std::size_t p_pageIndex) const
{
return m_pages[p_pageIndex].get();
}
/**
* Get the page
*
* \param p_pageIndex The idnex to get
* \return The page
*/
[[nodiscard]]
Page* GetPageAt(const std::size_t p_pageIndex)
{
@@ -822,7 +1053,13 @@ class StableSlotMap
}
private:
/**
* The pages
*/
eastl::vector<eastl::unique_ptr<Page>> m_pages;
/**
* The keys containing the indices to our data
*/
eastl::vector<SlotMapKey> m_keys;
/**