diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp index c4b945d..14eded2 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/Asset.hpp @@ -6,6 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_ENGINE_ASSET_ASSET_HPP #define BIGFOOT_ENGINE_ASSET_ASSET_HPP +#include #include #include @@ -33,6 +34,7 @@ class AssetBase }; template + requires AssetTraits class Asset: public AssetBase { public: diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetConcepts.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetConcepts.hpp new file mode 100644 index 0000000..1038b9a --- /dev/null +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetConcepts.hpp @@ -0,0 +1,40 @@ +/********************************************************************* + * \file AssetConcepts.hpp + * + * \author Romain BOULLARD + * \date August 2026 + *********************************************************************/ +#ifndef BIGFOOT_ENGINE_ASSET_ASSETCONCEPTS_HPP +#define BIGFOOT_ENGINE_ASSET_ASSETCONCEPTS_HPP +#include + +#include + +#include + +namespace Bigfoot +{ +class AssetBase; + +/** + * The traits struct passed to Asset (e.g. AssetATraits). + * Must name the generated flatbuffers table type for the asset. + */ +template +concept AssetTraits = requires { + typename TRAITS::FLAT; + typename TRAITS::FLAT::NativeTableType; + { TRAITS::FLAT::GetFullyQualifiedName() } -> std::convertible_to; +}; + +/** + * A concrete Asset type (e.g. AssetA), usable with AssetContainer, AssetLibrary and References. + */ +template +concept AssetType = std::derived_from && !std::same_as && + requires(const ASSET& p_asset) { + { ASSET::GetTypeID() } -> std::convertible_to; + { p_asset.GetHeader().uuid } -> std::convertible_to; + }; +} // namespace Bigfoot +#endif diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp index 8f5f365..480e6fc 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetContainer.hpp @@ -7,6 +7,7 @@ #ifndef BIGFOOT_ENGINE_ASSET_ASSETCONTAINER_HPP #define BIGFOOT_ENGINE_ASSET_ASSETCONTAINER_HPP #include +#include #include #include @@ -284,6 +285,7 @@ class AssetContainerBase /****************************************************************************************/ template + requires AssetType class AssetContainer: public AssetContainerBase { using SlotMap = StableSlotMap; diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp index fa34daf..e1c6bb2 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/AssetLibrary.hpp @@ -6,6 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_ENGINE_ASSET_ASSETLIBRARY_HPP #define BIGFOOT_ENGINE_ASSET_ASSETLIBRARY_HPP +#include #include #include @@ -31,6 +32,7 @@ class AssetLibrary * \return The AssetContainer for the Asset type. Nullptr if not found */ template + requires AssetType [[nodiscard]] bool Insert(AssetContainer* p_assetContainer) { diff --git a/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp b/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp index 7c48858..4a8a9aa 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/Asset/Reference.hpp @@ -6,6 +6,7 @@ *********************************************************************/ #ifndef BIGFOOT_ENGINE_ASSET_REFERENCE_HPP #define BIGFOOT_ENGINE_ASSET_REFERENCE_HPP +#include #include #include @@ -43,6 +44,7 @@ class ReferenceBase [[nodiscard]] const ASSET* Get() const { + static_assert(AssetType, "ASSET must derive from AssetBase (and not be AssetBase itself)"); return m_handle ? static_cast(m_handle->GetAsset()) : nullptr; } @@ -54,6 +56,7 @@ class ReferenceBase [[nodiscard]] ASSET* Get() { + static_assert(AssetType, "ASSET must derive from AssetBase (and not be AssetBase itself)"); return m_handle ? static_cast(m_handle->GetAsset()) : nullptr; }