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) {
61 Grindstone::AssetFunctions::Increment(T::GetStaticType(), uuid);
65 AssetReference(AssetReference&& other) noexcept : GenericAssetReference(other.uuid) {
69 AssetReference& operator=(
const AssetReference& other) {
70 if (uuid != other.uuid) {
72 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
77 Grindstone::AssetFunctions::Increment(T::GetStaticType(), uuid);
84 AssetReference& operator=(AssetReference&& other)
noexcept {
85 if (uuid != other.uuid) {
87 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
99 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
105 if (uuid.IsValid()) {
106 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
112 [[nodiscard]] T* GetUnchecked() {
113 return reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
117 [[nodiscard]]
const T* GetUnchecked()
const {
118 return reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
122 [[nodiscard]] T* Get() {
123 T* asset =
reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
124 return asset && asset->assetLoadStatus == Grindstone::AssetLoadStatus::Ready
130 [[nodiscard]]
const T* Get()
const {
131 T* asset =
reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
132 return asset && asset->assetLoadStatus == Grindstone::AssetLoadStatus::Ready