36 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
41 auto& storage = add_storage<gfx::shader>();
46 auto& storage = add_storage<gfx::texture>();
52 auto& storage = add_storage<material>();
58 auto& storage = add_storage<mesh>();
64 auto& storage = add_storage<animation_clip>();
70 auto& storage = add_storage<prefab>();
76 auto& storage = add_storage<scene_prefab>();
82 auto& storage = add_storage<physics_material>();
88 auto& storage = add_storage<ui_tree>();
94 auto& storage = add_storage<style_sheet>();
100 auto& storage = add_storage<audio_clip>();
106 auto& storage = add_storage<font>();
112 auto& storage = add_storage<script>();
122 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
133 for(
auto& pair : storages_)
135 auto& storage = pair.second;
136 storage->unload_all(pool_);
140 std::lock_guard<std::mutex> lock(db_mutex_);
147 for(
auto& pair : storages_)
149 auto& storage = pair.second;
150 storage->unload_group(pool_, group);
154 remove_database(group);
158auto asset_manager::get_database(
const std::string& key) ->
asset_database&
161 return databases_[protocol.generic_string()];
164void asset_manager::remove_database(
const std::string& key)
168 std::lock_guard<std::mutex> lock(db_mutex_);
169 databases_.erase(protocol.generic_string());
176 std::lock_guard<std::mutex> lock(db_mutex_);
177 auto& db = get_database(protocol);
183 std::lock_guard<std::mutex> lock(db_mutex_);
184 auto& db = get_database(protocol);
188auto asset_manager::add_asset(
const std::string& key) -> hpp::uuid
190 auto meta = generate_metadata(key);
191 return add_asset_info_for_key(key, meta,
false);
197 return add_asset_info_for_key(key, meta,
override);
202 std::lock_guard<std::mutex> lock(db_mutex_);
203 auto& db = get_database(key);
204 return db.add_asset(key, meta,
override);
209 std::lock_guard<std::mutex> lock(db_mutex_);
210 for(
auto& kvp : databases_)
212 auto& db = kvp.second;
213 const auto& meta = db.get_metadata(uid);
214 if(!meta.location.empty())
225 meta.
type = p.extension().string();
228 if(meta.
type.empty())
248 std::lock_guard<std::mutex> lock(db_mutex_);
249 auto& db = get_database(key);
250 db.remove_asset(key);
Manages asset metadata and provides functionality for adding, removing, and querying assets.
Manages assets, including loading, unloading, and storage.
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.
asset_manager(rtti::context &ctx)
Constructs an asset manager with the given context.
auto generate_metadata(const fs::path &p) const -> asset_meta
void unload_all()
Unloads all assets.
auto init(rtti::context &ctx) -> bool
Initializes the asset manager with the given context.
~asset_manager()
Destructs the asset manager.
auto get_metadata(const hpp::uuid &uid) const -> asset_database::meta
Gets metadata for a resource uid.
auto deinit(rtti::context &ctx) -> bool
Deinitializes the asset manager with the given context.
void remove_asset_info_for_key(const std::string &key)
Removes asset information for a specified key.
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 add_asset_info_for_path(const fs::path &path, const asset_meta &meta, bool override) -> hpp::uuid
Adds asset information for a specified path.
void remove_asset_info_for_path(const fs::path &path)
Removes asset information for a specified path.
void unload_group(const std::string &group)
Unloads all assets in a specified group.
void set_parent(asset_manager *parent)
Sets the parent asset manager.
#define APPLOG_TRACE(...)
path extract_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
path resolve_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
path convert_to_protocol(const path &_path)
Oposite of the resolve_protocol this function tries to convert to protocol path from an absolute one.
auto load_from_file< font >(tpp::thread_pool &pool, asset_handle< font > &output, const std::string &key) -> bool
auto load_from_file< gfx::texture >(tpp::thread_pool &pool, asset_handle< gfx::texture > &output, const std::string &key) -> bool
auto load_from_file< scene_prefab >(tpp::thread_pool &pool, asset_handle< scene_prefab > &output, const std::string &key) -> bool
auto load_from_file< style_sheet >(tpp::thread_pool &pool, asset_handle< style_sheet > &output, const std::string &key) -> bool
auto load_from_file< mesh >(tpp::thread_pool &pool, asset_handle< mesh > &output, const std::string &key) -> bool
auto load_from_file< material >(tpp::thread_pool &pool, asset_handle< material > &output, const std::string &key) -> bool
auto load_from_file< gfx::shader >(tpp::thread_pool &pool, asset_handle< gfx::shader > &output, const std::string &key) -> bool
auto load_from_file< physics_material >(tpp::thread_pool &pool, asset_handle< physics_material > &output, const std::string &key) -> bool
auto load_from_file< ui_tree >(tpp::thread_pool &pool, asset_handle< ui_tree > &output, const std::string &key) -> bool
auto load_from_file< prefab >(tpp::thread_pool &pool, asset_handle< prefab > &output, const std::string &key) -> bool
auto load_from_file< script >(tpp::thread_pool &pool, asset_handle< script > &output, const std::string &key) -> bool
auto load_from_file< audio_clip >(tpp::thread_pool &pool, asset_handle< audio_clip > &output, const std::string &key) -> bool
auto load_from_instance(tpp::thread_pool &pool, asset_handle< T > &output, std::shared_ptr< T > instance) -> bool
auto load_from_file< animation_clip >(tpp::thread_pool &pool, asset_handle< animation_clip > &output, const std::string &key) -> bool
void mesh_importer_init()
auto generate_uuid() -> hpp::uuid
void load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const animation_clip &obj)