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) {
67 AssetReference& operator=(
const AssetReference& other) {
68 if (uuid != other.uuid) {
70 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
75 Grindstone::AssetFunctions::Increment(T::GetStaticType(), uuid);
82 AssetReference& operator=(AssetReference&& other)
noexcept {
83 if (uuid != other.uuid) {
85 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
97 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
103 if (uuid.IsValid()) {
104 Grindstone::AssetFunctions::Decrement(T::GetStaticType(), uuid);
110 [[nodiscard]] T* GetUnchecked() {
111 return reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
115 [[nodiscard]]
const T* GetUnchecked()
const {
116 return reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
120 [[nodiscard]] T* Get() {
121 T* asset =
reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
122 return asset && asset->assetLoadStatus == Grindstone::AssetLoadStatus::Ready
128 [[nodiscard]]
const T* Get()
const {
129 T* asset =
reinterpret_cast<T*
>(Grindstone::AssetFunctions::Get(T::GetStaticType(), uuid));
130 return asset && asset->assetLoadStatus == Grindstone::AssetLoadStatus::Ready