|
Vulkan Schnee 0.0.1
High-performance rendering engine
|
A manager which is used to look up existing assets and their loading state. More...
#include <Asset.h>
Public Types | |
| using | RefType = Ref<Key, AssetClass> |
| using | RecordType = Record<Key, AssetClass> |
| using | ResultType = LoadResult<Key, AssetClass> |
Public Member Functions | |
| AssetManager ()=default | |
| virtual | ~AssetManager ()=default |
| template<typename... Args> | |
| void | declare (Key path, Args &&... args) |
| Adds an asset to the list in its unloaded state. | |
| void | add (Key path, AssetClass *asset) |
| Adds or overwrites a previously declared asset at a key. | |
| RefType | getOrCreateRef (const Key &path) |
| Gets a stable asset reference, creating a record if necessary. | |
| RefType | getRef (const Key &path) const |
| Gets a stable asset reference if a record exists, otherwise an expired ref. | |
| void | setAssetLoadingState (const Key &path, LoadState state) |
| Sets the record loading state without requiring a payload object. | |
| void | resolve (const Key &path, std::unique_ptr< AssetClass > asset) |
| Stores a loaded payload and resolves the record's ready future. | |
| void | fail (const Key &path, std::string error) |
| Marks the record as failed and resolves the ready future with an error. | |
| void | unloadAssetPayload (const Key &path) |
| Drops the loaded payload while preserving the stable record. | |
| bool | exists (Key path) |
| Checks if an asset already exists. This means it is declared and there is content. | |
| bool | isDeclared (Key path) |
| Checks if an asset has been declared. If it exists it is also declared. | |
| CpuLoadingState | getAssetLoadingState (const Key &path) |
| Gets a loading state for an asset. If the asset is not yet declared it will return that it is UNLOADED. | |
| std::optional< AssetClass * > | getAsset (const Key &path) |
| Try's to get an asset. If the asset does not exist (can be checked with exists) it will return a std::nullopt. | |
| virtual void | clear () |
| Clears out all resources. | |
| template<typename Func> | |
| void | forEachAsset (Func &&func) const |
| Iterates over all assets and calls the provided callback for each. | |
Private Member Functions | |
| std::shared_ptr< RecordType > | getOrCreateRecord (const Key &path) |
| std::shared_ptr< RecordType > | getRecord (const Key &path) const |
| void | completeRecord (const std::shared_ptr< RecordType > &record, bool success, std::string error={}) |
| void | syncRecordStateFromPayload (const std::shared_ptr< RecordType > &record) const |
Private Attributes | |
| std::unordered_map< Key, std::shared_ptr< RecordType > > | records |
A manager which is used to look up existing assets and their loading state.
| Key | The type of the assets key with which to access the data. This is most often the path to the asset on disc |
| AssetClass | The asset class which is a derivative of Asset::AssetBase. |
| using Asset::AssetManager< Key, AssetClass >::RecordType = Record<Key, AssetClass> |
| using Asset::AssetManager< Key, AssetClass >::RefType = Ref<Key, AssetClass> |
| using Asset::AssetManager< Key, AssetClass >::ResultType = LoadResult<Key, AssetClass> |
|
default |
|
virtualdefault |
| void Asset::AssetManager< Key, AssetClass >::add | ( | Key | path, |
| AssetClass * | asset ) |
Adds or overwrites a previously declared asset at a key.
| path | The key with which to access the asset |
| asset | The asset to manage |
Definition at line 396 of file Asset.h.
References completeRecord(), getOrCreateRecord(), Asset::LOADED, syncRecordStateFromPayload(), and TRACY_ZONE_SCOPED_NAMED.
|
virtual |
Clears out all resources.
Definition at line 499 of file Asset.h.
References records, TRACY_ZONE_SCOPED_NAMED, and Asset::UNLOADED.
|
private |
Definition at line 535 of file Asset.h.
References Asset::LoadResult< Key, AssetClass >::asset, Asset::LoadResult< Key, AssetClass >::error, Asset::LoadResult< Key, AssetClass >::generation, Asset::LoadResult< Key, AssetClass >::ref, and Asset::LoadResult< Key, AssetClass >::success.
Referenced by add(), declare(), fail(), resolve(), setAssetLoadingState(), and syncRecordStateFromPayload().
| void Asset::AssetManager< Key, AssetClass >::declare | ( | Key | path, |
| Args &&... | args ) |
Adds an asset to the list in its unloaded state.
| Args | arguments to feed the empty assets constructor at the location |
| path | location to create the asset at in the asset manager |
| args | arguments for the asset constructor |
Definition at line 384 of file Asset.h.
References completeRecord(), getOrCreateRecord(), Asset::LOADED, and syncRecordStateFromPayload().
| bool Asset::AssetManager< Key, AssetClass >::exists | ( | Key | path | ) |
Checks if an asset already exists. This means it is declared and there is content.
| path | the key to check |
Definition at line 470 of file Asset.h.
References getRecord().
| void Asset::AssetManager< Key, AssetClass >::fail | ( | const Key & | path, |
| std::string | error ) |
Marks the record as failed and resolves the ready future with an error.
Definition at line 450 of file Asset.h.
References completeRecord(), Asset::FAILED, and getOrCreateRecord().
|
inline |
| std::optional< AssetClass * > Asset::AssetManager< Key, AssetClass >::getAsset | ( | const Key & | path | ) |
Try's to get an asset. If the asset does not exist (can be checked with exists) it will return a std::nullopt.
| path | The asset to get |
Definition at line 490 of file Asset.h.
References getRecord(), syncRecordStateFromPayload(), and TRACY_ZONE_SCOPED_NAMED.
| CpuLoadingState Asset::AssetManager< Key, AssetClass >::getAssetLoadingState | ( | const Key & | path | ) |
Gets a loading state for an asset. If the asset is not yet declared it will return that it is UNLOADED.
| path | which asset to get the loading state for |
Definition at line 482 of file Asset.h.
References getRecord(), syncRecordStateFromPayload(), and Asset::UNLOADED.
|
private |
Definition at line 517 of file Asset.h.
References records.
Referenced by add(), declare(), fail(), getOrCreateRef(), resolve(), and setAssetLoadingState().
| AssetManager< Key, AssetClass >::RefType Asset::AssetManager< Key, AssetClass >::getOrCreateRef | ( | const Key & | path | ) |
Gets a stable asset reference, creating a record if necessary.
Definition at line 410 of file Asset.h.
References getOrCreateRecord().
|
nodiscardprivate |
Definition at line 529 of file Asset.h.
References records.
Referenced by exists(), getAsset(), getAssetLoadingState(), getRef(), and unloadAssetPayload().
|
nodiscard |
Gets a stable asset reference if a record exists, otherwise an expired ref.
Definition at line 415 of file Asset.h.
References getRecord().
| bool Asset::AssetManager< Key, AssetClass >::isDeclared | ( | Key | path | ) |
| void Asset::AssetManager< Key, AssetClass >::resolve | ( | const Key & | path, |
| std::unique_ptr< AssetClass > | asset ) |
Stores a loaded payload and resolves the record's ready future.
Definition at line 441 of file Asset.h.
References completeRecord(), getOrCreateRecord(), and Asset::LOADED.
| void Asset::AssetManager< Key, AssetClass >::setAssetLoadingState | ( | const Key & | path, |
| LoadState | state ) |
Sets the record loading state without requiring a payload object.
Definition at line 420 of file Asset.h.
References completeRecord(), Asset::FAILED, getOrCreateRecord(), Asset::LOADED, Asset::LOADING, Asset::REQUESTED_LOAD, and Asset::UNLOADED.
|
private |
Definition at line 550 of file Asset.h.
References AssetManager(), completeRecord(), Asset::FAILED, and Asset::LOADED.
Referenced by add(), declare(), getAsset(), and getAssetLoadingState().
| void Asset::AssetManager< Key, AssetClass >::unloadAssetPayload | ( | const Key & | path | ) |
Drops the loaded payload while preserving the stable record.
Definition at line 459 of file Asset.h.
References getRecord(), and Asset::UNLOADED.
|
private |
Definition at line 379 of file Asset.h.
Referenced by clear(), forEachAsset(), getOrCreateRecord(), getRecord(), and isDeclared().