Engine → Assets → asset_manager.h
asset_manager
| Type | Class |
| Namespace | conjure::assets |
| Include File Path | engine/include/conjure/assets/asset_manager.h |
| Source File Path | engine/src/assets/asset_manager.cpp |
| API ↗ | Cooking, caches and packs, Database, importers and hot reload, Assets, Referencing and loading assets |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | explicit asset_manager(
asset_manager_desc desc); |
Important
Copy constructor and assignment has been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~asset_manager(); | Releases internal handles, destroys payloads and asserts that no external strong reference is left (logs and continues in Distribution). |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mState | std::unique_ptr<state> | {} |
Functions
Public
add_source
add_sourcevoid add_source(
std::unique_ptr<asset_source> source);Adds a secondary source searched after the primary (plugin packs).
begin_frame
begin_framevoid begin_frame(
u64 frameIndex);bind
bindtemplate <declared_asset_type AssetType> [[nodiscard]] asset_ref<AssetType> bind(
const asset_id &id);Finds or creates the slot and binds a typed reference. When the slot's type is not yet known it is taken from the source, else from AssetType; a recorded type that differs from AssetType logs an ERROR once per uuid and yields an unbound reference.
bind_slot
bind_slot[[nodiscard]] const asset_slot *bind_slot(
const asset_id &id);Untyped bind for the scene bind pass. Null for the null uuid.
cancel_load
cancel_loadbool cancel_load(
const asset_id &id);Main thread. Gives up a first load that nothing waits for any more, for a caller about to discard the asset (the editor removing a prefab file it just wrote), so the load neither publishes the asset nor reports the source losing it. A QUEUED slot, or one in FINALISING waiting for its dependencies, returns to UNLOADED at once. A LOADING slot stays LOADING until the manager next drains its running job (update(), flush(), shutdown(), or a load_blocking() that waits for a job); the job's result is then dropped unread and the slot returns to UNLOADED, unless load(), load_batch() or load_blocking() asked for the asset again in between, which keeps the result. Dependencies the stage already queued are not cancelled: they load on, and collect() unloads them once nothing holds them. No event is fired for the given-up load. Returns true when the load was given up; false, changing nothing, while any asset_handle on the slot exists (a caller's or a dependent's), for a pinned slot (pin() asked for it to stay resident), for a slot that is not in a first load (UNLOADED, LOADED, RELOADING, FAILED), for an unknown or null uuid and after shutdown().
collect
collectu32 collect();Unloads every LOADED slot with zero strong references that is not pinned, releasing its dependency handles, until nothing changes. Returns how many were unloaded.
end_frame
end_framevoid end_frame();failed_ids
failed_ids[[nodiscard]] std::vector<asset_id> failed_ids(
assets_error code) const;Slots that are FAILED with the given code (the hot reload controller repairs CACHE_MISS). Main thread.
fallback
fallbacktemplate <declared_asset_type AssetType> [[nodiscard]] AssetType *fallback() noexcept;The type's fallback payload, created lazily from its loader; nullptr when the type is unregistered or has no fallback. Pinned for the manager's lifetime.
find
find[[nodiscard]] std::optional<asset_id> find(
std::string_view assetPath) const;Resolves "mount://path#sub" through the sources.
find_slot
find_slot[[nodiscard]] const asset_slot *find_slot(
const asset_id &id) const noexcept;The slot of a uuid without creating one: nullptr until something binds it. Read-only callers (the scripting bindings' state queries) use it so a uuid a script merely asks about never costs a permanent slot.
flush
flushvoid flush();Runs update() until no load is in flight: every queued load is terminal, or UNLOADED when cancel_load() gave it up.
frame_index
frame_index[[nodiscard]] u64 frame_index() const noexcept;get_or_fallback
get_or_fallbacktemplate <declared_asset_type AssetType> [[nodiscard]] AssetType *get_or_fallback(
const asset_ref<AssetType> &ref) noexcept;ref.get(), or the type's fallback while the asset is not LOADED.
is_pinned
is_pinned[[nodiscard]] bool is_pinned(
const asset_id &id) const noexcept;is_shut_down
is_shut_down[[nodiscard]] bool is_shut_down() const noexcept;last_error
last_error[[nodiscard]] const core::error *last_error(
const asset_id &id) const noexcept;The error of a FAILED slot (or of the last failed reload, until collect() unloads the slot), else nullptr. Valid until the slot changes state.
load
load[[nodiscard]] asset_handle load(
const asset_id &id,
asset_load_priority priority = asset_load_priority::NORMAL);Queues a load (UNLOADED -> QUEUED) and returns a handle. Other states are left alone (FAILED needs retry_failed()), except that a LOADING slot whose load cancel_load() gave up keeps its job's result again. Unbound handle for the null uuid.
load_batch
load_batch[[nodiscard]] asset_load_batch load_batch(
std::span<const asset_id> ids,
asset_load_priority priority = asset_load_priority::NORMAL);load_blocking
load_blocking[[nodiscard]] core::result<asset_handle> load_blocking(
const asset_id &id,
blocking_load_warning warning = blocking_load_warning::WARN_INSIDE_FRAME);Main thread. Runs the whole pipeline inline, dependencies first, and returns the LOADED handle or the failure (the slot is then FAILED). Waits for an in-flight job up to blockingTimeoutSeconds (TIMEOUT; the slot then stays with the async pipeline, which finishes it on a later update()). Inside a frame it logs one WARN per frame unless warning is blocking_load_warning::EXPECTED; an EXPECTED call does not use up the frame's WARN.
make_handle
make_handle[[nodiscard]] asset_handle make_handle(
const asset_id &id);An owning handle on the slot; binds, never loads. Unbound for the null uuid.
pin
pinvoid pin(
const asset_id &id,
bool pinned);A pinned slot is never unloaded by collect(), and cancel_load() does not give up its first load.
reload
reloadvoid reload(
const asset_id &id);LOADED -> RELOADING through the normal pipeline; the old payload stays published until the new one finalises. Ignored in other states.
shutdown
shutdownvoid shutdown();Refuses new work, waits for in-flight jobs, discards their completions and returns queued slots to UNLOADED.
state_of
state_of[[nodiscard]] asset_state state_of(
const asset_id &id) const noexcept;UNLOADED for unknown uuids.
stats
stats[[nodiscard]] asset_manager_stats stats() const noexcept;subscribe
subscribe[[nodiscard]] asset_subscription subscribe(
asset_event_callback callback);swap_source
swap_sourcevoid swap_source(
std::unique_ptr<asset_source> source);Replaces the primary source (editor: cache -> pack preview). Loaded payloads stay. Safe while loads are in flight: a job reading from the old source finishes its read first, and jobs that have not started resolve the new source.
type_of
type_of[[nodiscard]] std::optional<asset_type_id> type_of(
const asset_id &id) const;The asset type of a uuid: the bound slot's recorded type, else the first source that contains it; nullopt when no slot records it and no source knows it. Never binds.
types
types[[nodiscard]] asset_type_registry &types() noexcept;[[nodiscard]] const asset_type_registry &types() const noexcept;unsubscribe
unsubscribevoid unsubscribe(
asset_subscription subscription);Takes effect immediately, including for events the current update() has not delivered yet.
update
updatevoid update();Dispatches queued loads, drains completions, finalises under the budget (at least one slot per call), destroys retired payloads and fires events.
Private
bind_typed
bind_typed[[nodiscard]] const asset_slot *bind_typed(
const asset_id &id,
asset_type_id type);fallback_payload
fallback_payload[[nodiscard]] void *fallback_payload(
asset_type_id type) noexcept;