#include <AssetManager.h>
Inherits AssetManagerBus::Handler.
Classes | |
struct | Descriptor |
Public Types | |
typedef AZStd::unordered_map< AssetType, AssetHandler * > | AssetHandlerMap |
typedef AZStd::unordered_map< AssetType, AssetCatalog * > | AssetCatalogMap |
typedef AZStd::unordered_map< AssetId, AssetData * > | AssetMap |
typedef AZStd::unordered_map< AssetContainerKey, AZStd::weak_ptr< AssetContainer > > | WeakAssetContainerMap |
typedef AZStd::unordered_map< AssetContainer *, AZStd::shared_ptr< AssetContainer > > | OwnedAssetContainerMap |
Public Member Functions | |
AZ_CLASS_ALLOCATOR (AssetManager, SystemAllocator) | |
void | RegisterHandler (AssetHandler *handler, const AssetType &assetType) |
void | UnregisterHandler (AssetHandler *handler) |
void | RegisterCatalog (AssetCatalog *catalog, const AssetType &assetType) |
void | UnregisterCatalog (AssetCatalog *catalog) |
Unregister catalog from the asset system. | |
void | GetHandledAssetTypes (AssetCatalog *catalog, AZStd::vector< AZ::Data::AssetType > &assetTypes) |
void | SuspendAssetRelease () |
Prevents assets from being released when no longer referenced. | |
void | ResumeAssetRelease () |
Resumes releasing assets that are no longer referenced. Any currently un-referenced assets will be released upon calling this. | |
AssetData::AssetStatus | BlockUntilLoadComplete (const Asset< AssetData > &asset) |
template<class AssetClass > | |
Asset< AssetClass > | GetAsset (const AssetId &assetId, AssetLoadBehavior assetReferenceLoadBehavior, const AssetLoadParameters &loadParams=AssetLoadParameters{}) |
Asset< AssetData > | GetAsset (const AssetId &assetId, const AssetType &assetType, AssetLoadBehavior assetReferenceLoadBehavior, const AssetLoadParameters &loadParams=AssetLoadParameters{}) |
template<class AssetClass > | |
Asset< AssetClass > | FindOrCreateAsset (const AssetId &assetId, AssetLoadBehavior assetReferenceLoadBehavior) |
Asset< AssetData > | FindOrCreateAsset (const AssetId &assetId, const AssetType &assetType, AssetLoadBehavior assetReferenceLoadBehavior) |
template<class AssetClass > | |
Asset< AssetClass > | FindAsset (const AssetId &assetId, AssetLoadBehavior assetReferenceLoadBehavior) |
Asset< AssetData > | FindAsset (const AssetId &assetId, AssetLoadBehavior assetReferenceLoadBehavior) |
template<class AssetClass > | |
Asset< AssetClass > | CreateAsset (const AssetId &assetId, AssetLoadBehavior assetReferenceLoadBehavior=AssetLoadBehavior::Default) |
Asset< AssetData > | CreateAsset (const AssetId &assetId, const AssetType &assetType, AssetLoadBehavior assetReferenceLoadBehavior=AssetLoadBehavior::Default) |
void | SaveAsset (const Asset< AssetData > &asset) |
void | ReloadAsset (const AssetId &assetId, AssetLoadBehavior assetReferenceLoadBehavior, bool isAutoReload=false) |
void | ReloadAssetFromData (const Asset< AssetData > &asset) |
void | AssignAssetData (const Asset< AssetData > &asset) |
AssetHandler * | GetHandler (const AssetType &assetType) |
AssetStreamInfo | GetLoadStreamInfoForAsset (const AssetId &assetId, const AssetType &assetType) |
AssetStreamInfo | GetSaveStreamInfoForAsset (const AssetId &assetId, const AssetType &assetType) |
void | DispatchEvents () |
void | SetAssetInfoUpgradingEnabled (bool enable) |
bool | GetAssetInfoUpgradingEnabled () const |
bool | ShouldCancelAllActiveJobs () const |
void | SetParallelDependentLoadingEnabled (bool enable) |
bool | GetParallelDependentLoadingEnabled () const |
void | PrepareShutDown () |
bool | HasActiveJobsOrStreamerRequests () |
Static Public Member Functions | |
static bool | Create (const Descriptor &desc) |
static void | Destroy () |
static bool | IsReady () |
static AssetManager & | Instance () |
static bool | SetInstance (AssetManager *assetManager) |
Protected Types | |
typedef AZStd::unordered_map< AssetId, Asset< AssetData > > | ReloadMap |
typedef AZStd::intrusive_list< AssetDatabaseJob, AZStd::list_base_hook< AssetDatabaseJob > > | ActiveJobList |
using | AssetRequestMap = AZStd::unordered_map< AssetId, AZStd::shared_ptr< AssetDataStream > > |
The AssetDataStream read requests that are pending or processing for a specific asset. | |
using | BlockingRequestMap = AZStd::unordered_multimap< AssetId, WaitForAsset * > |
Protected Member Functions | |
AssetManager (const Descriptor &desc) | |
void | WaitForActiveJobsAndStreamerRequestsToFinish () |
void | NotifyAssetReady (Asset< AssetData > asset) |
void | NotifyAssetPreReload (Asset< AssetData > asset) |
void | NotifyAssetReloaded (Asset< AssetData > asset) |
void | NotifyAssetReloadError (Asset< AssetData > asset) |
void | NotifyAssetError (Asset< AssetData > asset) |
void | NotifyAssetCanceled (AssetId assetId) |
void | NotifyAssetContainerReady (Asset< AssetData > asset) |
void | ReleaseAsset (AssetData *asset, AssetId assetId, AssetType assetType, bool removeAssetFromHash, int creationToken) |
void | OnAssetUnused (AssetData *asset) |
void | AddJob (AssetDatabaseJob *job) |
void | RemoveJob (AssetDatabaseJob *job) |
void | AddActiveStreamerRequest (AssetId assetId, AZStd::shared_ptr< AssetDataStream > readRequest) |
void | RescheduleStreamerRequest (AssetId assetId, AZ::IO::IStreamerTypes::Deadline newDeadline, AZ::IO::IStreamerTypes::Priority newPriority) |
void | RemoveActiveStreamerRequest (AssetId assetId) |
void | AddBlockingRequest (AssetId assetId, WaitForAsset *blockingRequest) |
void | RemoveBlockingRequest (AssetId assetId, WaitForAsset *blockingRequest) |
void | ValidateAndPostLoad (AZ::Data::Asset< AZ::Data::AssetData > &asset, bool loadSucceeded, bool isReload, AZ::Data::AssetHandler *assetHandler=nullptr) |
void | PostLoad (AZ::Data::Asset< AZ::Data::AssetData > &asset, bool loadSucceeded, bool isReload, AZ::Data::AssetHandler *assetHandler=nullptr) |
void | QueueAssetReload (AZ::Data::Asset< AZ::Data::AssetData > asset, bool signalLoaded) |
void | UpdateDebugStatus (const AZ::Data::Asset< AZ::Data::AssetData > &asset) |
AZStd::shared_ptr< AssetContainer > | GetAssetContainer (Asset< AssetData > asset, const AssetLoadParameters &loadParams=AssetLoadParameters{}, bool isReload=false) |
virtual AZStd::shared_ptr< AssetContainer > | CreateAssetContainer (Asset< AssetData > asset, const AssetLoadParameters &loadParams=AssetLoadParameters{}, bool isReload=false) const |
void | ReleaseAssetContainersForAsset (AssetData *asset) |
void | ReleaseOwnedAssetContainer (AssetContainer *assetContainer) |
void | OnAssetReady (const Asset< AssetData > &asset) override |
void | OnAssetReloaded (const Asset< AssetData > &asset) override |
void | OnAssetReloadError (const Asset< AssetData > &asset) override |
void | OnAssetError (const Asset< AssetData > &asset) override |
void | OnAssetCanceled (AssetId asset) override |
void | OnAssetContainerReady (AssetContainer *container) override |
void | OnAssetContainerCanceled (AssetContainer *container) override |
AssetStreamInfo | GetModifiedLoadStreamInfoForAsset (const Asset< AssetData > &asset, AssetHandler *handler) |
Get the load stream info for an asset, including missing-asset substitution and custom AssetHandler overrides. | |
void | QueueAsyncStreamLoad (Asset< AssetData > asset, AZStd::shared_ptr< AssetDataStream > dataStream, const AZ::Data::AssetStreamInfo &streamInfo, bool isReload, AssetHandler *handler, const AssetLoadParameters &loadParameters, bool signalLoaded) |
Queue an async file load with the AssetDataStream as the first step in an asset load. | |
void | RegisterAssetLoading (const Asset< AssetData > &asset) |
bool | ValidateAndRegisterAssetLoading (const Asset< AssetData > &asset) |
void | UnregisterAssetLoading (const Asset< AssetData > &asset) |
Protected Attributes | |
AssetHandlerMap | m_handlers |
AssetCatalogMap | m_catalogs |
AZStd::recursive_mutex | m_catalogMutex |
AssetMap | m_assets |
AZStd::recursive_mutex | m_assetMutex |
WeakAssetContainerMap | m_assetContainers |
OwnedAssetContainerMap | m_ownedAssetContainers |
AZStd::unordered_multimap< AssetId, AssetContainer * > | m_ownedAssetContainerLookup |
AZStd::recursive_mutex | m_assetContainerMutex |
AZStd::thread::id | m_mainThreadId |
IDebugAssetEvent * | m_debugAssetEvents { nullptr } |
int | m_creationTokenGenerator = 0 |
ReloadMap | m_reloads |
ActiveJobList | m_activeJobs |
AssetRequestMap | m_activeAssetDataStreamRequests |
AZStd::recursive_mutex | m_activeJobOrRequestMutex |
BlockingRequestMap | m_activeBlockingRequests |
AZStd::recursive_mutex | m_activeBlockingRequestMutex |
bool | m_enableParallelDependentLoading = true |
bool | m_assetInfoUpgradingEnabled = true |
bool | m_cancelAllActiveJobs = false |
AZStd::atomic_int | m_suspendAssetRelease { 0 } |
Static Protected Attributes | |
static EnvironmentVariable< AssetManager * > | s_assetDB |
Friends | |
class | AssetData |
class | AssetDatabaseJob |
class | ReloadAssetJob |
class | LoadAssetJob |
class | AssetContainer |
class | WaitForAsset |
AssetDatabase handles the creation, refcounting and automatic destruction of assets.
In general for any events while loading/saving/etc. create an AssetEventHandler and pass it to AssetDatabase::GetAsset(). You can also connect to AssetBus if you want to listen for events without holding an asset. If an asset is ready at the time you connect to AssetBus or GetAsset() is called, your handler will be notified immediately, otherwise all events are dispatched asynchronously.
|
protected |
The set of all blocking requests that currently exist, grouped by AssetId. The information is used internally to route LoadAssetJob processing to any thread that currently is blocked waiting for that load to complete.
Assign new data for the specified asset Id. This is effectively reloading the asset with the provided data. Listeners will be notified to process the new data.
AssetData::AssetStatus AZ::Data::AssetManager::BlockUntilLoadComplete | ( | const Asset< AssetData > & | asset | ) |
Blocks the current thread until the specified asset has finished loading (whether successful or not)
asset | a valid asset which has already been requested to load. It is an error to block on an asset which has not been requested to load already This will return as soon as the asset has finished loading (i.e. the appropriate internal AssetJobBus notification has triggered) It does not wait for the AssetManager to notify external listeners via the AssetBus OnAsset* events. If the asset is loaded successfully, the return state may be ReadyPreNotify or Ready depending on thread timing |
Asset< AssetClass > AZ::Data::AssetManager::CreateAsset | ( | const AssetId & | assetId, |
AssetLoadBehavior | assetReferenceLoadBehavior = AssetLoadBehavior::Default |
||
) |
Creates an in-memory asset and returns the pointer. If the asset already exists it will return NULL (then you should use GetAsset/FindAsset to obtain it).
assetReferenceLoadBehavior | the AssetLoadBehavior set on the returned Asset<T> object. Important (only) when the Asset<T> is saved to disk as this behavior will be preserved and used when loading the asset containing this reference |
|
protectedvirtual |
Creates a new shared AssetContainer with an optional loadFilter
Asset< AssetClass > AZ::Data::AssetManager::FindAsset | ( | const AssetId & | assetId, |
AssetLoadBehavior | assetReferenceLoadBehavior | ||
) |
Locates an existing in-memory asset. If the asset is unknown, a null asset pointer is returned.
assetReferenceLoadBehavior | the AssetLoadBehavior set on the returned Asset<T> object. Important (only) when the Asset<T> is saved to disk as this behavior will be preserved and used when loading the asset containing this reference This specifically does not have a default parameter to ensure callers intentionally choose the correct behavior For asset references intended to be saved to disk |
Asset< AssetClass > AZ::Data::AssetManager::FindOrCreateAsset | ( | const AssetId & | assetId, |
AssetLoadBehavior | assetReferenceLoadBehavior | ||
) |
Locates an existing in-memory asset, if the asset is unknown, a new in-memory asset will be created. The asset will not be queued for load.
assetReferenceLoadBehavior | the AssetLoadBehavior set on the returned Asset<T> object. Important (only) when the Asset<T> is saved to disk as this behavior will be preserved and used when loading the asset containing this reference This specifically does not have a default parameter to ensure callers intentionally choose the correct behavior For asset references intended to be saved to disk |
Asset< AssetClass > AZ::Data::AssetManager::GetAsset | ( | const AssetId & | assetId, |
AssetLoadBehavior | assetReferenceLoadBehavior, | ||
const AssetLoadParameters & | loadParams = AssetLoadParameters{} |
||
) |
Gets an asset from the database, if not present it loads it from the catalog/stream. For events register a handler by calling RegisterEventHandler().
assetId | a valid id of the asset |
assetReferenceLoadBehavior | the AssetLoadBehavior set on the returned Asset<T> object. Important (only) when the Asset<T> is saved to disk as this behavior will be preserved and used when loading the asset containing this reference This specifically does not have a default parameter to ensure callers intentionally choose the correct behavior For asset references intended to be saved to disk |
loadParams | optional set of parameters to control loading Keep in mind that this is an async operation, the asset will not be loaded after the call to this function completes. |
Asset< AssetData > AZ::Data::AssetManager::GetAsset | ( | const AssetId & | assetId, |
const AssetType & | assetType, | ||
AssetLoadBehavior | assetReferenceLoadBehavior, | ||
const AssetLoadParameters & | loadParams = AssetLoadParameters{} |
||
) |
Gets an asset from the database, if not present it loads it from the catalog/stream. For events register a handler by calling RegisterEventHandler().
assetId | a valid id of the asset |
assetType | type id of the asset |
assetReferenceLoadBehavior | the AssetLoadBehavior set on the returned Asset<T> object. Important (only) when the Asset<T> is saved to disk as this behavior will be preserved and used when loading the asset containing this reference This specifically does not have a default parameter to ensure callers intentionally choose the correct behavior For asset references intended to be saved to disk |
loadParams | optional set of parameters to control loading Keep in mind that this async operation, asset will not be loaded after the call to this function completes. |
|
protected |
Gets a root asset and dependencies as individual async loads if necessary.
assetId | a valid id of the asset |
loadFilter | optional filter predicate for dependent asset loads. If the asset container is already loaded just hand back a new shared ptr |
AssetHandler * AZ::Data::AssetManager::GetHandler | ( | const AssetType & | assetType | ) |
Gets a pointer to an asset handler for a type. Returns nullptr if a handler for that type does not exist.
bool AZ::Data::AssetManager::HasActiveJobsOrStreamerRequests | ( | ) |
Returns whether or not any threaded asset requests are currently active.
void AZ::Data::AssetManager::PrepareShutDown | ( | ) |
This method must be invoked before you start unregistering handlers manually and shutting down the asset manager. This method ensures that all jobs in flight are either canceled or completed. This method is automatically called in the destructor but if you are unregistering handlers manually, you must invoke it yourself.
void AZ::Data::AssetManager::RegisterCatalog | ( | AssetCatalog * | catalog, |
const AssetType & | assetType | ||
) |
Register a catalog with the system for a particular asset type. A catalog should be registered for each asset type it is responsible for.
void AZ::Data::AssetManager::RegisterHandler | ( | AssetHandler * | handler, |
const AssetType & | assetType | ||
) |
Register handler with the system for a particular asset type. A handler should be registered for each asset type it handles. Please note that all the handlers are registered just once during app startup from the main thread and therefore this is not a thread safe method and should not be invoked from different threads.
|
protected |
Releases all references to asset containers that are currently attempting to load this asset. If all "external" references to the asset are destroyed (i.e. nothing but loading code references the asset), this makes sure that the containers are cleaned up and the loading is canceled as a part of destroying the AssetData.
|
protected |
Clears all references to the owned asset container.
void AZ::Data::AssetManager::ReloadAsset | ( | const AssetId & | assetId, |
AssetLoadBehavior | assetReferenceLoadBehavior, | ||
bool | isAutoReload = false |
||
) |
Requests a reload of a given asset from storage.
Reloads an asset from provided in-memory data. Ownership of the provided asset data is transferred to the asset manager.
Triggers an asset save an asset if possible. In general most assets will NOT support save as they are generated from external tool. This is the interface for the rare cases we do save. If you want to know the state of the save (if completed and result) listen on the AssetBus.
void AZ::Data::AssetManager::SetAssetInfoUpgradingEnabled | ( | bool | enable | ) |
Old 'legacy' assetIds and asset hints can be automatically replaced with new ones during deserialize / assignment. This operation can be somewhat costly, and its only useful if the program subsequently re-saves the files its loading so that the asset hints and assetIds actually persist. Thus, it can be disabled in situations where you know you are not going to be saving over or creating new source files (for example builders/background apps) By default, it is enabled.
void AZ::Data::AssetManager::SetParallelDependentLoadingEnabled | ( | bool | enable | ) |
Parallel dependent loading is enabled by default, but needs to be disabled by Asset Builders or other tools connecting directly with the Asset Processor because dependency information isn't guaranteed to be complete and usable for loading dependencies when querying during asset building. It only becomes usable after assets have finished building.
void AZ::Data::AssetManager::UnregisterHandler | ( | AssetHandler * | handler | ) |
Unregister handler from the asset system. Please note that all the handlers are unregistered just once during app shutdown from the main thread and therefore this is not a thread safe method and should not be invoked from different threads.
|
protected |