Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
assets.hpp
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include "
core_types.hpp
"
12
13
#include <atomic>
14
#include <string>
15
#include <string_view>
16
#include <toast/events/event.hpp>
17
#include <
toast/export.hpp
>
18
#include <
toast/uid.hpp
>
19
#include <utility>
20
21
namespace
assets {
22
23
// Public load functions
24
auto
TOAST_API load(toast::UID uid) ->
HandleBase
;
25
auto
TOAST_API load(std::string_view uri) ->
HandleBase
;
26
auto
TOAST_API resolveURI(std::string_view uri) -> std::optional<toast::UID>;
27
33
auto
TOAST_API listByType(std::string_view type) -> std::vector<toast::UID>;
34
39
auto
TOAST_API typeOf(toast::UID uid) -> std::string;
40
41
auto
TOAST_API save(toast::UID uid) -> bool;
42
46
template
<
typename
T>
47
auto
load(
toast::UID
uid) ->
Handle<T>
{
48
auto
base = load(uid);
49
// Carry the UID anyway, so the result is an unresolved handle (uid set, ptr null)
50
return
Handle<T>
(base.hasValue() ? &base.get() :
nullptr
, base.uid(), base.path());
51
}
52
53
template
<
typename
T>
54
auto
load(std::string_view uri) -> Handle<T> {
55
auto
base = load(uri);
56
return
Handle<T>(base.hasValue() ? &base.get() :
nullptr
, base.uid(), base.path());
57
}
58
59
}
60
61
namespace
event {
62
66
struct
ReloadAssetsManifest
:
public
Event<ReloadAssetsManifest> { };
67
68
struct
PrefabAssetReloaded :
public
Event<PrefabAssetReloaded> {
69
toast::UID
uid;
70
71
explicit
PrefabAssetReloaded(
toast::UID
uid) : uid(uid) { }
72
};
73
77
struct
ScriptAssetReloaded :
public
Event<ScriptAssetReloaded> {
78
toast::UID
uid;
79
80
explicit
ScriptAssetReloaded(
toast::UID
uid) : uid(uid) { }
81
};
82
86
struct
ShaderAssetReloaded :
public
Event<ShaderAssetReloaded> {
87
toast::UID
uid;
88
89
explicit
ShaderAssetReloaded(
toast::UID
uid) : uid(uid) { }
90
};
91
95
struct
MaterialAssetReloaded :
public
Event<MaterialAssetReloaded> {
96
toast::UID
uid;
97
98
explicit
MaterialAssetReloaded(
toast::UID
uid) : uid(uid) { }
99
};
100
101
struct
VoxelPaletteAssetReloaded :
public
Event<VoxelPaletteAssetReloaded> {
102
toast::UID
uid;
103
104
explicit
VoxelPaletteAssetReloaded(
toast::UID
uid) : uid(uid) { }
105
};
106
108
struct
DataAssetReloaded :
public
Event<DataAssetReloaded> {
109
toast::UID
uid;
110
111
explicit
DataAssetReloaded(
toast::UID
uid) : uid(uid) { }
112
};
113
117
struct
AssetReplaced :
public
Event<AssetReplaced> {
118
toast::UID
uid;
119
std::string type;
120
121
AssetReplaced(
toast::UID
uid, std::string type) : uid(uid), type(std::move(type)) { }
122
};
123
127
struct
UIAssetReloaded :
public
Event<UIAssetReloaded> {
128
toast::UID
uid;
129
std::string type;
130
131
UIAssetReloaded(
toast::UID
uid, std::string type) : uid(uid), type(std::move(type)) { }
132
};
133
137
struct
ClearUnusedAssets
:
public
Event<ClearUnusedAssets> { };
138
139
}
assets::HandleBase
Base class for type-erased asset handles.
Definition
core_types.hpp:72
assets::Handle
Type-safe smart pointer for assets.
Definition
core_types.hpp:149
core_types.hpp
Base types for the asset system.
export.hpp
event::ClearUnusedAssets
Fired to request the unloading of all unused assets.
Definition
assets.hpp:137
event::ReloadAssetsManifest
Fired to request a refresh of the asset manifest.
Definition
assets.hpp:66
toast::UID
Definition
uid.hpp:20
uid.hpp
Unique identifier for everything that exists in our engine.
engine
src
toast
assets
assets.hpp
Generated by
1.17.0