Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Asset::AssetManager< Key, AssetClass > Class Template Reference

A manager which is used to look up existing assets and their loading state. More...

#include <Asset.h>

Collaboration diagram for Asset::AssetManager< Key, AssetClass >:

Public Types

using RefType = Ref<Key, AssetClass>
 Stable reference type returned by this manager.
using RecordType = Record<Key, AssetClass>
 Internal record type stored by this manager.
using ResultType = LoadResult<Key, AssetClass>
 Completion result type for async loads.

Public Member Functions

 AssetManager ()=default
 Creates an empty asset manager.
virtual ~AssetManager ()=default
 Destroys the manager object.
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

Detailed Description

template<typename Key, typename AssetClass>
class Asset::AssetManager< Key, AssetClass >

A manager which is used to look up existing assets and their loading state.

Template Parameters
KeyThe type of the assets key with which to access the data. This is most often the path to the asset on disc
AssetClassThe asset class which is a derivative of Asset::AssetBase.

Definition at line 358 of file Asset.h.

Member Typedef Documentation

◆ RecordType

template<typename Key, typename AssetClass>
using Asset::AssetManager< Key, AssetClass >::RecordType = Record<Key, AssetClass>

Internal record type stored by this manager.

Definition at line 361 of file Asset.h.

◆ RefType

template<typename Key, typename AssetClass>
using Asset::AssetManager< Key, AssetClass >::RefType = Ref<Key, AssetClass>

Stable reference type returned by this manager.

Definition at line 360 of file Asset.h.

◆ ResultType

template<typename Key, typename AssetClass>
using Asset::AssetManager< Key, AssetClass >::ResultType = LoadResult<Key, AssetClass>

Completion result type for async loads.

Definition at line 362 of file Asset.h.

Constructor & Destructor Documentation

◆ AssetManager()

template<typename Key, typename AssetClass>
Asset::AssetManager< Key, AssetClass >::AssetManager ( )
default

Creates an empty asset manager.

Referenced by syncRecordStateFromPayload().

Here is the caller graph for this function:

◆ ~AssetManager()

template<typename Key, typename AssetClass>
virtual Asset::AssetManager< Key, AssetClass >::~AssetManager ( )
virtualdefault

Destroys the manager object.

Member Function Documentation

◆ add()

template<typename Key, typename AssetClass>
void Asset::AssetManager< Key, AssetClass >::add ( Key path,
AssetClass * asset )

Adds or overwrites a previously declared asset at a key.

Parameters
pathThe key with which to access the asset
assetThe asset to manage

Definition at line 491 of file Asset.h.

References completeRecord(), getOrCreateRecord(), Asset::LOADED, and syncRecordStateFromPayload().

Here is the call graph for this function:

◆ clear()

template<typename Key, typename AssetClass>
void Asset::AssetManager< Key, AssetClass >::clear ( )
virtual

Clears out all resources.

Definition at line 594 of file Asset.h.

References records, and Asset::UNLOADED.

◆ completeRecord()

template<typename Key, typename AssetClass>
void Asset::AssetManager< Key, AssetClass >::completeRecord ( const std::shared_ptr< RecordType > & record,
bool success,
std::string error = {} )
private

Definition at line 630 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().

Here is the caller graph for this function:

◆ declare()

template<typename Key, typename AssetClass>
template<typename... Args>
void Asset::AssetManager< Key, AssetClass >::declare ( Key path,
Args &&... args )

Adds an asset to the list in its unloaded state.

Template Parameters
Argsarguments to feed the empty assets constructor at the location
Parameters
pathlocation to create the asset at in the asset manager
argsarguments for the asset constructor

Definition at line 479 of file Asset.h.

References completeRecord(), getOrCreateRecord(), Asset::LOADED, and syncRecordStateFromPayload().

Here is the call graph for this function:

◆ exists()

template<typename Key, typename AssetClass>
bool Asset::AssetManager< Key, AssetClass >::exists ( Key path)

Checks if an asset already exists. This means it is declared and there is content.

Parameters
paththe key to check
Returns
true if it exists

Definition at line 565 of file Asset.h.

References getRecord().

Here is the call graph for this function:

◆ fail()

template<typename Key, typename AssetClass>
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 545 of file Asset.h.

References completeRecord(), Asset::FAILED, and getOrCreateRecord().

Here is the call graph for this function:

◆ forEachAsset()

template<typename Key, typename AssetClass>
template<typename Func>
void Asset::AssetManager< Key, AssetClass >::forEachAsset ( Func && func) const
inline

Iterates over all assets and calls the provided callback for each.

Template Parameters
FuncCallable type that accepts (const Key&, AssetClass*)
Parameters
funcThe callback to invoke for each asset

Definition at line 460 of file Asset.h.

References records.

◆ getAsset()

template<typename Key, typename AssetClass>
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.

Parameters
pathThe asset to get
Returns
If it exists a pointer to the Asset. If it didn't exist a std::nullopt

Definition at line 585 of file Asset.h.

References getRecord(), and syncRecordStateFromPayload().

Here is the call graph for this function:

◆ getAssetLoadingState()

template<typename Key, typename AssetClass>
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.

Parameters
pathwhich asset to get the loading state for
Returns
The loading state of an asset

Definition at line 577 of file Asset.h.

References getRecord(), syncRecordStateFromPayload(), and Asset::UNLOADED.

Here is the call graph for this function:

◆ getOrCreateRecord()

template<typename Key, typename AssetClass>
std::shared_ptr< typename AssetManager< Key, AssetClass >::RecordType > Asset::AssetManager< Key, AssetClass >::getOrCreateRecord ( const Key & path)
private

Definition at line 612 of file Asset.h.

References records.

Referenced by add(), declare(), fail(), getOrCreateRef(), resolve(), and setAssetLoadingState().

Here is the caller graph for this function:

◆ getOrCreateRef()

template<typename Key, typename AssetClass>
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 505 of file Asset.h.

References getOrCreateRecord().

Here is the call graph for this function:

◆ getRecord()

template<typename Key, typename AssetClass>
std::shared_ptr< typename AssetManager< Key, AssetClass >::RecordType > Asset::AssetManager< Key, AssetClass >::getRecord ( const Key & path) const
nodiscardprivate

Definition at line 624 of file Asset.h.

References records.

Referenced by exists(), getAsset(), getAssetLoadingState(), getRef(), and unloadAssetPayload().

Here is the caller graph for this function:

◆ getRef()

template<typename Key, typename AssetClass>
AssetManager< Key, AssetClass >::RefType Asset::AssetManager< Key, AssetClass >::getRef ( const Key & path) const
nodiscard

Gets a stable asset reference if a record exists, otherwise an expired ref.

Definition at line 510 of file Asset.h.

References getRecord().

Here is the call graph for this function:

◆ isDeclared()

template<typename Key, typename AssetClass>
bool Asset::AssetManager< Key, AssetClass >::isDeclared ( Key path)

Checks if an asset has been declared. If it exists it is also declared.

Parameters
pathkey to check
Returns
true if it is declared. If it is declared and exists this is also true

Definition at line 571 of file Asset.h.

References records.

◆ resolve()

template<typename Key, typename AssetClass>
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 536 of file Asset.h.

References completeRecord(), getOrCreateRecord(), and Asset::LOADED.

Here is the call graph for this function:

◆ setAssetLoadingState()

template<typename Key, typename AssetClass>
void Asset::AssetManager< Key, AssetClass >::setAssetLoadingState ( const Key & path,
LoadState state )

Sets the record loading state without requiring a payload object.

Definition at line 515 of file Asset.h.

References completeRecord(), Asset::FAILED, getOrCreateRecord(), Asset::LOADED, Asset::LOADING, Asset::REQUESTED_LOAD, and Asset::UNLOADED.

Here is the call graph for this function:

◆ syncRecordStateFromPayload()

template<typename Key, typename AssetClass>
void Asset::AssetManager< Key, AssetClass >::syncRecordStateFromPayload ( const std::shared_ptr< RecordType > & record) const
private

Definition at line 645 of file Asset.h.

References AssetManager(), completeRecord(), Asset::FAILED, and Asset::LOADED.

Referenced by add(), declare(), getAsset(), and getAssetLoadingState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unloadAssetPayload()

template<typename Key, typename AssetClass>
void Asset::AssetManager< Key, AssetClass >::unloadAssetPayload ( const Key & path)

Drops the loaded payload while preserving the stable record.

Definition at line 554 of file Asset.h.

References getRecord(), and Asset::UNLOADED.

Here is the call graph for this function:

Member Data Documentation

◆ records

template<typename Key, typename AssetClass>
std::unordered_map<Key, std::shared_ptr<RecordType> > Asset::AssetManager< Key, AssetClass >::records
private

Definition at line 474 of file Asset.h.

Referenced by clear(), forEachAsset(), getOrCreateRecord(), getRecord(), and isDeclared().


The documentation for this class was generated from the following file:
  • /workspace/magerbeton/gl3-vulkan/code/Engine/include/Engine/Core/Asset.h