-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1177 allow identifying assets in code from their path #1337
Changes from all commits
4e54728
38414b3
b2d8aaf
c41711b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,7 +30,7 @@ | |||||||||||||
|
||||||||||||||
/// @brief Avoid using this field, use @ref getId() instead. | ||||||||||||||
/// @todo This was added as a dirty fix for #692, should be removed once the issue is fixed. | ||||||||||||||
uuids::uuid reflectedId; | ||||||||||||||
std::string idOrPath; | ||||||||||||||
|
||||||||||||||
~AnyAsset(); | ||||||||||||||
|
||||||||||||||
|
@@ -73,7 +73,11 @@ | |||||||||||||
|
||||||||||||||
/// @brief Gets the UUID of the asset. | ||||||||||||||
/// @return Asset UUID. | ||||||||||||||
uuids::uuid getId() const; | ||||||||||||||
std::string getId() const; | ||||||||||||||
|
||||||||||||||
/// @brief Gets the path of the asset. | ||||||||||||||
/// @return Asset path. | ||||||||||||||
std::string getPath() const; | ||||||||||||||
|
||||||||||||||
/// @brief Checks if the handle is null. | ||||||||||||||
/// @return Whether the handle is null. | ||||||||||||||
|
@@ -111,9 +115,10 @@ | |||||||||||||
/// @brief Decrements the reference count of the asset. | ||||||||||||||
void decRef() const; | ||||||||||||||
|
||||||||||||||
uuids::uuid mId; ///< UUID of the asset. | ||||||||||||||
void* mRefCount; ///< Void pointer to avoid including `<atomic>` in the header. | ||||||||||||||
int mVersion; ///< Last known version of the asset. | ||||||||||||||
uuids::uuid mId; ///< UUID of the asset. | ||||||||||||||
void* mRefCount; ///< Void pointer to avoid including `<atomic>` in the header. | ||||||||||||||
int mVersion; ///< Last known version of the asset. | ||||||||||||||
std::string path; ///< Path of the asset. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
/// @brief Handle to an asset of a specific type. | ||||||||||||||
|
@@ -160,10 +165,11 @@ | |||||||||||||
inline AnyAsset::operator Asset<T>() const | ||||||||||||||
{ | ||||||||||||||
Asset<T> asset; | ||||||||||||||
asset.reflectedId = reflectedId; | ||||||||||||||
asset.idOrPath = idOrPath; | ||||||||||||||
asset.mId = mId; | ||||||||||||||
asset.mRefCount = mRefCount; | ||||||||||||||
asset.mVersion = mVersion; | ||||||||||||||
asset.path = path; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
asset.incRef(); | ||||||||||||||
return asset; | ||||||||||||||
} | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -247,7 +247,6 @@ namespace cubos::engine | |||||
struct Entry | ||||||
{ | ||||||
Entry(); | ||||||
|
||||||
Status status{Status::Unloaded}; ///< The status of the asset. | ||||||
AssetMeta meta; ///< The metadata associated with the asset. | ||||||
|
||||||
|
@@ -308,6 +307,11 @@ namespace cubos::engine | |||||
/// @return Lock guard. | ||||||
std::unique_lock<std::shared_mutex> lockWrite(const AnyAsset& handle) const; | ||||||
|
||||||
/// @brief Checks if the given ID is of the correct type. | ||||||
/// @param id ID to check. | ||||||
/// @return The ID as a string. | ||||||
std::string checkIdType(const std::string& id) const; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/// @brief Gets a pointer to the entry associated with the given handle. | ||||||
/// @param handle Handle to get the entry for. | ||||||
/// @return Entry for the given handle, or nullptr if there is no such entry. | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,7 +27,7 @@ | |||||
} | ||||||
|
||||||
AnyAsset::AnyAsset(uuids::uuid id) | ||||||
: reflectedId(id) | ||||||
: idOrPath(uuids::to_string(id)) | ||||||
, mId(id) | ||||||
, mRefCount(nullptr) | ||||||
, mVersion(-1) | ||||||
|
@@ -38,54 +38,67 @@ | |||||
: mRefCount(nullptr) | ||||||
, mVersion(-1) | ||||||
{ | ||||||
|
||||||
if (auto id = uuids::uuid::from_string(str)) | ||||||
{ | ||||||
reflectedId = id.value(); | ||||||
idOrPath = str; | ||||||
mId = id.value(); | ||||||
} | ||||||
else | ||||||
{ | ||||||
CUBOS_ERROR("Could not create asset handle, invalid UUID: \"{}\"", str); | ||||||
if (str.find('/') != std::string::npos || str.find('\\') != std::string::npos) | ||||||
{ | ||||||
idOrPath = str; | ||||||
path = str; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
else | ||||||
{ | ||||||
CUBOS_ERROR("Could not create asset handle, invalid UUID or Path: \"{}\"", str); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
AnyAsset::AnyAsset(const AnyAsset& other) | ||||||
: reflectedId(other.reflectedId) | ||||||
: idOrPath(other.idOrPath) | ||||||
, mId(other.mId) | ||||||
, mRefCount(other.mRefCount) | ||||||
, mVersion(other.mVersion) | ||||||
, path(other.path) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
this->incRef(); | ||||||
} | ||||||
|
||||||
AnyAsset::AnyAsset(AnyAsset&& other) noexcept | ||||||
: reflectedId(other.reflectedId) | ||||||
: idOrPath(other.idOrPath) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
, mId(other.mId) | ||||||
, mRefCount(other.mRefCount) | ||||||
, mVersion(other.mVersion) | ||||||
, path(other.path) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
other.mRefCount = nullptr; | ||||||
} | ||||||
|
||||||
AnyAsset& AnyAsset::operator=(const AnyAsset& other) | ||||||
{ | ||||||
this->decRef(); | ||||||
reflectedId = other.reflectedId; | ||||||
idOrPath = other.idOrPath; | ||||||
mId = other.mId; | ||||||
mRefCount = other.mRefCount; | ||||||
mVersion = other.mVersion; | ||||||
path = other.path; | ||||||
this->incRef(); | ||||||
return *this; | ||||||
} | ||||||
|
||||||
AnyAsset& AnyAsset::operator=(AnyAsset&& other) noexcept | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
this->decRef(); | ||||||
reflectedId = other.reflectedId; | ||||||
idOrPath = other.idOrPath; | ||||||
mId = other.mId; | ||||||
mRefCount = other.mRefCount; | ||||||
mVersion = other.mVersion; | ||||||
other.mRefCount = nullptr; | ||||||
path = other.path; | ||||||
return *this; | ||||||
} | ||||||
|
||||||
|
@@ -96,22 +109,27 @@ | |||||
|
||||||
int AnyAsset::getVersion() const | ||||||
{ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return reflectedId == mId ? mVersion : 0; | ||||||
return uuids::uuid::from_string(idOrPath) == mId ? mVersion : 0; | ||||||
} | ||||||
|
||||||
std::string AnyAsset::getId() const | ||||||
{ | ||||||
return idOrPath; | ||||||
} | ||||||
|
||||||
uuids::uuid AnyAsset::getId() const | ||||||
std::string AnyAsset::getPath() const | ||||||
{ | ||||||
return reflectedId; | ||||||
return path; | ||||||
} | ||||||
|
||||||
bool AnyAsset::isNull() const | ||||||
{ | ||||||
return reflectedId.is_nil(); | ||||||
return idOrPath.empty(); | ||||||
} | ||||||
|
||||||
bool AnyAsset::isStrong() const | ||||||
{ | ||||||
return reflectedId == mId && mRefCount != nullptr; | ||||||
return uuids::uuid::from_string(idOrPath) == mId && mRefCount != nullptr; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
void AnyAsset::makeWeak() | ||||||
|
@@ -126,20 +144,20 @@ | |||||
|
||||||
return Type::create(std::move(name)) | ||||||
.with(ConstructibleTrait::typed<AnyAsset>().withBasicConstructors().build()) | ||||||
.with(FieldsTrait().withField("id", &AnyAsset::reflectedId)); | ||||||
.with(FieldsTrait().withField("id", &AnyAsset::idOrPath)); | ||||||
} | ||||||
|
||||||
void AnyAsset::incRef() const | ||||||
{ | ||||||
if (reflectedId == mId && mRefCount != nullptr) | ||||||
if (uuids::uuid::from_string(idOrPath) == mId && mRefCount != nullptr) | ||||||
{ | ||||||
static_cast<std::atomic<int>*>(mRefCount)->fetch_add(1); | ||||||
} | ||||||
} | ||||||
|
||||||
void AnyAsset::decRef() const | ||||||
{ | ||||||
if (reflectedId == mId && mRefCount != nullptr) | ||||||
if (uuids::uuid::from_string(idOrPath) == mId && mRefCount != nullptr) | ||||||
{ | ||||||
static_cast<std::atomic<int>*>(mRefCount)->fetch_sub(1); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invalid case style for private member
path