Engine → Assets → asset_database.h
asset_database
| Type | Class |
| Namespace | conjure::assets |
| Include File Path | engine/include/conjure/assets/asset_database.h |
| Source File Path | engine/src/assets/asset_database.cpp |
| API ↗ | Database, importers and hot reload, Assets |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | asset_database(
core::vfs::file_system &fileSystem,
importer_registry &importers,
const asset_type_registry &types,
core::jobs::job_system *jobs = nullptr); | jobs (optional) parallelises source hashing during scan(); without it hashing runs inline. Imports take their job system as an argument. |
Important
Copy constructor and assignment has been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~asset_database(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mCache | std:: | nullptr | |
| private | mCacheRoot | std::string | {} | |
| private | mChildren | std:: | {} | |
| private | mEntries | std::vector<entry> | {} | |
| private | mFileSystem | core::vfs::file_system * | nullptr | |
| private | m | std::vector<usize> | {} | |
| private | mImporters | importer_registry * | nullptr | |
| private | mIndexById | core:: | {} | |
| private | mIndexByPath | core:: | {} | |
| private | mJobs | core::jobs::job_system * | nullptr | |
| private | mMounts | std::vector<asset_mount> | {} | |
| private | mMutex | mutable std:: | {} | |
| private | mPlatform | std::string | {} | |
| private | m | std::vector<usize> | {} | |
| private | m | core:: | {} | |
| private | mStale | std::vector<asset_id> | {} | |
| private | mTypes | const asset_ | nullptr |
Functions
Public
add_file
add_file[[nodiscard]] core::result<asset_id> add_file(
std::string_view assetPath);Registers a source that exists on disk but was not scanned yet, creating its .meta. NOT_FOUND when the file is missing, ALREADY_EXISTS when it is known, INVALID_ARGUMENT when the path leaves its mount ("assets://../x", an absolute path).
add_mount
add_mount[[nodiscard]] core::result<void> add_mount(
std::string_view mountName,
std::string_view rootPath);Adds a mount. ALREADY_EXISTS for a repeated name, INVALID_ARGUMENT for an empty one. Mounts are scanned in the order they were added.
asset_path_of
asset_path_of[[nodiscard]] std::optional<std::string> asset_path_of(
const asset_id &id) const;"mount://relative#sub" of a record.
cache
cache[[nodiscard]] const asset_cache *cache() const noexcept;The cache opened by open(), or nullptr.
collect_dependents
collect_dependentsTransitive dependents including the roots, depth ascending, deduplicated.
contains
contains[[nodiscard]] bool contains(
const asset_id &id) const;Allocation-free lookups for the load path (cache_asset_source asks on every job): whether a record exists, its cooked type (nullopt when unknown or never imported) and its status.
create_asset
create_asset[[nodiscard]] core::result<asset_id> create_asset(
std::string_view assetPath,
std::string_view importerId,
std::span<const std::byte> initialBytes);Writes a new source and its .meta with the given importer, then registers it. The source is removed again when its .meta cannot be written; INVALID_ARGUMENT when the path leaves its mount or one of its names is not portable (core::vfs::path_utils::is_portable_name), before anything is written.
delete_asset
delete_asset[[nodiscard]] core::result<void> delete_asset(
const asset_id &id);Deletes the source, its .meta, its blobs and its records.
dependency_closure
dependency_closure[[nodiscard]] core::result<std::vector<asset_id>> dependency_closure(
std::span<const asset_id> roots) const;The roots plus everything they depend on, transitively, in uuid order. NOT_FOUND (assets) when a root is unknown.
file_path_of
file_path_of[[nodiscard]] std::optional<std::string> file_path_of(
const asset_id &id) const;File-system path of a record's source.
find
find[[nodiscard]] std::optional<asset_record> find(
const asset_id &id) const;find_by_file_path
find_by_file_path[[nodiscard]] std::optional<asset_id> find_by_file_path(
std::string_view filePath) const;The primary whose source is the given file-system path ("assets/a.png").
find_by_path
find_by_path[[nodiscard]] std::optional<asset_id> find_by_path(
std::string_view assetPath) const;import
import[[nodiscard]] core::result<import_report> import(
std::span<const asset_id> ids,
core::jobs::job_system &jobs);Imports the sources of the given ids (sub-asset ids import their primary), one job per source, writes blobs into the cache and merges the results. A failing source is recorded IMPORT_FAILED and keeps its previous blob; the call itself fails only with INVALID_STATE before open().
import_stale
import_stale[[nodiscard]] core::result<import_report> import_stale(
core::jobs::job_system &jobs);Imports every stale primary.
is_open
is_open[[nodiscard]] bool is_open() const noexcept;mark_source_missing
mark_source_missing[[nodiscard]] core::result<void> mark_source_missing(
const asset_id &id);Marks a primary (and its sub-assets) MISSING_SOURCE without a full scan: the hot reload controller calls it when the watcher reports the source file removed, so later loads fail with NOT_FOUND while an already loaded payload stays loaded. NOT_FOUND for an unknown id; a sub-asset id marks its primary.
mark_source_present
mark_source_present[[nodiscard]] core::result<void> mark_source_present(
const asset_id &id);Reverses mark_source_missing() once the source file exists again (the file was moved back or re-created): the status returns to OK (or NO_IMPORTER), the size and write time are refreshed and the source is stale if its content changed. NOT_FOUND for an unknown id or when the file is still absent.
mounts
mounts[[nodiscard]] std::span<const asset_mount> mounts() const noexcept;move_asset
move_asset[[nodiscard]] core::result<void> move_asset(
const asset_id &id,
std::string_view newAssetPath);Renames the source and its .meta; the uuid and every sub-asset uuid are kept. INVALID_ARGUMENT when the new path leaves its mount or one of its names is not portable (core::vfs::path_utils::is_portable_name), before anything is moved.
open
open[[nodiscard]] core::result<void> open(
std::string_view cacheRoot,
std::string_view platform);Opens the cache under cacheRoot for a platform and loads the db.bin snapshot when it is valid. Must precede scan().
owners_of_side_file
owners_of_side_file[[nodiscard]] std::vector<asset_id> owners_of_side_file(
std::string_view assetPath) const;platform
platform[[nodiscard]] std::string_view platform() const noexcept;read_meta
read_meta[[nodiscard]] core::result<asset_meta> read_meta(
const asset_id &id) const;Reads the .meta of a primary (or of a sub-asset's primary).
record_count
record_count[[nodiscard]] usize record_count() const;records
records[[nodiscard]] std::vector<asset_record> records() const;save_snapshot
save_snapshot[[nodiscard]] core::result<void> save_snapshot() const;Persists the records to <cacheRoot>/db.bin. Purely a cache; rebuilt when missing.
scan
scan[[nodiscard]] core::result<scan_report> scan();Walks every mount in sorted order, creates missing .meta files, applies the duplicate-uuid policy, hashes changed sources, marks removed sources MISSING_SOURCE, computes the stale set, deletes leftover *.tmp blobs and saves the snapshot. A .meta that cannot be written leaves its record META_INVALID (retried by the next scan) instead of failing the scan. INVALID_STATE before open().
set_importer
set_importer[[nodiscard]] core::result<void> set_importer(
const asset_id &id,
std::string_view importerId);Makes a registered importer the one a primary's .meta names ("import as"): the way to import a file with an importer that reads its format without claiming its extension, such as a .glb as collision geometry instead of a render model. The meta takes the importer's version and default settings, since the previous importer's settings mean nothing to it, and the asset is stale until its next import; its uuid is kept. Naming the importer the meta already has changes nothing. NO_IMPORTER for an id that is not registered; otherwise the errors of read_meta and write_meta.
stale_ids
stale_ids[[nodiscard]] std::vector<asset_id> stale_ids() const;The stale primaries computed by the last scan() or import().
status_of
status_of[[nodiscard]] std::optional<asset_record_status> status_of(
const asset_id &id) const;type_of
type_of[[nodiscard]] std::optional<asset_type_id> type_of(
const asset_id &id) const;types
types[[nodiscard]] const asset_type_registry &types() const noexcept;vfs
vfs[[nodiscard]] core::vfs::file_system &vfs() const noexcept;write_meta
write_meta[[nodiscard]] core::result<void> write_meta(
const asset_id &id,
const asset_meta &meta);Writes the .meta of a primary and refreshes the record (settings hash, importer). A changed uuid is refused with INVALID_ARGUMENT and logged: it would orphan references. A sub-asset the last import dropped (no blob) gets no record back from the meta. An imported primary switched to another importer is stale until its next import, even when both importers share a version and settings.
Private
apply_import_results
apply_import_results[[nodiscard]] core::result<void> apply_import_results(
std::vector<source_job> &jobs,
import_report &report);detect_cycles_locked
detect_cycles_lockedvoid detect_cycles_locked();ensure_open
ensure_open[[nodiscard]] core::result<void> ensure_open() const;file_path_for
file_path_for[[nodiscard]] std::string file_path_for(
u32 mountIndex,
std::string_view relativePath) const;find_entry_locked
find_entry_lockedhash_source
hash_sourcehash_source_bytes
hash_source_bytes[[nodiscard]] u64 hash_source_bytes(
std::span<const std::byte> primaryBytes,
std::span<const std::string> sideFiles) const;load_snapshot
load_snapshot[[nodiscard]] core::result<void> load_snapshot();mount_index
mount_index[[nodiscard]] std::optional<u32> mount_index(
std::string_view mountName) const noexcept;rebuild_graphs_locked
rebuild_graphs_lockedvoid rebuild_graphs_locked();rebuild_indexes_locked
rebuild_indexes_lockedvoid rebuild_indexes_locked();recompute_stale
recompute_stalevoid recompute_stale();register_source
register_source[[nodiscard]] core::result<asset_id> register_source(
u32 mountIndex,
std::string_view relativePath,
bool &outMetaCreated);set_source_status
set_source_status[[nodiscard]] core::result<void> set_source_status(
const asset_id &id,
bool present);write_import_log
write_import_log[[nodiscard]] core::result<void> write_import_log(
const import_report &report) const;