cesium-native 0.52.0
Loading...
Searching...
No Matches
CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext > Class Template Reference

A depot for CesiumUtility::SharedAsset instances, which are potentially shared between multiple objects. More...

#include <CesiumAsync/SharedAssetDepot.h>

Inheritance diagram for CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >:
CesiumUtility::ReferenceCounted< T, true > CesiumUtility::IDepotOwningAsset< TAssetType >

Public Types

using FactorySignature
 Signature for the callback function that will be called to fetch and create a new instance of TAssetType if one with the given key doesn't already exist in the depot.
 

Public Member Functions

 SharedAssetDepot (std::function< FactorySignature > factory)
 Creates a new SharedAssetDepot using the given factory callback to load new assets.
 
SharedFuture< CesiumUtility::ResultPointer< TAssetType > > getOrCreate (const TContext &context, const TAssetKey &assetKey)
 Gets an asset from the depot if it already exists, or creates it using the depot's factory if it does not.
 
bool invalidate (const TAssetKey &assetKey)
 Invalidates the previously-cached asset with the given key, so that the next call to getOrCreate will create the asset instead of returning the existing one.
 
bool invalidate (TAssetType &asset)
 Invalidates the previously-cached asset, so that the next call to getOrCreate will create the asset instead of returning the existing one.
 
size_t getAssetCount () const
 Returns the total number of distinct assets contained in this depot, including both active and inactive assets.
 
size_t getActiveAssetCount () const
 Gets the number of assets owned by this depot that are active, meaning that they are currently being used in one or more places.
 
size_t getInactiveAssetCount () const
 Gets the number of assets owned by this depot that are inactive, meaning that they are not currently being used.
 
int64_t getInactiveAssetTotalSizeBytes () const
 Gets the total bytes used by inactive (unused) assets owned by this depot.
 
void operator= (const SharedAssetDepot< TAssetType, TAssetKey, TContext > &other)=delete
 
- Public Member Functions inherited from CesiumUtility::ReferenceCounted< T, true >
void addReference () const
 Adds a counted reference to this object. Use CesiumUtility::IntrusivePointer instead of calling this method directly.
 
void releaseReference () const
 Removes a counted reference from this object. When the last reference is removed, this method will delete this instance. Use CesiumUtility::IntrusivePointer instead of calling this method directly.
 
std::int32_t getReferenceCount () const noexcept
 Returns the current reference count of this instance.
 
void addReference () const
 Adds a counted reference to this object. Use CesiumUtility::IntrusivePointer instead of calling this method directly.
 
void releaseReference () const
 Removes a counted reference from this object. When the last reference is removed, this method will delete this instance. Use CesiumUtility::IntrusivePointer instead of calling this method directly.
 
std::int32_t getReferenceCount () const noexcept
 Returns the current reference count of this instance.
 

Public Attributes

std::atomic< int64_t > inactiveAssetSizeLimitBytes
 The maximum total byte usage of assets that have been loaded but are no longer needed.
 

Detailed Description

template<typename TAssetType, typename TAssetKey, typename TContext = SharedAssetContext>
class CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >

A depot for CesiumUtility::SharedAsset instances, which are potentially shared between multiple objects.

Template Parameters
TAssetTypeThe type of asset stored in this depot. This should be derived from CesiumUtility::SharedAsset.
TAssetKeyThe key type used to uniquely identify assets in this depot.
TContextThe type of context passed to the factory function when creating a new asset. This defaults to SharedAssetContext. This type must contain a field named asyncSystem of type AsyncSystem.

Definition at line 56 of file SharedAssetDepot.h.

Member Typedef Documentation

◆ FactorySignature

template<typename TAssetType, typename TAssetKey, typename TContext = SharedAssetContext>
using CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::FactorySignature
Initial value:
const TContext& context,
const TAssetKey& key)
A value that will be available in the future, as produced by AsyncSystem.
Definition Future.h:29

Signature for the callback function that will be called to fetch and create a new instance of TAssetType if one with the given key doesn't already exist in the depot.

Parameters
asyncSystemThe AsyncSystem used by this SharedAssetDepot.
pAssetAccessorThe IAssetAccessor used by this SharedAssetDepot. Use this to fetch the asset.
keyThe TAssetKey for the asset that should be loaded by this factory.
Returns
A Future that resolves to a ResultPointer containing the loaded asset, or any error information if the asset failed to load.

Definition at line 90 of file SharedAssetDepot.h.

Constructor & Destructor Documentation

◆ SharedAssetDepot()

template<typename TAssetType, typename TAssetKey, typename TContext>
CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::SharedAssetDepot ( std::function< FactorySignature > factory)

Creates a new SharedAssetDepot using the given factory callback to load new assets.

Parameters
factoryThe factory to use to fetch and create assets that don't already exist in the depot. See FactorySignature.

Definition at line 339 of file SharedAssetDepot.h.

◆ ~SharedAssetDepot()

template<typename TAssetType, typename TAssetKey, typename TContext>
CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::~SharedAssetDepot ( )
virtual

Definition at line 351 of file SharedAssetDepot.h.

Member Function Documentation

◆ getActiveAssetCount()

template<typename TAssetType, typename TAssetKey, typename TContext>
size_t CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::getActiveAssetCount ( ) const

Gets the number of assets owned by this depot that are active, meaning that they are currently being used in one or more places.

Definition at line 504 of file SharedAssetDepot.h.

◆ getAssetCount()

template<typename TAssetType, typename TAssetKey, typename TContext>
size_t CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::getAssetCount ( ) const

Returns the total number of distinct assets contained in this depot, including both active and inactive assets.

Definition at line 497 of file SharedAssetDepot.h.

◆ getInactiveAssetCount()

template<typename TAssetType, typename TAssetKey, typename TContext>
size_t CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::getInactiveAssetCount ( ) const

Gets the number of assets owned by this depot that are inactive, meaning that they are not currently being used.

Definition at line 511 of file SharedAssetDepot.h.

◆ getInactiveAssetTotalSizeBytes()

template<typename TAssetType, typename TAssetKey, typename TContext>
int64_t CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::getInactiveAssetTotalSizeBytes ( ) const

Gets the total bytes used by inactive (unused) assets owned by this depot.

Definition at line 518 of file SharedAssetDepot.h.

◆ getOrCreate()

template<typename TAssetType, typename TAssetKey, typename TContext>
SharedFuture< CesiumUtility::ResultPointer< TAssetType > > CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::getOrCreate ( const TContext & context,
const TAssetKey & assetKey )

Gets an asset from the depot if it already exists, or creates it using the depot's factory if it does not.

Parameters
contextThe context to pass to the factory function.
assetKeyThe key uniquely identifying the asset to get or create.
Returns
A shared future that resolves when the asset is ready or fails.

Definition at line 379 of file SharedAssetDepot.h.

◆ invalidate() [1/2]

template<typename TAssetType, typename TAssetKey, typename TContext>
bool CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::invalidate ( const TAssetKey & assetKey)

Invalidates the previously-cached asset with the given key, so that the next call to getOrCreate will create the asset instead of returning the existing one.

Anyone already using the existing asset may continue to do so.

If an asset with the given key does not exist in the depot, this method does nothing.

Parameters
assetKeyThe asset key to invalidate.
Returns
True if the asset was invalidated; false if the asset key does not exist in the depot or was already invalidated.

Definition at line 474 of file SharedAssetDepot.h.

◆ invalidate() [2/2]

template<typename TAssetType, typename TAssetKey, typename TContext>
bool CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::invalidate ( TAssetType & asset)

Invalidates the previously-cached asset, so that the next call to getOrCreate will create the asset instead of returning the existing one.

Anyone already using the existing asset may continue to do so.

If the asset is not associated with the depot, or if it has already been invalidated, this method does nothing. If another asset with the same key already exists in the depot, invalidating this one will not affect it.

Parameters
assetThe asset to invalidate.
Returns
True if the asset was invalidated; false if the asset is not owned by the depot or was already invalidated.

Definition at line 481 of file SharedAssetDepot.h.

Member Data Documentation

◆ inactiveAssetSizeLimitBytes

template<typename TAssetType, typename TAssetKey, typename TContext = SharedAssetContext>
std::atomic<int64_t> CesiumAsync::SharedAssetDepot< TAssetType, TAssetKey, TContext >::inactiveAssetSizeLimitBytes
Initial value:
=
static_cast<int64_t>(16 * 1024 * 1024)

The maximum total byte usage of assets that have been loaded but are no longer needed.

When cached assets are no longer needed, they're marked as candidates for deletion. However, this deletion doesn't actually occur until the total byte usage of deletion candidates exceeds this threshold. At that point, assets are cleaned up in the order that they were marked for deletion until the total dips below this threshold again.

Default is 16MiB.

Definition at line 73 of file SharedAssetDepot.h.


The documentation for this class was generated from the following file: