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
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:
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST_F(HardReferenceFixture, GetUUID_ShouldReturnTheUUID)
|
||||
{
|
||||
UUID uuid;
|
||||
HardReference<AssetA> hardRef {uuid};
|
||||
|
||||
|
||||
EXPECT_EQ(hardRef.GetUUID(), uuid);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,6 @@ table InnerTable
|
||||
{
|
||||
asset_a_ref: HardReference (native_inline, bigfoot_ref: "::Bigfoot::AssetA");
|
||||
asset_a_refs: [HardReference] (native_inline, bigfoot_ref: "::Bigfoot::AssetA");
|
||||
|
||||
any_asset: HardReference (native_inline, bigfoot_ref: "::Bigfoot::AssetBase");
|
||||
any_assets: [SoftReference] (native_inline, bigfoot_ref: "::Bigfoot::AssetBase");
|
||||
}
|
||||
|
||||
table AssetC
|
||||
|
||||
+6
-56
@@ -46,10 +46,6 @@ namespace Bigfoot {
|
||||
class AssetA;
|
||||
} // namespace Bigfoot
|
||||
|
||||
namespace Bigfoot {
|
||||
class AssetBase;
|
||||
} // namespace Bigfoot
|
||||
|
||||
namespace Bigfoot {
|
||||
class AssetB;
|
||||
} // namespace Bigfoot
|
||||
@@ -57,10 +53,6 @@ class AssetB;
|
||||
namespace flatbuffers {
|
||||
Flat::Bigfoot::HardReference PackHardReferenceAssetA(const ::Bigfoot::HardReference<::Bigfoot::AssetA>& p_asset);
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetA> UnPackHardReferenceAssetA(const Flat::Bigfoot::HardReference& p_asset);
|
||||
Flat::Bigfoot::HardReference PackHardReferenceAssetBase(const ::Bigfoot::HardReference<::Bigfoot::AssetBase>& p_asset);
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetBase> UnPackHardReferenceAssetBase(const Flat::Bigfoot::HardReference& p_asset);
|
||||
Flat::Bigfoot::SoftReference PackSoftReferenceAssetBase(const ::Bigfoot::SoftReference<::Bigfoot::AssetBase>& p_asset);
|
||||
::Bigfoot::SoftReference<::Bigfoot::AssetBase> UnPackSoftReferenceAssetBase(const Flat::Bigfoot::SoftReference& p_asset);
|
||||
Flat::Bigfoot::HardReference PackHardReferenceAssetB(const ::Bigfoot::HardReference<::Bigfoot::AssetB>& p_asset);
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetB> UnPackHardReferenceAssetB(const Flat::Bigfoot::HardReference& p_asset);
|
||||
Flat::Bigfoot::SoftReference PackSoftReferenceAssetB(const ::Bigfoot::SoftReference<::Bigfoot::AssetB>& p_asset);
|
||||
@@ -81,8 +73,6 @@ struct InnerTableT : public ::flatbuffers::NativeTable {
|
||||
}
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetA> asset_a_ref{};
|
||||
eastl::vector<::Bigfoot::HardReference<::Bigfoot::AssetA>> asset_a_refs{};
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetBase> any_asset{};
|
||||
eastl::vector<::Bigfoot::SoftReference<::Bigfoot::AssetBase>> any_assets{};
|
||||
};
|
||||
|
||||
struct InnerTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
@@ -97,9 +87,7 @@ struct InnerTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_ASSET_A_REF = 4,
|
||||
VT_ASSET_A_REFS = 6,
|
||||
VT_ANY_ASSET = 8,
|
||||
VT_ANY_ASSETS = 10
|
||||
VT_ASSET_A_REFS = 6
|
||||
};
|
||||
const Flat::Bigfoot::HardReference *asset_a_ref() const {
|
||||
return GetStruct<const Flat::Bigfoot::HardReference *>(VT_ASSET_A_REF);
|
||||
@@ -107,21 +95,12 @@ struct InnerTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
const ::flatbuffers::Vector<const Flat::Bigfoot::HardReference *> *asset_a_refs() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const Flat::Bigfoot::HardReference *> *>(VT_ASSET_A_REFS);
|
||||
}
|
||||
const Flat::Bigfoot::HardReference *any_asset() const {
|
||||
return GetStruct<const Flat::Bigfoot::HardReference *>(VT_ANY_ASSET);
|
||||
}
|
||||
const ::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *> *any_assets() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *> *>(VT_ANY_ASSETS);
|
||||
}
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<Flat::Bigfoot::HardReference>(verifier, VT_ASSET_A_REF, 1) &&
|
||||
VerifyOffset(verifier, VT_ASSET_A_REFS) &&
|
||||
verifier.VerifyVector(asset_a_refs()) &&
|
||||
VerifyField<Flat::Bigfoot::HardReference>(verifier, VT_ANY_ASSET, 1) &&
|
||||
VerifyOffset(verifier, VT_ANY_ASSETS) &&
|
||||
verifier.VerifyVector(any_assets()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
InnerTableT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
@@ -139,12 +118,6 @@ struct InnerTableBuilder {
|
||||
void add_asset_a_refs(::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::HardReference *>> asset_a_refs) {
|
||||
fbb_.AddOffset(InnerTable::VT_ASSET_A_REFS, asset_a_refs);
|
||||
}
|
||||
void add_any_asset(const Flat::Bigfoot::HardReference *any_asset) {
|
||||
fbb_.AddStruct(InnerTable::VT_ANY_ASSET, any_asset);
|
||||
}
|
||||
void add_any_assets(::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *>> any_assets) {
|
||||
fbb_.AddOffset(InnerTable::VT_ANY_ASSETS, any_assets);
|
||||
}
|
||||
explicit InnerTableBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
@@ -159,12 +132,8 @@ struct InnerTableBuilder {
|
||||
inline ::flatbuffers::Offset<InnerTable> CreateInnerTable(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const Flat::Bigfoot::HardReference *asset_a_ref = nullptr,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::HardReference *>> asset_a_refs = 0,
|
||||
const Flat::Bigfoot::HardReference *any_asset = nullptr,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *>> any_assets = 0) {
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::HardReference *>> asset_a_refs = 0) {
|
||||
InnerTableBuilder builder_(_fbb);
|
||||
builder_.add_any_assets(any_assets);
|
||||
builder_.add_any_asset(any_asset);
|
||||
builder_.add_asset_a_refs(asset_a_refs);
|
||||
builder_.add_asset_a_ref(asset_a_ref);
|
||||
return builder_.Finish();
|
||||
@@ -285,8 +254,6 @@ inline void InnerTable::UnPackTo(InnerTableT *_o, const ::flatbuffers::resolver_
|
||||
(void)_resolver;
|
||||
{ auto _e = asset_a_ref(); if (_e) _o->asset_a_ref = ::flatbuffers::UnPackHardReferenceAssetA(*_e); }
|
||||
{ auto _e = asset_a_refs(); if (_e) { _o->asset_a_refs.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->asset_a_refs[_i] = ::flatbuffers::UnPackHardReferenceAssetA(*_e->Get(_i)); } } else { _o->asset_a_refs.resize(0); } }
|
||||
{ auto _e = any_asset(); if (_e) _o->any_asset = ::flatbuffers::UnPackHardReferenceAssetBase(*_e); }
|
||||
{ auto _e = any_assets(); if (_e) { _o->any_assets.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->any_assets[_i] = ::flatbuffers::UnPackSoftReferenceAssetBase(*_e->Get(_i)); } } else { _o->any_assets.resize(0); } }
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<InnerTable> CreateInnerTable(::flatbuffers::FlatBufferBuilder &_fbb, const InnerTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
@@ -299,14 +266,10 @@ inline ::flatbuffers::Offset<InnerTable> InnerTable::Pack(::flatbuffers::FlatBuf
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const InnerTableT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _asset_a_ref = ::flatbuffers::PackHardReferenceAssetA(_o->asset_a_ref);
|
||||
auto _asset_a_refs = _fbb.CreateVectorOfNativeStructs<Flat::Bigfoot::HardReference, ::Bigfoot::HardReference<::Bigfoot::AssetA>>(_o->asset_a_refs.data(), _o->asset_a_refs.size(), ::flatbuffers::PackHardReferenceAssetA);
|
||||
auto _any_asset = ::flatbuffers::PackHardReferenceAssetBase(_o->any_asset);
|
||||
auto _any_assets = _fbb.CreateVectorOfNativeStructs<Flat::Bigfoot::SoftReference, ::Bigfoot::SoftReference<::Bigfoot::AssetBase>>(_o->any_assets.data(), _o->any_assets.size(), ::flatbuffers::PackSoftReferenceAssetBase);
|
||||
return Flat::Bigfoot::CreateInnerTable(
|
||||
_fbb,
|
||||
&_asset_a_ref,
|
||||
_asset_a_refs,
|
||||
&_any_asset,
|
||||
_any_assets);
|
||||
_asset_a_refs);
|
||||
}
|
||||
|
||||
inline AssetCT::AssetCT(const AssetCT &o)
|
||||
@@ -357,16 +320,13 @@ inline ::flatbuffers::Offset<AssetC> AssetC::Pack(::flatbuffers::FlatBufferBuild
|
||||
inline const ::flatbuffers::TypeTable *InnerTableTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 1 }
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 0 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Flat::Bigfoot::HardReferenceTypeTable,
|
||||
Flat::Bigfoot::SoftReferenceTypeTable
|
||||
Flat::Bigfoot::HardReferenceTypeTable
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 4, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
::flatbuffers::ST_TABLE, 2, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
@@ -445,16 +405,6 @@ namespace flatbuffers {
|
||||
inline Flat::Bigfoot::HardReference PackHardReferenceAssetA(const ::Bigfoot::HardReference<::Bigfoot::AssetA>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
inline ::Bigfoot::HardReference<::Bigfoot::AssetA> UnPackHardReferenceAssetA(const Flat::Bigfoot::HardReference& p_asset) { return {UnPack(p_asset.uuid())}; }
|
||||
#endif // FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETA
|
||||
#ifndef FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETBASE
|
||||
#define FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETBASE
|
||||
inline Flat::Bigfoot::HardReference PackHardReferenceAssetBase(const ::Bigfoot::HardReference<::Bigfoot::AssetBase>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
inline ::Bigfoot::HardReference<::Bigfoot::AssetBase> UnPackHardReferenceAssetBase(const Flat::Bigfoot::HardReference& p_asset) { return {UnPack(p_asset.uuid())}; }
|
||||
#endif // FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETBASE
|
||||
#ifndef FLATBUFFERS_BIGFOOT_REF_SOFTREFERENCEASSETBASE
|
||||
#define FLATBUFFERS_BIGFOOT_REF_SOFTREFERENCEASSETBASE
|
||||
inline Flat::Bigfoot::SoftReference PackSoftReferenceAssetBase(const ::Bigfoot::SoftReference<::Bigfoot::AssetBase>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
inline ::Bigfoot::SoftReference<::Bigfoot::AssetBase> UnPackSoftReferenceAssetBase(const Flat::Bigfoot::SoftReference& p_asset) { return {UnPack(p_asset.uuid())}; }
|
||||
#endif // FLATBUFFERS_BIGFOOT_REF_SOFTREFERENCEASSETBASE
|
||||
#ifndef FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETB
|
||||
#define FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETB
|
||||
inline Flat::Bigfoot::HardReference PackHardReferenceAssetB(const ::Bigfoot::HardReference<::Bigfoot::AssetB>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
|
||||
Reference in New Issue
Block a user