Maps URI schemes to filesystem roots and manages asset lifetime.
More...
#include <asset_manager.hpp>
|
| auto | load (toast::UID uid) -> Asset * |
| | Loads an asset by UID, returning the cached copy if already resident.
|
| auto | load (std::string_view uri) -> Asset * |
| | Loads an asset by virtual URI, returning the cached copy if already resident.
|
| auto | save (toast::UID uid) -> bool |
| | Serializes the cached asset at the given UID back to its backing file.
|
| auto | save (std::string_view uri) -> bool |
| | Serializes the cached asset at the given URI back to its backing file.
|
| auto | saveBytes (std::string_view uri, const std::vector< uint8_t > &data) -> bool |
| | Writes raw bytes to the path resolved by a virtual URI, bypassing the manifest.
|
|
void | replacePrefab (toast::UID uid, const Prefab &prefab) |
| auto | loadBytes (std::string_view uri) -> std::optional< std::vector< uint8_t > > |
| | Reads raw bytes from the URI, bypassing the manifest.
|
|
auto | tryLoadBytes (std::string_view uri) -> std::optional< std::vector< uint8_t > > |
| | Like loadBytes() but silent on misses.
|
| void | reloadManifest () |
| | Re-reads the project manifest from disk.
|
| void | clearUnusedAssets () |
| | Evicts all assets whose ref count is zero from the cache.
|
| auto | search (std::string_view query) -> std::vector< Handle< Asset > > |
| | Searches the manifest for entries whose path contains the given query string.
|
|
auto | listByType (std::string_view type) -> std::vector< toast::UID > |
|
void | pollModifiedAssets () |
| | Searches what assets have been modified.
|
|
auto | hasPendingReloads () const -> bool |
|
auto | applyPendingReloads () -> std::vector< ReloadedAsset > |
| | Reloads the assets pollModifiedAssets() changed.
|
|
auto | getCachePath () const -> const std::filesystem::path & |
|
|
static auto | get () noexcept -> AssetManager & |
|
static auto | isInitialized () noexcept -> bool |
| static void | setPaths (Paths &&paths) |
| | Configures the five fixed special URI roots; must be called before Engine::init().
|
| static void | registerDatabase (std::string_view name, std::filesystem::path root) |
| | Registers a content database scheme.
|
| static void | clearDatabases () |
| | Removes all content database schemes (non-fixed), leaving only special roots intact.
|
|
static auto | projectRoot () -> const std::filesystem::path & |
| | Returns the project root path (project:// root).
|
| static auto | resolveURI (std::string_view uri) -> std::optional< toast::UID > |
| | Maps a virtual URI to its manifest UID.
|
| static auto | getURI (toast::UID uid) -> std::string |
| static auto | typeOf (toast::UID uid) -> std::string |
| | Looks up an asset's type string in the manifest without loading it.
|
|
static void | setLoadMode (SaveMode mode) |
| | Selects the asset load mode.
|
| static auto | getLoadMode () -> SaveMode |
| static void | mountPack (std::string_view scheme, const std::filesystem::path &pak_path) |
| | Mounts a .pak archive at a URI scheme.
|
Maps URI schemes to filesystem roots and manages asset lifetime.
Fixed special schemes (always registered via setPaths):
- project:// the project root folder
- artwork:// raw art source files (textures, models before baking)
- cache:// generated or baked files that can be rebuilt
- core:// engine built-in assets (default shaders, primitives)
- saved:// user save data and preferences
Content database schemes (registered via registerDatabase after ProjectSettings loads):
- assets:// default content database (always present for a new project)
- <name>:// additional databases listed in the project's databases array
Roots are configured via setPaths() then registerDatabase() before any load call. Assets stay resident in the cache until clearUnusedAssets() is called and their ref count is zero.
- See also
- Paths, Handle, setPaths(), registerDatabase()
◆ clearDatabases()
| void assets::AssetManager::clearDatabases |
( |
| ) |
|
|
static |
Removes all content database schemes (non-fixed), leaving only special roots intact.
- Note
- Used by reloadSettings to reset before re-registering databases from updated project settings
◆ clearUnusedAssets()
| void assets::AssetManager::clearUnusedAssets |
( |
| ) |
|
Evicts all assets whose ref count is zero from the cache.
- Note
- Assets still referenced by an Handle will not be evicted; safe to call periodically
◆ getLoadMode()
| auto assets::AssetManager::getLoadMode |
( |
| ) |
-> SaveMode |
|
static |
◆ getURI()
| auto assets::AssetManager::getURI |
( |
toast::UID | uid | ) |
-> std::string |
|
static |
- Returns
- The path of the given UID
This is useful for debugging, or printing which file you have
◆ load() [1/2]
| auto assets::AssetManager::load |
( |
std::string_view | uri | ) |
-> Asset * |
Loads an asset by virtual URI, returning the cached copy if already resident.
- Parameters
-
| uri | Virtual path, e.g. "assets://characters/knight.node" |
- Returns
- Raw pointer owned by the manager; null if the URI could not be resolved or the asset failed to parse
- Note
- Resolves the URI to a UID via the manifest, then delegates to load(UID)
◆ load() [2/2]
Loads an asset by UID, returning the cached copy if already resident.
- Parameters
-
| uid | The asset's manifest UID |
- Returns
- Raw pointer owned by the manager; do not delete; null if the asset was not found or failed to parse
- Note
- The returned pointer stays valid until clearUnusedAssets() is called and the ref count reaches zero
◆ loadBytes()
| auto assets::AssetManager::loadBytes |
( |
std::string_view | uri | ) |
-> std::optional< std::vector< uint8_t > > |
Reads raw bytes from the URI, bypassing the manifest.
You should 99% of the time not use this
◆ mountPack()
| void assets::AssetManager::mountPack |
( |
std::string_view | scheme, |
|
|
const std::filesystem::path & | pak_path ) |
|
static |
Mounts a .pak archive at a URI scheme.
- Parameters
-
| scheme | URI scheme without "://" |
| pak_path | Absolute path to the .pak file |
After mounting, reads for that scheme go to the pack instead of the filesystem
◆ registerDatabase()
| void assets::AssetManager::registerDatabase |
( |
std::string_view | name, |
|
|
std::filesystem::path | root ) |
|
static |
Registers a content database scheme.
- Note
- Call after setPaths and before AssetManager construction (or before reloadManifest)
◆ reloadManifest()
| void assets::AssetManager::reloadManifest |
( |
| ) |
|
Re-reads the project manifest from disk.
- Note
- Call after importing or creating a new asset; does not evict the asset cache
◆ resolveURI()
| auto assets::AssetManager::resolveURI |
( |
std::string_view | uri | ) |
-> std::optional< toast::UID > |
|
static |
Maps a virtual URI to its manifest UID.
- Parameters
-
| uri | A string of the form scheme://relative/path |
- Returns
- The UID from the manifest, or nullopt if the scheme is unknown or the path has no manifest entry
◆ save() [1/2]
| auto assets::AssetManager::save |
( |
std::string_view | uri | ) |
-> bool |
Serializes the cached asset at the given URI back to its backing file.
- Parameters
-
| uri | Virtual path of the asset to save |
- Returns
- false if the URI cannot be resolved, the asset is not cached, or the write fails
◆ save() [2/2]
| auto assets::AssetManager::save |
( |
toast::UID | uid | ) |
-> bool |
Serializes the cached asset at the given UID back to its backing file.
- Parameters
-
| uid | The asset's manifest UID |
- Returns
- false if the asset is not currently cached or the write fails
◆ saveBytes()
| auto assets::AssetManager::saveBytes |
( |
std::string_view | uri, |
|
|
const std::vector< uint8_t > & | data ) -> bool |
Writes raw bytes to the path resolved by a virtual URI, bypassing the manifest.
- Parameters
-
| uri | Virtual path, e.g. "cache://generated/mesh.bin" |
| data | Bytes to write |
- Returns
- false on write failure
- Note
- Useful for newly created assets that are not yet in the manifest; does not update the manifest
◆ search()
| auto assets::AssetManager::search |
( |
std::string_view | query | ) |
-> std::vector< Handle< Asset > > |
Searches the manifest for entries whose path contains the given query string.
- Parameters
-
| query | Substring to search for in manifest paths |
- Returns
- Loaded asset handles for all matching entries; empty vector if none found
◆ setPaths()
| void assets::AssetManager::setPaths |
( |
Paths && | paths | ) |
|
|
static |
Configures the five fixed special URI roots; must be called before Engine::init().
- Parameters
-
| paths | Filesystem paths for each fixed scheme (project, artwork, cache, core, saved) |
- Warning
- Not thread-safe after initialization; call this before creating the AssetManager or spawning load threads
◆ typeOf()
| auto assets::AssetManager::typeOf |
( |
toast::UID | uid | ) |
-> std::string |
|
static |
Looks up an asset's type string in the manifest without loading it.
- Returns
- The manifest type
The documentation for this class was generated from the following files: