16 struct GenericAssetReference {
17 GenericAssetReference() =
default;
19 GenericAssetReference(
const GenericAssetReference& other) =
default;
20 GenericAssetReference(GenericAssetReference&& other) =
default;
22 GenericAssetReference& operator=(
const GenericAssetReference& other)
noexcept {
27 GenericAssetReference& operator=(GenericAssetReference&& other)
noexcept {
32 operator bool()
const noexcept {
33 return uuid.IsValid();
37 bool IsValid()
const noexcept {
38 return uuid.IsValid();
45 struct AssetReference :
public GenericAssetReference {
46 static_assert(std::is_base_of_v<Grindstone::Asset, T>,
"T not derived from Grindstone::Asset");
48 static AssetReference<T> CreateWithoutIncrement(
Uuid uuid) {
49 return AssetReference(uuid);
52 static AssetReference<T> CreateAndIncrement(
Uuid uuid) {
53 Grindstone::AssetFunctions::Increment(T::GetStaticType(), uuid);
54 return AssetReference(uuid);
57 AssetReference() : GenericAssetReference() {}
59 AssetReference(
const AssetReference& other) : GenericAssetReference(other.uuid) {
60 Grindstone::AssetFunctions::Increment(T::GetStaticType(), uuid);
63 AssetReference(AssetReference&& other) noexcept : GenericAssetReference(other.uuid) {}
65 AssetReference& operator=(
const AssetReference& other)
noexcept {
66 if (uuid != other.uuid) {
68 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
72 Grindstone::AssetFunctions::Increment(T::GetStaticType(), uuid);
78 AssetReference& operator=(AssetReference&& other)
noexcept {
79 if (uuid != other.uuid) {
81 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
93 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
100 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
106 [[nodiscard]] T* GetUnchecked() {
107 return reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
111 [[nodiscard]]
const T* GetUnchecked()
const {
112 return reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
116 [[nodiscard]] T* Get() {
117 T* asset =
reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
118 return asset && asset->assetLoadStatus == Grindstone::AssetLoadStatus::Ready
124 [[nodiscard]]
const T* Get()
const {
125 T* asset =
reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
126 return asset && asset->assetLoadStatus == Grindstone::AssetLoadStatus::Ready