|
Unravel Engine C++ Reference
|
Thread-safe handle to an asset. More...
#include <asset_handle.h>
Public Types | |
| using | asset_link_t = asset_link<T> |
| using | state_t = typename asset_link_t::state_t |
| using | state_ptr = std::shared_ptr<state_t> |
| using | task_future_t = typename asset_link_t::task_future_t |
Public Member Functions | |
| auto | operator== (const asset_handle &rhs) const -> bool |
| Equality operator for asset handles. | |
| auto | version () const -> uintptr_t |
| operator bool () const | |
| Conversion operator to bool. | |
| auto | id () const -> std::string |
| Gets the string identifier of the asset. | |
| auto | uid () const -> hpp::uuid |
| Gets the unique identifier of the asset. | |
| auto | name () const -> std::string |
| Gets the name of the asset derived from its path. | |
| auto | extension () const -> std::string |
| auto | get (bool wait=true) const -> std::shared_ptr< T > |
| Gets the shared pointer to the asset. | |
| auto | is_valid () const -> bool |
| Checks if the handle references a task. | |
| auto | is_ready () const -> bool |
| Checks if the task is ready. | |
| auto | is_deferred () const -> bool |
| Checks if the handle has a deferred job not yet submitted to workers. | |
| auto | is_loading () const -> bool |
| Checks if the asset is currently loading. | |
| void | submit () |
| Submits a deferred task to the thread pool for execution. Does nothing if the task is already submitted or invalid. | |
| void | demote_to_deferred () |
| Demotes a fully loaded asset back to deferred state. | |
| auto | last_access () const -> std::chrono::steady_clock::time_point |
| Gets the last access timestamp. | |
| auto | task_id () const |
| Gets the task ID (may be empty if there's no task). | |
| void | set_internal_job (const task_future_t &future) |
| Sets the internal job future. | |
| void | set_internal_ids (const hpp::uuid &internal_uid, const std::string &internal_id=get_empty_id()) |
| Sets the internal IDs (uid + string identifier). | |
| void | set_internal_id (const std::string &internal_id=get_empty_id()) |
| Sets the internal string identifier. | |
| void | invalidate () |
| Invalidates the handle, resetting its state. | |
| auto | peek () const -> std::shared_ptr< T > |
| Returns the loaded asset if it is currently in memory, or nullptr otherwise. | |
| void | ensure () |
| Ensures the asset link is initialized. | |
Static Public Member Functions | |
| static auto | get_empty () -> const asset_handle & |
| Gets an empty asset handle. | |
| static auto | get_empty_id () -> const std::string & |
| Gets the conventional empty string identifier ("None"). | |
Thread-safe handle to an asset.
The handle is a cheap value (shared_ptr to the link). All accessors are safe to call concurrently from any thread; mutators publish their changes atomically so other threads always observe a consistent state.
Definition at line 144 of file asset_handle.h.
| using asset_handle< T >::asset_link_t = asset_link<T> |
Definition at line 146 of file asset_handle.h.
| using asset_handle< T >::state_ptr = std::shared_ptr<state_t> |
Definition at line 148 of file asset_handle.h.
| using asset_handle< T >::state_t = typename asset_link_t::state_t |
Definition at line 147 of file asset_handle.h.
| using asset_handle< T >::task_future_t = typename asset_link_t::task_future_t |
Definition at line 149 of file asset_handle.h.
|
inline |
Demotes a fully loaded asset back to deferred state.
Publishes a new snapshot that preserves uid / id but drops the task; also clears the weak-asset cache. Caller should follow with a load_from_file(deferred) to set up a new deferred task.
Definition at line 330 of file asset_handle.h.
|
inline |
Ensures the asset link is initialized.
Definition at line 498 of file asset_handle.h.
|
inline |
Definition at line 214 of file asset_handle.h.
|
inline |
Gets the shared pointer to the asset.
| wait | If true, waits for the task to complete if not ready. |
If the handle was registered with deferred loading, the first call to get() triggers the actual load on the thread pool. Subsequent calls behave as before (wait or poll).
Definition at line 227 of file asset_handle.h.
|
inlinestatic |
Gets an empty asset handle.
Definition at line 455 of file asset_handle.h.
|
inlinestatic |
Gets the conventional empty string identifier ("None").
Definition at line 469 of file asset_handle.h.
|
inline |
Gets the string identifier of the asset.
Returns by value — the caller receives a snapshot of the current id. Binding to const auto& is still safe (the temporary's lifetime is extended to the binding's scope).
Definition at line 181 of file asset_handle.h.
|
inline |
Invalidates the handle, resetting its state.
Publishes an empty snapshot so any concurrent reader observing the link after this call sees a fully-cleared state.
Definition at line 431 of file asset_handle.h.
|
inline |
Checks if the handle has a deferred job not yet submitted to workers.
Definition at line 295 of file asset_handle.h.
|
inline |
Checks if the asset is currently loading.
Definition at line 304 of file asset_handle.h.
|
inline |
Checks if the task is ready.
Definition at line 286 of file asset_handle.h.
|
inline |
Checks if the handle references a task.
Definition at line 277 of file asset_handle.h.
|
inline |
Gets the last access timestamp.
Definition at line 353 of file asset_handle.h.
|
inline |
Gets the name of the asset derived from its path.
Definition at line 209 of file asset_handle.h.
|
inline |
Conversion operator to bool.
Definition at line 169 of file asset_handle.h.
|
inline |
Equality operator for asset handles.
Definition at line 154 of file asset_handle.h.
|
inline |
Returns the loaded asset if it is currently in memory, or nullptr otherwise.
Unlike get(), this does NOT force-load, does NOT submit deferred tasks, does NOT wait, and does NOT update last-access. Intended for iteration use cases — e.g. walking the asset manager's loaded set to build a dependency graph — where we only care about what is already resident and must not have side effects.
Definition at line 485 of file asset_handle.h.
|
inline |
Sets the internal string identifier.
Publishes a new snapshot; preserves uid and task.
Definition at line 415 of file asset_handle.h.
|
inline |
Sets the internal IDs (uid + string identifier).
Publishes a new snapshot; preserves the current task.
Definition at line 399 of file asset_handle.h.
|
inline |
Sets the internal job future.
Publishes a new snapshot with the given task; preserves uid + id. Also clears the weak-asset cache so the next get() resolves the new task.
Definition at line 381 of file asset_handle.h.
|
inline |
Submits a deferred task to the thread pool for execution. Does nothing if the task is already submitted or invalid.
Definition at line 314 of file asset_handle.h.
|
inline |
Gets the task ID (may be empty if there's no task).
Definition at line 366 of file asset_handle.h.
|
inline |
Gets the unique identifier of the asset.
Returns by value — the caller receives a snapshot of the current uid. Binding to const auto& is still safe (the temporary's lifetime is extended to the binding's scope).
Definition at line 197 of file asset_handle.h.
|
inline |
Definition at line 159 of file asset_handle.h.