Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren>2021-09-23 15:56:45 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-23 16:00:45 +0300
commit9b12b23d0bace4056ed14ff3e3e8415eb4ff75af (patch)
treeca6568dc8a705ed12776217d61b94616df712cf3 /source/blender/blenlib/intern/uuid.cc
parent222fd1abf09ae65b7082f58bf2ac43422c77162c (diff)
Assets: add Asset Catalog system
Catalogs work like directories on disk (without hard-/symlinks), in that an asset is only contained in one catalog. See T90066 for design considerations. #### Known Limitations Only a single catalog definition file (CDF), is supported, at `${ASSET_LIBRARY_ROOT}/blender_assets.cats.txt`. In the future this is to be expanded to support arbitrary CDFs (like one per blend file, one per subdirectory, etc.). The current implementation is based on the asset browser, which in practice means that the asset browser owns the `AssetCatalogService` instance for the selected asset library. In the future these instances will be accessible via a less UI-bound asset system. The UI is still very rudimentary, only showing the catalog ID for the currently selected asset. Most notably, the loaded catalogs are not shown yet. The UI is being implemented and will be merged soon. #### Catalog Identifiers Catalogs are internally identified by UUID. In older designs this was a human-readable name, which has the problem that it has to be kept in sync with its semantics (so when renaming a catalog from X to Y, the UUID can be kept the same). Since UUIDs don't communicate any human-readable information, the mapping from catalog UUID to its path (stored in the Catalog Definition File, CDF) is critical for understanding which asset is stored in which human-readable catalog. To make this less critical, and to allow manual data reconstruction after a CDF is lost/corrupted, each catalog also has a "simple name" that's stored along with the UUID. This is also stored on each asset, next to the catalog UUID. #### Writing to Disk Before saving asset catalogs to disk, the to-be-overwritten file gets inspected. Any new catalogs that are found thre are loaded to memory before writing the catalogs back to disk: - Changed catalog path: in-memory data wins - Catalogs deleted on disk: they are recreated based on in-memory data - Catalogs deleted in memory: deleted on disk as well - New catalogs on disk: are loaded and thus survive the overwriting #### Tree Design This implements the initial tree structure to load catalogs into. See T90608, and the basic design in T90066. Reviewed By: Severin Maniphest Tasks: T91552 Differential Revision: https://developer.blender.org/D12589
Diffstat (limited to 'source/blender/blenlib/intern/uuid.cc')
-rw-r--r--source/blender/blenlib/intern/uuid.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc
index ae34bcb3d32..c1f7f8dfecd 100644
--- a/source/blender/blenlib/intern/uuid.cc
+++ b/source/blender/blenlib/intern/uuid.cc
@@ -24,6 +24,7 @@
#include <cstring>
#include <ctime>
#include <random>
+#include <sstream>
#include <string>
/* Ensure the UUID struct doesn't have any padding, to be compatible with memcmp(). */
@@ -137,3 +138,34 @@ std::ostream &operator<<(std::ostream &stream, bUUID uuid)
stream << buffer;
return stream;
}
+
+namespace blender::bke {
+
+bUUID::bUUID(const std::string &string_formatted_uuid)
+{
+ const bool parsed_ok = BLI_uuid_parse_string(this, string_formatted_uuid.c_str());
+ if (!parsed_ok) {
+ std::stringstream ss;
+ ss << "invalid UUID string " << string_formatted_uuid;
+ throw std::runtime_error(ss.str());
+ }
+}
+
+bUUID::bUUID(const ::bUUID &struct_uuid)
+{
+ *(static_cast<::bUUID *>(this)) = struct_uuid;
+}
+
+uint64_t bUUID::hash() const
+{
+ /* Convert the struct into two 64-bit numbers, and XOR them to get the hash. */
+ const uint64_t *uuid_as_int64 = reinterpret_cast<const uint64_t *>(this);
+ return uuid_as_int64[0] ^ uuid_as_int64[1];
+}
+
+bool operator==(bUUID uuid1, bUUID uuid2)
+{
+ return BLI_uuid_equal(uuid1, uuid2);
+}
+
+} // namespace blender::bke