Skip to content
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

Closed

Conversation

GalaxyCrush
Copy link
Contributor

Description

Changed the Assets::entry functions to search for assets using paths instead of uuids.
Changed the Assets::load to update the mID of the AnyAsset handle.

Checklist

  • Self-review changes.
  • Evaluate impact on the documentation.
  • Ensure test coverage.
  • Write new samples.
  • Add entry to the changelog's unreleased section.

Copy link
Contributor

PR Preview Action v1.4.8
🚀 Deployed preview to https://GameDevTecnico.github.io/cubos/preview/pr-1337/
on branch gh-pages at 2024-09-29 15:46 UTC

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/2)

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
std::string path; ///< Path of the asset.
std::string mPath; ///< Path of the asset.

asset.mId = mId;
asset.mRefCount = mRefCount;
asset.mVersion = mVersion;
asset.path = path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
asset.path = path;
asset.path = mPath;

@@ -503,6 +512,22 @@ std::unique_lock<std::shared_mutex> Assets::lockWrite(const AnyAsset& handle) co
abort();
}

std::string Assets::checkIdType(const std::string& id) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-convert-member-functions-to-static ⚠️
method checkIdType can be made static

Suggested change
std::string Assets::checkIdType(const std::string& id) const
std::string Assets::checkIdType(const std::string& id)

/// @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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-convert-member-functions-to-static ⚠️
method checkIdType can be made static

Suggested change
std::string checkIdType(const std::string& id) const;
static std::string checkIdType(const std::string& id) ;

{
return "UUID";
}
else if (id.find('/') != std::string::npos || id.find('\\') != std::string::npos)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-else-after-return ⚠️
do not use else after return

Suggested change
else if (id.find('/') != std::string::npos || id.find('\\') != std::string::npos)
if (id.find('/') != std::string::npos || id.find('\\') != std::string::npos)

CUBOS_INFO("Assets::entry 1 Current ID type: {}", checkIdType(id));
if (Assets::checkIdType(id) == "Path")
{
for (auto asset : mEntries)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ performance-for-range-copy ⚠️
loop variable is copied but only used as const reference; consider making it a const reference

Suggested change
for (auto asset : mEntries)
for (const auto& asset : mEntries)

uuids::uuid uuid = uuids::uuid{};
if (Assets::checkIdType(id) == "Path")
{
for (auto asset : mEntries)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ performance-for-range-copy ⚠️
loop variable is copied but only used as const reference; consider making it a const reference

Suggested change
for (auto asset : mEntries)
for (const auto& asset : mEntries)

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
std::string path; ///< Path of the asset.
std::string mPath; ///< Path of the asset.

asset.mId = mId;
asset.mRefCount = mRefCount;
asset.mVersion = mVersion;
asset.path = path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
asset.path = path;
asset.mPath = mPath;

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
std::string path; ///< Path of the asset.
std::string mPath; ///< Path of the asset.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (2/2)

asset.mId = mId;
asset.mRefCount = mRefCount;
asset.mVersion = mVersion;
asset.path = path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
asset.path = path;
asset.path = mPath;

if (str.find('/') != std::string::npos || str.find('\\') != std::string::npos)
{
idOrPath = str;
path = str;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
path = str;
mPath = str;

, mId(other.mId)
, mRefCount(other.mRefCount)
, mVersion(other.mVersion)
, path(other.path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
, path(other.path)
, mPath(other.mPath)

, mId(other.mId)
, mRefCount(other.mRefCount)
, mVersion(other.mVersion)
, path(other.path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
, path(other.path)
, mPath(other.mPath)

mId = other.mId;
mRefCount = other.mRefCount;
mVersion = other.mVersion;
path = other.path;
this->incRef();
return *this;
}

AnyAsset& AnyAsset::operator=(AnyAsset&& other) noexcept
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
AnyAsset& AnyAsset::operator=(AnyAsset&& other) noexcept
mPath = other.mPath;

@@ -96,22 +109,27 @@

int AnyAsset::getVersion() const
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
{
mPath = other.mPath;

}

bool AnyAsset::isStrong() const
{
return reflectedId == mId && mRefCount != nullptr;
return uuids::uuid::from_string(idOrPath) == mId && mRefCount != nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for private member path

Suggested change
return uuids::uuid::from_string(idOrPath) == mId && mRefCount != nullptr;
return mPath;

{
this->incRef();
}

AnyAsset::AnyAsset(AnyAsset&& other) noexcept
: reflectedId(other.reflectedId)
: idOrPath(other.idOrPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ performance-move-constructor-init ⚠️
move constructor initializes class member by calling a copy constructor

Copy link

codecov bot commented Sep 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 84 lines in your changes missing coverage. Please review.

Project coverage is 42.41%. Comparing base (3a4258d) to head (c41711b).
Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
engine/src/assets/assets.cpp 0.00% 52 Missing ⚠️
engine/src/assets/asset.cpp 0.00% 20 Missing ⚠️
engine/src/render/mesh/plugin.cpp 0.00% 9 Missing ⚠️
engine/include/cubos/engine/assets/asset.hpp 0.00% 2 Missing ⚠️
engine/src/scene/bridge.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1337      +/-   ##
==========================================
+ Coverage   36.18%   42.41%   +6.23%     
==========================================
  Files         402      409       +7     
  Lines       32096    29284    -2812     
==========================================
+ Hits        11614    12421     +807     
+ Misses      20482    16863    -3619     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GalaxyCrush GalaxyCrush deleted the 1177-allow-identifying-assets-in-code-from-their-path branch September 29, 2024 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow identifying assets in code from their path
1 participant