|
Unravel Engine C++ Reference
|
Manages assets, including loading, unloading, and storage. More...
#include <asset_manager.h>
Public Member Functions | |
| asset_manager (rtti::context &ctx) | |
| Constructs an asset manager with the given context. | |
| ~asset_manager () | |
| Destructs the asset manager. | |
| void | set_parent (asset_manager *parent) |
| Sets the parent asset manager. | |
| auto | init (rtti::context &ctx) -> bool |
| Initializes the asset manager with the given context. | |
| auto | deinit (rtti::context &ctx) -> bool |
| Deinitializes the asset manager with the given context. | |
| void | unload_all () |
| Unloads all assets. | |
| void | unload_group (const std::string &group) |
| Unloads all assets in a specified group. | |
| auto | load_database (const std::string &protocol) -> bool |
| Loads an asset database from a protocol. | |
| void | save_database (const std::string &protocol, const fs::path &path) |
| Saves the asset database to a specified path. | |
| void | remove_asset_info_for_path (const fs::path &path) |
| Removes asset information for a specified path. | |
| void | remove_asset_info_for_key (const std::string &key) |
| Removes asset information for a specified key. | |
| void | register_asset_info_for_path (const fs::path &path, bool override) |
| auto | add_asset_info_for_path (const fs::path &path, const asset_meta &meta, bool override) -> hpp::uuid |
| Adds asset information for a specified path. | |
| auto | add_asset_info_for_key (const std::string &key, const asset_meta &meta, bool override) -> hpp::uuid |
| Adds asset information for a specified key. | |
| auto | get_metadata (const hpp::uuid &uid) const -> asset_database::meta |
| Gets metadata for a resource uid. | |
| auto | get_metadata_for_path (const fs::path &path) const -> asset_database::meta |
| auto | get_metadata_for_key (const std::string &key) const -> asset_database::meta |
| auto | generate_metadata (const fs::path &p) const -> asset_meta |
| template<typename HeaderT > | |
| auto | get_header (const hpp::uuid &uid) const -> std::shared_ptr< HeaderT > |
| Gets typed header info for an asset without loading it. | |
| template<typename S , typename... Args> | |
| auto | add_storage (Args &&... args) -> asset_storage< S > & |
| Adds a storage for a specific type. | |
| template<typename T > | |
| auto | get_asset (const std::string &key, load_flags flags=load_flags::standard, load_mode mode=load_mode::immediate) -> asset_handle< T > |
| Gets an asset by its key. | |
| template<typename T > | |
| auto | get_asset (const hpp::uuid &uid, load_flags flags=load_flags::standard, load_mode mode=load_mode::immediate) -> asset_handle< T > |
| Gets an asset by its UUID. | |
| template<typename T > | |
| auto | register_asset (const std::string &key) -> asset_handle< T > |
| Registers an asset by key without loading it. The actual load is triggered on the first handle.get() call. | |
| template<typename T > | |
| auto | register_asset (const hpp::uuid &uid) -> asset_handle< T > |
| Registers an asset by UUID without loading it. The actual load is triggered on the first handle.get() call. | |
| template<typename T > | |
| void | preload_assets () |
| Triggers loading on all deferred handles of a given type. Non-blocking: starts background loads but does not wait. | |
| void | preload_all_assets () |
| Triggers loading on all deferred handles across every registered storage. Non-blocking: starts background loads but does not wait. Useful for game runtime preloading after scene deserialization. | |
| template<typename T > | |
| auto | find_asset (const std::string &key) const -> const asset_handle< T > & |
| Finds an asset by its key. | |
| template<typename T > | |
| auto | get_asset_from_instance (const std::string &key, std::shared_ptr< T > entry) -> asset_handle< T > |
| Gets an asset handle from an instance. | |
| template<typename T > | |
| void | rename_asset (const std::string &key, const std::string &new_key) |
| Renames an asset. | |
| template<typename T > | |
| void | unload_asset (const std::string &key) |
| Unloads an asset by its key. | |
| template<typename T > | |
| auto | get_assets (const std::string &group={}) const -> std::vector< asset_handle< T > > |
| Gets all assets in a specified group. | |
| template<typename T , typename F > | |
| auto | get_assets_with_predicate (F &&predicate) const -> std::vector< asset_handle< T > > |
| Gets all assets that satisfy a predicate. | |
| template<typename T , typename F > | |
| void | for_each_asset (F &&callback) |
| Applies a callback function to each asset. | |
| auto | get_all_assets (const std::string &group) const -> std::vector< std::string > |
| Gets all assets. | |
| void | evict_unused_assets (const std::string &group, std::chrono::steady_clock::duration max_idle) |
| Evicts full-loaded assets not accessed within the given duration. Demotes them back to deferred state so they can be re-loaded on next access. | |
| auto | add_asset (const std::string &key, bool override=false) -> hpp::uuid |
| Adds an asset with a specified key. | |
| auto | add_asset_for_path (const fs::path &path, bool override=false) -> hpp::uuid |
| Adds an asset with a specified path. | |
Manages assets, including loading, unloading, and storage.
Definition at line 18 of file asset_manager.h.
| unravel::asset_manager::asset_manager | ( | rtti::context & | ctx | ) |
Constructs an asset manager with the given context.
| ctx | The context for the asset manager. |
Definition at line 24 of file asset_manager.cpp.
|
default |
Destructs the asset manager.
| auto unravel::asset_manager::add_asset | ( | const std::string & | key, |
| bool | override = false ) -> hpp::uuid |
Adds an asset with a specified key.
| key | The key of the asset. |
Definition at line 210 of file asset_manager.cpp.
| auto unravel::asset_manager::add_asset_for_path | ( | const fs::path & | path, |
| bool | override = false ) -> hpp::uuid |
Adds an asset with a specified path.
| path | The path of the asset. |
| override | Whether to override the asset if it already exists. |
Definition at line 216 of file asset_manager.cpp.
| auto unravel::asset_manager::add_asset_info_for_key | ( | const std::string & | key, |
| const asset_meta & | meta, | ||
| bool | override ) -> hpp::uuid |
Adds asset information for a specified key.
| key | The key of the asset. |
| meta | The metadata of the asset. |
Definition at line 228 of file asset_manager.cpp.
| auto unravel::asset_manager::add_asset_info_for_path | ( | const fs::path & | path, |
| const asset_meta & | meta, | ||
| bool | override ) -> hpp::uuid |
Adds asset information for a specified path.
| path | The path of the asset. |
| meta | The metadata of the asset. |
Definition at line 222 of file asset_manager.cpp.
|
inline |
Adds a storage for a specific type.
| S | The type of storage. |
| Args | The arguments for constructing the storage. |
| args | The arguments for constructing the storage. |
Definition at line 142 of file asset_manager.h.
| auto unravel::asset_manager::deinit | ( | rtti::context & | ctx | ) | -> bool |
Deinitializes the asset manager with the given context.
| ctx | The context to deinitialize. |
Definition at line 121 of file asset_manager.cpp.
| void unravel::asset_manager::evict_unused_assets | ( | const std::string & | group, |
| std::chrono::steady_clock::duration | max_idle ) |
Evicts full-loaded assets not accessed within the given duration. Demotes them back to deferred state so they can be re-loaded on next access.
| group | The group to evict assets from. |
| max_idle | Maximum idle duration before eviction. |
Definition at line 304 of file asset_manager.cpp.
|
inline |
Finds an asset by its key.
| T | The type of the asset. |
| key | The key of the asset. |
Definition at line 264 of file asset_manager.h.
|
inline |
Applies a callback function to each asset.
| T | The type of the assets. |
| F | The callback function. |
| callback | The callback function. |
Definition at line 380 of file asset_manager.h.
| auto unravel::asset_manager::generate_metadata | ( | const fs::path & | p | ) | const -> asset_meta |
Definition at line 272 of file asset_manager.cpp.
| auto unravel::asset_manager::get_all_assets | ( | const std::string & | group | ) | const -> std::vector<std::string> |
Gets all assets.
Definition at line 159 of file asset_manager.cpp.
|
inline |
Gets an asset by its UUID.
| T | The type of the asset. |
| uid | The UUID of the asset. |
| flags | The load flags for the asset. |
| mode | Whether to load immediately or defer until first get(). |
Definition at line 181 of file asset_manager.h.
|
inline |
Gets an asset by its key.
| T | The type of the asset. |
| key | The key of the asset. |
| flags | The load flags for the asset. |
| mode | Whether to load immediately or defer until first get(). |
Definition at line 159 of file asset_manager.h.
|
inline |
Gets an asset handle from an instance.
| T | The type of the asset. |
| key | The key of the asset. |
| entry | The shared pointer to the asset instance. |
Definition at line 278 of file asset_manager.h.
|
inline |
Gets all assets in a specified group.
| T | The type of the assets. |
| group | The group to get assets from. |
Definition at line 345 of file asset_manager.h.
|
inline |
Gets all assets that satisfy a predicate.
| T | The type of the assets. |
| F | The predicate function. |
| predicate | The predicate function. |
Definition at line 367 of file asset_manager.h.
|
inline |
Gets typed header info for an asset without loading it.
| HeaderT | The header info type (e.g. texture_header_info). |
| uid | The UUID of the asset. |
Definition at line 124 of file asset_manager.h.
| auto unravel::asset_manager::get_metadata | ( | const hpp::uuid & | uid | ) | const -> asset_database::meta |
Gets metadata for a resource uid.
| uid | The the uuid of the resource. |
Definition at line 235 of file asset_manager.cpp.
| auto unravel::asset_manager::get_metadata_for_key | ( | const std::string & | key | ) | const -> asset_database::meta |
Definition at line 256 of file asset_manager.cpp.
| auto unravel::asset_manager::get_metadata_for_path | ( | const fs::path & | path | ) | const -> asset_database::meta |
Definition at line 250 of file asset_manager.cpp.
| auto unravel::asset_manager::init | ( | rtti::context & | ctx | ) | -> bool |
Initializes the asset manager with the given context.
| ctx | The context to initialize with. |
Definition at line 35 of file asset_manager.cpp.
| auto unravel::asset_manager::load_database | ( | const std::string & | protocol | ) | -> bool |
Loads an asset database from a protocol.
| protocol | The protocol to load from. |
Definition at line 194 of file asset_manager.cpp.
| void unravel::asset_manager::preload_all_assets | ( | ) |
Triggers loading on all deferred handles across every registered storage. Non-blocking: starts background loads but does not wait. Useful for game runtime preloading after scene deserialization.
Definition at line 312 of file asset_manager.cpp.
|
inline |
Triggers loading on all deferred handles of a given type. Non-blocking: starts background loads but does not wait.
| T | The type of the assets to preload. |
Definition at line 244 of file asset_manager.h.
|
inline |
Registers an asset by UUID without loading it. The actual load is triggered on the first handle.get() call.
| T | The type of the asset. |
| uid | The UUID of the asset. |
Definition at line 224 of file asset_manager.h.
|
inline |
Registers an asset by key without loading it. The actual load is triggered on the first handle.get() call.
| T | The type of the asset. |
| key | The key of the asset. |
Definition at line 207 of file asset_manager.h.
| void unravel::asset_manager::register_asset_info_for_path | ( | const fs::path & | path, |
| bool | override ) |
| void unravel::asset_manager::remove_asset_info_for_key | ( | const std::string & | key | ) |
Removes asset information for a specified key.
| key | The key of the asset. |
Definition at line 297 of file asset_manager.cpp.
| void unravel::asset_manager::remove_asset_info_for_path | ( | const fs::path & | path | ) |
Removes asset information for a specified path.
| path | The path of the asset. |
Definition at line 291 of file asset_manager.cpp.
|
inline |
Renames an asset.
| T | The type of the asset. |
| key | The current key of the asset. |
| new_key | The new key for the asset. |
Definition at line 295 of file asset_manager.h.
| void unravel::asset_manager::save_database | ( | const std::string & | protocol, |
| const fs::path & | path ) |
Saves the asset database to a specified path.
| protocol | The protocol to use for saving. |
| path | The path to save the database to. |
Definition at line 203 of file asset_manager.cpp.
| void unravel::asset_manager::set_parent | ( | asset_manager * | parent | ) |
Sets the parent asset manager.
| parent | The parent asset manager. |
Definition at line 30 of file asset_manager.cpp.
| void unravel::asset_manager::unload_all | ( | ) |
Unloads all assets.
Definition at line 132 of file asset_manager.cpp.
|
inline |
Unloads an asset by its key.
| T | The type of the asset. |
| key | The key of the asset. |
Definition at line 327 of file asset_manager.h.
| void unravel::asset_manager::unload_group | ( | const std::string & | group | ) |
Unloads all assets in a specified group.
| group | The group to unload. |
Definition at line 146 of file asset_manager.cpp.