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

Non-owning handle to an asset record managed by AssetManager. More...

#include <Asset.h>

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

Public Types

using RecordType = Record<Key, AssetClass>
 Record type referenced by this handle.
using Result = LoadResult<Key, AssetClass>
 Completion result type returned by readyFuture().

Public Member Functions

 Ref ()=default
 Creates an empty ref that points to no record.
LoadState getState () const
 Gets the current loading state.
bool isLoaded () const
 Checks whether the referenced asset has a loaded payload.
AssetClass * get () const
 Gets the loaded payload.
std::shared_ptr< RecordType > sharedRecord () const
 Gets a shared handle to the underlying record, keeping it (and its asset payload) alive as long as any returned shared_ptr is held.
uint64_t getGeneration () const
 Gets the current record generation.
const std::string & getError () const
 Gets the last load error reported by the record.
std::shared_future< Result > readyFuture () const
 Gets a future for completion of the current generation.
 operator bool () const
 Checks whether this ref still points to a live record.

Private Member Functions

 Ref (std::shared_ptr< RecordType > record)

Static Private Member Functions

static std::shared_future< Result > expiredFuture ()

Private Attributes

std::weak_ptr< RecordType > record_

Detailed Description

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

Non-owning handle to an asset record managed by AssetManager.

Ref keeps access to an asset's state, payload pointer, completion future, generation, and error string without owning the underlying record. A default-constructed ref or a ref whose manager record has been erased evaluates to false.

Template Parameters
KeyAsset lookup key type.
AssetClassAsset payload type.

Definition at line 179 of file Asset.h.

Member Typedef Documentation

◆ RecordType

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

Record type referenced by this handle.

Definition at line 182 of file Asset.h.

◆ Result

template<typename Key, typename AssetClass>
using Asset::Ref< Key, AssetClass >::Result = LoadResult<Key, AssetClass>

Completion result type returned by readyFuture().

Definition at line 183 of file Asset.h.

Constructor & Destructor Documentation

◆ Ref() [1/2]

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

Creates an empty ref that points to no record.

◆ Ref() [2/2]

template<typename Key, typename AssetClass>
Asset::Ref< Key, AssetClass >::Ref ( std::shared_ptr< RecordType > record)
inlineexplicitprivate

Definition at line 274 of file Asset.h.

Member Function Documentation

◆ expiredFuture()

template<typename Key, typename AssetClass>
std::shared_future< Result > Asset::Ref< Key, AssetClass >::expiredFuture ( )
inlinestaticprivate

Definition at line 276 of file Asset.h.

Referenced by Asset::Ref< Asset::MeshPath, Animation >::readyFuture().

Here is the caller graph for this function:

◆ get()

template<typename Key, typename AssetClass>
AssetClass * Asset::Ref< Key, AssetClass >::get ( ) const
inlinenodiscard

Gets the loaded payload.

Returns
Pointer to the asset payload when loaded, otherwise nullptr.

Definition at line 213 of file Asset.h.

◆ getError()

template<typename Key, typename AssetClass>
const std::string & Asset::Ref< Key, AssetClass >::getError ( ) const
inlinenodiscard

Gets the last load error reported by the record.

Returns
Error string, or an empty string when no error exists or the record has expired.

Definition at line 245 of file Asset.h.

◆ getGeneration()

template<typename Key, typename AssetClass>
uint64_t Asset::Ref< Key, AssetClass >::getGeneration ( ) const
inlinenodiscard

Gets the current record generation.

Returns
Generation value, or 0 when the record has expired.

Definition at line 235 of file Asset.h.

◆ getState()

template<typename Key, typename AssetClass>
LoadState Asset::Ref< Key, AssetClass >::getState ( ) const
inlinenodiscard

Gets the current loading state.

Returns
Current record state, or UNLOADED when the record has expired.

Definition at line 194 of file Asset.h.

Referenced by Asset::Ref< Asset::MeshPath, Animation >::isLoaded().

Here is the caller graph for this function:

◆ isLoaded()

template<typename Key, typename AssetClass>
bool Asset::Ref< Key, AssetClass >::isLoaded ( ) const
inlinenodiscard

Checks whether the referenced asset has a loaded payload.

Returns
True when the current state is LOADED.

Definition at line 204 of file Asset.h.

◆ operator bool()

template<typename Key, typename AssetClass>
Asset::Ref< Key, AssetClass >::operator bool ( ) const
inlineexplicitnodiscard

Checks whether this ref still points to a live record.

Returns
True when the referenced record still exists.

Definition at line 266 of file Asset.h.

◆ readyFuture()

template<typename Key, typename AssetClass>
std::shared_future< Result > Asset::Ref< Key, AssetClass >::readyFuture ( ) const
inlinenodiscard

Gets a future for completion of the current generation.

Returns
Shared future that resolves to LoadResult when the generation succeeds or fails.

Definition at line 256 of file Asset.h.

◆ sharedRecord()

template<typename Key, typename AssetClass>
std::shared_ptr< RecordType > Asset::Ref< Key, AssetClass >::sharedRecord ( ) const
inlinenodiscard

Gets a shared handle to the underlying record, keeping it (and its asset payload) alive as long as any returned shared_ptr is held.

Used to pin asset-owned data (e.g. unpacked mesh vertices) for asynchronous uploads: a consumer can alias this record's lifetime without owning a copy of the data.

Definition at line 226 of file Asset.h.

Member Data Documentation

◆ record_

template<typename Key, typename AssetClass>
std::weak_ptr<RecordType> Asset::Ref< Key, AssetClass >::record_
private

Definition at line 289 of file Asset.h.


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