Vulkan Schnee 0.0.1
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>
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< RecordTypegetOrCreateRecord (const Key &path)
std::shared_ptr< RecordTypegetRecord (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 250 of file Asset.h.

Member Typedef Documentation

◆ RecordType

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

Definition at line 253 of file Asset.h.

◆ RefType

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

Definition at line 252 of file Asset.h.

◆ ResultType

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

Definition at line 254 of file Asset.h.

Constructor & Destructor Documentation

◆ AssetManager()

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

Referenced by syncRecordStateFromPayload().

Here is the caller graph for this function:

◆ ~AssetManager()

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

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
Author
Konstantin Passig
Date
03.12.2025

Definition at line 396 of file Asset.h.

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

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.

Author
Konstantin Passig
Date
03.12.2025

Definition at line 499 of file Asset.h.

References records, TRACY_ZONE_SCOPED_NAMED, 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 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().

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
Author
Konstantin Passig
Date
03.12.2025

Definition at line 384 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 470 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 450 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
Author
Konstantin Passig
Date
21.01.2026

Definition at line 365 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
Author
Konstantin Passig
Date
03.12.2025

Definition at line 490 of file Asset.h.

References getRecord(), syncRecordStateFromPayload(), and TRACY_ZONE_SCOPED_NAMED.

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
Author
Konstantin Passig
Date
03.12.2025

Definition at line 482 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 517 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 410 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 529 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 415 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
Author
Konstantin Passig
Date
03.12.2025

Definition at line 476 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 441 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 420 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 550 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 459 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 379 of file Asset.h.

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


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