3#include <engine/engine_export.h>
4#include <hpp/filesystem.hpp>
53 return uid() == rhs.uid() &&
id() == rhs.id() &&
is_valid() == rhs.is_valid();
58 return uintptr_t(get_cached_asset().
get());
74 auto id() const -> const
std::
string&
81 static const std::string empty;
89 auto uid() const -> const hpp::uuid&
96 static const hpp::uuid empty;
106 return fs::path(
id()).stem().string();
111 return fs::path(
id()).extension().string();
119 auto get(
bool wait =
true) const ->
std::shared_ptr<T>
121 if(
auto cached_asset = get_cached_asset())
128 bool should_get = ready || (!ready && wait);
130 if(valid && should_get)
132 auto task = link_->task;
135 task.change_priority(tpp::priority::high());
138 auto value = task.get();
142 link_->weak_asset = value;
147 static const std::shared_ptr<T> empty = std::make_shared<T>();
157 return link_ && link_->task.valid();
166 return is_valid() && link_->task.is_ready();
178 return link_->task.id;
181 return tpp::job_id{};
191 link_->task = future;
192 link_->weak_asset = {};
203 link_->uid = internal_uid;
204 link_->id = internal_id;
214 link_->id = internal_id;
224 auto task_count = link_->task.use_count();
227 APPLOG_TRACE(
"{} - task leak use_count {}",
id(), task_count);
255 static const std::string empty{
"None"};
264 static_assert(
sizeof(
asset_link_t) >= 1,
"Type must be fully defined");
267 link_ = std::make_shared<asset_link_t>();
272 auto get_cached_asset() const ->
std::shared_ptr<T>
276 return link_->weak_asset.lock();
282 std::shared_ptr<asset_link_t> link_;
tpp::job_shared_future< T > task_future
#define APPLOG_TRACE(...)
Represents a handle to an asset, providing access and management functions.
static auto get_empty_id() -> const std::string &
Gets an empty string identifier.
auto is_valid() const -> bool
Checks if the handle is valid.
auto operator==(const asset_handle &rhs) const -> bool
Equality operator for asset handles.
void set_internal_job(const typename asset_link_t::task_future_t &future)
Sets the internal job future.
void invalidate()
Invalidates the handle, resetting its state.
auto uid() const -> const hpp::uuid &
Gets the unique identifier of the asset.
static auto get_empty() -> const asset_handle &
Gets an empty asset handle.
void set_internal_ids(const hpp::uuid &internal_uid, const std::string &internal_id=get_empty_id())
Sets the internal IDs.
auto get(bool wait=true) const -> std::shared_ptr< T >
Gets the shared pointer to the asset.
asset_link< T > asset_link_t
auto extension() const -> std::string
auto name() const -> std::string
Gets the name of the asset derived from its path.
auto is_ready() const -> bool
Checks if the task is ready.
auto task_id() const
Gets the task ID.
void ensure()
Ensures the asset link is initialized.
auto id() const -> const std::string &
Gets the string identifier of the asset.
auto version() const -> uintptr_t
void set_internal_id(const std::string &internal_id=get_empty_id())
Sets the internal string identifier.
Represents a link to an asset, including its task and weak pointer.
hpp::uuid uid
Unique identifier for the asset.
task_future< std::shared_ptr< T > > task_future_t
std::weak_ptr< T > weak_asset_t
task_future_t task
Task future for the asset.
weak_asset_t weak_asset
Weak pointer to the asset.