Cleanup
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m15s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 5m48s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m39s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m29s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m20s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m25s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m18s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 1m10s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 7m28s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m16s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 3m55s
Bigfoot / Clang Format Checks (push) Canceled after 0s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Canceled after 2m13s
Bigfoot / Sonarqube (push) Skipped

This commit is contained in:
2026-08-18 17:30:39 +02:00
parent 9978ff358b
commit 870bfe57e6
@@ -17,26 +17,26 @@ namespace Bigfoot
template<class ASSET>
AssetTypeID GetAssetTypeID();
template<class ASSET>
class HardReference
template<class DERIVED, class ASSET>
class ReferenceBase
{
public:
HardReference() = default;
ReferenceBase() = default;
HardReference(const UUID& p_uuid):
ReferenceBase(const UUID& p_uuid):
m_uuid(p_uuid)
{
Acquire();
}
HardReference(const HardReference& p_ref):
ReferenceBase(const ReferenceBase& p_ref):
m_uuid(p_ref.m_uuid),
m_handle(p_ref.m_handle)
{
Acquire();
}
HardReference(HardReference&& p_ref) noexcept:
ReferenceBase(ReferenceBase&& p_ref) noexcept:
m_uuid(std::exchange(p_ref.m_uuid, UUID::NULL_UUID)),
m_handle(std::exchange(p_ref.m_handle, nullptr))
{
@@ -60,12 +60,12 @@ class HardReference
return m_handle ? static_cast<ASSET*>(m_handle->GetAsset()) : nullptr;
}
~HardReference()
~ReferenceBase()
{
Release();
}
HardReference& operator=(const HardReference& p_ref)
ReferenceBase& operator=(const ReferenceBase& p_ref)
{
if (this != &p_ref)
{
@@ -77,7 +77,7 @@ class HardReference
return *this;
}
HardReference& operator=(HardReference&& p_ref) noexcept
ReferenceBase& operator=(ReferenceBase&& p_ref) noexcept
{
if (this != &p_ref)
{
@@ -89,7 +89,7 @@ class HardReference
}
[[nodiscard]]
bool operator==(const HardReference& p_ref) const
bool operator==(const ReferenceBase& p_ref) const
{
return m_uuid == p_ref.m_uuid;
}
@@ -108,7 +108,7 @@ class HardReference
{
m_handle = assetContainer->AcquireContainerHandle(m_uuid);
}
m_handle->IncrementHardRefCount();
DERIVED::IncrementCount(*m_handle);
}
}
@@ -116,7 +116,7 @@ class HardReference
{
if (m_handle)
{
m_handle->DecrementHardRefCount();
DERIVED::DecrementCount(*m_handle);
m_handle = nullptr;
}
}
@@ -126,111 +126,37 @@ class HardReference
};
template<class ASSET>
class SoftReference
class HardReference: public ReferenceBase<HardReference<ASSET>, ASSET>
{
public:
SoftReference() = default;
SoftReference(const UUID& p_uuid):
m_uuid(p_uuid)
{
Acquire();
}
SoftReference(const SoftReference& p_ref):
m_uuid(p_ref.m_uuid),
m_handle(p_ref.m_handle)
{
Acquire();
}
SoftReference(SoftReference&& p_ref) noexcept:
m_uuid(std::exchange(p_ref.m_uuid, UUID::NULL_UUID)),
m_handle(std::exchange(p_ref.m_handle, nullptr))
{
}
[[nodiscard]]
const UUID& GetUUID() const
{
return m_uuid;
}
[[nodiscard]]
const ASSET* Get() const
{
return m_handle ? static_cast<const ASSET*>(m_handle->GetAsset()) : nullptr;
}
[[nodiscard]]
ASSET* Get()
{
return m_handle ? static_cast<ASSET*>(m_handle->GetAsset()) : nullptr;
}
~SoftReference()
{
Release();
}
SoftReference& operator=(const SoftReference& p_ref)
{
if (this != &p_ref)
{
Release();
m_uuid = p_ref.m_uuid;
m_handle = p_ref.m_handle;
Acquire();
}
return *this;
}
SoftReference& operator=(SoftReference&& p_ref) noexcept
{
if (this != &p_ref)
{
Release();
m_uuid = std::exchange(p_ref.m_uuid, UUID::NULL_UUID);
m_handle = std::exchange(p_ref.m_handle, nullptr);
}
return *this;
}
[[nodiscard]]
bool operator==(const SoftReference& p_ref) const
{
return m_uuid == p_ref.m_uuid;
}
private:
void Acquire()
static void IncrementCount(ContainerHandle& p_handle)
{
if (!m_uuid)
{
return;
}
if (AssetContainerBase* assetContainer = g_activeAssetLibrary->GetAssetContainer(GetAssetTypeID<ASSET>()))
{
if (!m_handle)
{
m_handle = assetContainer->AcquireContainerHandle(m_uuid);
}
m_handle->IncrementSoftRefCount();
}
p_handle.IncrementHardRefCount();
}
void Release()
static void DecrementCount(ContainerHandle& p_handle)
{
if (m_handle)
{
m_handle->DecrementSoftRefCount();
m_handle = nullptr;
}
p_handle.DecrementHardRefCount();
}
UUID m_uuid = UUID::NULL_UUID;
ContainerHandle* m_handle = nullptr;
friend ReferenceBase<HardReference<ASSET>, ASSET>;
};
template<class ASSET>
class SoftReference: public ReferenceBase<SoftReference<ASSET>, ASSET>
{
private:
static void IncrementCount(ContainerHandle& p_handle)
{
p_handle.IncrementSoftRefCount();
}
static void DecrementCount(ContainerHandle& p_handle)
{
p_handle.DecrementSoftRefCount();
}
friend ReferenceBase<SoftReference<ASSET>, ASSET>;
};
} // namespace Bigfoot
#endif