Unravel Engine C++ Reference
Loading...
Searching...
No Matches
unravel::asset_manager Class 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.
 
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 generate_metadata (const fs::path &p) const -> asset_meta
 
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) -> 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) -> asset_handle< T >
 Gets an asset by its UUID.
 
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.
 

Detailed Description

Manages assets, including loading, unloading, and storage.

Definition at line 18 of file asset_manager.h.

Constructor & Destructor Documentation

◆ asset_manager()

unravel::asset_manager::asset_manager ( rtti::context & ctx)

Constructs an asset manager with the given context.

Parameters
ctxThe context for the asset manager.

Definition at line 23 of file asset_manager.cpp.

◆ ~asset_manager()

unravel::asset_manager::~asset_manager ( )
default

Destructs the asset manager.

Member Function Documentation

◆ add_asset_info_for_key()

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.

Parameters
keyThe key of the asset.
metaThe metadata of the asset.
Returns
The UUID of the added asset.

Definition at line 200 of file asset_manager.cpp.

◆ add_asset_info_for_path()

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.

Parameters
pathThe path of the asset.
metaThe metadata of the asset.
Returns
The UUID of the added asset.

Definition at line 194 of file asset_manager.cpp.

◆ add_storage()

template<typename S , typename... Args>
auto unravel::asset_manager::add_storage ( Args &&... args) -> asset_storage<S>&
inline

Adds a storage for a specific type.

Template Parameters
SThe type of storage.
ArgsThe arguments for constructing the storage.
Parameters
argsThe arguments for constructing the storage.
Returns
A reference to the added storage.

Definition at line 122 of file asset_manager.h.

◆ deinit()

auto unravel::asset_manager::deinit ( rtti::context & ctx) -> bool

Deinitializes the asset manager with the given context.

Parameters
ctxThe context to deinitialize.
Returns
True if deinitialization was successful, false otherwise.

Definition at line 120 of file asset_manager.cpp.

◆ find_asset()

template<typename T >
auto unravel::asset_manager::find_asset ( const std::string & key) const -> const asset_handle<T>&
inline

Finds an asset by its key.

Template Parameters
TThe type of the asset.
Parameters
keyThe key of the asset.
Returns
A constant reference to the handle of the asset.

Definition at line 179 of file asset_manager.h.

◆ for_each_asset()

template<typename T , typename F >
void unravel::asset_manager::for_each_asset ( F && callback)
inline

Applies a callback function to each asset.

Template Parameters
TThe type of the assets.
FThe callback function.
Parameters
callbackThe callback function.

Definition at line 295 of file asset_manager.h.

◆ generate_metadata()

auto unravel::asset_manager::generate_metadata ( const fs::path & p) const -> asset_meta

Definition at line 222 of file asset_manager.cpp.

◆ get_asset() [1/2]

template<typename T >
auto unravel::asset_manager::get_asset ( const hpp::uuid & uid,
load_flags flags = load_flags::standard ) -> asset_handle<T>
inline

Gets an asset by its UUID.

Template Parameters
TThe type of the asset.
Parameters
uidThe UUID of the asset.
flagsThe load flags for the asset.
Returns
The handle to the asset.

Definition at line 156 of file asset_manager.h.

◆ get_asset() [2/2]

template<typename T >
auto unravel::asset_manager::get_asset ( const std::string & key,
load_flags flags = load_flags::standard ) -> asset_handle<T>
inline

Gets an asset by its key.

Template Parameters
TThe type of the asset.
Parameters
keyThe key of the asset.
flagsThe load flags for the asset.
Returns
The handle to the asset.

Definition at line 138 of file asset_manager.h.

◆ get_asset_from_instance()

template<typename T >
auto unravel::asset_manager::get_asset_from_instance ( const std::string & key,
std::shared_ptr< T > entry ) -> asset_handle<T>
inline

Gets an asset handle from an instance.

Template Parameters
TThe type of the asset.
Parameters
keyThe key of the asset.
entryThe shared pointer to the asset instance.
Returns
The handle to the asset.

Definition at line 193 of file asset_manager.h.

◆ get_assets()

template<typename T >
auto unravel::asset_manager::get_assets ( const std::string & group = {}) const -> std::vector<asset_handle<T>>
inline

Gets all assets in a specified group.

Template Parameters
TThe type of the assets.
Parameters
groupThe group to get assets from.
Returns
A vector of handles to the assets.

Definition at line 260 of file asset_manager.h.

◆ get_assets_with_predicate()

template<typename T , typename F >
auto unravel::asset_manager::get_assets_with_predicate ( F && predicate) const -> std::vector<asset_handle<T>>
inline

Gets all assets that satisfy a predicate.

Template Parameters
TThe type of the assets.
FThe predicate function.
Parameters
predicateThe predicate function.
Returns
A vector of handles to the assets that satisfy the predicate.

Definition at line 282 of file asset_manager.h.

◆ get_metadata()

auto unravel::asset_manager::get_metadata ( const hpp::uuid & uid) const -> asset_database::meta

Gets metadata for a resource uid.

Parameters
uidThe the uuid of the resource.
Returns
Meta object containing information.

Definition at line 207 of file asset_manager.cpp.

◆ init()

auto unravel::asset_manager::init ( rtti::context & ctx) -> bool

Initializes the asset manager with the given context.

Parameters
ctxThe context to initialize with.
Returns
True if initialization was successful, false otherwise.

Definition at line 34 of file asset_manager.cpp.

◆ load_database()

auto unravel::asset_manager::load_database ( const std::string & protocol) -> bool

Loads an asset database from a protocol.

Parameters
protocolThe protocol to load from.
Returns
True if the database was loaded successfully, false otherwise.

Definition at line 172 of file asset_manager.cpp.

◆ remove_asset_info_for_key()

void unravel::asset_manager::remove_asset_info_for_key ( const std::string & key)

Removes asset information for a specified key.

Parameters
keyThe key of the asset.

Definition at line 246 of file asset_manager.cpp.

◆ remove_asset_info_for_path()

void unravel::asset_manager::remove_asset_info_for_path ( const fs::path & path)

Removes asset information for a specified path.

Parameters
pathThe path of the asset.

Definition at line 240 of file asset_manager.cpp.

◆ rename_asset()

template<typename T >
void unravel::asset_manager::rename_asset ( const std::string & key,
const std::string & new_key )
inline

Renames an asset.

Template Parameters
TThe type of the asset.
Parameters
keyThe current key of the asset.
new_keyThe new key for the asset.

Definition at line 210 of file asset_manager.h.

◆ save_database()

void unravel::asset_manager::save_database ( const std::string & protocol,
const fs::path & path )

Saves the asset database to a specified path.

Parameters
protocolThe protocol to use for saving.
pathThe path to save the database to.

Definition at line 181 of file asset_manager.cpp.

◆ set_parent()

void unravel::asset_manager::set_parent ( asset_manager * parent)

Sets the parent asset manager.

Parameters
parentThe parent asset manager.

Definition at line 29 of file asset_manager.cpp.

◆ unload_all()

void unravel::asset_manager::unload_all ( )

Unloads all assets.

Definition at line 131 of file asset_manager.cpp.

◆ unload_asset()

template<typename T >
void unravel::asset_manager::unload_asset ( const std::string & key)
inline

Unloads an asset by its key.

Template Parameters
TThe type of the asset.
Parameters
keyThe key of the asset.

Definition at line 242 of file asset_manager.h.

◆ unload_group()

void unravel::asset_manager::unload_group ( const std::string & group)

Unloads all assets in a specified group.

Parameters
groupThe group to unload.

Definition at line 145 of file asset_manager.cpp.


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