me-main #1

Merged
Nate Rupsis merged 123 commits from me-main into main 2023-02-13 18:39:11 +01:00
5 changed files with 44 additions and 15 deletions
Showing only changes of commit 99e71ec1f2 - Show all commits

View File

@ -23,11 +23,15 @@ struct ID;
namespace blender::asset_system { namespace blender::asset_system {
class AssetLibrary;
class AssetRepresentation { class AssetRepresentation {
AssetIdentifier identifier_; AssetIdentifier identifier_;
/** Indicate if this is a local or external asset, and as such, which of the union members below /** Indicate if this is a local or external asset, and as such, which of the union members below
* should be used. */ * should be used. */
const bool is_local_id_ = false; const bool is_local_id_ = false;
/** Asset library that owns this asset representation. */
const AssetLibrary *owner_asset_library_;
struct ExternalAsset { struct ExternalAsset {
std::string name; std::string name;
@ -44,10 +48,13 @@ class AssetRepresentation {
/** Constructs an asset representation for an external ID. The asset will not be editable. */ /** Constructs an asset representation for an external ID. The asset will not be editable. */
AssetRepresentation(AssetIdentifier &&identifier, AssetRepresentation(AssetIdentifier &&identifier,
StringRef name, StringRef name,
std::unique_ptr<AssetMetaData> metadata); std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library);
/** Constructs an asset representation for an ID stored in the current file. This makes the asset /** Constructs an asset representation for an ID stored in the current file. This makes the asset
* local and fully editable. */ * local and fully editable. */
AssetRepresentation(AssetIdentifier &&identifier, ID &id); AssetRepresentation(AssetIdentifier &&identifier,
ID &id,
const AssetLibrary &owner_asset_library);
AssetRepresentation(AssetRepresentation &&other); AssetRepresentation(AssetRepresentation &&other);
/* Non-copyable type. */ /* Non-copyable type. */
AssetRepresentation(const AssetRepresentation &other) = delete; AssetRepresentation(const AssetRepresentation &other) = delete;
@ -65,6 +72,7 @@ class AssetRepresentation {
AssetMetaData &get_metadata() const; AssetMetaData &get_metadata() const;
/** Returns if this asset is stored inside this current file, and as such fully editable. */ /** Returns if this asset is stored inside this current file, and as such fully editable. */
bool is_local_id() const; bool is_local_id() const;
const AssetLibrary &owner_asset_library() const;
}; };
} // namespace blender::asset_system } // namespace blender::asset_system

View File

@ -169,13 +169,14 @@ AssetRepresentation &AssetLibrary::add_external_asset(StringRef relative_asset_p
std::unique_ptr<AssetMetaData> metadata) std::unique_ptr<AssetMetaData> metadata)
{ {
AssetIdentifier identifier = asset_identifier_from_library(relative_asset_path); AssetIdentifier identifier = asset_identifier_from_library(relative_asset_path);
return asset_storage_->add_external_asset(std::move(identifier), name, std::move(metadata)); return asset_storage_->add_external_asset(
std::move(identifier), name, std::move(metadata), *this);
} }
AssetRepresentation &AssetLibrary::add_local_id_asset(StringRef relative_asset_path, ID &id) AssetRepresentation &AssetLibrary::add_local_id_asset(StringRef relative_asset_path, ID &id)
{ {
AssetIdentifier identifier = asset_identifier_from_library(relative_asset_path); AssetIdentifier identifier = asset_identifier_from_library(relative_asset_path);
return asset_storage_->add_local_id_asset(std::move(identifier), id); return asset_storage_->add_local_id_asset(std::move(identifier), id, *this);
} }
bool AssetLibrary::remove_asset(AssetRepresentation &asset) bool AssetLibrary::remove_asset(AssetRepresentation &asset)

View File

@ -17,15 +17,24 @@ namespace blender::asset_system {
AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier, AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier,
StringRef name, StringRef name,
std::unique_ptr<AssetMetaData> metadata) std::unique_ptr<AssetMetaData> metadata,
: identifier_(identifier), is_local_id_(false), external_asset_() const AssetLibrary &owner_asset_library)
: identifier_(identifier),
is_local_id_(false),
owner_asset_library_(&owner_asset_library),
external_asset_()
{ {
external_asset_.name = name; external_asset_.name = name;
external_asset_.metadata_ = std::move(metadata); external_asset_.metadata_ = std::move(metadata);
} }
AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier, ID &id) AssetRepresentation::AssetRepresentation(AssetIdentifier &&identifier,
: identifier_(identifier), is_local_id_(true), local_asset_id_(&id) ID &id,
const AssetLibrary &owner_asset_library)
: identifier_(identifier),
is_local_id_(true),
owner_asset_library_(&owner_asset_library),
local_asset_id_(&id)
{ {
if (!id.asset_data) { if (!id.asset_data) {
throw std::invalid_argument("Passed ID is not an asset"); throw std::invalid_argument("Passed ID is not an asset");
@ -75,6 +84,11 @@ bool AssetRepresentation::is_local_id() const
return is_local_id_; return is_local_id_;
} }
const AssetLibrary &AssetRepresentation::owner_asset_library() const
{
return *owner_asset_library_;
}
} // namespace blender::asset_system } // namespace blender::asset_system
using namespace blender; using namespace blender;

View File

@ -15,18 +15,21 @@
namespace blender::asset_system { namespace blender::asset_system {
AssetRepresentation &AssetStorage::add_local_id_asset(AssetIdentifier &&identifier, ID &id) AssetRepresentation &AssetStorage::add_local_id_asset(AssetIdentifier &&identifier,
ID &id,
const AssetLibrary &owner_asset_library)
{ {
return *local_id_assets_.lookup_key_or_add( return *local_id_assets_.lookup_key_or_add(
std::make_unique<AssetRepresentation>(std::move(identifier), id)); std::make_unique<AssetRepresentation>(std::move(identifier), id, owner_asset_library));
} }
AssetRepresentation &AssetStorage::add_external_asset(AssetIdentifier &&identifier, AssetRepresentation &AssetStorage::add_external_asset(AssetIdentifier &&identifier,
StringRef name, StringRef name,
std::unique_ptr<AssetMetaData> metadata) std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library)
{ {
return *external_assets_.lookup_key_or_add( return *external_assets_.lookup_key_or_add(std::make_unique<AssetRepresentation>(
std::make_unique<AssetRepresentation>(std::move(identifier), name, std::move(metadata))); std::move(identifier), name, std::move(metadata), owner_asset_library));
} }
bool AssetStorage::remove_asset(AssetRepresentation &asset) bool AssetStorage::remove_asset(AssetRepresentation &asset)

View File

@ -35,9 +35,12 @@ class AssetStorage {
/** See #AssetLibrary::add_external_asset(). */ /** See #AssetLibrary::add_external_asset(). */
AssetRepresentation &add_external_asset(AssetIdentifier &&identifier, AssetRepresentation &add_external_asset(AssetIdentifier &&identifier,
StringRef name, StringRef name,
std::unique_ptr<AssetMetaData> metadata); std::unique_ptr<AssetMetaData> metadata,
const AssetLibrary &owner_asset_library);
/** See #AssetLibrary::add_external_asset(). */ /** See #AssetLibrary::add_external_asset(). */
AssetRepresentation &add_local_id_asset(AssetIdentifier &&identifier, ID &id); AssetRepresentation &add_local_id_asset(AssetIdentifier &&identifier,
ID &id,
const AssetLibrary &owner_asset_library);
/** See #AssetLibrary::remove_asset(). */ /** See #AssetLibrary::remove_asset(). */
bool remove_asset(AssetRepresentation &asset); bool remove_asset(AssetRepresentation &asset);